|
Post by mikefloutier on Mar 11, 2022 22:08:53 GMT
OK, if that works for you. The normal variables (I, J, K, L) in SB are 16-bit, unsigned. That means they can store only positive values up to 65535 (2^16 - 1). That's good for most stuff, but a little small for precise calculations. The code I referenced uses the P array, which stores 32-bit signed integers. That means it can handle very large numbers, both positive and negative. These are the usual integers in modern computers. That lets me directly divide 6000000 by the SB value of BPM to get the ms per beat. (Although that value itself is small. Not sure how SB would handle the arithmetic without P though.) The P array is described in one sentence of the manual; easy to overlook. Many thanks Dave, I’ll hunt it down.
|
|
|
Post by mikefloutier on Mar 13, 2022 16:01:25 GMT
Hi Dave, I’ve been making, trying to make, some mods to my main bit of code with this AR-909 handler BUT have come up against a brick wall in my understanding.
I’m trying to detect 3 types of pedal presses; < 250ms, 250 - 500ms, and > 500ms.
This is my code but it only seems to result in one outcome, any ideas. Think I may have the If, Else, End thing messed up but...😂
If M0 == B0 $21 # detect CC21 on Ch 1 Snd B0 $22 $127 # toggles AB3 transport on quick tap, NB keep it < 250ms! End
If M0 == B0 $21 # detect CC21 on MIDI channel 1 Ass timer = T00 # read timer (presumably on 127, press) If M2 == 0 # CC value is 127 on press, 0 on release Ass theDelay = 0 # zero delay for the first pat switch If timer > $250 If timer < $500 # shortish click, hence pat seq 0,1,2 or 2,3,0 UpdatePattern # switch immediately to fill, from Pat 0 or 2 Ass basisDelay = $1400 # Ass a 1.4sec delay to next pat select realDelay basisDelay # get theDelay from basisDelay UpdatePattern # delay allows for cymbal crash on beat 1 End else # is a hold, so revert to main or alt, after fill (eg. 0,1,0) If timer > $500 # to cater for a < 250ms tap; used to start transport UpdatePattern # immediate switch to fill (delay 0). Ass basisDelay = $1600 # just after end of fill realDelay basisDelay # get theDelay from basisDelay UpdatePatternRevert # revert to main or alt pat End End End End
|
|
|
Post by uncledave on Mar 14, 2022 10:39:11 GMT
Hi Mike. Yes, I think so. My first boss had a commenting technique that's useful here. It's the "Here with" comment identifying the reason a group of statements is executed. It clarifies the logic that brought execution to a certain place. In your code it would be If timer > $250 If timer < $500 do stuff End Else # here with timer <= 250 If timer > $500 do stuff End End
So the second block obviously isn't going to fire. It's just the else to the upper one, like If timer > $250 If timer < $500 do stuff Else # here with timer >= 500 do long press stuff End Else # here with timer <= 250 do short press stuff End
|
|
|
Post by mikefloutier on Mar 14, 2022 22:04:31 GMT
Sorry Dave, I’m not getting it, are you saying I can’t have my If in between the Else and the End?
Or is it something different?
The reason I put in the “If timer > 500ms” was partly to handle a longer hold BUT also because without it the “hold” code would be triggered by a “start/stop transport” short click.
|
|
|
Post by uncledave on Mar 15, 2022 0:00:11 GMT
Sure, you can have the If there. But it's meaningless, since you only get there when the outer If condition is False, so as my comment says, timer is <= 250. So If timer > $500 will never happen, at that point in the code. My rewrite sorts out the 3 conditions: >= 500, > 250, and <= 250.
|
|
|
Post by mikefloutier on Mar 15, 2022 8:42:16 GMT
Sure, you can have the If there. But it's meaningless, since you only get there when the outer If condition is False, so as my comment says, timer is <= 250. So If timer > $500 will never happen, at that point in the code. My rewrite sorts out the 3 conditions: >= 500, > 250, and <= 250. Thanks Dave, I think I get it now. Having seen the nesting business with Ifs, I was concentrating on the AND side of things, forgetting that my 2nd If would be ignored if the first was false. Trying to run before I can walk 😂
|
|