Javascript and deferlow
Posted: Sat Oct 17, 2020 10:31 am
I'm trying to do some simple clip controlling with the Javascript LiveAPI (code below) but for the live of me I cannot figure out how to use "deferlow" when getting the "jsliveapi: Changes cannot be triggered by notifications. You will need to defer your response." error.
My code basically runs off of function list() which receives the output of midiparse. When a certain note is played, the following code runs:
This is working fine. The issue I'm having is with the callback function playingStatusChange(), which is this:
What the code should do is to simply set the start and loop markers of the clip to its length - 4 beats, so that it loops the last measure of the clip.
This is where I'm sometimes getting the above mentioned error. The clip always starts playing, so the "fire" call is working, but it'll occasionally skip setting the markers.
So, my question is, is "deferlow" a keyword that I need to add before the .set() calls? I've only found info about the "deferlow" object, but nothing about using it in Javascript. The script has the default outlet but I'm not using it. Should I remove that? Or should I just wire up the outlet to a deferlow object regardless?
Any hints are much appreciated!
My code basically runs off of function list() which receives the output of midiparse. When a certain note is played, the following code runs:
Code: Select all
function loop(trackNum){
var clipSlot = new LiveAPI("live_set tracks " + trackNum + " clip_slots 0");
if(clipSlot.get("is_recording") == 1){
clipSlot.call("stop")
var clip = new LiveAPI(clipSlot.get("clip"))
var observer = new LiveAPI(playingStatusChange)
observer.path = "live_set tracks " + trackNum + " clip_slots 0 clip"
observer.property = "playing_status"
} else {
if(clipSlot.get("has_clip") == 1){
clipSlot.call("delete_clip")
}
clipSlot.call("fire")
}
}Code: Select all
function playingStatusChange(data){
if(this.get("is_recording") == 0 && this.get("is_playing") == 0 && this.get("is_triggered") == 0) {
if(this.get("length") > 4){
var loopStart = this.get("length") - 4;
this.set("loop_start", loopStart)
this.set("start_marker", loopStart)
}
this.call("fire")
}
}This is where I'm sometimes getting the above mentioned error. The clip always starts playing, so the "fire" call is working, but it'll occasionally skip setting the markers.
So, my question is, is "deferlow" a keyword that I need to add before the .set() calls? I've only found info about the "deferlow" object, but nothing about using it in Javascript. The script has the default outlet but I'm not using it. Should I remove that? Or should I just wire up the outlet to a deferlow object regardless?
Any hints are much appreciated!

