Adding a value with a timer

Scr1pter

2016-06-21 09:17:33

Hi,

Is it possible to create a variable which gets higher when a timer gets repeated?
For example:
You create a rule in a timer:
zq=50

The timer gets repeated 5 times with a repeat delay of 1000 ms.
On another translator I used the variable zq as mouse movement X.
I expected that the cursor jumps from 50 to 100, then to 150 etc.
However, it stays at 50.

I also tried something like
zq=50
zr=zq+50
and used zr as X in the mouse movement.

The mouse movement is just a test, I need this functionality for something else.
(But with the mouse movement I can test it very well.)

Thanks for any help!

Scr1pter

2016-06-21 15:25:58

OK, I've already solved it.
Took a bit time, but it seems fine.

Thanks anyway.

Scr1pter

2016-06-21 16:59:16

Well, it's almost solved.
I still have a small issue and hope somebody can help me out.

I use a timer to get the sequencer time of my DAW.
Once the sequencer get started, the timer's variable gets filled with ms.
(Both are synced)

When I press a key in my sequencer, I jump to another section.
In order to smoothly jump to a section, I use MTS, and it really works!

But my problem is, that I need some kind of formula, otherwise the rule field will
contain plenty of lines and it will not work forever but until the last line.

In this example it's 100 BPM, so each measure is 2,400 seconds long.
I work with three variables:
gc = is inside of the timer (value is 5)
zt = is the running time of the sequencer, zt=zt+gc (each 5 ms it gets raised by 5)
zq= is the delay time which will be calculated (it delays the key when jumping to a section)

In practice this means:
When you are between two measures (e.g. measure 3 and 4) and press a key,
MTS will wait until measure 4 has been reached.
Then it will jump.

Currently this is the code:

Code: Select all

zt=zt+gc
if zt<2400 then zq=2400-zt
if zt>2400 then zq=4800-zt
if zt>4800 then zq=7200-zt
if zt>7200 then zq=9600-zt
if zt>9600 then zq=12000-zt
if zt>12000 then zq=14400-zt
As you can see, once the sequencer ran for more than 12000 seconds, it will not work anymore.
In theory the formula would be:
x = zt/2400
if x is not Integer (e.g 3,1) round it up till the next integer (4).
Then zq=zt*4.
Example:
You press the key at 3600 ms.
Then you calculate 3600/2400, which is 1,5.
MTS makes a 2 out of the 1,5 and calculates 3600x2, which would be 7200 - measure 4.

I have no idea if such a code is possible in MTS.

Edit
This code seems a bit better, but sometimes it's a bit too early or too late I think

Code: Select all

zt=zt+gc
if zt==4800 then zt=0
if zt<2400 then zq=2400-zt

florian

2016-07-04 15:03:55

Hi, not sure what MTS is (Multitrack Studio?), but such a formula is definitely possible with MIDI Translator Pro (MT Pro).

I believe the general formula you're trying to implement is:

Code: Select all

wait_time = next_bar_boundary - current_time
with
next_bar_boundary = round_up_to_multiples_of_2400(current_time)
with
round_up_to_multiples_of_2400 = round_up(current_time / 2400) * 2400
A division in MT Pro will always round down, but you can force rounding up with a trick:

Code: Select all

round_up = round_down((current_time + 2399) / 2400)
So, in terms of MT Rules, it looks like this:

Code: Select all

zt=zt+gc
zq=zt+2399
zq=zq/2400
zq=zq*2400
zq=zq-zt
However, your problem can be solved in a more elegant way: The slightly esoteric % modulus operator. It calculates the remainder of a division. So you can just subtract the remainder of a division by 2400 from 2400 and get the number of milliseconds to the next 2400 boundary:

Code: Select all

zt=zt+gc
zq=zt % 2400
zq=2400-zq
The only drawback is that if you're exactly on a boundary, it'll delay for the entire bar. You can work around that by starting the timer with zt=-5 instead of 0. Or, e.g. calculate the new time after the calculation:

Code: Select all

zq=zt % 2400
zq=2400-zq
zt=zt+gc
OR, add an if statement (if you cannot prevent it):

Code: Select all

zt=zt+gc
zq=zt % 2400
zq=2400-zq
if zq==2400 then zq=0
Hope that makes sense!
Florian

PS: all rules are written by hand, let me know if they don't work!