How to toggle MIDI buttons?

Monte

2011-01-28 16:56:16

My organ console have MIDI buttons with two conditions: on or off. They send and receive program change messages of the form: CB pp (the same message for on and off). I want to use 4 of the buttons with the following behaviour: it is not allowed that more than one button is on, but it is allowed that no button is on. So if there a button is on and I am activating another button, the first button must go off. Obviously the translators have to handle the status of the buttons with global variables. But I have no idea how to do this.

Attigo

2011-02-02 17:55:20

Hi Monte,

This a good question, I can help you out for sure, but first, a little more detail...

When you press one button, do you want to send just a Note ON or a Note ON and OFF? This also applies to the other button being pressed, do you want this to send a Note ON and a Note OFF for the other button it is deactivating?

thanks,
Scott

Monte

2011-02-02 22:52:41

Hello Scott,

it's not important to me which messages the buttons are sending. But to simplify the process all buttons should work similar.

Monte

Attigo

2011-02-02 23:20:55

I understand that, but how do you want them to act though? Read my last post...

Do you want the button you press to turn off the other button that could/would be on, in terms of messages, not LEDs? Or will the button send a Note ON on press and Note OFF on release?

Maybe I'm not explaining this clear enough?

Scott

Monte

2011-02-02 23:42:28

Hello Scott,

unfortunately my english is to bad, I think I don't understand your question really.
Do you want the button you press to turn off the other button that could/would be on, in terms of messages, not LEDs?
It is important that the LED's show the correct state of the buttons.
Or will the button send a Note ON on press and Note OFF on release?
The button is sending a program change message on press and no message on release.

I hope, this helps?

Monte

Attigo

2011-02-03 14:17:01

Ok, yes, thes helps, but do you know which messages you need to send to turn the LEDs on or off?

Scott

Monte

2011-02-03 19:54:33

Hello Scott,

the LED'S can't be toggled seperately, if you press the button once the LED will light on, if you press the button next time the LED will light off.

Best regards,
Monte

Attigo

2011-02-03 20:20:59

Ok, so this sounds like functionality built into the firmware that you will not be able to over-ride. Do you think this is possible?

Scott

Monte

2011-02-03 21:54:20

Hello Scott,

I don't know if it is possible with MT, but I think it is possible to write a program which can handle this. Here an idea how to do it in pseudo code:

Code: Select all

init() {
	number_of_buttons = 4;
	off = false;
	on = true;
	// button[i] stores the state of the buttons
	for i=1 to number_of_buttons do button[i]=off;
}

send_to_organ(program_change i) {
	// send MIDI message CB i to organ console
	...
}

receive_from_organ() program_change i {
	// receive MIDI message from organ console
	// toggle stored button state, but don't send back to organ
	toggle_button(i, false)
	...
}

toggle_button(i, really_send_msg_to_organ) {
	if really_send_msg_to_organ then send_to_organ(i);
	if button[i]==on then button[i]=off else button[i]=on;
}

proc_main() {
	init();
	repeat // wait for MIDI message from organ
	{
		i=receive_from_organ();
		if 1<=i<=number_of_buttons then 
			for j=1 to number_of_buttons {
				if i!=j then if button[j]==on then toggle_button(j,true)
					else if button[i]==off then toggle_button(i,true)					
			}
	}
	until END_SIGNAL
}
What do you think, is it possible with MT?

Kind regards,
Monte

Attigo

2011-02-03 22:19:16

Yes, like I said before, this is possible with MT, I just don't know if we can actually control the LEDs? If the unit has stuff in the firmware that control these LEDs, and they are not fed by MIDI, then we might not be able to have feedback with what you want...

Scott

Monte

2011-02-03 22:35:19

Scott, I think it is not necessary to make a difference between the LED's and the buttons. If MT sends the programm change message to the button then the LED will toggle. So what's the problem?

Monte

Attigo

2011-02-03 23:12:22

There is a difference, the button sends MIDI, the LED receives MIDI. We can make the buttons act the way you want, but if the LED control is done by the unit itself, and not by MIDI from software, then we will not be able to make the LEDs act how you want.

If you think the LEDs do change with this program change message, which was all I was asking really, then I can go ahead and show you how this can be done with MT...

The file is a little too large to just post up code, so I have created a Preset for you:

The Preset treats each button as different modes and therefore I use different presets for each button. There is a 'master' preset that switches each mode, and this also de-activates a mode if that mode is already selected - like you asked. Each mode, when activated sets a variable, so we can keep track of which mode is selected and also sets all the LEDs accordingly.

I don't know what messages and values each button sends or receives, all you told me was "CB oo", so I left those fields blank for you to fill in, but remember that you will need to set for example the first mode, the buttons when activated as (values) 1, 0, 0, 0 & for deactivation 0, 0, 0, 0, get me?

Also, I do not know the name of the MIDI ports so you will also need to set that up, and then define the Preset properties for each preset. The Master Preset 'Button Switcher' will receive from the unit, where as the Button mode presets send to the unit.

I hope this makes sense to you and you can get everything working...

Scott
4 Button Toggle.bmtp
(5.38 KiB) Downloaded 292 times

Monte

2011-02-04 00:43:16

Hello Scott,

thank you very much, this is a big help!
I don't know what messages and values each button sends or receives, all you told me was "CB oo", so I left those fields blank for you to fill in
CB 0B, CB 0C, CB 0D and CB 0E - i filled these values into the 4 corresponding transposers of the preset "Button switcher". So the transposers and the presets are working like a charme :-) I guess to set the LED's accordingly I have to change the outgoing actions of the 8 transposers named "Set LED's" the same way? I tried it but it doesn't work. There happens a kind of back coupling effect.

Best regards,
Monte