Wednesday, March 2, 2016

15. Melodic minor scales

The 12 notes within each octave is represented in the Python list called keys, as in the last example.


We list the semitone intervals of a minor scale, inside the minor list. We copy it to melodic_minor list and then change two of the values.


Inside the main loop, iterated over all keys, we use i%7 (i modulo 7) as index into melodic_minor so we only access indexes 0 through 6.


Also we print a new line only if i is 7. The default end, for a print statement, is new line, unless we override it.


# mus15.py
# melodic minor scales

import music21 as m21

minor = [2,1,2,2,1,2,2]
melodic_minor = minor[:]
melodic_minor[-3] += 1
melodic_minor[-1] -= 1
print('melodic minor = ',melodic_minor)

keys = ['C','C#','D','D#',
        'E','F','F#','G',
        'G#','A','A#','B']

print('The 12 melodic minor scales:')
for key in keys:
    n = m21.note.Note(key)
    midi = n.pitch.midi
    for i in range(8):
        n = m21.note.Note(midi = midi)
        if i<7: print(n.name, end= ' - ')
        else: print(n.name)
        midi = n.pitch.midi
        midi += melodic_minor[i%7]

This will generate this output:


melodic minor =  [2, 1, 2, 2, 2, 2, 1]
The 12 melodic minor scales:
C - D - E- - F - G - A - B - C
C# - E- - E - F# - G# - B- - C - C#
D - E - F - G - A - B - C# - D
E- - F - F# - G# - B- - C - D - E-
E - F# - G - A - B - C# - E- - E
F - G - G# - B- - C - D - E - F
F# - G# - A - B - C# - E- - F - F#
G - A - B- - C - D - E - F# - G
G# - B- - B - C# - E- - F - G - G#
A - B - C - D - E - F# - G# - A
B- - C - C# - E- - F - G - A - B-
B - C# - D - E - F# - G# - B- - B

No comments:

Post a Comment