Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Toggle button not working #26

Open
noamsmadja opened this issue May 8, 2020 · 12 comments
Open

Toggle button not working #26

noamsmadja opened this issue May 8, 2020 · 12 comments

Comments

@noamsmadja
Copy link

noamsmadja commented May 8, 2020

I was trying to set up a toggle button as such. the button lights up when pressed once. then turns down when pressed again. thus trying to set up toggle mute. but, it so happens i need to press the button twice for the toggle to happen.

i think the problem is, said button outputs value 127 when pressed first. then value 0 when pressed again. where in the miditoobs, the toggle is expecting 127 each time the button is pressed.

i tried editing config manually but i dont see a field for the value. as in when value 127 mute: true. then create another listener for that midi key with value 0 mute: false.

am i doing something wrong?

@lebaston100
Copy link
Owner

Currently that is intended behaviour. But i want to change that in the future. It's the same base problem as this one: #24

If you want to use the toggle function in the meantime you have to program your controller to send a value of 127 every time the button is pressed.

@cpyarger
Copy link
Contributor

cpyarger commented May 10, 2020 via email

@LukeBoland
Copy link

I changed

    def handle_midi_input(self, message, deviceID, deviceName):
        self.log.debug("Received %s %s %s %s %s", str(message), "from device", deviceID, "/", deviceName)

        if message.type == "note_on":
            return self.handle_midi_button(deviceID, message.channel, message.type, message.note)

to

    def handle_midi_input(self, message, deviceID, deviceName):
        self.log.debug("Received %s %s %s %s %s", str(message), "from device", deviceID, "/", deviceName)

        if message.type == "note_on" or message.type == "note_off":
            return self.handle_midi_button(deviceID, message.channel, message.type, message.note)

and then manually added a "note_off" entry in the config file to get this behavior.

That seemed to be the only change needed in main.py. I may look at setup.py next to make button-mapping easier...

@lebaston100
Copy link
Owner

Implementation is the easy part here, the thing i'm worried about is UX. Because for the controllers that use "note_on" and "note_off" you get a "double" even which could confuse users.

@LukeBoland
Copy link

Well, that's what's working for me, and at least there's enough information here for others who need that functionality to implement it, and get running.

Might need to add a question like the "is this a fader or a button" for buttons that asks whether it's a momentary or toggle button, and if toggle, what to set the on and off to separately. Or ignore the off.

Two very similar edits got setup.py working with mapping note_off.

@lebaston100
Copy link
Owner

yea, the information is now here if someone needs it.
I'll think about how to aproach that because it's the same for the value in control_change messages.

@widdowson
Copy link

widdowson commented May 15, 2020

You might also consider having the config prompt ask someone to press and release a button. Then, have them do it again.
That will either give you four events (If I'm understanding this issue correctly) 1) on 127 2) off 127 3) on 0 4) off 0, or it will give you potentially enough data from which to autodetect what kind of button/toggle something is.

That's a little more "automagical" of a solution; your choice of course on whether you want to be intuitive and sensing, or explicit, in your UX.

@noamsmadja
Copy link
Author

I changed

    def handle_midi_input(self, message, deviceID, deviceName):
        self.log.debug("Received %s %s %s %s %s", str(message), "from device", deviceID, "/", deviceName)

        if message.type == "note_on":
            return self.handle_midi_button(deviceID, message.channel, message.type, message.note)

to

    def handle_midi_input(self, message, deviceID, deviceName):
        self.log.debug("Received %s %s %s %s %s", str(message), "from device", deviceID, "/", deviceName)

        if message.type == "note_on" or message.type == "note_off":
            return self.handle_midi_button(deviceID, message.channel, message.type, message.note)

and then manually added a "note_off" entry in the config file to get this behavior.

That seemed to be the only change needed in main.py. I may look at setup.py next to make button-mapping easier...

I made the change you suggested but i couldn't figure about where to add the "note_off" in the config file.
"5": { "msg_type": "control_change", "msgNoC": 112, "input_type": "button", "action": "{\"request-type\": \"ToggleMute\", \"message-id\" : \"1\", \"source\": \"elgato\"}", "deviceID": 1, "bidirectional": false }

this is the code that was added for the toggleMute button i chose. but i don't see a "note_on" so it is not obvious for me how to duplicate the entry with a note off

@lebaston100
Copy link
Owner

Your controller seems to send control_change messages, not note_on or note_off.
If you use the most recent setup.py from github there will also be a value named msgVoV that is the midi control change value. You would have to add a check to the main.py to check for that value, that's something i will do in the future.
Or you can try to reprogramm your controller to send note_on and note_off, these would go into the "msg_type" field.

@noamsmadja
Copy link
Author

updated my setup.py with the one on github.
{also, my coding skill is very basic but thought i would try to help 👯 }

i see now that my controller sends control_change and i can't change that in my controller. with that said i headed to main.py to try and figure where to start:

I figured that since handle_midi_input receives message.type: "control_change" the handle_midi_fader function is handling my input. I was thinking that by allowing the function to add "or value == 0" in the if statement, it will also fire the toggle but it didn't do the trick.
if input_type == "button": if (value == 127 or value == 0) and not self.send_action(result): continue

since my toggle sends either 0 or 127 i thought the problem is that nothing fires when it sends 0 but i guess i didnt understand that correctly :D

I will wait for that feature to be added since it seems I can't figure how to implement it myself :)

@lebaston100
Copy link
Owner

Try something in that direction instead. I've not tested in but in theory it should check if the msgVoV matches the current input value so it doesn't trigger the same action twice.
if input_type == "button": if value == result["msgVoV"] and not self.send_action(result): continue

@noamsmadja
Copy link
Author

worked.

changed to what lebaston100 suggested and set the button a setMute. then headed into the config file du[licated the entry and changed to mute on 127 and unmute on 0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants