Need help with Groups in Duplex

I’m working on a Duplex setup for an APC40MkII, and are making quite good progress, but have been stuck fiddeling with groups for the entire day.
One thing I want to achieve is having the SHIFT button act as, well, a shift button, giving temporary functionality to some buttons. Having them in toggle mode works fine, but I’ve only got it to work partially as a momentary button.
With the groups set up like this, it shows only GroupA when starting and only GroupB when pressing shift, but upon releasing shift, it instead of showing GroupA shows no Group. And this behavior is only from the APC, using the Duplex Window controlls works correctly.

...

Any ideas on how to fix it? More info on how different types and exclusive works would also be greatly appreciated. There are some other quirks I prob need help solving, but lets start with this one.

Oh, haha, i seem to have forgotten to paste in the code. Well, i’ve managed to kind of solve the problem, and since i’ve seen a few others use an APC40 MkII, i’ll share my findings.

The groups and buttons are set up like this in the control-map (sorry for the missing brackets, couldn’t figure out how to get them showing with the brackets still there):

State name=“ShiftStateA” value=“D-7” match=“0” type=“trigger” hide_when_inactive=“true” active=“true” exclusive=“alt”
State name=“ShiftStateB” value=“D-7” match=“127” type=“trigger” hide_when_inactive=“true” exclusive=“alt”
State name=“BankStateA” value=“G-7” match=“0” type=“trigger” hide_when_inactive=“true” active=“true” exclusive=“altbank”
State name=“BankStateB” value=“G-7” match=“127” type=“trigger” hide_when_inactive=“true” exclusive=“altbank”

Param value=“D-7” type=“button” name=“Shift” size=“0.8” maximum=“127” minimum="0 "
Param value=“G-7” type=“togglebutton” name=“Bank” size=“0.8” maximum=“127” minimum=“0”

The reason why i couldn’t get it working is beacuse the APC sends NOTE_OFF with value 0x7F(127). This usually isn’t a problem, however, the check in StateController.lua doesn’t properly take this into account when in trigger mode and matching to value.

Modifying this statement (beginning on line 93 in StateController.lua):

    if (state.xarg.match == msg_val) then
      self:enable(state.xarg.name,msg)
    else

to instead look like this

    if (state.xarg.match == msg_val) or
    ((state.xarg.match == 0) and msg.is_note_off )then
      self:enable(state.xarg.name,msg)
    else

fixes the problem. It adds an extra statement that makes NOTE_OFF count as true if matching to value 0 (match=“0”). There is probably better ways of doing it. Maybe during message construction, instead of only using the msg.is_not_off variable, one could also set the value by multiplying it with the last bit of the first digit of the status byte (<100x>? ?? yy, value = x*yy), since it will always be 0 if note off and 1 if note on, no matter how manufacturers choose to set the note off value.

On a side note, this also makes the BANK button function properly for state control, if set as togglebutton, thats why i included the controlmapping for that as well.
Naively i thought that this would also be true for the PAN, SENDS and USER buttons, since they function exactly the same. All act as toggle buttons, all send note on 127 and note off 127, all have a led. If controlling states, they work as toggles but without leds lighting up (or they do light up if activated from the duplex control surface, not from the APC) if both state and button is set to toggle.
So why keeping the buttons as togglebuttons but changing the state to “trigger” makes on button work perfectly and completly breaks the others, I have no idea.

Hey, I’m thinking of getting an APC40 mk2 and was hoping you might have shared your script somewhere? (I’ll happily contribute in github etc…)

Also, are you still finding it a useful tool with Renoise?