send/receive race condition - track dependencies

Questions and discussion about building and using Max for Live devices
Post Reply
alex-weej
Posts: 7
Joined: Sun Dec 18, 2011 7:17 pm

send/receive race condition - track dependencies

Post by alex-weej » Sun Aug 27, 2017 4:27 pm

Disclaimer: I'm quite new to Max, so apologies if some of this is wrong/presumptuous... :)

In my style I have generally 2-4 bass instruments and a few acid lines, all of which need *usually* follow the same note.

Using a send/receive pair between tracks to effectively have independent 2 MIDI inputs to an instrument would allow you to just punch in a pattern on the track's own MIDI channel, and then use the other channel to transpose this. I tried it, and quickly discovered that it doesn't work properly, because there is a race condition between the two sources of MIDI data -- the data coming via the send/receive arrives late.

I looked for solutions and found that generally they involve putting a reasonably large delay on the direct MIDI data. Too small a delay and it's unreliable, but too large and you introduce noticeable latency.

Aside from a unilateral feature in Live to do this specific thing, I feel like we should be able to solve this directly with M4L if only track dependencies were a thing (not sure how possible this as an automatic feature with Max as the send/receive channel is a dynamic property of the patch), or at least manually specifiable. Effectively you would then be processing MIDI messages within Max in transactions, so two simultaneous notes on the two separate MIDI tracks would arrive together and be processable together.

Does this make sense? Any thoughts?

Thanks all :)

Alex

chapelier fou
Posts: 5264
Joined: Mon May 15, 2006 12:15 pm

Re: send/receive race condition - track dependencies

Post by chapelier fou » Sun Aug 27, 2017 7:19 pm

Why not use Live's internal routing ?
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
iMac 27" Retina i5 3,2 GHz OS 10.11.3 L10.0.1 M4L.

alex-weej
Posts: 7
Joined: Sun Dec 18, 2011 7:17 pm

Re: send/receive race condition - track dependencies

Post by alex-weej » Sun Aug 27, 2017 8:06 pm

I didn't think that was possible because it's not just a simple merge of the MIDI events. If I need a Max patch, I need 2 MIDI inputs somehow, and Live only offers one per track.

chapelier fou
Posts: 5264
Joined: Mon May 15, 2006 12:15 pm

Re: send/receive race condition - track dependencies

Post by chapelier fou » Mon Aug 28, 2017 5:02 am

Not if you route two tracks into one.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
iMac 27" Retina i5 3,2 GHz OS 10.11.3 L10.0.1 M4L.

broc
Posts: 1151
Joined: Mon Jul 26, 2004 8:37 am

Re: send/receive race condition - track dependencies

Post by broc » Mon Aug 28, 2017 9:32 am

Notice that M4L instruments can also be used as *multi-instruments* with 16 different MIDI inputs, if MIDI is routed from other tracks on different output channels.

alex-weej
Posts: 7
Joined: Sun Dec 18, 2011 7:17 pm

Re: send/receive race condition - track dependencies

Post by alex-weej » Mon Aug 28, 2017 10:40 am

If I route two tracks into one, can Max process simultaneous MIDI events somehow? Or at least in a guaranteed order? The use case is having two MIDI tracks trigger notes at the exact same sample time for an arpeggiator.

Will have a play regardless. Thanks

chapelier fou
Posts: 5264
Joined: Mon May 15, 2006 12:15 pm

Re: send/receive race condition - track dependencies

Post by chapelier fou » Mon Aug 28, 2017 12:04 pm

Nothing in the world is simultaneous.
Kidding aside, you should be fine.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
iMac 27" Retina i5 3,2 GHz OS 10.11.3 L10.0.1 M4L.

broc
Posts: 1151
Joined: Mon Jul 26, 2004 8:37 am

Re: send/receive race condition - track dependencies

Post by broc » Mon Aug 28, 2017 12:44 pm

You can use [buddy] to ensure that "simultaneous" inputs are processed in a specified order.

alex-weej
Posts: 7
Joined: Sun Dec 18, 2011 7:17 pm

Re: send/receive race condition - track dependencies

Post by alex-weej » Mon Aug 28, 2017 4:22 pm

Thanks for the tips, both.

I tried setting one MIDI track as the input to another, but between the In / Auto / Off options I couldn't get the MIDI data to merge. Am I missing something there? If I set it to In, it uses the other track's MIDI to control the instrument. If I set it to Auto, it uses the data in the track's own sequencer track.

As for 'buddy', it seems like it's not quite suitable because the MIDI data isn't *always* synchronised. Basically what I realised is that I *must* process the "other" track's MIDI signal first, in order to set the transposition value for any MIDI note coming in on the main channel *even if it is scheduled for the exact same sample*.

So it was probably a red herring to talk in terms of transactions/batching, at least for this particular problem. I just always need to process a specific MIDI input *first* in case they are scheduled for the same sample.

Any ideas?

Thanks again! :)

broc
Posts: 1151
Joined: Mon Jul 26, 2004 8:37 am

Re: send/receive race condition - track dependencies

Post by broc » Mon Aug 28, 2017 5:21 pm

Regarding the timing problem, I think you could just delay all main events by 1ms using [pipe] and if needed compensate by setting the track delay to -1ms.
Last edited by broc on Mon Aug 28, 2017 8:39 pm, edited 1 time in total.

chapelier fou
Posts: 5264
Joined: Mon May 15, 2006 12:15 pm

Re: send/receive race condition - track dependencies

Post by chapelier fou » Mon Aug 28, 2017 7:43 pm

alex-weej wrote:Thanks for the tips, both.

I tried setting one MIDI track as the input to another, but between the In / Auto / Off options I couldn't get the MIDI data to merge. Am I missing something there? If I set it to In, it uses the other track's MIDI to control the instrument. If I set it to Auto, it uses the data in the track's own sequencer track.
Set your "merge" track : monitor to IN, and input source as "no input" (that's the tricky part).
Then create as many MIDI tracks as you need, with this "merge track" selected as output.
MacBook Pro 13" Retina i7 2.8 GHz OS 10.13, L10.0.1, M4L.
iMac 27" Retina i5 3,2 GHz OS 10.11.3 L10.0.1 M4L.

broc
Posts: 1151
Joined: Mon Jul 26, 2004 8:37 am

Re: send/receive race condition - track dependencies

Post by broc » Mon Aug 28, 2017 8:56 pm

chapelier fou wrote:
alex-weej wrote:Thanks for the tips, both.

I tried setting one MIDI track as the input to another, but between the In / Auto / Off options I couldn't get the MIDI data to merge. Am I missing something there? If I set it to In, it uses the other track's MIDI to control the instrument. If I set it to Auto, it uses the data in the track's own sequencer track.
Set your "merge" track : monitor to IN, and input source as "no input" (that's the tricky part).
Then create as many MIDI tracks as you need, with this "merge track" selected as output.
Correct. Thanks for the clarification. I've deleted the wrong part of my previous post.

Post Reply