/** 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.applet.*; import java.awt.*; import java.awt.event.*; import com.softsynth.jmsl.*; import com.softsynth.jmsl.view.*; public class ShapeDemo extends java.applet.Applet implements ActionListener { MusicShape myShape; MusicShapeEditor se; TextArea textArea; Button startButton; Button stopButton; public void init() { // 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")); add("Center", p); // build a prefabricated 4 dimensional shape myShape = new MusicShape(4); 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); startButton.addActionListener(this); stopButton.addActionListener(this); } public void start() { JMSLRandom.randomize(); JMSL.clock = new DefaultMusicClock(); } public void stop() { myShape.finish(); } void handleStart() { myShape.finish(); myShape.launch(JMSL.now()); } void handleStop() { myShape.finish(); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == startButton) handleStart(); if (source == stopButton) handleStop(); } public static void main(String args[]) { ShapeDemo applet = new ShapeDemo(); Frame f = new Frame("Shape Demo"); f.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); f.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); f.setSize(800,600); f.setVisible(true); } }