Sunday, March 13, 2016

19. Triads of C major scale

The pitches lists holds the notes in C-major scale (octaves 4 and 5).


In the 7-length chord list, we put the root note as one of the first seven, next 2 above, and last, 4 above.


Then, in the for loop, we go over the chord list. n1, n2, n3 will get the midi values for the notes. By n2 - n1, we find semitones from 1st to 2nd note. By n3 - n1, we find semitone interval from 1st to 3rd note.


Using if and elif, we find the name of interval of n2 - n1 and n3 - n1.


The chords, with major 3 interval, for n2 - n1, chord 1 (I, Tonic), chord 4 (IV, Subdominant), chord 5 (V, Dominant).


# mus19.py
# Triads of C major

import music21 as m21
from writeMIDI import writeMIDI

notes = []

pitches = ['C4','D4','E4','F4','G4','A4','B4',
           'C5','D5','E5','F5','G5','A5','B5']

chord = 7*[None]
for i in range(7):
    chord[i] = pitches[i],pitches[i+2],pitches[i+4]

for i,c in enumerate(chord):
    print('\nChord {}: {}'.format(i+1,c))
    n1 = m21.note.Note(c[0]).pitch.midi
    n2 = m21.note.Note(c[1]).pitch.midi
    n3 = m21.note.Note(c[2]).pitch.midi
    print('n2-n1 = ',n2-n1, end = ' ')
    if n2 - n1 == 3: print('\tminor third')
    elif n2 - n1 == 4: print('\tmajor third')
    print('n3-n1 = ',n3-n1, end = '')
    if n3 - n1 == 7: print('\tperfect fifth')
    elif n3 - n1 == 6: print('\tdiminished fifth')
    notes.append((c[0],2*i,1,120))
    notes.append((c[1],2*i,1,120))
    notes.append((c[2],2*i,1,120))
    
writeMIDI('C','piano',120,notes,'mus19')

This is the printout:

Chord 1: ('C4', 'E4', 'G4')
n2-n1 =  4  major third
n3-n1 =  7 perfect fifth

Chord 2: ('D4', 'F4', 'A4')
n2-n1 =  3  minor third
n3-n1 =  7 perfect fifth

Chord 3: ('E4', 'G4', 'B4')
n2-n1 =  3  minor third
n3-n1 =  7 perfect fifth

Chord 4: ('F4', 'A4', 'C5')
n2-n1 =  4  major third
n3-n1 =  7 perfect fifth

Chord 5: ('G4', 'B4', 'D5')
n2-n1 =  4  major third
n3-n1 =  7 perfect fifth

Chord 6: ('A4', 'C5', 'E5')
n2-n1 =  3  minor third
n3-n1 =  7 perfect fifth

Chord 7: ('B4', 'D5', 'F5')
n2-n1 =  3  minor third
n3-n1 =  6 diminished fifth

This will generate this:


No comments:

Post a Comment