package jmsltestsuite; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import com.softsynth.jmsl.Composable; import com.softsynth.jmsl.Instrument; import com.softsynth.jmsl.InstrumentPlayable; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.JMSLMixerContainer; import com.softsynth.jmsl.MusicList; import com.softsynth.jmsl.SequentialCollection; import com.softsynth.jmsl.jsyn.JSynMusicDevice; import com.softsynth.jmsl.jsyn.SynthNoteInstrument; import com.softsynth.jsyn.SynthCircuit; import com.softsynth.jsyn.SynthException; import com.softsynth.jsyn.SynthNote; import com.softsynth.jsyn.circuits.RingModBell; import com.softsynth.jsyn.util.BussedVoiceAllocator; public class TestEvSchedMusicList { /** Build an instrument and a shape and play it on a JSyn voice. */ public static void main(String args[]) { BussedVoiceAllocator allocator1; BussedVoiceAllocator allocator2; MusicList list1; MusicList list2; JSynMusicDevice.instance().open(); JMSL.clock.setAdvance(0.5); allocator1 = new BussedVoiceAllocator(8) { public SynthCircuit makeVoice() throws SynthException { SynthNote circ = new RingModBell(); circ.amplitude.set(1.0 / getMaxVoices()); return addVoiceToMix(circ); } }; allocator2 = new BussedVoiceAllocator(8) { public SynthCircuit makeVoice() throws SynthException { SynthNote circ = new RingModBell(); circ.amplitude.set(1.0 / getMaxVoices()); return addVoiceToMix(circ); } }; JMSLMixerContainer mixer = new JMSLMixerContainer(); mixer.start(); SynthNoteInstrument ins1 = new SynthNoteInstrument(); ins1.setAllocator(allocator1); mixer.addInstrument(ins1); SynthNoteInstrument ins2 = new SynthNoteInstrument(); ins2.setAllocator(allocator2); mixer.addInstrument(ins2); list1 = new MusicList(); list1.add(new PlayableTestNote(0.125, 62, 30, 2.5)); list1.add(new PlayableTestNote(0.125, 64, 40, 2.5)); list1.add(new PlayableTestNote(0.125, 66, 50, 0.5)); list1.add(new PlayableTestNote(0.125, 68, 60, 2.5)); list1.add(new PlayableTestNote(0.125, 70, 70, 1.5)); list1.add(new PlayableTestNote(0.125, 72, 50, 0.5)); list1.setInstrument(ins1); list2 = new MusicList(); list2.add(new PlayableTestNote(0.125, 65, 30, 2.5)); list2.add(new PlayableTestNote(0.125, 67, 40, 2.5)); list2.add(new PlayableTestNote(0.125, 69, 50, 0.5)); list2.add(new PlayableTestNote(0.125, 71, 60, 2.5)); list2.add(new PlayableTestNote(0.125, 73, 70, 1.5)); list2.add(new PlayableTestNote(0.125, 75, 50, 0.5)); list2.setInstrument(ins2); jmsltestsuite.TestLurker lurk = new jmsltestsuite.TestLurker(); list1.addPlayLurker(lurk); list2.addPlayLurker(lurk); // ParallelCollection p = new ParallelCollection(list1, list2); SequentialCollection col = new SequentialCollection(); col.add(list1); col.add(list2); col.setRepeats(10); col.launch(JMSL.now() + 2); Frame f = new Frame("MusicLists with Lurker posting events to EventScheduler"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { JMSL.closeMusicDevices(); System.exit(0); } }); f.setSize(600, 200); f.setVisible(true); } } class PlayableTestNote implements InstrumentPlayable { double[] dar; public PlayableTestNote(double dur, double pitch, double amp, double hold) { dar = new double[4]; dar[0] = dur; dar[1] = pitch; dar[2] = amp; dar[3] = hold; } public double play(double playTime, Composable parent, Instrument ins) { JMSL.out.println("TestPlayable playing at " + playTime); return ins.play(playTime, parent.getTimeStretch(), dar); // return playTime + dur * parent.getTimeStretch(); } }