Sunday, February 28, 2016

14. Harmonic 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 harmonic_minor list and then set the last two values, either raise or decrease by a semitone.


Inside the main loop, iterated over all keys, we use i%7 (i modulo 7) as index into harmonic_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.


# mus14.py
# harmonic minor scales

import music21 as m21

minor = [2,1,2,2,1,2,2]
harmonic_minor = minor[:]
harmonic_minor[-2] += 1
harmonic_minor[-1] -= 1
print('harmonic minor = ',harmonic_minor)

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

print('The 12 harmonic 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 += harmonic_minor[i%7]

This will generate this output:


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

No comments:

Post a Comment