What's new

Help with basic on controller logic

KrisY

Noob in frenzy loop
Greetings coders. I got a little issue with a pedal script seeming to be correct, but not behaving.

This is my little code that goes off on controller, I want only one controller (sustain pedal/cc64) to trigger a message until the opposite direction has triggered. As to not have multiple triggers on < 64 and so on.

Code:
on controller
        
    if ($CC_NUM = 64)

        if (%CC[64] > 63 and $lastcc64value <= 63) 

            { Pedal DOWN : }

            add_text_line($label,"------------Pedaling DOWN.")
            
        end if
        

        if (%CC[64] < 64 and $lastcc64value >= 64) 

            add_text_line($label,"------------Pedaling UP.")
            
        end if
    
        $lastcc64value := %CC[64]

    end if

end on

{end on controller}
 

EvilDragon

KSP Wizard
Your logic is wrong :)

Code:
on controller
    if ($CC_NUM = 64)
        if (sh_right(%CC[$CC_NUM], 6) # $last_value)
            $last_value := sh_right(%CC[$CC_NUM], 6)

            if ($last_value = 1)
                { pedal down code }
            else
                { pedal upcode }
            end if
        end if
    end if
end on
sh_right is shifting the value of %CC[$CC_NUM] to the right by 6 bits, which is equivalent to dividing with 2^6, which is 64 (which gives you a 0-to-1 flip-flop from MIDI CC that has 0-127 range), but it's faster to do than just regular divide operation.
 
OP
K

KrisY

Noob in frenzy loop
Your logic is wrong :)

sh_right is shifting the value of %CC[$CC_NUM] to the right by 6 bits, which is equivalent to dividing with 2^6, which is 64 (which gives you a 0-to-1 flip-flop from MIDI CC that has 0-127 range), but it's faster to do than just regular divide operation.
Alright, I think I´m starting to get this shift-bits stuff. Thanks for spelling it out. The previous message ended here as well. Though, the script i got above is actually working, I must have done something wrong while testing, one issue was that Logic was sending wacky on-off messages even if the message active was 127 :/.

But the shift-bits version is seems more scaled off, less resource demanding. Great! Will try this out now.

Thanks a bunch! :)
 
Top Bottom