Old 08-15-2014, 04:05 PM   #1
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default Syncing external hardware - a simple solution

If the title caught your interest, you probably have a piece of hardware with a built-in sequencer that you'd like to synchronize with Reaper. For me, it's FutureRetro Revolution - a TB303 clone, where the internal sequencer is an essential part of the deal. Unfortunately, when using external sync from Reaper, it lags noticeably enough to kill all groove, and this led me on a quest for proper MIDI sync solution.

Reaper's option "shift output to MIDI device" didn't help - apparently, the shift time is limited to audio buffer size. My audio card has maximum buffer size of 8192 samples, which is not enough to compensate for a 10 msec lag. Even if it were possible, this would result in all audio being delayed by the same amount, which makes playing much less enjoyable.

Next I considered hardware solutions - InnerClock SynGen and the ExpertSleepers suite of modules and plugins. SyncGen is close to perfect, but very expensive - on par with what I paid for the Revolution! The ES suite is better in that it provides not only MIDI clock, but 5 MIDI outputs with sample-accurate timing. This isn't cheap either, and to use it you need a modular case, two ES modules (one of which is currently out of stock) and their plugin; besides, you must work at 48 Khz.

Back to square one. Problem with Reaper is that when playback starts, it sends MIDI Start immediately, and the device has no time to catch up. If we could give it a count-in (like the drummer counting "1,2,3,4" to other band members), it would have the time to compensate for the lag and start in sync.

So I implemented this idea as JS plugin, and it works.
Plugin page in Reaper stash:

https://stash.reaper.fm/v/21479/adjus...20MIDI%20clock

Direct download:
https://stash.reaper.fm/21479/adjustable%20MIDI%20clock


Important: Make sure to uncheck "Send clock/SPP to this device" in preferences, or your hardware will get two conflicting clocks and probably become very confused (I didn't try it )

Parameters:

slider1: count-in (0,1 or 2 bars).

slider2: additional shift of the MIDI Start message (-10..+10 msec).

slider3: shifts the MIDI clock messages (pulses) back or forward, in percent of a pulse duration.

slider4: clock rate multiplier: normal, half-time or double time. This was added for completeness, and because it was trivial to do. I considered adding odd multipliers too (e.g. 2/3 or 3/2 clock are just as easy to do), but I'm not sure if that's really useful.

I have achieved nearly perfect sync with the Revolution and MPC1000, using slider2=0 and slider3 at about -90%. Interestingly, I found that tempo-based shift works better at different tempos than time-based one.

Please let me know if you find this useful!
Suggestions for improvements are welcome too.
boreg is offline   Reply With Quote
Old 08-15-2014, 07:15 PM   #2
Dannii
Human being with feelings
 
Dannii's Avatar
 
Join Date: Mar 2010
Location: Adelaide, South Australia (originally from Geelong)
Posts: 5,594
Default

Nice one! Just downloaded and will give it a shot later on.
I have a lot of MIDI hardware in my studio and often sync things to REAPER via MIDI (even two computers both running REAPER) and I have had timing issues with some configurations so this will certainly be worth a shot.
__________________
Dannii is offline   Reply With Quote
Old 08-15-2014, 11:47 PM   #3
4x4uk
Human being with feelings
 
4x4uk's Avatar
 
Join Date: Jan 2013
Location: Newcastle UK
Posts: 474
Default

Excellent I will be trying this out later in the week.

All of my outboard gear and guitar racks are midi controlled/sequenced

I have always had midi timing issues and normally have midi timing turned off and use my external sequencer to control timing except when I am creating sending sequences to it from reaper

Last edited by 4x4uk; 08-15-2014 at 11:53 PM.
4x4uk is offline   Reply With Quote
Old 08-16-2014, 02:23 AM   #4
sinkmusic
Human being with feelings
 
sinkmusic's Avatar
 
Join Date: Feb 2006
Location: decepticon mothership in a hidden place inside a mountain
Posts: 3,676
Default

Great, thank you !
sinkmusic is offline   Reply With Quote
Old 08-16-2014, 05:18 AM   #5
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Excellent, really curious to know how it works for you.
boreg is offline   Reply With Quote
Old 08-17-2014, 09:59 AM   #6
Mink99
Human being with feelings
 
Mink99's Avatar
 
Join Date: Jan 2011
Location: Zürich
Posts: 1,008
Default

Hi,

this plug is based on the work of SUBZ
(http://forum.cockos.com/showpost.php...87&postcount=9) very much like the one I had build some weeks ago.

Code:
desc:simple MIDI clock generator even more Simple
slider1:0<-32,32,1>Offset

@init
prev_count = 24;
prev_play_state = 0;

noteOnMsg = $x90;  
noteOffMsg = $x80;

clockMsg = $xF8;
startMsg = $xFA;
stopMsg = $xFC;
contMsg = $xFB;

time_div = 24;

pdc_midi = 0.0;

@slider
// time_div = slider3;

offset_start = slider1;
@block

my_beat_position = beat_position; /* save the current beat_position so we can extrapolate it */
beats_per_sample = (tempo/60)/srate; /* get the beats per sample so we can track the beat position at a given sample */

//offset = 0; /* reset offset from current block start */
offset = offset_start; /* reset offset from current block start */


(play_state != prev_play_state) ? (
  (play_state == 0) ?  midisend(offset,stopMsg,0);
  (play_state == 1 || play_state == 5) ? midisend(offset,startMsg,0);
  prev_play_state = play_state;
);

@sample

_C = (my_beat_position*time_div)%time_div;
prev_count != _C ? (
  midisend(offset,clockMsg,0);
  prev_count = _C ;
);


my_beat_position += beats_per_sample; /* advance the beat with the current known tempo so we are tracking it sample accurate */
offset += 1; /* advance offset so we send the midi notes at the correct time */
while these plugs all work fine, they are just a workaround for the inherent reaper sync problems.
When the design of the Midi Sync features was done, it seemed to be a good idea to tie this clock to the audio clock directly.
but the result is serious problems with PDC.

In the meantime, audio latencies have been enourmously decreased, down to 2 msec, while midi latencies have increased (due to USB problems and awkward or non existing dedicate drivers), under windows.

a major overhaul of this area of sync for reaper would be useful. But, as I see from the responses in the forum obviously the reaper community does not see sync as an issue.
Mink99 is offline   Reply With Quote
Old 08-18-2014, 01:43 AM   #7
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Hi Mink99,

Of course I've studied all available implementations before making my own. While there's no escaping that the basic math remains the same, there are a few significant differences:
  • processing MIDI in @sample block (like in the example you posted) is inefficient;
  • another implementation I've seen does all processing in @block, but still loops over all samples in block to check when to send the clock messages. Again, this is inefficient - I calculate the exact positions of pulses within a block instead. Thus the main loop executes just a few times per block, instead of samplesblock times.
  • finally, no implementation I've seen allows shifting the MIDI start and clock messages, which is kind of the whole point

As for your last point, I don't think the MIDI sync problem is specific to Reaper - if it were, products like SyncGen wouldn't have appeared. IMHO, the problem is that pretty much all MIDI interfaces today work over USB, which was never designed for realtime data transmission.

If anything, I'm grateful that Reaper gives me the tools to DIY a custom solution.
boreg is offline   Reply With Quote
Old 08-18-2014, 12:35 PM   #8
Mink99
Human being with feelings
 
Mink99's Avatar
 
Join Date: Jan 2011
Location: Zürich
Posts: 1,008
Default

No doubt, it is one of the advantages of reaper that you can help yourself.


btw, tested your js against mine on my machine.



Hardware : Win 7 64 : Motu 128 midi express : 360 Midi Patchbay : Volca Drums : audio recorded

Audio : RME Hammerfall DSP on 6 ms latency, 44.1
2 ms difference, jours was 1 ms before the tick and mine was 1 ms behind the tick, both without shifting.

Audio : RME Hammerfall DSP on 2 ms latency 44.1
1 ms difference, jours was 2 ms behind the tick and mine was only 1 ms behind the tick, both without shifting.

I would say, mission accomplished.....

Last edited by Mink99; 08-23-2014 at 07:45 AM.
Mink99 is offline   Reply With Quote
Old 08-22-2014, 04:49 AM   #9
norlee
Human being with feelings
 
Join Date: Nov 2009
Posts: 3
Default

Fantastic! you have solved my biggest gripe with Reaper!

Previously I defected to Studio One 2 - that worked spot on out of the box - but I prefer Reaper, now with this installed my R8 kicks off on time!

Many thanks.

PS. This really should have been addressed in the core software by now, I really can't understand why it's still not fixed.
norlee is offline   Reply With Quote
Old 08-23-2014, 05:54 AM   #10
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Thanks norlee, glad to hear it!
Btw, I made a couple of minor changes (uploaded to stash, same link):
  • No re-sync when switching between play and record
  • Added 2/3 and 4/3 clock multipliers, 'cause they're neat
boreg is offline   Reply With Quote
Old 08-24-2014, 10:22 PM   #11
midiot
Human being with feelings
 
midiot's Avatar
 
Join Date: Feb 2011
Posts: 217
Default

excellent
__________________
midi will out live humanity
midiot is offline   Reply With Quote
Old 09-15-2014, 03:29 PM   #12
whiteaxxxe
Banned
 
Join Date: Jul 2014
Location: United States of Europe, Germany, Mönchengladbach
Posts: 2,047
Default

Quote:
Originally Posted by boreg View Post
As for your last point, I don't think the MIDI sync problem is specific to Reaper - if it were, products like SyncGen wouldn't have appeared. IMHO, the problem is that pretty much all MIDI interfaces today work over USB, which was never designed for realtime data transmission.
Windows is sloppy with MIDI-timing to the outer world, its not Reapers fault. and MIDI was never a realtime-data-protocol, MIDI is a serial protocol. that has nothing to do with USB, USB can handle lots of MIDI-data easily, but loads of such data cause MIDI by itself to get into timing problems. if possible, sent MIDI-data for different devices out on different USB-busses. most of the times that isnt possible, then think of thinning out the MIDI-data stream or move for example PCs more in front of the point, where they should be sent. (there never was this kind of f*** when it all ran on Ataris ...)
whiteaxxxe is offline   Reply With Quote
Old 11-12-2014, 05:03 AM   #13
Mink99
Human being with feelings
 
Mink99's Avatar
 
Join Date: Jan 2011
Location: Zürich
Posts: 1,008
Default

Not 64 Bit ?
Mink99 is offline   Reply With Quote
Old 11-12-2014, 08:30 AM   #14
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Hi TonE,

I wasn't aware of this plugin when I made mine. Of course, if it does the job for you, there's no reason to switch. For my needs, the crucial point is delaying the MIDI start message for a bar or two, thus allowing the external hardware to start in sync - this is a feature this plugin doesn't have.
boreg is offline   Reply With Quote
Old 01-01-2020, 01:53 AM   #15
Kron8089
Human being with feelings
 
Join Date: Dec 2019
Posts: 3
Default

How would i use this to affect an outboard midi sequencer ? I want it to affect the midi out clock to the sequencer but can't seem to get it to work.
Kron8089 is offline   Reply With Quote
Old 01-01-2020, 05:21 AM   #16
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Hi Kron,

Can you elaborate what exactly isn't working?
Does the sequencer start when you start playback in Reaper?

Of course, the external sequencer should be configured for external MIDI sync. Other than that, it's hard to suggest anything without additional details.
boreg is offline   Reply With Quote
Old 01-01-2020, 04:12 PM   #17
Kron8089
Human being with feelings
 
Join Date: Dec 2019
Posts: 3
Default

The sequencer starts when I press play, but the the adjustable midi clock plugin doesn't seem to be doing anything to Reapers timing. Do I have to put it on the master track ?
Kron8089 is offline   Reply With Quote
Old 01-02-2020, 10:45 AM   #18
domzy
Human being with feelings
 
Join Date: Feb 2017
Posts: 4,015
Default

Quote:
Originally Posted by Kron8089 View Post
The sequencer starts when I press play, but the the adjustable midi clock plugin doesn't seem to be doing anything to Reapers timing. Do I have to put it on the master track ?
it's not supposed to do anything to Reaper's timing - it's just for adjusting the MIDI clock output
domzy is online now   Reply With Quote
Old 01-02-2020, 04:55 PM   #19
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Quote:
Originally Posted by Kron8089 View Post
The sequencer starts when I press play, but the the adjustable midi clock plugin doesn't seem to be doing anything to Reapers timing. Do I have to put it on the master track ?
OK, here's a brief user manual ))
  • Add the plugin to a track whose MIDI output goes to the external sequencer.
  • Make sure Reaper does not send MIDI clock to this output (Preferences - MIDI devices - uncheck "Send clock/SPP"); the plugin will do it.
  • Turn on the metronome in Reaper and in the sequencer.
  • Start playback in Reaper. With default count-in of 1 bar, the sequencer will start from the next measure.
  • If the MIDI output is lagging, you'll hear "flamming" between the two metronomes. This is what we're trying to reduce.
  • Stop Reaper, set the "clock offset" slider to e.g. -80% and try again.
  • See if the two metronomes are closer now. If you notice the sequencer is playing too early, move the clock offset towards zero. Basically, tweak until you're satisfied ))
  • If the clock offset doesn't appear to make any difference, try the "start offset".

Hope this helps!
boreg is offline   Reply With Quote
Old 01-03-2020, 03:26 AM   #20
Kron8089
Human being with feelings
 
Join Date: Dec 2019
Posts: 3
Default

Wow ! This effect has saved Reaper for me, finally my entire studio now plays in sync !! Thanks so much Boreg.
Kron8089 is offline   Reply With Quote
Old 01-03-2020, 10:30 AM   #21
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

You're welcome, glad to hear it helped.
boreg is offline   Reply With Quote
Old 05-11-2021, 09:43 PM   #22
deseipel
Human being with feelings
 
Join Date: Jul 2020
Posts: 29
Default

I'd been using Reaper as a Master with an external Korg Electribe. I set Reaper to do a 2 bar count in and it WAS working. The sequencer started when it was supposed to. Suddenly, for reasons I don't yet understand, it stopped working and now just starts immediately when I press play in Reaper.

Did something change in Reaper or is there a setting to control clock & playback with count in? I'm losing my mind
deseipel is offline   Reply With Quote
Old 05-12-2021, 03:56 PM   #23
boreg
Human being with feelings
 
Join Date: Jul 2009
Posts: 157
Default

Hi deseipel,

Make sure Reaper is configured *not* to send MIDI clock and start/stop to this device.
boreg is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.