/** * InsToot07EZa.java * * Play a JSyn SynthNote with JMSL * * This version uses a SynthNote that ships with JSyn * * @author Nick Didkovsky */ /* * (C) 2003 Nick Didkovsky, All Rights Reserved * JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom. */ package jmsltutorial; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.JSynInsFromClassName; import com.softsynth.jmsl.jsyn.JSynMusicDevice; import com.softsynth.jmsl.view.MusicShapeEditor; import com.softsynth.jsyn.AppletFrame; public class InsToot07EZa extends java.applet.Applet implements ActionListener { String SYNTHNOTE_CLASSNAME; MusicShape myShape; Button startButton; Button stopButton; JSynInsFromClassName ins; JMSLMixerContainer mixer; public void init() { SYNTHNOTE_CLASSNAME = "com.softsynth.jsyn.circuits.FilteredSawtoothBL"; } /** Handle some JSyn init's, start the MusicShape */ public void start() { JSynMusicDevice.instance().open(); JMSL.clock.setAdvance(0.25); mixer = new JMSLMixerContainer(); mixer.start(); buildMyShape(); // Build a JSyn Instrument by passing in synthnote class name and desired polyphony ins = new JSynInsFromClassName(8, SYNTHNOTE_CLASSNAME); // connect the instrument to the mixer mixer.addInstrument(ins); // hand the instrument to the MusicShape myShape.setInstrument(ins); // now proceed with GUI layour: start / stop buttons and MusicShape editor setLayout(new BorderLayout()); Panel p = new Panel(); p.setLayout(new BorderLayout()); p.add(BorderLayout.WEST, startButton = new Button("START")); p.add(BorderLayout.EAST, stopButton = new Button("STOP")); add(BorderLayout.SOUTH, p); MusicShapeEditor se = new MusicShapeEditor(); se.addMusicShape(myShape); add(BorderLayout.NORTH, se.getComponent()); startButton.addActionListener(this); stopButton.addActionListener(this); /* Synchronize Java display. */ getParent().validate(); getToolkit().sync(); } /** Stop the MusicShape, close Music Devices */ public void stop() { myShape.finishAll(); removeAll(); // remove all gui components mixer.stop(); JMSL.closeMusicDevices(); } /** Build a MusicShape using standard names for dimensions: "duration", "pitch", "amplitude", "hold" * pitch can be fractional even though they look like midi notes. * */ void buildMyShape() { myShape = new MusicShape(4); myShape.useStandardDimensionNameSpace(); myShape.add(0.125, 52, 0.25, 1.12); myShape.add(0.125, 42, 0.25, 0.12); myShape.add(0.25, 80, 0.25, 0.2); myShape.add(0.125, 67, 0.25, 2.0); myShape.add(0.25, 67.5, 0.25, 2.0); myShape.add(0.25, 68, 0.25, 2.0); myShape.add(1.25, 68.5, 0.25, 1.0); myShape.setRepeats(10000); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == startButton) myShape.launch(JMSL.now()); if (source == stopButton) myShape.finishAll(); } /* Can be run as either an application or as an applet. */ public static void main(String args[]) { InsToot07EZa applet = new InsToot07EZa(); AppletFrame frame = new AppletFrame("JMSL Tutorial", applet); frame.setSize(600, 400); frame.show(); frame.test(); } }