Syncing multiple loops using Groove

My ultimate goal with my current Max project is to create a software version of the ‘Electrix Repeater’ so that I can:

- record loops and overdub on a channel
- create multiple synced loops that can be individually triggered or volume adjusted

I’m currently using a groove object to record, and I am using a bang signal to a timer that is setting the end position when I toggle my recording on and off.

I have successfully created a second groove object and buffer in order to add a second loop. I can get the timing of the loops to be even, but the problem is that I am not matching the start point of the two loops, so they are only in sync if I trigger the second recording at the exact point that the first loop starts.

I am trying to set it up to properly sync both loops at no matter what point I begin my recording.

My next challenge is to add the ‘sound on sound’ looping to each individual track, so that I can essentially add an overdubbed track while also retaining the previous recording, and allow this to go on infinitely. I am still working on that challenge as well.

As a matter of fact, I’ve just finished patching an overdub/sync/slice with groove~/record~.
I finally got it working, but must say, that you will probably save yourself lots of trouble by using the signal-approach instead (index~/play~/wave~,whatever..and poke~).

If you want to stick with groove~, here’s what i did:

For overdub, use two buffers per loop and "swap play/record".
For sync, i took some inspiration from the fripp~ external (which sadly didn’t work for me):
Instead of "hard-triggering" the recording of a second loop, send the master loop-length to the second looper and delay the record off trigger to match the loop length. This way you can start recording the second loop whenever it hits you, record over multiple passes of the first loop, and still stay in sync.
I also (optionally) multiply the sync-loop-length with a sync-factor, so I can record f.e. a 9/8 against a 4/4 loop.

Two more little tips (these apply for max4.6, don’t know bout max5):

Don’t use send/receive for time-critical tasks. Even when scheduler in audio interrup is checked, they will sometimes arrive one vector too late.

Don’t send a "set buffer" message to a groove~ immediatly followed by a play message. Sometimes groove~ just won’t start to play. This one really drove me crazy, because it only happens very rarely. Rather switch between two groove~ objects instead.

Use the "setloop" message for loop start/end pos. Seems to work more reliable than the inlets.

I’d really like to post my patch, but unfortunately it ended up real messy, so I don’t think it will be of any "educational" value.

I think AndrewB’s index~/poke~ patch should really make it into max’s examples/tutorial folder.
IMO, it isn’t obvious, that you can actually play/record into the exact same sample in a buffer at the same time. And this patch is beautifully simple,too.