/* * Created on Oct 2, 2005 by Nick Didkovsky * */ package jmsltestsuite; import java.io.IOException; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.JMSLRandom; import com.softsynth.jmsl.midi.MidiIO; import com.softsynth.jmsl.midi.MidiLogger; /** * You can use MidiLogger to simply write MIDI events into the logger and finally write out a MIDI * file. Do not expect to hear anything in this example. Just writes a few events to the logger and * creates a MIDI file. * * MOD 11/1/07 send program changes and play independent material on two different midi channels w/two different sounds. Nick D * * @author Nick Didkovsky, (c) 2005 Nick Didkovsky, nick@didkovsky.com * */ public class MidiLoggerNonRealTimeTest2 { public static void main(String[] args) { MidiLogger logger = new MidiLogger(); double startTime = JMSL.realTime(); logger.setMidiLogging(true); int NOT_USED = 0; // sustain cello tone for five seconds on ch 2 int desiredChannel = 1; int whatToAddToStatusToGetMidiChannel = desiredChannel - 1; logger.log(startTime, MidiIO.PROGRAM_CHANGE + whatToAddToStatusToGetMidiChannel, 8, NOT_USED); // a fast chromatic run for (int i = 0; i < 25; i++) { logger.log(startTime, MidiIO.NOTE_ON + whatToAddToStatusToGetMidiChannel, 60 + i, 100); logger.log(startTime + 0.1, MidiIO.NOTE_OFF + whatToAddToStatusToGetMidiChannel, 60 + i, 0); startTime += 0.0625; } // Now for some out-of-order time stamps which MidiLogger will sort before writing file. // Fill a four second span with a uniformly random distribution of note events for (int i = 0; i < 25; i++) { double onTime = startTime + JMSLRandom.choose(4.0); double offTime = onTime + JMSLRandom.choose(2.0); int pitch = JMSLRandom.choose(60, 84); int vel = JMSLRandom.choose(30, 70); int channel = JMSLRandom.choose() < 0.5 ? 0 : 1; logger.log(onTime, MidiIO.NOTE_ON + channel, pitch, vel); logger.log(offTime, MidiIO.NOTE_OFF + channel, pitch, 0); } try { // write out the MIDI file logger.writeMidiFile("MidiLoggerNonRealTimeTest2.MID"); } catch (IOException e) { e.printStackTrace(); } } }