[jmsl] Navigating Sequential Sequence
jmsl at music.columbia.edu
jmsl at music.columbia.edu
Mon Apr 27 08:34:29 EDT 2009
If I go
sequenceCol.get(current).launch(JMSL.now(), null);
It just plays that one collection and stops.
Thanks,
Chi
----- Original Message -----
From: <jmsl at music.columbia.edu>
To: <jmsl at music.columbia.edu>
Sent: Monday, April 27, 2009 8:31 AM
Subject: Re: [jmsl] Navigating Sequential Sequence
> Hi Chi
>
> Use an int counter to maintain the current sequence.
> Then mySequence.get(current).launch(JMSL.now(), null);
> These are good questions for the JMSL, can you post there?
> Thanks
> Nick
>
> ----- Original Message -----
> From: <jmsl at music.columbia.edu>
> To: <jmsl at music.columbia.edu>
> Sent: Monday, April 27, 2009 8:30 AM
> Subject: [jmsl] Navigating Sequential Sequence
>
>
>> Hi,
>>
>> I'm trying to implement function to start, stop, next, previous for a
>> sequential collection.
>> 1. should be able to move the pointer (currentSequence) and launch the
>> collection from where the pointer is.
>> 2. Also, should be able to move the pointer while playing. The function
>> should sequenceCol.finishAll() right away, then resume from where the
>> pointer is.
>> 3. When the playback reaches to the end, the pointer should come back to
>> where it started.
>> The way I'm doing doesn't seem to work. Is there a simpler way? Here's
>> the code.
>> Thanks,
>>
>> Chi
>>
>> private SequentialCollection sequenceCol;
>> private SequenceBehavior sequenceBehavior;
>> private int currentSequence, startedSequence;
>> private JCheckBoxMenuItem sequencePlayCB;
>>
>> private void buildCollection() {
>> sequenceCol = new SequentialCollection();
>> sequenceCol.setRepeats(Integer.MAX_VALUE);
>> sequenceBehavior = new SequenceBehavior();
>> sequenceCol.setBehavior(sequenceBehavior);
>> sequenceCol.addStartPlayable(new SequencePlayable());
>> sequenceCol.addRepeatPlayable(new SequencePlayable());
>> }
>>
>> privat void buildGui() {
>> m.add(sequencePlayCB = new JCheckBoxMenuItem("Play Sequence"));
>> sequencePlayCB.setMnemonic(KeyEvent.VK_Q);
>> sequencePlayCB.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0));
>> sequencePlayCB.addItemListener(new ItemListener() {
>> public void itemStateChanged(ItemEvent e) {
>> if (sequencePlayCB.getState()) {
>> playSequence();
>> } else {
>> stopSequence();
>> }
>> }
>> });
>>
>> m.add(mi = new JMenuItem("Previous Sequence"));
>> mi.setMnemonic(KeyEvent.VK_V);
>> mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 0));
>> mi.addActionListener(new ActionListener() {
>> public void actionPerformed(ActionEvent e) {
>> prevSequence();
>> }
>> });
>>
>> m.add(mi = new JMenuItem("Next Sequence"));
>> mi.setMnemonic(KeyEvent.VK_N);
>> mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0));
>> mi.addActionListener(new ActionListener() {
>> public void actionPerformed(ActionEvent e) {
>> nextSequence();
>> }
>> });
>>
>> m.add(mi = new JMenuItem("Add Sequence"));
>> mi.setMnemonic(KeyEvent.VK_D);
>> mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, 0));
>> mi.addActionListener(new ActionListener() {
>> public void actionPerformed(ActionEvent e) {
>> addSequence();
>> }
>> });
>>
>> m.add(mi = new JMenuItem("Remove Sequence"));
>> mi.setMnemonic(KeyEvent.VK_R);
>> mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
>> mi.addActionListener(new ActionListener() {
>> public void actionPerformed(ActionEvent e) {
>> removeSequence();
>> }
>> });
>>
>> }
>>
>> private void playSequence() {
>> if (sequenceCol.size() > 0) {
>> startedSequence=currentSequence; // Record where it started
>> sequenceCol.launch(JMSL.now());
>> }
>> }
>>
>> private void stopSequence() {
>> sequenceCol.finishAll();
>> currentSequence=startedSequence; // go back to where it started
>> sequenceBehavior.setStart(currentSequence);
>> }
>>
>> private void prevSequence() {
>> if (currentSequence>0) {
>> currentSequence--;
>> sequenceBehavior.setStart(currentSequence);
>> // If playing, stop, move, resume
>> if (sequencePlayCB.getState()) {
>> sequenceCol.finishAll();
>> try {sequenceCol.waitForDone();}
>> catch (InterruptedException e) {e.printStackTrace();}
>> sequenceCol.launch(JMSL.now());
>> }
>> }
>> }
>>
>> private void nextSequence() {
>> if (currentSequence<sequenceCol.size()-1) {
>> currentSequence++;
>> sequenceBehavior.setStart(currentSequence);
>> // If playing, stop, move, resume.
>> if (sequencePlayCB.getState()) {
>> sequenceCol.finishAll();
>> try {sequenceCol.waitForDone();}
>> catch (InterruptedException e) {e.printStackTrace();}
>> sequenceCol.launch(JMSL.now());
>> }
>> }
>> }
>>
>> private void addSequence() {
>> ParallelCollection pc = new ParallelCollection();
>> for (int i = 0; i < 21; i++)
>> if (ms[i] != null && playingCol.contains(ms[i]))
>> pc.add((AutoMS)ms[i].clone());
>> sequenceCol.add(pc);
>> }
>>
>> private void removeSequence() {
>> if (sequenceCol.size() > 0) {
>> if (currentSequence >= sequenceCol.size()-1) currentSequence =
>> sequenceCol.size()-1;
>> sequenceCol.remove(currentSequence);
>> }
>> }
>>
>> class SequencePlayable implements Playable {
>> public double play(double playTime, Composable thing) throws
>> InterruptedException {
>> if ( currentSequence < sequenceCol.size() ) {
>> sequenceBehavior.setStart(currentSequence);
>> currentSequence++;
>> return playTime;
>> }
>> if ( currentSequence >= sequenceCol.size() ) {
>> stopSequence();
>> }
>> return playTime;
>> }
>> }
>>
>> class SequenceBehavior implements Behavior {
>> private int start = 0;
>> public Composable choose(SequentialCollection collection) {
>> return collection.get(start);
>> }
>>
>> public void setStart(int start) {
>> this.start = start;
>> }
>> }
>>
>>
>> _______________________________________________
>> jmsl mailing list
>> jmsl at music.columbia.edu
>> http://music.columbia.edu/mailman/listinfo/jmsl
>>
>
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl
>
More information about the jmsl
mailing list