Periodically outputting an element from a list

Chalisque's icon

Hi,

Sorry if this has been asked before, or there is an easy solution I missed.

I want to take a list, say, [60,62,64,65,67,69,71] and then output
60 immediately,
followed by 62 a delay (say 300) later
followed by 64 another interval of 300 on
followed by 65 after another interval.

Is there an easy way to do this?

Lee's icon

hi

Max Patch
Copy patch and select New From Clipboard in Max.

try this

Chalisque's icon

Thanks. I ended up learning about Javascript tasks and wrote:

inlets = 2;
outlets = 1;

var delaytime;

function msg_int(a) {
    if( inlet == 1 ) {
        delaytime = a;
    } else if(inlet == 0) {
        list(a);
    }
}
function maketask(x) {
    var z = x;
    return function() { outlet(0,z.shift()); };
}
function list() {
    if( inlet == 0 ) {
        var a = [].slice.call(arguments);
        new Task(maketask(a),this).repeat(a.length);
    }
}

though it's nice to see a pure Max version.

Christopher Dobrian's icon
Lee's icon

mine wins ;)

Wetterberg's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I like this way:

Using javascript for basic sequencing seems... irrational to me. I don't know.

Roman Thilenius's icon

javascript ... sequencing ... irrational ... agree.

[zl nth] and [counter] is all you need.

Wetterberg's icon

I did it with my method because I can then:

1) Stop the count. If it's a feedback loop it just goes.
2) Modify the count direction and parameters easily.
3) I can replace the metro with a different system, for instance [transport]. This makes it work with larger patches.
4) 9/10 times you know exactly how long the list will be (I suspect OPs list is always the same length) so the zl nth bit can easily be omitted, making my patch, like, 3 objects.
5) you can feed the list into a multislider, and have a good visual representation of the data. Then you can just use the "fetch" method, and skip the nth bits.

Christopher Dobrian's icon

I'm certainly not trying to engage in a debate of whose solution is better, but just want to point out a "feature" of the solution I linked to. Each list that comes in is immediately sent to pipe with the appropriate timings, so pipe then takes care of all the memorization and scheduling of the individual events (and one could even stop or flush all of the remaining events if need be, by sending the appropriate message to the pipe). So by that method each list that comes in gets handled fully and independently, whereas with some other methods a subsequent list might interfere with the prior one's completion. Depending on what one wants, it might be considered desirable to have all lists get handled fully, or it might be considered desirable to supersede (abandon the remaining events of) the prior list if a new one comes in. If one wants to devise a system whereby each incoming list gets appended and doesn't get sent out until the previous one is completed, that would be yet another way to handle things.

Lee's icon

Damn, I meant to put a wink after my comment...

oh...

I blame the OP for not giving tight enough requirements. shame on you!

:)

Roman Thilenius's icon

"i like wetterberg’s but it also leaves a metro on when there is no list input, which is inefficient scheduler-wise."

except when you make sure that the metro does not run when not needed, like good girls do.

-110