Here's an example of writing Stream Byter code to divide an incoming clock signal (don't try and use this to multiply...) by an arbitrary fraction. I've defaulted it to 3/4 as this was written for a customer, but you can change the fraction near the top of the rules. It also handles things if the tempo is changed. I have added comments too.
IF LOAD # constants: numerator, denominator ASS K0 = 3 4 # <- change as required
# labels SET LB0 K0 +D SET LB1 K1 +D
# variables ASS L0 = 0 # L0 - tick counter END # load
# start/continue, reset tick counter IF M0 == FA ASS L0 = 0 END IF M0 == FB ASS L0 = 0 END
# process ticks IF M0 == F8
# block all ticks XX = XX +B
# calculations MAT L1 = T00 / K0 # L1 - split in tick interval MAT L2 = L0 % K1 # L2 - tick mod
# expand (delay and send) IF L2 < K0 MAT L3 = L1 * L2 # calc delay SND F8 +DL3 # issue re-timed tick END
# increment tick count (force 0-959 range) MAT L0 = L0 + 1 MAT L0 = L0 % 3C0
END # process tick
Attached is a scene with it in, so you don't even have to copy and paste it!
Multiplication is actually quite a bit harder as ticks have to be added at the right time (tempo wise). Problem is, you don't know the tempo until the second incoming tick, so the first inserted tick will always be wrong. Most apps/devices won't notice this too much.
So, doing simple multiplications like 2X or 3X could be done with the Stream Byter as it stands, but more elaborate multipliers like fractions or > 3 really require Stream Byter to support conditional looping. I plan to add looping in an upcoming update.
If a simple clock doubler would suffice for now, the me know and I can post that here.
Hi Nic, tested and have it working pretty well! By using it though, I realised I send the same midi out to other devices too, which should get the normal, uneffected tempo. So I'm trying to send specific midi notes instead of clock ticks, but I'm not sure I'm doing it wrong in midifire or where I try to pick-up this note... wouldn't SND 99 3E +DL2 send a D4 on channel 10?
A clock tick would be 'F8', but in clock sync, a tick is generated 24 times per quarter note.
If you want to generate notes based on the clock tick (or multiple thereof) you need to count the ticks as they come though (which my code already does) and then calculate whether you want a note to be sent using the % (mod) function.
MAT L2 = L0 % C # on every 12th tick = double speed IF L2 == 0 SND <your note on> SND <your note off> +D200 END
Hi Nic, I’m wondering, since it’s possible to set the tempo of the Dynamic Clock on the fly (eg. via tap tempo), is it possible (if the current tempo has been stored in an array), to apply math to the tempo value directly, and then use that calculated value to set the tempo in Dynamic Clock via Sysex or CCs?
Yes, you can set an absolute tempo value in the Dynamic Clock via a sysex message.
Assuming your tempo is stored in variable 'K0':
ASS L0 = 00 00 00 # empty tempo MAT I0 = K0 / 3E8 # thousands MAT L0 = I0 * 10 MAT I0 = K0 % 3E8 # hundreds MAT I0 = I0 / 64 MAT L0 = L0 + I0 MAT I0 = K0 % 64 # tens MAT L1 = I0 / A MAT L1 = L1 * 10 MAT I0 = K0 % A # units MAT L1 = L1 + I0 SND F0 5A L0 L1 L2 F7
Stream Byter variables are integers, so the above only sets whole number BPM values, even though the sysex message to Dynamic Clock allows for up to 2 decimal places in the tempo value. If you wanted to store/set more precise values (up to hundredths) then you would need to store the post decimal value in, say, K1 and do similar calculations to set the tenths/hundredths byte (L2) in the sysex message.