/* * Created on Sep 22, 2003 * */ package jmsltestsuite; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.jsyn.*; import com.softsynth.jsyn.LineOut; import com.softsynth.jsyn.SynthOutput; /** * Test update() on TunedSynthNoteInstrument (the highest JSyn Instrument in the class tree to * implement update(). Enter pitch, amplitude, hold values and click play() Then change amplitude * value while it is sustaining and click update(). The amplitude should change. While sustaining, * change both the pitch and the amplitude and click update(). no change, since it has not found a * SynthNote to update() - it looks up SynthNotes by matching pitch (or more generally, the * updateDimension). * * @author Nick Didkovsky, email: didkovn@mail.rockefeller.edu, (c) 2003 Nick Didkovsky, all rights * reserved. * */ public class UpdateSynthNoteInstrumentTest extends Frame implements ActionListener { TextField durationField; TextField pitchField; TextField amplitudeField; TextField holdField; Button playButton; Button updateButton; TunedSynthNoteInstrument ins; LineOut out; public UpdateSynthNoteInstrumentTest() { String title = "TunedSynthNoteInstrument update() test"; setTitle(title); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { JMSL.closeMusicDevices(); System.exit(0); } }); setUpJSyn(); setUpGUI(); } private void setUpGUI() { setLayout(new GridLayout(0, 2)); add(new Label("duration")); add(durationField = new TextField("10.0")); add(new Label("pitch")); add(pitchField = new TextField("60.0")); add(new Label("amplitude")); add(amplitudeField = new TextField("0.5")); add(new Label("hold")); add(holdField = new TextField("9.0")); add(playButton = new Button("play()")); add(updateButton = new Button("update()")); playButton.addActionListener(this); updateButton.addActionListener(this); } private void setUpJSyn() { JSynMusicDevice.instance().edit(this); JSynMusicDevice.instance().open(); out = new LineOut(); out.start(); String className = "com.softsynth.jmsl.jsyn.circuits.AutopanningSawtooth"; BVAClassName allocator = new BVAClassName(8, className); ins = new TunedSynthNoteInstrument(); ins.setAllocator(allocator); if (ins.getNumOutputs() == 1) { ((SynthOutput) ins.getOutput(0)).connect(0, out.input, 0); ((SynthOutput) ins.getOutput(0)).connect(0, out.input, 1); } else { ((SynthOutput) ins.getOutput(0)).connect(0, out.input, 0); ((SynthOutput) ins.getOutput(1)).connect(0, out.input, 1); } } public static void main(String[] args) { JMSL.clock.setAdvance(0.5); UpdateSynthNoteInstrumentTest testUpdate = new UpdateSynthNoteInstrumentTest(); testUpdate.pack(); testUpdate.setVisible(true); } public void actionPerformed(ActionEvent ev) { Object source = ev.getSource(); if (source == playButton) { ins.play(JMSL.now(), 1.0, getDoubleArr()); } if (source == updateButton) { ins.update(JMSL.now(), 1.0, getDoubleArr()); } } private double[] getDoubleArr() { double[] data = new double[4]; data[0] = new Double(durationField.getText()).doubleValue(); data[1] = new Double(pitchField.getText()).doubleValue(); data[2] = new Double(amplitudeField.getText()).doubleValue(); data[3] = new Double(holdField.getText()).doubleValue(); return data; } }