Install
mdpw22.zip |
InstallDownload mdpw22.zip and extract it. You will find mdpw.jar. Add the jar file to your Java development environment. There are at least three ways.
Top of this page| Next step How to make a NoteI will show you an example of only one note first. You will understand how to use "Player Class". The arguments of :mn represent pitch(0-127), duration(positive double), velocity(-64 - 63) and program number (0 - 127, 129) respectively.import com.cwbp.mdpw.*; public class tNote { public static void main(String[] a){ // Create Player class Player p = new MIDIFilePlayer(); // file name to output p.init("tNote.mid"); // Set tempo p.setTempo(120); // Create one note and play p.play(new DataNote(60, 1, 0, 1)); // Do write to the file. p.end(); } } Top of this page| Next step How to make a SequenceYou can make a sequnece of notes by DataSequence class. Create a instance and add notes to it. If you omitt arguments of DataNote, the valeus of the note before are applied.import com.cwbp.mdpw.*; public class tSeq { public static void main(String[] a){ Player p = new MIDIFilePlayer(); // Create Sequence DataSequence s = new DataSequence(); // Add notes to the sequence s.addElement(new DataNote(60, 1, 0, 0));//C s.addElement(new DataNote(62, 1)); //D s.addElement(new DataNote(64, 1)); //E // Write to a file p.init("tSeq.mid"); p.setTempo(120); p.play(s); p.end(); } } Top of this page| Next step How to make a ChordYou can make a chord by DataChord class. If you omit arguments of DataNote, the valeus of the note before are applied.import com.cwbp.mdpw.*; public class tChord { public static void main(String[] a){ Player p = new MIDIFilePlayer(); DataChord c = new DataChord(); c.addElement(new DataNote(60, 1, 0, 0));//C c.addElement(new DataNote(64, 1)); //E c.addElement(new DataNote(67, 1)); //G p.init("tChord.mid"); p.setTempo(120); p.play(c); p.end(); } } Top of this page| Next step How to make a musical pieceYou can make a musical piece by sequences and chords. Both can contain both. You can make a seqence as the melody, a sequence of chords as the accompaniment and a chord of those two. And you will find how to repeat by repeated invocation of play method of Player class.import com.cwbp.mdpw.*; public class tSample { public static void main(String[] a){ Player p = new MIDIFilePlayer(); DataChord c = new DataChord(); //Chord:C c.addElement(new DataNote(60, 2, 0, 0)); c.addElement(new DataNote(64, 2)); c.addElement(new DataNote(67, 2)); DataSequence b = new DataSequence(); //Chord part b.addElement(c); b.addElement(c); DataSequence s = new DataSequence(); //Melody s.addElement(new DataNote(60, 1, 16, 0)); s.addElement(new DataNote(62, 1)); s.addElement(new DataNote(64, 1)); s.addElement(new DataNote(64, 1, 0)); //Rest DataChord m = new DataChord(); //Phrase 1 m.addElement(s); m.addElement(b); p.init("tSample.mid"); p.setTempo(120); p.play(m); //Repeat 2 times p.play(m); p.end(); } }Are you inspired? Enjoy Music Programing. Top of this page |