Ejemplo n.º 1
0
 def make_notes(self, sym):
     sym = sym.strip()
     if sym in MAKE_NOTE_EXCEPTIONS:
         # look up in dictionary
         letter = self.rn2letter(sym)
         print 'due to roman not giving right pitches', sym, letter
         sym = letter
     chord_sym = sym2chord(sym)
     midi = []
     if chord_sym is not None:
         midi = [pch.midi for pch in chord_sym.pitches]
         # take away duplicates
         midi = list(set(midi))
         midi = sorted(midi)
         # double the tonic on top
         if sym in ['I', 'I7', 'i']:
             doubled_note = midi[0]
             midi.append(doubled_note+12)
             print 'doubled tonic on top', midi
         elif len(midi) > 4 and '11' in sym:
             # 11th creates half step with 3rd if major (not checking if major here)
             # shift 11th up an octave to make
             print midi
             # 1,3,11,5,7,9
             reduced_midi = midi[:2] + [midi[3]] + [midi[2]+12]
             midi = reduced_midi
         elif len(midi) > 4:
             reduced_midi = midi[:3] + [midi[-1]]
             midi = reduced_midi
     return midi
 def gen_continuation(self, seq, n,
                      m=1, return_chord=False):
     seq_cont = copy(seq)
     for i in range(n):
         seq_cont.append(self.sample_next(seq_cont, m=m))
     if not return_chord:
         return seq_cont
     else:
         return [sym2chord(sym) for sym in seq_cont]
 def gen_seq(self, n, return_chord=False):
     # returns chords not sym labels
     seq = [self.sample_start()]
     for i in range(1, n):
         seq.append(self.sample_next(seq))
     if not return_chord:
         return seq
     else:
         return [sym2chord(sym) for sym in seq]
 def sample_next(self, seq, m=1, return_chord=False):
     # m here is for length of context
     assert m == 1
     seq_len = len(seq)
     if seq_len == 0:
         ind = self.sample_multinomial(self.start_probs)
     elif seq_len < m:
         assert False, 'ERROR: Not yet implemented'
     else:
         ind = self.get_idx(seq[-m])
     sym = self.sample_multinomial(self.ngram[ind, :])
     if not return_chord:
         return sym
     else:
         return sym2chord(sym)
 def sample_start(self, return_chord=False):
     sym = self.sample_multinomial(self.start_probs)
     if not return_chord:
         return sym
     else:
         return sym2chord(sym)