|
Post by prehm on Mar 26, 2023 22:18:01 GMT
Hey there. i want to write a simple script that shows 2 buttons in the GUI for octave transpose. I want to mention that I have zero experience in coding so please bear with me.. i just read through the tutorial section and here is what I came up with: # StreamByter - Audeonic Apps if load set include factory standard_includes end set Q0 octdown +button Set Q4 octup +button Assign L$1 = $36 if control_q0_moved Math L$1 = L$1 - $12 end if control_q4_moved Math L$1 = L$1 + $12 end Math M1 = M1 - $36 Math M1 = M1 + L$1 what I expect the buttons to do is to alter the value of the variable in increments of 12. since variables can’t hold negative values, I nudged the incoming midi signal down by 36 so that I can transpose three octaves before the variable hits 0. I hope that makes sense.. i can hit install and don’t get an error, but pushing a button does not do anything. could Someone please point me to whats wrong here? thanks! 
|
|
|
Post by redheronmusic on Mar 27, 2023 17:18:52 GMT
You were close. Two adjustments 1. Some of your setup was outside the if load, so the transpose (Assign L$1 ... ) was getting reset with every message reception. 2. You only want to transpose notes, not other MIDI messages, so lets check that the message is a note (MT = 80 or 90, so we just check for MT < 90) before we transpose a message.
One note - if you change transpose while a note is held, you will end up with a stuck note. If this is an issue, there are SB approaches to handle this.
if load set include factory standard_includes set Q0 octdown +button Set Q4 octup +button Assign L$1 = $36 end
if control_q0_moved Math L$1 = L$1 - $12 end
if control_q4_moved Math L$1 = L$1 + $12 end
if MT <= 90 Math M1 = M1 - $36 Math M1 = M1 + L$1 end
We can make this fancier, display the current transpose, check that the transpose stays within +/- 3 octave range, transposed notes remain within valid note range, etc., but this code does work. And you don't really need to do the +36 offset - the math just (mostly) works. (Try it yourself, from install press octdown four times, and you will see notes moved down 48 values.)
|
|
|
Post by prehm on Mar 27, 2023 18:37:10 GMT
Great, thank you! What do you mean by SB approaches? I think stuck notes would indeed be a problem in my use case. What would I have to do to avoid that? Triggering something like a „panic“ event after every button push?
|
|
|
Post by redheronmusic on Mar 27, 2023 19:15:13 GMT
There are other StreamByter (SB) code blocks that keep track of notes that are sounding. When there is a change that would result in abandoned notes (such as changing transposition in this case), they send the appropriate note offs.
|
|
|
Post by prehm on Mar 28, 2023 7:27:35 GMT
Oh cool. Where can I find documentation about these?
|
|
|
Post by redheronmusic on Apr 4, 2023 15:57:21 GMT
The examples I was thinking about were for more complicated cases where we were keeping track of number of note instances from chords, etc.
This case is much simpler, all you need to do is loop 128 times with note off. You might be lucky if your board responds to Cc 123 - all notes off. But some don't.
|
|