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
to instead look like this
if (state.xarg.match == msg_val) or
((state.xarg.match == 0) and msg.is_note_off )then
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.