/** * ShapeDemo.java * * Build a shape, display in a shape editor, print it, play it. * * @author Phil Burk and Nick Didkovsky */ /* * (C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved JMSL is based upon * HMSL (C) Phil Burk, Larry Polansky and David Rosenboom. */ package jmslexamples; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; import java.awt.Panel; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import com.softsynth.jmsl.DefaultMusicClock; import com.softsynth.jmsl.EventScheduler; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.JMSLRandom; import com.softsynth.jmsl.MessagePrinter; import com.softsynth.jmsl.MusicShape; import com.softsynth.jmsl.view.MusicShapeEditor; import com.softsynth.jmsl.view.TextAreaOut; public class MusicShapeDemo extends Frame implements ActionListener { MusicShape myShape; MusicShapeEditor se; TextArea textArea; Button startButton; Button stopButton; public void init() { JMSLRandom.randomize(); JMSL.setIsApplet(true); // a place for printed output setLayout(new BorderLayout()); textArea = new TextArea(10, 80); add("South", textArea); JMSL.setSTDOut(new TextAreaOut(textArea)); Panel p = new Panel(); p.add(startButton = new Button("Start")); p.add(stopButton = new Button("Stop")); stopButton.setEnabled(false); add("Center", p); // build a prefabricated 4 dimensional shape myShape = new MusicShape(4); myShape.useStandardDimensionNameSpace(); myShape.prefab(); myShape.print(); myShape.setRepeats(10); myShape.addRepeatPlayable(new MessagePrinter("REPEATS")); // build a shape editor to view the shape se = new MusicShapeEditor(); se.addMusicShape(myShape); add("North", se.getComponent()); startButton.addActionListener(this); stopButton.addActionListener(this); } public void stop() { myShape.finishAll(); try { myShape.waitForDone(); } catch (InterruptedException e) { e.printStackTrace(); } } void handleStart() { myShape.finish(); try { myShape.waitForDone(); } catch (InterruptedException e) { e.printStackTrace(); } myShape.launch(JMSL.now()); stopButton.setEnabled(true); startButton.setEnabled(false); } void handleStop() { myShape.finishAll(); stopButton.setEnabled(false); startButton.setEnabled(true); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == startButton) handleStart(); if (source == stopButton) handleStop(); } public static void main(String args[]) { MusicShapeDemo demo = new MusicShapeDemo(); demo.setTitle("Shape Demo"); demo.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); demo.init(); demo.setSize(800, 700); demo.setVisible(true); } }