No song position data between Reason 11 and Max 8 using [rtin]?

Dan Steeby's icon

I'm trying to build a transport integration between Reason 11 and Max/MSP 8 in Windows 10. I am using Max's [rtin] object to get realtime MIDI data through a loopMIDI virtual MIDI port, and while I'm getting 'start', 'stop', 'continue' and 'tick' events from Reason 11 through this object, I'm not getting any 'song position' data, which should be bit 242 in the incoming MIDI data if I'm reading my MIDI implementation charts properly. I have the "Send Song Position Pointer" option checked in my Reason 11 preferences, which I think is what I should need to set to get this working. Does anyone have any insights as to why I wouldn't be getting this data while I'm getting other realtime data events? I've also tried this through a 'real' physical MIDI port, so I don't think that loopMIDI is the cause of the problem at this time. Many thanks for any input!

broc's icon

song position is a 'system common message', not realtime.
So it may not be received with [rtin], try using [midiin].

Dan Steeby's icon

Ah, many thanks. Yes, I see messages coming out of [midiin] that look like this:

print - 242
print - 0
print - 0

That '242' looks like exactly what I was looking for. The 2nd value appears to be the position of the song in ticks (it is 0 in the example above, but this value changes if I start the song somewhere other than the beginning-- it is 16 if I start at measure 1, 32 at measure 2, etc.

Can anyone explain what the 3rd number might be? It seems to be always 0.

broc's icon

The song position pointer counts in steps of 1/16 notes. So you get 16 after 1 bar at 4/4. But as one midi byte can count only from 0 to 127, a second byte is needed and the value is calculated with the formula "byte1+128*byte2".
For example, after 10 bars at 4/4 the song position would be:
160 represented by the midi message 242 32 1.

Dan Steeby's icon

Thanks for that explanation, and that formula looks key. I'm pretty new to Max, so would also like to ask for help on how to handle the 3 messages being sent from [midiin], to listen for the 1st of these messages to be 242, and when that occurs to take the next 2 messages, perform the math operations needed, and spit out a final song position value. I've got a grip on the [*] and [+] objects to do the math for me, it's just the handling of the sequence of messages that has me stumped. Thanks for any additional help!

Source Audio's icon

here is patch with midi clock and SPP both send and receive.

Max Patch
Copy patch and select New From Clipboard in Max.

Dan Steeby's icon

Wow, many thanks! This looks much more robust than what I had cobbled together.

I feel that I'm prettty close to my goal of building a transport integration, but one thing still eludes me. How can I get the transport to set its tempo to match the incoming MIDI tempo? It appears that 'set tempo' midi messages are meta so are not actually transmitted? What would the trick be to get the Max transport to recognize the tempo of the incoming MIDI data and then track it? Thanks again for your help, this has probably saved me a week of research.

Source Audio's icon

why would you track tempo ?
midi clock is running the progress of the ticks,
in my opinion transport would just be disturbing.
If you want to measure incoming tempo
you could bang timer from incoming ticks (sel 248)
and expr 60000($f1*24) to get bpm, but it will fluctuate
and won't be really reliable if one uses float tempos in .00 range
adding round object could also help.

Source Audio's icon

but if you want transport ...

Max Patch
Copy patch and select New From Clipboard in Max.

Dan Steeby's icon

Hi and thanks again, this is really helpful.

My goal is to get Max's transport to 'shadow' Reason 11, so that if I set loop points in Reason the Max transport will loop on those measures as well, if I change tempo in Reason, Max will be able to follow along at the new tempo, and if I scrub to a specific point within Reason, Max will update its position in the transport accordingly.

The latest patch provided doesn't seem to track the tempo coming from Reason. If I set a 4 bar loop in Reason at 200bpm, the patch provided's transport counts up to about 6 bars then resets to the beginning at the loop point, and then just stays at 'start of the track' rather than continuing. I'm hoping to have something that will be able to know Reason is at 200bpm and will set the transport to match that, as well as when the song position is reset to the beginning of the track or some other point that the transport will update its position to match and continue to play back at the current tempo. I also found the transport's 'tempo' outlet and it is currently reading about 73bpm rather than 200.

Can you advise me on how to achieve these things based on the last patch provided, or one of the other previous patches provided?

broc's icon

I've found that Logic sends at loop jump the following messages:

- Stop
- Song Position (loop start)
- Continue

So after connecting the continue outlet (251, see picture) loops work for me as expected. But the tempo recognition seems still unreliable.


Source Audio's icon

that's why I suggested using counter as in my initial patch.
Needs no tempo recognition.
Skipped tick bangs to timer could happen if overdrive is disabled,
or scheduler is set to high value, or cpu load gets high etc.
A shame is that 20 years ago on 100 mhz powerbook all this worked perfectly.

All infos are in front of you, you can see what the clock source is sending
and adjust the patch to that.
Different DAWs also send SPP and Start, Stop, Continue differently.
You have to detect what exactly Resason sends and adjust that.
----------

Source Audio's icon

here is a patch to display order of received messages

Max Patch
Copy patch and select New From Clipboard in Max.

stop spp continue should be correct order of loop turnarround,
stop usually used to send all notes off, before restarting the loop.

Dan Steeby's icon

Many thanks again everyone!

I ran Source Audio's patch again and connected the 'continue' outlet up as Broc suggested and tried again. The loop points are now working as I would expect them to and the tempo tracking seems to be working pretty well at BPM's less than about 130. Above that it seems to lose track of the tempo. I'll know to use this solution for project at slower-than-130-bpm tempos and think about option to get around this issue for faster tracks in the future.

Per Source Audio's most recent patch I was able to confirm that Reason's order of commands seems to match Live's order, thanks for helping to confirm that.

Source Audio's icon

As first I am sorry about a mistake in the patch I posted.
You'll see split 20. 400. which is meant to avoid sending
wrong timer results after a longer pause.
But it should be inserted AFTER the expr and NOT BEFORE.
So tempos higher than 125 bpm (20ms) were ignored.
With that fixed it should run ok, but still,
higher tempos produce large fluctuation at tempo detection.
------------
I can run counter based clock synced slave with all the wild tempo changes
quite reliably.
Could you explain a bit why is transport based solution really needed ?
I have nothing against transport as such, but also see no benefit of it.

You can also try to use hostsync~
Reason as rewire host -> Max should be no problem.
here is patch with both transport and counter receiver

Max Patch
Copy patch and select New From Clipboard in Max.

Dan Steeby's icon

Hi all, and many thanks again, Source Audio, I'll try out this new patch. Strangely, Reason 11 has DONE AWAY WITH REWIRE! It's been ubiquitous for ~20 years, but I guess all things change! I had started my research with Rewire, as I also assumed that would be the way to go, but then made that discovery. Reason 11 DOES now support Ableton Link, so maybe I should use that for tempo control/matching and then use the song position data just to jump to new parts of the track at loop points/scrubbing. I'll review your latest patch and try to come up with a solution based on it and Ableton Link and see how that works out.

As a Max noob, I'm trying to figure out a way to integrate Max with my current workflow, which is Reason 11. I have tried Ableton Live, and while I can appreciate Max for Live, I would prefer to stick with Reason for my traditional DAW work. It seems logical to me that Max would be most useful if it could be synced with a DAW, and the transport could follow along so it is aware of what measure it is in for things like playing back looping bars, making use of [timepoint] objects, etc. I may be totally wrong about this, but this seems like the natural place for me to start from my perspective. Hopefully that adequately explains the 'why' of what I'm trying to accomplish.

Dan Steeby's icon

Source Audio, this new patch's tempo tracking seems to work beautifully. I've got a track in Reason with tempo ranging from 60 to 200 bpm and sliding all over the place, and the tempo is dead on in Max.

Source Audio's icon

Glad it finally works .
It is really surprising that reason gave up rewire.

John J.A. Jannone's icon

Source Audio I tried your patch but I can't get anything - I set up Clock Sync in Reason11's Sync Settings, and typically I have no problem with MIDI moving between Reason and Max... Any thoughts about what I might be missing? Thanks!

Source Audio's icon

Hard to say without exact infos about reason settings
and midi routing.
I am sure it has nothing to do with the patch itself.

John J.A. Jannone's icon

Thanks. I just needed to click "send clock" and it worked great. SMH.