JMUSIC.MyFavoriteMelodyJava History

Hide minor edits - Show changes to output

Changed line 52 from:
// play phrases twice
to:
// repeat each phrase a second time
Changed lines 67-68 from:
// play the score as MIDI (and exit, since Java Sound does not shut down properly)
to:
// play the score as MIDI (and exit, since JavaSound does not
//
shut down properly)
Changed lines 1-2 from:
(:source lang=Java header="This sample program demonstrates how to create more interesting music." tabwidth=3 -trim :)
to:
(:source lang=Java header="This program demonstrates how to create more interesting music." tabwidth=3 -trim :)
Changed lines 1-2 from:
(:source lang=Java header="This sample program has everything you need to create MIDI files. Use it to test your jMusic installation." tabwidth=3 -trim :)
to:
(:source lang=Java header="This sample program demonstrates how to create more interesting music." tabwidth=3 -trim :)
Added lines 1-78:
(:source lang=Java header="This sample program has everything you need to create MIDI files. Use it to test your jMusic installation." tabwidth=3 -trim :)

import jm.JMC;
import jm.music.data.*;
import jm.util.*;
import jm.music.tools.*;

/**
* Plays a melody as a round in three parts
* @author Andrew Sorensen and Andrew Brown (modified by Bill Manaris)
*/

public final class MyFavoriteMelody implements JMC
{
public static void main(String[] args)
{
// Create the data objects we want to use
Score score = new Score("Row Your Boat");

// Parts can have a name, instrument, and channel.
Part flute = new Part("Flute", FLUTE, 0);
Part trumpet = new Part("Trumpet", TRUMPET, 1);
Part clarinet = new Part("Clarinet", CLARINET, 2);

// Let's write the music in a convenient way...
// "Row, row, row your boat gently down the stream"
int[] pitches1 = {C4, C4, C4, D4, E4, E4, D4, E4, F4, G4};
double[] rhythms1 = {QN, QN, EN, EN, QN, EN, EN, EN, EN, HN};
// "merrily, merrily, merrily, merrily"
int[] pitches2 = {C5, C5, G4, G4, E4, E4, C4, C4};
double[] rhythms2 = {EN, EN, EN, EN, EN, EN, EN, EN};
// "life is but a dream."
int[] pitches3 = {G4, F4, E4, D4, C4};
double[] rhythms3 = {EN, EN, EN, EN, HN};

// add the notes to a phrase
Phrase phrase1 = new 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
Phrase phrase2 = phrase1.copy();
phrase2.setStartTime(4.0); // four beats into the piece
Phrase 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);

// play phrases twice
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 Java Sound does not shut down properly)
//Play.midi(score, true);

// display the score in a music notation (CPN) window
View.notate(score);

// write the score to a MIDI file
Write.midi(score, "rowboat.mid");
}
}

(:sourcend:)