Friday, February 19, 2016

2. Midi Numbers

Each note is composed of 4 values which were listed last time.


The first could be a string corresponding to note number, such as 'C4'.


However, it could also be a midi number, such as 60 for 'C4'. (60 is 'C4', 61 is 'C#4', ... 72 is 'C5', ...)


Here we use midi numbers to generate same output as first program. It should be noted that we have to know the whole step, half step sequence in the Major Scale.


# mus2.py
# C major scale

from writeMIDI import writeMIDI

# beats per minute
bpm = 130

major = [2,2,1,2,2,2,1]

notes = []

midi = 60
for i in range(8):
    notes.append((midi,i,1,120))
    midi += major[i%7]

writeMIDI("piano",bpm,notes,'mus2')

This will generate this:


No comments:

Post a Comment