INNER CODE UNIT · Python
__generate_chord_tone
jisungk/deepjazz · grammar.py:54
def __generate_chord_tone(lastChord):
lastChordNoteNames = [p.nameWithOctave for p in lastChord.pitches]
return note.Note(random.choice(lastChordNoteNames))
''' Helper function to generate a scale tone. '''
def __generate_scale_tone(lastChord):
# Derive major or minor scales (minor if 'other') based on the quality
# of the lastChord.
scaleType = scale.WeightedHexatonicBlues() # minor pentatonic
if lastChord.quality == 'major':
scaleType = scale.MajorScale()
# Can change later to deriveAll() for flexibility. If so then use list
# comprehension of form [x for a in b for x in a].
scales = scaleType.derive(lastChord) # use deriveAll() later for flexibility
allPitches = list(set([pitch for pitch in scales.getPitches()]))
allNoteNames = [i.name for i in allPitches] # octaves don't matter
# Return a note (no octave here) in a scale that matches the lastChord.