# myFavoriteMelody.py Version 1.0 17-Nov-2006 (bzm) # # This program demonstrates how to create more interesting music. # # Plays a melody as a round in three parts. # # written by Andrew Sorensen and Andrew Brown (ported to Python by Bill Manaris) # from jMusic import * # Create the data objects we want to use score = Score("Row Your Boat") # Parts can have a name, instrument, and channel. flute = Part("Flute", FLUTE, 0) trumpet = Part("Trumpet", TRUMPET, 1) clarinet = Part("Clarinet", CLARINET, 2) # Let's write the music in a convenient way... # "Row, row, row your boat gently down the stream" pitches1 = [C4, C4, C4, D4, E4, E4, D4, E4, F4, G4] rhythms1 = [QN, QN, EN, EN, QN, EN, EN, EN, EN, HN] # "merrily, merrily, merrily, merrily" pitches2 = [C5, C5, G4, G4, E4, E4, C4, C4] rhythms2 = [EN, EN, EN, EN, EN, EN, EN, EN] # "life is but a dream." pitches3 = [G4, F4, E4, D4, C4] rhythms3 = [EN, EN, EN, EN, HN] # add the notes to a phrase phrase1 = Phrase(0.0) phrase1.addNoteList(pitches1, rhythms1) phrase1.addNoteList(pitches2, rhythms2) phrase1.addNoteList(pitches3, rhythms3) # make two new phrases and change start times to make a round phrase2 = phrase1.copy() phrase2.setStartTime(4.0) # four beats into the piece phrase3 = phrase1.copy() phrase3.setStartTime(8.0) # eight beats into the piece # play different parts in different octaves Mod.transpose(phrase1, 12) Mod.transpose(phrase3, -12) # repeat each phrase a second time Mod.repeat(phrase1, 2) Mod.repeat(phrase2, 2) Mod.repeat(phrase3, 2) # add phrases to the parts flute.addPhrase(phrase1) trumpet.addPhrase(phrase2) clarinet.addPhrase(phrase3) # add parts to the score score.addPart(flute) score.addPart(trumpet) score.addPart(clarinet) # play the score as MIDI (and exit, since JavaSound does not # shut down properly) Play.midi(score, 1) # display the score in a music notation (CPN) window View.notate(score) # write the score to a MIDI file Write.midi(score, "rowboat.mid")