Sunday, February 28, 2016

13. Minor Scales

The 12 notes within each octave is represented in the Python list called keys.


We use the semitone intervals of a minor scale, inside the minor list. The minor list contains the last two elements of major plus the first five elements. In Python we can use negative numbers to indicate index from last element.


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


We can see A (natural) minor scale has same notes as C major (its relative). The only difference is the root is A or C in the two cases.


# mus13.py
# minor scales

import music21 as m21

major = [2,2,1,2,2,2,1]
# minor = last 2 + first 5 (of major)
minor = major[-2:]+major[:5]
print('minor = ',minor)

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

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

This will generate this output:


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

No comments:

Post a Comment