josef
Converser
Posts: 19
|
Post by josef on Feb 18, 2020 19:50:18 GMT
Hi Nic, I want to ask you to take a look at my script. Found something similar in this thread: audeonic.boards.net/thread/743/cc7-range-127-30-where “CC7 range 0-127 To Range (30-50) where (0=30 and 127=50)” This could almost be the solution for me, but it does not work for inverted ranges. One thing I learned by now is that StreamByter accepts integers only. Well, the manual says that very clearly. What I am not sure about is calculation with negative numbers. My project: CC1 is source for several controllers, scaled to individual ranges. Ranges (lower and upper limit) can be set by sliders in StreamByter. Inverted ranges should also be possible, for instance lower limit 50, upper limit 30, resulting in a negative number for range. My script is working now. Strange is only the number display in the label box for inverted ranges. But outgoing midi values are exactly as they should be. The label display is not important, I will remove this anyway later. Here my code — is there anything wrong or odd? Would be good to know before I continue. Thanks! Josef IF LOAD set name mood_+_bs-16i set sli 1 SET Q0 Cutoff__<def 0 7F SET Q4 Cutoff__>mod 0 7F ASS Q0 = $46 0 0 0 $60 END
IF M0 == B0 01 # ModWheel, Ch. 1 MAT K0 = Q4 - Q0 # range MAT K0 = M2 * K0 IF Q4 >= Q0 MAT K0 = K0 / $127 else MAT K0 = K0 / $128 END MAT K0 = K0 + Q0 IF K0 != K1 # filter duplicates SND B5 $75 K0 ASS K1 = K0 SET LB0 K0 +decimal END END
B0 = XX +B
|
|
josef
Converser
Posts: 19
|
Post by josef on Feb 18, 2020 21:05:13 GMT
update: a few more lines, but no negative values any more. Maybe it could be a bit shorter, but I have no idea at the moment.
IF LOAD set name mood_+_bs-16i set sli 1 SET Q0 Cutoff__<def 0 7F SET Q4 Cutoff__>mod 0 7F ASS Q0 = $46 0 0 0 $60 END
IF M0 == B0 01 # ModWheel, Ch. 1 IF Q4 >= Q0 MAT K0 = Q4 - Q0 # range MAT K0 = M2 * K0 MAT K0 = K0 / $127 MAT K0 = Q0 + K0 else MAT K0 = Q0 - Q4 # inverted range MAT K0 = M2 * K0 MAT K0 = K0 / $127 MAT K0 = Q0 - K0 END IF K0 != K1 # filter duplicates SND B5 $75 K0 ASS K1 = K0 SET LB0 K0 +decimal END END
B0 = XX +B
|
|
nic
Soapbox Supremo
Troublemaker
Press any key to continue
Posts: 2,011
|
Post by nic on Feb 19, 2020 19:45:02 GMT
Hi josef, Yeah, your second script is pretty much how I would have done it. The I, J, K and L arrays are unsigned integers, but the P array is signed, so if you want to work with negative numbers you should use the P array for that. Although that makes no difference to your script since you're always dealing with positive numbers with your if/else clause. Regards, Nic.
|
|
josef
Converser
Posts: 19
|
Post by josef on Feb 19, 2020 21:10:38 GMT
Hi Nic,
your hint with the P array is fantastic! Now I understand what signed integers means. The code is much shorter and easier now. The new script works also perfectly. Thanks! Josef
IF LOAD set name mood_+_bs-16i set sli 1 SET Q0 Cutoff__<def 0 7F SET Q4 Cutoff__>mod 0 7F ASS Q0 = $46 0 0 0 $60 END
IF M0 == B0 01 # ModWheel, Ch. 1 MAT P0 = Q4 - Q0 # range MAT P0 = M2 * P0 MAT P0 = P0 / $127 MAT P0 = P0 + Q0 IF P0 != P1 # filter duplicates SND B5 $75 P0 ASS P1 = P0 SET LB0 P0 +decimal END END
XX = XX +B
|
|