/* * Created on Dec 6 2016 by Nick * */ package jmslexamples.simple; import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import com.didkovsky.portview.swing.ViewFactorySwing; import com.jsyn.swing.JAppletFrame; import com.softsynth.jmsl.EventScheduler; import com.softsynth.jmsl.Instrument; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.JMSLMixerContainer; import com.softsynth.jmsl.MusicShape; import com.softsynth.jmsl.jsyn2.JSynMusicDevice; import com.softsynth.jmsl.jsyn2.JSynUnitVoiceInstrument; import com.softsynth.jmsl.view.MusicShapeEditor; /** * Create a multidimensional MusicShape and Instrument that plays all input * ports of a JSyn UnitVoice * * @author Nick Didkovsky, (c) 2005 Nick Didkovsky, nick@didkovsky.com * */ public class JSyn2DimensionFun extends JFrame { JMSLMixerContainer mixer; Instrument instrument; MusicShape myMusicShape; public void start() { initJMSL(); initMusicDevices(); buildMixer(); buildInstrument(); buildMusicShape(); buildMusicShapeEditor(); launchMusicShape(); } private void buildMusicShapeEditor() { MusicShapeEditor se = new MusicShapeEditor(); se.addMusicShape(myMusicShape); setLayout(new BorderLayout()); add(BorderLayout.NORTH, se.getComponent()); add(BorderLayout.SOUTH, mixer.getPanAmpControlPanel()); } private void buildMusicShape() { // build a MusicShape from all the dimensions the JSynUnitVoiceInstrument pulled // from the // UnitVoice myMusicShape = new MusicShape(instrument.getDimensionNameSpace()); // generate random performance data for each dimension. First 4 dimensions are // duration,pitch, amplitude, hold myMusicShape.prefab(); myMusicShape.print(); // now assign the instrument to the musicShape so that the MusicShape hands its // data to the // instrument while it is performing myMusicShape.setInstrument(instrument); // repeat forever myMusicShape.setRepeats(10000); } private void initJMSL() { JMSL.setViewFactory(new ViewFactorySwing()); JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); JMSL.clock.setAdvance(0.2); } private void initMusicDevices() { JSynMusicDevice.instance().open(); } private void buildMixer() { mixer = new JMSLMixerContainer(); mixer.start(); } private void buildInstrument() { // instrument = new JSynUnitVoiceInstrument(8, com.jsyn.instruments.SubtractiveSynthVoice.class.getName()); instrument = new JSynUnitVoiceInstrument(8, com.softsynth.jmsl.jsyn2.unitvoices.FilteredSawtoothBL.class.getName()); mixer.addInstrument(instrument); } private void launchMusicShape() { myMusicShape.launch(JMSL.now()); } public void stop() { myMusicShape.finishAll(); try { myMusicShape.waitForDone(); } catch (InterruptedException e) { e.printStackTrace(); } JMSL.scheduler.stop(); JMSL.closeMusicDevices(); } public static void main(String[] args) { JSyn2DimensionFun jf = new JSyn2DimensionFun(); jf.setSize(800, 700); jf.setVisible(true); jf.start(); jf.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { jf.stop(); System.exit(0); } }); } }