def get_harmonies(path): s = converter.parse(path) cc = s.chordify() harmonies = [] for c in cc.flat.getElementsByClass(Chord): harmonies.append(chordSymbolFigureFromChord(c)) return harmonies
def add_piano_closing(roman, duration, piano, show_symbols=False): '''Generate a closing riff and add it to the keyboard part''' symbol = ChordSymbol(chordSymbolFigureFromChord(roman)) if show_symbols: print symbol piano.append(symbol) # Leadsheet chord symbol filled = 0 length_weight = 2 # Longer notes later in the bar root = roman.root() # Root pitch of the chord (NOT a note object) while filled < duration: # TODO DRY with other piano func chord = Chord(deepcopy(roman.pitches)) # invert chord randomly, root inversion twice as likely as others max_inv=len(chord.pitches) chord.inversion(random.randint(0,max_inv)%max_inv) # Add an extra root note 1 octave lower root = deepcopy(chord.root()) root.octave -= 1 chord.add(root) # TODO above same procedure as main riff func, but we should # make more fancy # Rhythm similar to bass method below length = min(random.randint(1,length_weight),duration-filled) # cap at time left chord.quarterLength = length/2.0 piano.append(chord) filled += length length_weight += length # Longer notes later in the bar
def writeChordSequenceToFile(self, outfile): chords = [] for part in self.getParts(): # type: Part chords = part.recurse().getElementsByClass(ChordSymbol) outfile.write(', '.join([ str(harmony.chordSymbolFigureFromChord(elt)) + "@" + str(elt.getOffsetInHierarchy(part)) for elt in chords ]))
def roman2letter(sym): # print 'roman2letter', sym chord_sym = sym2roman(sym) if chord_sym is None: # return sym, False return None ch = chord.Chord(chord_sym.pitches) lettername, ch_type = harmony.chordSymbolFigureFromChord(ch, True) # print lettername, ch_type return lettername
def printChordSequenceForFile(self): chords = [] for part in self.getParts(): # type: Part chords = part.recurse().getElementsByClass(ChordSymbol) for elt in chords: # type: ChordSymbol start = elt.getOffsetInHierarchy(part) print(str(harmony.chordSymbolFigureFromChord(elt)) + "@" + str(start), end=', ') if len(chords) > 0: print()
def roman2letter_transpose(sym, transpose=0, translation_dict={}, return_dict=False): # print 'roman2letter', sym if sym in ROMAN_RELABELS.keys(): sym = ROMAN_RELABELS[sym] key = tokenize_transpose(sym, transpose) if key in translation_dict: return translation_dict[key] rn = roman.RomanNumeral(sym) rn.transpose(transpose, inPlace=True) pitches = rn.pitches # pitches = [pch.midi+transpose for pch in rn.pitches] ch = chord.Chord(pitches) # print ch # ch = sym2chord(sym, transpose=transpose) if ch is None: # return sym, False return None lettername, ch_type = harmony.chordSymbolFigureFromChord(ch, True) # somehow music21 is not able to cope with ## ch = roman2letter_transpose('V', transpose=-1) # if lettername == 'Chord Symbol Cannot Be Identified': # rn.transpose(transpose, inPlace=True) # ch = chord.Chord(rn.pitches) # lettername, ch_type = harmony.chordSymbolFigureFromChord(ch, True) # from resource.py for co_replacements in LETTER_PARTIAL_CO_RELABELS: all_in = True for replacements in co_replacements: if replacements[0] not in lettername: all_in = False if all_in: for replacements in co_replacements: lettername = lettername.replace(replacements[0], replacements[1]) for k, v in LETTER_PARTIAL_RELABELS_FOR_USER.iteritems(): if k in lettername: lettername = lettername.replace(k, v) translation_dict[key] = lettername # print lettername#, ch_type if return_dict: return lettername, translation_dict return lettername
def add_piano_riff(roman, duration, piano, show_symbols=False): '''Given a Roman chord, duration in eighths/quavers and a keyboard part, generate a riff and add it to the keyboard part''' # Add a chord symbol at the start symbol = ChordSymbol(chordSymbolFigureFromChord(roman)) if show_symbols: print symbol piano.append(symbol) # Add the actual notes filled = 0 while filled < duration: # NOTE: higher chance to rest if on beat = more syncopated rhythm to piano if random.randint(0, 1 + filled%2 + filled%4): # XXX: Must deepcopy, do not change original or it will break bassline chord = Chord(deepcopy(roman.pitches)) # invert chord randomly, root inversion twice as likely as others max_inv=len(chord.pitches) chord.inversion(random.randint(0,max_inv)%max_inv) # TODO try randomly ommitting some chord notes # Randomly hold notes for longer if we have longer before # the next chord change max_length = min(duration-filled, 4) # Cap at 1/2 bar length = random.randint(1,max_length) chord.quarterLength = length/2.0 # length is in eighths # Add an extra root note 1 octave lower root = deepcopy(chord.root()) root.octave -= 1 chord.add(root) # Add the chord at soft volume and update duration chord.volume = Volume(velocity=16,velocityIsRelative=False) piano.append(chord) filled += length else: piano.append(Rest(quarterLength=0.5)) filled += 1
# print(m) seq_acordes = [ u"D°", "Abm", "D5", "A7(11+)", "Am(11+)", "D7/9", "Am6", "Em6", "Am7", "Am6", "Am7", "D7/9b"] acorde = 'Dbm7' # acorde21 = obter_acorde21_desenho_listanotas_idxnotas(acorde); # print(acorde21) acorde, desenho_acorde_str, lista_idx_notas, lista_notas, flag_sucesso, msg = obter_acorde21_desenho_listanotas_idxnotas( 'E7(#9)') acorde_str, modo = harmony.chordSymbolFigureFromChord(acorde, True) acorde.quality acorde.pitchedCommonName
pitches = ChromaticScale().getPitches('C', 'B') # Loop over all possible roots for add1 in range(13): for kind in harmony.CHORD_TYPES.keys(): for root in pitches: ref = harmony.ChordSymbol(root=root, kind=kind) basses = [None] + list(ref.pitches)[1:] inversions = [] for bass in basses: bass = bass.name if bass else None chord = harmony.ChordSymbol(root=root, kind=kind, bass=bass) if add1 > 0: chord.add(add1 - 1) key = chordSymbolIndex(chord) try: name = harmony.chordSymbolFigureFromChord(chord) except: continue if name == 'Chord Symbol Cannot Be Identified': continue if key not in chords: inversions.append(key) names, _ = chords.setdefault(key, [[], None]) if name in names: continue names.append(name) for key in inversions: chords[key][1] = inversions # Save in file with open('maps.py', 'w') as file: