[jmsl] Navigating Sequential Sequence

jmsl at music.columbia.edu jmsl at music.columbia.edu
Tue Apr 28 06:56:18 EDT 2009


Hi Chi

Here's a little demo which does what I think you want.  It start a 
sequential collection with the specified child.  When it gets to the 
end, it replays starting with the originally requested child (in other 
words it loops from N..end, N..end, N..end) . If you mean it should 
restart from child 0 (ie play from N .. end, 0..end, 0..end), then there 
is one line I've commented which you should change to get this behavior.

Let me know if this works for you.

Regarding stopping and restarting from the new cursor position, 
finishAll() and waitForDone() then set new new behavior and launch will 
do it

thanks,
Nick Didkovsky

/*
 * Created on Apr 28, 2009 by Nick Didkovsky
 *
 */
package behavior;

import com.softsynth.jmsl.*;

public class SequentialCursorBehavior implements Behavior {

    int currentCursorPosition;
    int originalCursorPos;

    public SequentialCursorBehavior(int pos) {
        this.currentCursorPosition = pos;
        this.originalCursorPos = pos;
    }

    public Composable choose(SequentialCollection col) {
        Composable nextChild = col.get(currentCursorPosition);
        if (currentCursorPosition == col.size() - 1) {
            currentCursorPosition = originalCursorPos;
            // if you want this to restart at the very beginning of the 
seq then set curr to 0
        } else {
            currentCursorPosition++;
        }
        return nextChild;
    }

    public static void main(String[] args) {
        SequentialCollection seq = new SequentialCollection();
        seq.setRepeats(Integer.MAX_VALUE);

        class TalkingMusicJob extends MusicJob {
            int jobID = 0;

            public TalkingMusicJob(int jobID) {
                this.jobID = jobID;
            }

            public double repeat(double playTime) {
                System.out.println(jobID + "");
                return playTime + 1;
            }
        }
       
        for (int i = 0; i < 5; i++) {
            seq.add(new TalkingMusicJob(i));
        }

        seq.setBehavior(new SequentialCursorBehavior(2));   // start 
with third child (zero based)
        seq.launch(JMSL.now());
    }
}


jmsl at music.columbia.edu wrote:
> 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
>>
>
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl


More information about the jmsl mailing list