A Python dictionary is unordered. It is possible to use an OrderedDict from the standard collections module.
For the 7 modes (given in the order), with roots of C through B, we only get white keys. For 'C' root, we have major (Ionian), and for 'A' we have minor (Dorian).
In the printouts, we can see that the scale is shifted left, for the next mode, and a value an octave above is the new value, replacing the rightmost note (a left rotate operation for the semitone intervals).
The MIDI has 7 scales, with each scale taking 2 measures, with a total length of 14 measures or 14 bars.
# mus17.py
# Modes
import music21 as m21
from writeMIDI import writeMIDI
from collections import OrderedDict
SCALE = OrderedDict()
SCALE['Ionian'] = [2,2,1,2,2,2,1] # major
SCALE['Dorian'] = [2,1,2,2,2,1,2]
SCALE['Phrygian'] = [1,2,2,2,1,2,2]
SCALE['Lydian'] = [2,2,2,1,2,2,1]
SCALE['Mixolydian'] = [2,2,1,2,2,1,2]
SCALE['Aeolian'] = [2,1,2,2,1,2,2] # minor
SCALE['Locrian'] = [1,2,2,1,2,2,2]
start = 0
notes = []
def scale(root, n, kind):
global start
start += 8
print('\nroot = {} \tkind = {}'.format(root,kind))
p = m21.pitch.Pitch(root)
midi = p.midi
for i in range(8):
if i<7: print('{},'.format(midi),end=' ')
else: print('{}'.format(midi))
n.append((midi,start+i,1,120))
midi += SCALE[kind][i%7]
keys = 'CDEFGAB'
lett = 0
for kind in SCALE:
scale(keys[lett],notes,kind)
lett += 1
writeMIDI('C','piano',130,notes,'mus17')
This is the printout:
root = C kind = Ionian
60, 62, 64, 65, 67, 69, 71, 72
root = D kind = Dorian
62, 64, 65, 67, 69, 71, 72, 74
root = E kind = Phrygian
64, 65, 67, 69, 71, 72, 74, 76
root = F kind = Lydian
65, 67, 69, 71, 72, 74, 76, 77
root = G kind = Mixolydian
67, 69, 71, 72, 74, 76, 77, 79
root = A kind = Aeolian
69, 71, 72, 74, 76, 77, 79, 81
root = B kind = Locrian
71, 72, 74, 76, 77, 79, 81, 83
This will generate this MIDI:
No comments:
Post a Comment