Saturday, February 20, 2016

4. Chords

Chords are composed of multiple notes harmonizing at same time.


Here lists are built up so chords will contain more intervals.


For example, for the dyad, the interval is 7 semitones.


The printouts will show the six created lists.


In the measure function, we iterate over all notes in a list and add a note for 3 of the 4 beats at the 6 different measures.


# mus4.py
# Chords

import music21 as m21
from writeMIDI import writeMIDI

# beats per minute
bpm = 130

notes = []

# dyad
m1 = ['C3','G3']
# triad
m2 = m1 + ['E4']
# tetrad
m3 = m2 + ['B3']
# pentad
m4 = m3 + ['F#4']
# hexad
m5 = m4 + ['A4']
# heptad
m6 = m5 + ['D5']

# lists
print('m1 =',m1)
print('m2 =',m2)
print('m3 =',m3)
print('m4 =',m4)
print('m5 =',m5)
print('m6 =',m6)

def measure(meas,m):
    for n in m:
        notes.append((n,4*meas,3,115))
        
measure(0,m1)
measure(1,m2)
measure(2,m3)
measure(3,m4)
measure(4,m5)
measure(5,m6)

key = 'C'
writeMIDI(key,"piano",bpm,notes,'mus4')

PrintOut:


m1 = ['C3', 'G3']
m2 = ['C3', 'G3', 'E4']
m3 = ['C3', 'G3', 'E4', 'B3']
m4 = ['C3', 'G3', 'E4', 'B3', 'F#4']
m5 = ['C3', 'G3', 'E4', 'B3', 'F#4', 'A4']
m6 = ['C3', 'G3', 'E4', 'B3', 'F#4', 'A4', 'D5']

This will generate this for mus4.mid:



Or piano roll: (The only view given from now on):


No comments:

Post a Comment