package jmsltestsuite; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import com.didkovsky.portview.PVFrame; import com.softsynth.jmsl.*; import com.softsynth.jmsl.midi.*; import com.softsynth.jmsl.view.MusicShapeEditor; import com.softsynth.jmsl.view.PVFrameAdapter; /** * Set JMSL.midi to MidiIO_JavaSound and play some Midi melodies * * MOD 4/14/09: adding non-real-time example, which plays the MusicShape with * MIDI logging on, Midi quiet, and non real time music clock * * @author Nick Didkovsky */ public class JavaSoundMidiTest { public static void main(String args[]) { boolean NON_REAL_TIME = false; PVFrame myFrame = new PVFrameAdapter(); try { MusicDevice dev = new MidiIOFactory().getMidiIO(MidiIOFactory.MidiIO_JAVASOUND); // in case this machine does not have a soundbank in jre, load one // from url JMSL.setIsApplet(true); // flag to use url if soundbank not found. // If you know where a // soundbank is on your machine, comment this isApplet() line out // and use the file // version instead ((MidiIO_JavaSound) dev).setSoundbankFile(File // f); URL soundbankURL = new URL("http://www.algomusic.com/javasound/soundbank.gm"); ((MidiIO_JavaSound) dev).setSoundbankURL(soundbankURL); dev.edit((Frame) myFrame.getComponent()); dev.open(); } catch (IOException e1) { e1.printStackTrace(); } JMSL.clock.setAdvance(0.1); MusicShape s = new MusicShape(4); s.add(0.5, 64, 100, 2.0); s.add(0.5, 66, 90, 2.5); s.add(0.25, 69, 80, 1.5); s.add(0.25, 72, 70, 0.25); s.add(0.25, 75, 100, 2.0); s.setInstrument(new MidiInstrument(1)); // Midi ins on channel 1 s.setRepeats(10); if (NON_REAL_TIME) { JMSL.clock = new NonRealTimeMusicClock(); JMSL.midi.setQuiet(true); JMSL.midi.setMidiLogging(true); s.addStopPlayable(new Playable() { public double play(double playTime, Composable parent) throws InterruptedException { JMSL.midi.setMidiLogging(false); try { JMSL.midi.writeMidiFile("logs/testMidiFile2.MID"); } catch (IOException e) { e.printStackTrace(); } return playTime; } }); } if (!NON_REAL_TIME) { MusicShapeEditor se = new MusicShapeEditor(); se.addMusicShape(s); myFrame.add(se.getComponent()); myFrame.pack(); } else { myFrame.setSize(320, 200); } myFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { JMSL.midi.close(); System.exit(0); } }); myFrame.setVisible(true); s.launch(JMSL.now()); } }