Latch Buttons & If Statements

madjazz

2019-10-01 05:24:12

For some reason, I need two latch-style buttons in Touchable to turn an Ableton Live device on and off: one to turn the device on, and the other to turn it off. Below is what the MTP Log Window shows when I operate these two buttons... The first button that turns the device on sends this midi data: 1: MIDI IN [touchAble]: 90 70 7F 2: IN   0.0  Note On on ch. 1 with any note set 'pp' to note=112 with any velocity and 'ga' to velocity=127 3: RULE 0.0  condition satisfied: if pp==112 then rr=57 4: RULE 0.0  assignment: (if pp==112 then rr=57) = 57 5: RULE 0.0  condition satisfied: if pp==112 then qq=127 6: RULE 0.0  assignment: (if pp==112 then qq=127) = 127 7: MIDI OUT [Bome MIDI Translator 2 Virtual Out]: B1 39 7F 8: OUT  0.0  Control Change on ch. 2 with CC#:rr=57 and value:qq=127 9: MIDI OUT [Bome MIDI Translator 2 Virtual Out]: 90 70 7F 10: MIDI IN [touchAble]: 90 70 00 11: IN   0.2  Note Off on ch. 1 with any note=112 and any velocity=0 And the second button that turns the device off sends this midi data 1: MIDI IN [touchAble]: 90 71 7F 2: IN   0.0  Note On on ch. 1 with any note set 'pp' to note=113 with any velocity and 'ga' to velocity=127 3: RULE 0.0  condition satisfied: if pp==113 then rr=57 4: RULE 0.0  assignment: (if pp==113 then rr=57) = 57 5: RULE 0.0  condition satisfied: if pp==113 then qq=0 6: RULE 0.0  assignment: (if pp==113 then qq=0) = 0 7: MIDI OUT [Bome MIDI Translator 2 Virtual Out]: B1 39 00 8: OUT  0.0  Control Change on ch. 2 with CC#:rr=57 and value:qq=0 9: MIDI OUT [Bome MIDI Translator 2 Virtual Out]: 90 71 7F 10: MIDI IN [touchAble]: 90 71 00 11: IN   0.2  Note Off on ch. 1 with any note=113 and any velocity=0 I'm hoping there is a better way to do this that involves only a single latch style button that: turns the device on when pressed the first time; and when pressed the second time, turns the device off. Any thoughts on what to do differently to make this work with a single button? If not, could we use the IF statement to solve this?  When the button is pressed the first time, MTP sets a variable flag that indicates the device is on; and when the same button is pressed the button a second time, MTP sees that the flag is set, and so sends the right code to turn the device off, and then clears the flag? Many thanks.

Steve-Bome Forum Moderator

2019-10-01 06:01:14

Hi Rick,

If your input buttons are momentary, it would look like this. You need a different global variable for each button

Incoming: Note on MIDI Channel 1 Note 112 velocity 127

Rule:

// Set default

pp=0

// Toggle global variable

ga=ga^1

if ga==1 then pp=127

Outgoing

Note On, MIDI Channel 1 Note 112, vel0city pp


Then do another translator  for note 113 except use the global variable gb

(I’m assuming you are not already using global variables ga and gb anywhere else in the project.

———————–

Or if you want only one translator:

Incoming Note on MIDI channel 1 any note set note to pp, velocity 127

Rules:

// Get global variable into local variable qq

if pp==112 then qq=ga

if pp==113 then qq=gb

// Toggle it

qq=qq^1

// Put it back where it needs to go

if pp==112 then ga=qq

if pp==113 then gb=qq

// set default

rr=0

// Change if 1

if qq==1 then rr=127

Outgoing: Note on MIDI Channel 1, Note pp, velocity rr

 


Steve Caldwell
Bome Q and A Moderator and
Independent Bome Consultant/Specialist
bome@sniz.biz

Steve-Bome Forum Moderator

2019-10-02 18:39:54

comment

Did this help, Rick!

ricleif

2019-10-02 21:36:19

.

ricleif

2019-10-02 21:37:14

Not sure yet — will attempt coding over next few days.  Though, I am wondering: the problem here is that Touchable is not correctly latching the note by sending both a note on and off message in the same press (even though the UI element latches (that is, lights up and stays lit)?  Is this correct, or is this standard behavior when using notes as controller input?

Steve-Bome Forum Moderator

2019-10-02 22:56:46

comment

Not sure on touchable. If it sends note-on for first press and note-off for second press, etc. then you should not need any rules in MT Pro.

The rules would apply only for momentary to make the behavior latching. As far as the Touchable UI lights, I’m not sure, but I think it should follow the behavior of the button.

Let me know when you get to testing it.

Steve

madjazz

2019-10-02 22:58:49

Yes, Touchable is sending both the note on AND off with each individual button touch.  I’ve alerted them to the issue and they promise a fix in the next release.  In the mean time, looks like I can correct this behavior through MTP.  Will let you know what happens. Many thanks.

madjazz

2019-10-02 23:55:44

It worked! Awesome! Thank you!

Steve-Bome Forum Moderator

2019-10-03 00:15:56

comment

Great! You are welcome!