INNER CODE UNIT · Python
__generate_scale_tone
jisungk/deepjazz · grammar.py:59
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.
sNoteName = random.choice(allNoteNames)
lastChordSort = lastChord.sortAscending()
sNoteOctave = random.choice([i.octave for i in lastChordSort.pitches])
sNote = note.Note(("%s%s" % (sNoteName, sNoteOctave)))
return sNote