Please help debug/improve my first patch: a DJ style looper for Ableton
EDIT: link to latest version https://maxforlive.com/library/device/9497/dj-looper-v9
Hi guys, I have started learning Max some days ago. My goal was to make a DJ style looper (like the one on Traktor for example) without using a buffer.
Thanks to the great help in this forum I came up with this patch which kinda works!
Still I have some issues:
I am "randomly" getting sometimes the error "live.object: Cannot set LoopStart behind LoopEnd". To solve this particular issue I have added a switch logic to invert the operations of setting loop_start and loop_end properties on the clip but unfortunately this issue isn't solved.

The following is an edge case I was not able to solve. Basically it happens when you load a clip with the start marker placed after an inactive loop as shown in the following image:

The issue here is that when you activate looping the clip start marker will be instantly moved to the loop start position, even before I can set the loop_start and loop_end positions. This is the default behaviour in Live. My problem is that AFAIK there is no way using the Max Live Api to change loop_start and loop_end positions without before activating looping (if looping is deactivated loop_start=clip start and loop_end=clip end). I don't know if there is a solution for this but if anything comes to your mind please let me know!
Not sure I have used the deferlow objects in the right place.
Any suggestion on how to improve performance and stability of the patch in general will be very appreciated!
I would like to make this patch reliable to use in a live situation, so I also can share it with the Ableton community! 😎
This is far beyond my horizon, but I see a little inconsistency in the patch (might have nothing to do with the issue, though) :

ha, ha, that is a funny way to output sum of 2 floats
(zero can be ignored, or ?)
when trigger is needed, and not all the time.
but that is smallest problem of the whole patch.
This game with looping and live etc can be won only if one takes more control
of clip selection and playback from device itself.
the way it is - it functions only after clip starts playing is not going to work well.
in fact it would be better to place audio into device itself and then have freedom to trigger
any portion of it at any time.
synced to live transport or not.
Ehy SOURCE AUDIO, as mentioned the purpose of this device is to have a dj looper synced to Live transport. The clip should not go ahead on its own while you are looping, otherwise when you exit the loop you don't know at what position of the clip you are (maybe the clip is already ended and you don't know, which is bad)
I don’t know what dj looper is.
you are trying to play portions of audio file
sliced by beat values and synced to live transport.
is that dj looper definition ?
you are not queryng clip length ,
but still sum current play position and slice length, which can set loop end to a value exceeding clip length.
Is that intended so ?
No that is a bug, I should clamp the value of loop_end so it never exceed clip end (thanks for the catch XD).
By dj looper I mean the type of looper you find on dj softwares like Traktor, Rekordbox, Serato etc
Updated version with clamp of loop end (we never go beyond the clip end marker). Also I have reworked a bit the logic to switch the order for setting loop_start and loop_end, now it "should" prevent the error of invalid loop range. Please let me know if you have any suggestion or any bug to report!
Link to latest version: https://maxforlive.com/library/device/9497/dj-looper-v9
Does anyone know if there is a way to exit the loop "on beat"?
For example when activating a loop with division smaller the one beat (e.g. 1/8 or 1/16) there is the chance that when you exit the loop your clip is of out of sync by 1/8 or 1/16 respect to the metronome (transport beat). Could be possible to add a logic to force the loop exit to stay on the main beat?
there are many ways to do so,
let's say that you want only subbeats to quantise to 1/4 note
and only when switching looping off, is that correct ?
you separate output 0 of this buttons, let them only open a gate
which triggers at 1/4 beat.
maybe you need to close the gate on other states, like if playback stops,
or if you activate looping using any button before metro executes looping off
through the gate...

you may want to clear ex notifications before saving device,
or at init.
one should not see last audio title you used every time device gets loaded.


Hey! Thank you very much, that's a great idea 😎
I have tried what you have suggested, it seems to work with 1/8 loops most of the times but with 1/16 loops it still goes out of beat when exiting the loop, not sure why. Is there anything else I can try to improve the timing?
Here is the updated patch:

remove all this prints and wire connections to gates etc
directly.
P.S.
why do you run all 12 buttons through the gate ?
I though you want only 1/8 and 1/16 quantised to 1/4 beat.
I know nothing about timing in Live and also not in that
plugin.
When does it actually jump from old to new loop points,
does it run to current loop end if only loop start changed and so on.
In plain max all that could be controlled.
You have to find that out, and in first place while your device
is not in editing mode, because it seems that it differs when it comes to timing of events.
------
then a different question :
if you have audio file in 4/4 time signature and you loop
2nd 16th note in bar 2, and then turn looping off,
quntized or not.
What happens then ?
even if looping 0 was triggered at one of main transport 1/4 beats, but playback continues without jumping ahead or back to bring playback of your audio file 1/4 note aligned
you will allways be off, unless your 16th note slice was
next to 1/4 beat, which is only the 3rd one.
You asked only about getting out of looping, but same applies
to switching between different loop lengths.
if you go from 1/8 loop to 1 Bar loop, then a chance is to be 1/8 off, or ?
I thought that is what dj looper is about,
to pick any slice and run it at any position against main transport ?
All this are only questions, but you need to find answers and
force it to behave as your wished dj looper, whatever that might be.
maybe you need to set new start point before switching looping to off ?
Or you need to quantize looping 0 at position in the bar
which lets your audio file continue playback aligned.
For exampe if your loop is 2nd 16th note in a bar,
then you need 2nd 16th note to turn looping off,
maybe even slightly delayed, to execute before next 16th note.
As I said, I know nothing about timing in Live in that respect.
in normal world, quantized events have idle time,
means you prepare one action to execute
it on next quantized point.
like openning that gate to pass bang at 1/4 quarter note
or at point that matches you current slice.
Do you mean these wires?

They are already direct connections, not sure whay you mean.
The prints are only for debug but the result is the same even removing them.
I have tried this alternative approach, computing the delta between song current time and clip playing position and using a call to move_playing_pos for compensating the delta. Let me know what do you think!

see my P.S. post above