Exemple #1
0
 def addPause(self, note):
     firstNote = self.__notes[0]
     n = Note("A")
     n.octave = firstNote.octave
     n.volume = 0
     n.dur = firstNote.dur
     self.__notes.append(note)
Exemple #2
0
    def symbol2Note(self, symbol):
        if (symbol.name.islower()):
            n = Note(symbol.name.upper() + '#')
        else:
            n = Note(symbol.name)
        n.octave = self.getOctave()
        n.volume = self.getVolume()
        # 60 bpm faz uma batida por segundo, e uma batida é uma semínima (0.25)
        n.dur = (60 / self.getBeat()) / 4

        return n
notes = []
for t in range(len(g)):
    chord = {}
    vol_orig = g[t].mean()
    while g[t].mean() > 0:
        note_probs = np.dot(notes_start, g[t])
        i = note_probs.argmax()
        best_match = (g[t] * notes_start[i]).argmax()
        vol = float(g[t][best_match]) / notes_start[i][best_match]
        if vol < 1e-2: break  #if int(100*vol)
        if vol * g[t].mean() / vol_orig > 0.2:
            chord[i] = chord.get(i, 0) + vol
        #print i,vol
        g[t] -= (vol * notes_start[i]).astype(int)

    for i in chord:
        if active.get(i) and chord[i] > active[i].volume:
            notes.append(active[i])

        if active.get(i) and chord[i] < active[i].volume:
            active[i].dur += 0.25

        else:
            active[i] = Note(classes[i])
            active[i].time = t
            active[i].volume = 70  #max(int(min(100*chord[i], 100)),10)
    for i in set(active) - set(chord):  # + those new
        notes.append(active[i])
        del active[i]

test_output(notes)
notes = []
for t in range(len(g)):
  chord = {}
  vol_orig = g[t].mean()
  while g[t].mean() > 0:
    note_probs = np.dot(notes_start, g[t])
    i = note_probs.argmax()
    best_match = (g[t]*notes_start[i]).argmax()
    vol = float(g[t][best_match]) / notes_start[i][best_match]
    if vol < 1e-2: break #if int(100*vol)
    if vol * g[t].mean() / vol_orig > 0.2:
      chord[i] = chord.get(i,0) + vol
    #print i,vol
    g[t] -= (vol*notes_start[i]).astype(int)
  
  for i in chord:
    if active.get(i) and chord[i] > active[i].volume:
      notes.append(active[i])
        
    if active.get(i) and chord[i] < active[i].volume:
      active[i].dur += 0.25
    
    else:
      active[i] = Note(classes[i])
      active[i].time = t
      active[i].volume = 70#max(int(min(100*chord[i], 100)),10)
  for i in set(active) - set(chord): # + those new
    notes.append(active[i])
    del active[i]    

test_output(notes)