/** * InsToot10.java * * Demonstrate SynthNoteAllPorts Instrument. Control all input ports of an arbitrary SynthNote. * * Also shows how to use JMSLMixerContainer to mix instruments together and put up a pan/amp control for each * * @author Nick Didkovsky, (C) 2003 Nick Didkovsky, All Rights Reserved * */ package jmsltutorial; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.JSynMusicDevice; import com.softsynth.jmsl.jsyn.SynthNoteAllPortsInstrument; import com.softsynth.jmsl.view.MusicShapeEditor; import com.softsynth.jsyn.AppletFrame; public class InsToot10 extends java.applet.Applet implements ActionListener { String SYNTHNOTE_CLASSNAME; MusicShape myShape; Button startButton; Button stopButton; SynthNoteAllPortsInstrument ins; JMSLMixerContainer mixer; public void init() { SYNTHNOTE_CLASSNAME = "com.softsynth.jsyn.circuits.FilteredSawtoothBL"; } public void start() { JMSL.setIsApplet(true); JSynMusicDevice.instance().open(); JMSL.clock.setAdvance(0.25); mixer = new JMSLMixerContainer(); mixer.start(); buildMyInstrument(); buildMyShape(); myShape.setInstrument(ins); mixer.addInstrument(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")); startButton.setBackground(new Color(100, 255, 100)); p.add(BorderLayout.EAST, stopButton = new Button("STOP")); stopButton.setBackground(new Color(255, 100, 100)); add(BorderLayout.SOUTH, p); MusicShapeEditor se = new MusicShapeEditor(); se.addMusicShape(myShape); add(BorderLayout.NORTH, se.getComponent()); add(BorderLayout.CENTER, mixer.getPanAmpControlPanel()); startButton.addActionListener(this); stopButton.addActionListener(this); /* Synchronize Java display. */ getParent().validate(); getToolkit().sync(); } /** Some JSyn term's, and shut down activity */ public void stop() { myShape.finish(); removeAll(); mixer.stop(); JMSL.closeMusicDevices(); } /** Build a JSyn Instrument by passing in synthnote class name and desired polyphony */ void buildMyInstrument() { ins = new SynthNoteAllPortsInstrument(8, SYNTHNOTE_CLASSNAME); } /** 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() { // create a new MusicShape with the same DimensionNameSpace as the instrument myShape = new MusicShape(ins.getDimensionNameSpace()); for (int i = 0; i < 17; i++) { double[] data = new double[myShape.dimension()]; double duration = JMSLRandom.choose(); double pitch = JMSLRandom.choose(40, 80); double amplitude = JMSLRandom.choose(); double hold = duration * JMSLRandom.choose(2.0); data[0] = duration; data[1] = pitch; data[2] = amplitude; data[3] = hold; // we will choose random values for dimensions higher than 3 by using high/low limits for (int dim = 4; dim < myShape.dimension(); dim++) { double value = JMSLRandom.choose(myShape.getLowLimit(dim), myShape.getHighLimit(dim)); data[dim] = value; } myShape.add(data); } 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[]) { InsToot10 applet = new InsToot10(); AppletFrame frame = new AppletFrame("JMSL Tutorial", applet); frame.setSize(600, 600); frame.show(); frame.test(); } }