nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Sept 25, 2017 18:31:36 GMT
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! Regards, Nic.
|
|
|
Post by Dan on Dec 30, 2017 19:31:55 GMT
Hi Nic ...any chance for a clock multiply instead? Cheers
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Jan 2, 2018 11:12:33 GMT
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.
Regards, Nic.
|
|
|
Post by Dan on Jan 2, 2018 16:02:10 GMT
Hi Nic, thanks for your reply, it does make perfect sense. Ideally I'm looking for (up to) x16, but even a x2 or x4 would be an improvement.
In case, I'd like to use it with a midi-to-cv, to drive some eurorack modules at a much faster tempo and be able to get back the original clock with a clock divider module...
Thanks a lot
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Jan 8, 2018 12:58:59 GMT
Hi Dan,
Here's Stream Byter code for a clock doubler that you can try out. You could chain copies of this in series to make 4x, 8x, 16x.
The second tick in each block will always be wrong since we don't know the tempo until the second tick but once running I think it should stabilise OK.
Let me know how you get on.
IF LOAD ASS L0 = 0 # tick count END
# reset tick count IF M0 >= FA IF M0 <= FC ASS L0 = 0 0 0 END END
IF M0 == F8 ASS L1 = T0 IF L0 > 0 MAT L2 = L1 / 2 END SND M0 +DL2 # increment tick count (force 0-959 range) MAT L0 = L0 + 1 END
Regards, Nic.
|
|
|
Post by Dan on Jan 12, 2018 8:47:37 GMT
Hi Nic, Thanks a lot for this! I’ll give it a try over the weekend and let you know
|
|
|
Post by Dan on Jan 14, 2018 12:58:28 GMT
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?
Thanks
|
|
|
Post by Dan on Jan 14, 2018 13:06:21 GMT
Ah, I was missing the velocity, SND 99 3E 7F +DL2 would work! Thanks again Nic
|
|
|
Post by Dan on Jan 14, 2018 15:49:09 GMT
spoke too soon, it goes super-fast probably not sending M0 breaks something... are FA, FC, F8 clock ticks?
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Jan 15, 2018 10:29:17 GMT
Hi Dan,
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.
Something like:
MAT L2 = L0 % C # on every 12th tick = double speed IF L2 == 0 SND <your note on> SND <your note off> +D200 END
Regards, Nic.
|
|
|
Post by Dan on Jan 15, 2018 23:57:07 GMT
Thanks again Nic, getting much closer now! This is what I have at the moment
IF LOAD ASS L0 = 0 # tick count END
# reset tick count IF M0 >= FA IF M0 <= FC ASS L0 = 0 0 0 END END
IF M0 == F8 MAT L2 = L0 % 3 IF L2 == 0 SND 9F 7F 7F SND 8F 7F 7F +D200 END
MAT L0 = L0 + 1 END
Which kicks my trigger every 1/8 There’s an issue with stop/start though: sometimes, right on stop, it manages to emits the note anyway. when this happens on restart it’ll be off phase
Shouldn’t L0 = 0 0 0 reset L0, L1 and L2? Or am I missing something else? Like what you mentioned about the second tick being always off?
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Jan 16, 2018 10:31:56 GMT
Yes, ASS L0 = 0 0 0 will reset L0 to 2
I think what is happening is that the extra tick is the last duplicated tick which will be after the STOP.
The solution would be to add another flag variable (L3) that you set to 1 after seeing FA or FB and 0 after FC.
Then in your M0 == F8 section also check that L3 is 1 also.
Regards, Nic.
|
|
|
Post by Dan on Jan 16, 2018 23:08:18 GMT
...and that did the trick, fantastic! Didn’t have much time to stress-test it but seems to be stable enough Thanks a lot Nic
|
|
lid55
MidiFire Beta
Posts: 68
|
Post by lid55 on Jan 23, 2018 1:23:33 GMT
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?
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Jan 23, 2018 11:24:49 GMT
Hi lid55 , 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 F7Stream 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. Regards, Nic.
|
|