Live API & Call Jump (Javascript)

Christopher Purcell's icon

Hi folks,

I was wondering if somebody could lend some assistance - I'm trying to get to grips with using Javascript in M4L, and I've written a very basic script.

The script is functioning, to the best of my knowledge, but the approach I've used to call "jump" is incorrect, as the script jumps to the wrong marker in the session. I've quoted the troublesome excerpt below.

I believe I understand why: the script is being given the wrong id. I've attached two patchers to illustrate what I've done, and what it is that I need to do, but I don't know how to achieve this!

        function msg_int(id) {
            //input cue_point id, call jump if runningState == 0
                if (runningState == 0) {
                    var pathSet = "live_set cue_points " + id;
                    var pathStr = pathSet.toString()
                    var cuePoint = new LiveAPI(pathStr);
cuePoint.call("jump");
                }                        
        }

Any guidance kindly appreciated.

Thanks!

Chris

callJump - Incorrect id.maxpat
Max Patch

callJump - Correct id.maxpat
Max Patch

Christopher Purcell's icon

As is often the case, perseverance pays off. The path requires the index of the id, not the id itself.

For any other newcomers looking for the same answer: I created an array of the "live_set cue_points" ids, and then queried the location (index) of the incoming int within said array:

yourArray.indexOf(id);

I then appended this index to the path used for "call jump", as per my previous script excerpt.