/** * InsToot10.java * * Demonstrate SynthNoteAllPorts Instrument. Control all input ports of a SynthNote we designed in Wire. * * 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 InsToot10Simple extends java.applet.Applet implements ActionListener { String SYNTHNOTE_CLASSNAME; MusicShape myShape; Button startButton; Button stopButton; SynthNoteAllPortsInstrument ins; JMSLMixerContainer mixer; public void init() { SYNTHNOTE_CLASSNAME = "jmsltutorial.TutSquare"; } 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 by hand, "knowing" that rate values are in dimension 4 * */ void buildMyShape() { // create a new MusicShape with the same DimensionNameSpace as the instrument myShape = new MusicShape(ins.getDimensionNameSpace()); myShape.add(5.0, 60, 0.55, 4.8, 2.0); myShape.add(5.0, 70, 0.45, 4.8, 0.1); 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[]) { InsToot10Simple applet = new InsToot10Simple(); AppletFrame frame = new AppletFrame("JMSL Tutorial", applet); frame.setSize(600, 400); frame.show(); frame.test(); } }