Javascript and deferlow

Questions and discussion about building and using Max for Live devices
Post Reply
Posts: 3
Joined: Thu Oct 08, 2020 11:52 am

Javascript and deferlow

Post by ResonanceCascade » 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:

Code: Select all

function loop(trackNum){
	var clipSlot = new LiveAPI("live_set tracks " + trackNum + " clip_slots 0");
	if(clipSlot.get("is_recording") == 1){"stop")
		var clip = new LiveAPI(clipSlot.get("clip"))
		var observer = new LiveAPI(playingStatusChange)
		observer.path = "live_set tracks " + trackNum + " clip_slots 0 clip" = "playing_status"
	} else {
		if(clipSlot.get("has_clip") == 1){"delete_clip")
This is working fine. The issue I'm having is with the callback function playingStatusChange(), which is this:

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)
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!

Posts: 57
Joined: Thu Aug 21, 2014 5:40 pm

Re: Javascript and deferlow

Post by 19oclock » Sun Oct 18, 2020 4:43 am

Here's what's in my setup:

I have one a listener looking at "playing_slot_index" on each of my decks. When the index changes that resets all effects on the given deck; a property change by way of a notification. To fix the error I sent an integer through deferlow and then back into an inlet. It is received here:

An integer on inlet zero calls the function to reset effects on that deck. Pushing a message through deferlow as part of the process ought to fix it. Let me know if this (still) works!

Post Reply