Tuesday, February 23, 2016

8. Consonant to Dissonant Intervals

There is a list, interval, of 13 elements. While it is possible to write it all on one line, sometimes it is better to write on multiple lines.


The function, base, adds 13 'C4' quarter notes at beat 0, 2, 4, and so on. The 'C4' is midi number 60.


The function, consonant_to_dissonant, will add intervals such that midi number is 60 + appropriate interval. Again in this function, we use commas to separate lines.


# mus8.py
# consonant to dissonant intervals

from writeMIDI import writeMIDI

# beats per minute
bpm = 130

notes = []
midi = 60

# consonant to dissonant (semitones)
interval = [0, # Unison/prime
            12, # Octave
            7, # Perfect fifth
            5, # Perfect fourth
            4, # Major third
            8, # Minor sixth
            3, # Minor third
            9, # Major sixth
            2, # Major second
            10, # Minor seventh
            1, # Minor second
            11, # Major seventh
            6] # Augmented fourth/diminished fifth

def base(n):
    "Add 13 C4 quarter notes"
    for i in range(13):
        n.append((midi,2*i,1,120))
        
def consonant_to_dissonant(n):
    "Intervals from consonant to dissonant"
    for i in range(13):
        n.append((midi+interval[i], # Note midi number
                  2*i,              # Start in quarter lengths
                  1,                # Duration is 1 quarter note
                  120))             # Volume is 120

base(notes)
consonant_to_dissonant(notes)
writeMIDI('C','piano',bpm,notes,'mus8')

This will generate this:


No comments:

Post a Comment