package jmsltestsuite; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.score.Note; import com.softsynth.jmsl.score.NoteFactory; import com.softsynth.jmsl.score.Score; import com.softsynth.jmsl.score.ScoreCollection; import com.softsynth.jmsl.score.ScoreCollectionBehavior; import com.softsynth.jmsl.score.ScoreFrame; /** * * @author Nick Didkovsky 2012 */ public class ScoreChaseTest { public static void main(String args[]) { int w = 1000; int h = 400; int numStaves = 1; int numNotes = 1000; final Score score = new Score(numStaves, w, h, "Chase Test"); score.addMeasure(); for (int i = 0; i < numNotes; i++) { double wackedOutDuration = 0.125; Note n = score.addNote(wackedOutDuration, NoteFactory.MIDDLE_C, 0.5, 0.25); } final ScoreFrame f = new ScoreFrame(); f.addScore(score); f.setVisible(true); final Button chaseButton = new Button("chase"); final Button stopButton = new Button("stop"); final double songPointerTime = 5.5; chaseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { ScoreCollection col = score.getScoreCollection(); col.setRepeats(Integer.MAX_VALUE); boolean NO_LOOP = false; ((ScoreCollectionBehavior) col.getBehavior()).setStartEndLoop(0, col.size()-1, NO_LOOP); col.launch(JMSL.realTime() - songPointerTime); ((Container) (f.getComponent())).remove(chaseButton); ((Container) (f.getComponent())).add(BorderLayout.SOUTH, stopButton); f.pack(); } }); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { ScoreCollection col = score.getScoreCollection(); col.finishAll(); ((Container) (f.getComponent())).remove(stopButton); ((Container) (f.getComponent())).add(BorderLayout.SOUTH, chaseButton); f.pack(); } }); ((Container) (f.getComponent())).add(BorderLayout.SOUTH, chaseButton); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }