Transcribing Music

The following code samples demonstrate how to transcribe music via jythonMusic.


Ludwig van Beethoven – “Für Elise”

This code sample (Ch. 3, p. 56) demonstrates how to create phrases and add notes to them.  It generates the theme from one of the most popular classical pieces, Ludwig van Beethoven’s Bagatelle No. 25 in A minor for solo piano, commonly known as “Für Elise” (for Elise).

# furElise.py
# Generates the theme from Beethoven's Fur Elise.

from music import *

# theme has some repetition, so break it up to maximize economy
# (also notice how we line up corresponding pitches and durations)
pitches1   = [E5, DS5, E5, DS5, E5, B4, D5, C5]
durations1 = [SN, SN,  SN, SN,  SN, SN, SN, SN]
pitches2   = [A4, REST, C4, E4, A4, B4, REST, E4]
durations2 = [EN, SN,   SN, SN, SN, EN, SN,   SN]

pitches3 = [GS4, B4, C5, REST, E4]
durations3 = [SN,  SN, EN, SN,   SN]
pitches4 = [C5, B4, A4]
durations4 = [SN, SN, EN]

# create an empty phrase, and construct theme from the above motifs
theme = Phrase()   
theme.addNoteList(pitches1, durations1)
theme.addNoteList(pitches2, durations2)
theme.addNoteList(pitches3, durations3)
theme.addNoteList(pitches1, durations1)  # again
theme.addNoteList(pitches2, durations2)
theme.addNoteList(pitches4, durations4)

# play it
Play.midi(theme)

Harold Faltermeyer – “Axel F”

This code sample (Ch. 3, p. 63) demonstrates how to set the instrument and tempo of a phrase.  It creates  Harold Faltermeyer’s electronic instrumental theme from the 1984 film Beverly Hills Cop.

# axelF.py
# Generates Harold Faltermeyer's electronic instrumental theme 
# from the film Beverly Hills Cop (1984).

from music import *

# theme (notice how we line up corresponding pitches and rhythms)
pitches1   = [F4, REST, AF4, REST, F4, F4, BF4, F4, EF4]
durations1 = [QN, QN,   QN,  EN,   QN, EN, QN,  QN, QN] 
pitches2   = [F4, REST, C5, REST, F4, F4, DF5, C5, AF4]
durations2 = [QN, QN,   QN, EN,   QN, EN, QN,  QN, QN]
pitches3   = [F4, C5, F5, F4, EF4, EF4, C4, G4, F4]
durations3 = [QN, QN, QN, EN, QN,  EN,  QN, QN, DQN]

# create an empty phrase, and construct theme using pitch/rhythm data
theme = Phrase()   
theme.addNoteList(pitches1, durations1)
theme.addNoteList(pitches2, durations2)
theme.addNoteList(pitches3, durations3)

# set the instrument and tempo for the theme
theme.setInstrument(SYNTH_BASS_2)
theme.setTempo(220)

# play it
Play.midi(theme)

2Pac – “Changes”

This code sample (Ch. 3, p. 68) demonstrates how to use lists to create chord progressions.  It generates the main chord progression from 2Pac’s (Tupac Shakur’s) “Changes” (1998).  It so happens that this is the same chord progression as in Bruce Hornsby’s “The Way It Is” (1986).

# changesByTupac.py
# Plays main chord progression from 2Pac's "Changes" (1998).

from music import *

mPhrase = Phrase()
mPhrase.setTempo(105)

# section 1 - chords to be repeated
pitch1 = [[E4,G4,C5], [E4,G4,C5], [D4,G4,B4], A4, G4, [D4, FS4, A4], 
           [D4, G4, B4], [C4, E4, G4], E4, D4, C4, [G3, B4, D4]]
dur1   = [DEN,        DEN,        HN,         SQ, SQ, DEN,         
           DEN,          DQN,          EN, SN, SN, DQN]


# section 2 - embellishing chords
pitch2 = [A4, B4]
dur2   = [SN, SN] 

mPhrase.addNoteList(pitch1, dur1)  # add section 1 
mPhrase.addNoteList(pitch2, dur2)  # add section 2
mPhrase.addNoteList(pitch1, dur1)  # again, add section 1

Play.midi(mPhrase)

String Quartet – Hayden, Opus 64 no 5

This code sample (Ch. 3, p. 72) demonstrates how to create parts that contain phrases.  It plays four overlapping notes (each in a separate phrase), using a MIDI strings sound.

# stringQuartet.py
# Demonstrates how to create concurrent musical parts.
# Hayden, Opus 64 no 5

from music import *

stringsPart = Part(STRINGS, 0)   # create empty strings part
stringsPart.setTempo(104)

pitches1 =   [A5, REST, A5, REST, A5, REST, A5, A6, E6,  D6, D6, 
               CS6, D6, D6, CS6, D6, E6]
durations1 = [EN, EN,   EN, EN,   EN, EN,   WN, DHN, EN, EN, HN, 
               DEN, SN, DEN, TN, TN, QN]
violin1 = Phrase(0.0)                       # create a phrase
violin1.addNoteList(pitches1, durations1)   # addnotes to the phrase
stringsPart.addPhrase(violin1)              # now, add phrase to part

pitches2 =   [FS4, G4, FS4, E4, D4, REST, G4, A4, G4, FS4, E4]
durations2 = [QN,  QN, QN, QN, QN, DHN,  QN, QN, QN, QN,  QN]
violin2 = Phrase(3.0)                       # create a phrase
violin2.addNoteList(pitches2, durations2)   # addnotes to the phrase
stringsPart.addPhrase(violin2)              # now, add phrase to part

pitches3 =   [D4, E4, D4, A3, FS3, REST, E4, FS4, E4, D4, CS4]
durations3 = [QN, QN, QN, QN, QN,  DHN,  QN, QN,  QN, QN,  QN]
violin3 = Phrase(3.0)                       # create a phrase
violin3.addNoteList(pitches3, durations3)   # addnotes to the phrase
stringsPart.addPhrase(violin3)              # now, add phrase to part

pitches4 =   [D2, FS2, A2, D3, A2, REST, A2]
durations4 = [QN, QN,  QN, QN, QN, DHN,  QN]
violin4 = Phrase(7.0)                       # create a phrase
violin4.addNoteList(pitches4, durations4)   # addnotes to the phrase
stringsPart.addPhrase(violin4)              # now, add phrase to part

Play.midi(stringsPart)

Joseph Kosma – “Autumn Leaves” (Jazz Trio)

This code sample (Ch. 3, p. 77) demonstrates how to create a score containing different parts, each containing a different phrase.  This is a complete example of the Score, Part, Phrase, Note data structure.  It generates the theme from “Autumn Leaves”.

# autumnLeaves.py
# It plays the theme from "Autumn Leaves", in a Jazz trio arrangement
# (using trumpet, vibraphone, and acoustic bass instruments).

from music import *

##### define the data structure (score, parts, and phrases)
autumnLeavesScore = Score("Autumn Leaves (Jazz Trio)", 140) # 140 bpm

trumpetPart = Part(TRUMPET, 0)       # trumpet to MIDI channel 0
vibesPart  = Part(VIBES, 1)          # vibraphone to MIDI channel 1
bassPart    = Part(ACOUSTIC_BASS, 2) # bass to MIDI channel 2

melodyPhrase = Phrase()   # holds the melody
chordPhrase  = Phrase()   # holds the chords
bassPhrase   = Phrase()   # holds the bass line

##### create musical data
# melody
melodyPitch1 = [REST, E4, FS4, G4, C5, REST, D4, E4, FS4, B4,  B4] 
melodyDur1   = [QN,   QN, QN,  QN, WN, EN,   DQN,QN, QN,  DQN, HN+EN]
melodyPitch2 = [REST, C4, D4, E4, A4, REST, B3, A4, G4, E4]
melodyDur2   = [QN,   QN, QN, QN, WN, EN,   DQN,QN, QN, 6.0]

melodyPhrase.addNoteList(melodyPitch1, melodyDur1) # add to phrase
melodyPhrase.addNoteList(melodyPitch2, melodyDur2)

# chords
chordPitches1   = [REST, [E3, G3, A3, C4], [E3, G3, A3, C4], REST, 
                    [FS3, A3, C4]]
chordDurations1 = [WN,    HN,               QN,              QN,    
                    QN]           
chordPitches2   = [REST, [D3, FS3, G3, B3], [D3, FS3, G3, B3]]
chordDurations2 = [DHN,  HN,                QN]               
chordPitches3   = [REST, [C3, E3, G3, B3], REST, [E3, FS3, A3, C4], 
                    [E3, FS3, A3, C4]]
chordDurations3 = [QN,   QN,               DHN,  HN,                
                    QN]
chordPitches4   = [REST, [DS3, FS3, A3, B3], REST, [E3, G3, B3], 
                   [DS3, FS3, A3, B3]]
chordDurations4 = [QN,   QN,                 DHN,  HN,           
                   QN]
chordPitches5   = [REST, [E3, G3, B3], REST]
chordDurations5 = [QN,   HN,           HN]

chordPhrase.addNoteList(chordPitches1, chordDurations1)  # add them
chordPhrase.addNoteList(chordPitches2, chordDurations2)
chordPhrase.addNoteList(chordPitches3, chordDurations3)
chordPhrase.addNoteList(chordPitches4, chordDurations4)
chordPhrase.addNoteList(chordPitches5, chordDurations5)

# bass line
bassPitches1   = [REST, A2, REST, A2, E2, D2, REST, D2, A2, G2, REST, 
                   G2, D2, C2] 
bassDurations1 = [WN,   QN, EN,   EN, HN, QN, EN,   EN, HN, QN, EN,   
                   EN, HN, QN] 
bassDurations2 = [EN,   EN, HN, QN,  EN,   EN,  HN, QN, EN,   EN, HN,  
                   QN]
bassPitches2   = [REST, C2, G2, FS2, REST, FS2, C2, B1, REST, B1, FS2, 
                   E2] 
bassPitches3   = [REST, E2, E2, B1, E2, REST]
bassDurations3 = [EN,   EN, QN, QN, HN, HN]

bassPhrase.addNoteList(bassPitches1, bassDurations1)  # add them
bassPhrase.addNoteList(bassPitches2, bassDurations2)
bassPhrase.addNoteList(bassPitches3, bassDurations3)

##### combine musical material
trumpetPart.addPhrase(melodyPhrase) # add phrases to parts
vibesPart.addPhrase(chordPhrase)
bassPart.addPhrase(bassPhrase)

autumnLeavesScore.addPart(trumpetPart) # add parts to score
autumnLeavesScore.addPart(vibesPart)
autumnLeavesScore.addPart(bassPart)

Play.midi(autumnLeavesScore)  # play music

Deep Purple—“Smoke on the Water”

This code sample (Ch. 3, p. 83) demonstrates how to combine drums with other instruments.  It is the opening of Deep Purple’s “Smoke on the Water,” a rock riff from 1972. It combines melody, chords (actually, power-chords constructed from two simultaneous pitches), and drums. The emphasis here is on demonstrating how to combine the various building elements we have seen so far.

# DeepPurple.SmokeOnTheWater.py
#
# Demonstrates how to combine melodic lines, chords, and
# percussion.  This is based on the intro of "Smoke On the Water" 
# by Deep Purple.

from music import *

##### define the data structure
score  = Score("Deep Purple, Smoke On The Water", 110)  # 110 bpm

guitarPart = Part(OVERDRIVE_GUITAR, 0)
bassPart = Part(ELECTRIC_BASS, 1)
drumPart = Part(0, 9)    # using MIDI channel 9 (percussion)

guitarPhrase1 = Phrase()  # guitar opening melody
guitarPhrase2 = Phrase()  # guitar opening melody an octave lower
bassPhrase = Phrase()     # bass melody
drumPhrase = Phrase()     # drum pattern

##### create musical data
# guitar opening melody (16QN = 4 measures)
guitarPitches   = [G2, AS2, C3,  G2, AS2, CS3, C3, G2, AS2, C3,  AS2, 
                    G2]    
guitarDurations = [QN, QN,  DQN, QN, QN,  EN,  HN, QN, QN,  DQN, QN,  
                    DHN+EN]
guitarPhrase1.addNoteList(guitarPitches, guitarDurations)

# create a power-chord sound by repeating the melody an octave lower
guitarPhrase2 = guitarPhrase1.copy()
Mod.transpose(guitarPhrase2, -12)

# bass melody (32EN = 4 measures)
bassPitches1   = [G2, G2, G2, G2, G2, G2, G2, G2, G2, G2, 
                  G2, G2, G2, G2, G2, G2, G2, G2]
bassDurations1 = [EN, EN, EN, EN, EN, EN, EN, EN, EN, EN, 
                  EN, EN, EN, EN, EN, EN, EN, EN]
bassPitches2   = [AS2, AS2, C3, C3, C3, AS2, AS2, G2, G2, 
                  G2, G2, G2, G2, G2]
bassDurations2 = [EN,  EN,  EN, EN, EN, EN,  EN,  EN, EN, 
                  EN, EN, EN, EN, EN]
bassPhrase.addNoteList(bassPitches1, bassDurations1)
bassPhrase.addNoteList(bassPitches2, bassDurations2)

# snare drum pattern (2QN x 8 = 4 measures)
drumPitches   = [REST, SNR] * 8
drumDurations = [QN,   QN]  * 8
drumPhrase.addNoteList(drumPitches, drumDurations)
##### repeat material as needed
Mod.repeat(guitarPhrase1, 8)
Mod.repeat(guitarPhrase2, 6)
Mod.repeat(bassPhrase, 4)
Mod.repeat(drumPhrase, 2)

##### arrange material in time
guitarPhrase1.setStartTime(0.0)  # start at beginning
guitarPhrase2.setStartTime(32.0) # start after two repetitions
bassPhrase.setStartTime(64.0)    # start after two more repetitions
drumPhrase.setStartTime(96.0)    # start after two more repetitions

##### combine musical material
guitarPart.addPhrase(guitarPhrase1)
guitarPart.addPhrase(guitarPhrase2)
bassPart.addPhrase(bassPhrase)
drumPart.addPhrase(drumPhrase)
score.addPart(guitarPart)
score.addPart(bassPart)
score.addPart(drumPart)

##### write score to a MIDI file
Play.midi(score)