Toggle

sleepytom

2011-04-19 13:17:54

I'm having difficulty making a reliable solution for toggle notes
I'm trying to use presets and global variables, this works to a degree yet it can be very unreliable.

is there a better way to do this? What do your recommend Florian?

sleepytom

2011-04-21 10:46:25

does anyone actually use MT for anything reasonably complex? the lack of any useful information on this forum is a little concerning.

Attigo

2011-04-26 23:47:07

Hi sleepytom

I think you will find some very interesting stuff on the forum if you really had a look. I've done some interesting stuff before, you could try taking apart the Stanton SCS presets if you want to see some tricky stuff!

What kind of toggle do you want to do? Is this related to your other post?

thanks,
Scott

sleepytom

2011-04-27 10:11:49

Maybe there is interesting stuff here? i dunno? Mainly i see questions about very very simple translations.

I have a launchpad which i'm trying to build a decent controller from, as such i need to build some toggle switches that send note-on / note-off on alternate button pushes.

The method i've tried so far is to have a preset for each button, this prest simply sets a global var - so when button 1 is pushed it turns on preset1 which sets variable h1=1 - then back in my main preset (which is "always on") I have logic to send the correct midi commend dependent on the state of var H1. (essentially its if h1=1 send noteon / if h1=0 send noteoff)

This basic technique works but becomes unreliable when large numbers of buttons are being used. Currently i'm seeing missed midi notes / failure to work reliably which has pretty much made me abandon the project (which I had hoped to release to the public via the MT player.)

All of this is on OSX at the moment, I suspect the PC version might be more reliable, but I've not got my PC setup at the moment.

Surely a midi toggle is so basic that lots of people must want to do this?

DvlsAdvct

2011-04-27 18:54:16

This would all exist in the translator for the specific command. So

Input 90 00 pp (as an example)

xx=xx+1
if xx=1 then pp=127
if xx=0 then pp=0
when xx=2 then xx=0

Output 90 00 pp

It might need to be flipped (xx=0 then pp=127) depending on the initial order but that's how I do it for my MIDI Fighter.

sleepytom

2011-04-27 21:44:20

yeah i tried to do that to start with, it doesn't work on OSX, don't know about windows..

xx gets set to a very high number for no reason, even initialising it at 0 doesn't help.

form th following we can see that this doesn't work. Maybe all this is OSX bugs? I don't know but it makes it pretty much impossible to use MT

Code: Select all

: IN   0.0  on activation of this preset (New Preset)
1128: RULE 0.0  assignment: (xx=0) = 0
1129: IN   0.1  MIDI 90 00 7F,  pp=0x7F
1130: RULE 0.1  expression: (xx=xx+1) = 631220423
1131: MIDI OUT [Bome's Midi Translator 1 Virtual Out]: 99 00 7F
1132: MIDI OUT [Launchpad (Novation DMS Ltd)]: 99 00 7F

sleepytom

2011-04-27 21:46:25

and as a general comment why are variable names so limited. It would be much nicer to have proper vars which could have meaningful names.

DvlsAdvct

2011-04-27 21:47:39

Did you try the variable

if xx>2 then xx=0

sleepytom

2011-04-27 21:50:00

and osx doesn't seem to like when statements.

I'm getting the picture now that MT is a windows only app. the OSX functionality doesn't seem to work at all well.

This is a big disappointment to me.

DvlsAdvct

2011-04-27 21:53:41

If it really doesn't like if/when statements try labels. It would look something like

xx=xx+1
xx=1
Jump to 1
xx=2
Jump to 2
'1'
pp=127
exit rules, execute outgoing action
'2'
pp=0
xx=0
exit rules, execute outgoing action

Or something like that. I'm not in front of Bome's and doing this from very poor memory.

sleepytom

2011-04-27 21:57:19

the >=2 works but it still doesn't send the midi correctly.

the var toggle is working but its not setting the value of PP properly to the output note..

Code: Select all

1: IN   0.1  MIDI 90 00 7F
2: RULE 0.1  expression: (h1=h1+1) = 1
3: RULE 0.1  condition satisfied: if h1==1 then pp=0
4: RULE 0.1  assignment: (if h1==1 then pp=0) = 0
5: MIDI OUT [Bome's Midi Translator 1 Virtual Out]: 99 00 00
6: MIDI OUT [Launchpad (Novation DMS Ltd)]: 99 00 00
7: OUT  0.1  MIDI 99 00 00
8: IN   0.1  MIDI 90 00 7F
9: RULE 0.1  expression: (h1=h1+1) = 2
10: RULE 0.1  condition satisfied: if h1>=2 then h1=0
11: RULE 0.1  assignment: (if h1>=2 then h1=0) = 0
12: MIDI OUT [Bome's Midi Translator 1 Virtual Out]: 99 00 00
13: MIDI OUT [Launchpad (Novation DMS Ltd)]: 99 00 00
14: OUT  0.1  MIDI 99 00 00
- that is two button presses - which should send a note on then a note off. instead it just sends noteoff :(

DvlsAdvct

2011-04-27 22:01:51

Right right right, I've run into this issue before.

Try switching the variable values. So if you have it that h1=0 then pp=0 and h1=1 then pp=127 change it to h1=1 pp=0 and h1=0 pp=127, or reverse those so h1=0 pp=127, h1=1 pp=0. I can't remember the right order but I think that MIGHT fix it.

sleepytom

2011-04-27 22:03:52

yeah i tried that already - swapping them gets it to send the other value but not toggle between them

DvlsAdvct

2011-04-27 22:08:32

Out of curiosity, not to be an annoyance, I swear, can you post the readout if your rules are set as

when xx=1 pp=127
when xx=0 pp=0
and when xx=2 xx=0

In theory this would be "push button down" it sends 127, "release button" it sends 0

I just want to see it, and I can't do it on my own right now.

sleepytom

2011-04-27 22:13:40

This works

Code: Select all

h1=h1+1
if h1==1 then pp=127
if h1==1 then exit rules, execute Outgoing Action
if h1!=0 then pp=0
if h1>=2 then h1=0
I need to work out if i can get this to usably output the commands i need (ultimately I need each button push to send different velocities to the 2 outputs) This shouldn't be a problem using multiple translators (i hope).

Thanks for your help, i hope this will still work when i've copied it to all the buttons - this was my big problem with my other method - it would be reliable for one or two button but adding 16 caused it to become unreliable.

DvlsAdvct

2011-04-27 22:15:57

Well, good luck :)

DvlsAdvct

2011-04-29 18:03:03

Quick question.

I know the problem is solved but I realized something. If you change the input to 7F instead of pp does the original problem still occur?

florian

2011-04-29 19:31:19

Hi Sleepytom,

Midi Translator is working equally well on Windows and on OS X. Actually, the OS X version is the new code base which will be used on Windows, too, in future.
"xx" is a local variable, its value is undefined upon beginning of a Rules section, and it forgets its value upon exit.
As you've found out, using global variables like "g?" or "h?" (where ? is in the range 0..9 and a..z) works fine across translators.
These awkward two-letter variable names used to be convenient, but have become a pain as Midi Translator's functionality and versatility grew. This is one of the next big features to come. There are a number of other shortcomings in MT, but our main focus has always been on stability and performance. Only then convenience...

The shortest form of a toggle is done like this:

Code: Select all

Translator: Toggle MIDI note 00
Incoming: MIDI 90 00 7F
Rules: h1=127-h1
Outging: MIDI 90 00 h1
I acknowledge that the rule is a bit tricky: h1 will alternate between 0 and 127. Global variables are initialized with 0 and project start. Another trick is to set the value of the flag variable (i.e. h1 here) to the actual value used in the MIDI message, so you don't need to use a secondary local variable like pp to assign the MIDI value.

For a demo preset with some advanced functionality, check out one of the Frontier Design presets included with Midi Translator, you'll find them in the "Documents/Bome's Midi Translator/Presets" folder.

Hope this helps!
Florian

sleepytom

2011-04-30 12:24:43

Thanks Florian

The two letter variables are indeed a big annoyance - it would be very nice to be able to declare whatever variable names you wanted. It would also be great to be able to use arrays - at the moment it seems i must create a separate translator pair for each of my toggle buttons (one sends the midi out, the other sends the light control back to the launchpad), ideally I'd like to filter the incoming midi and dynamically change the global that i'm setting based on incoming midi note value. This would allow me to toggle all my buttons from a single translator.

The h1=127-h1 thing is a neat trick and something that i was conceptually trying to do when i started, i just got a bit confused by the variables format and ended up programming a stupid mess of translators to achieve the same thing!

Attigo

2011-04-30 13:06:16

Yes, I agree, named variables is my most wanted feature in MT...!!

:wink:

Scott

sleepytom

2011-04-30 13:19:16

i'd appreciate thoughts on the following approach - it seems to work well so far, and has a minimal number of translators.

Code: Select all

Project: toggtest
 Project MIDI IN ports:   Launchpad (Novation DMS Ltd)
 Project MIDI OUT ports:  Launchpad (Novation DMS Ltd), Bome's Midi Translator 1 Virtual Out
_____________________________________________________________
[x] Preset 0: Toggles
 Default MIDI OUT ports:  Bome's Midi Translator 1 Virtual Out

[x] Translator 0.0: tAll
Incoming: MIDI 90 pp 7F
Rules:
  if pp!=68 then skip next rule
  h1=127-h1
  if pp!=84 then skip next rule
  h2=127-h2
  if pp!=100 then skip next rule
  h3=127-h3
  if pp!=116 then skip next rule
  h4=127-h4
  if pp!=69 then skip next rule
  h5=127-h5
  if pp!=85 then skip next rule
  h6=127-h6
  if pp!=101 then skip next rule
  h7=127-h7
  if pp!=117 then skip next rule
  h8=127-h8
  if pp!=70 then skip next rule
  j1=127-j1
  if pp!=86 then skip next rule
  j2=127-j2
  if pp!=102 then skip next rule
  j3=127-j3
  if pp!=118 then skip next rule
  j4=127-j4
  if pp!=71 then skip next rule
  j5=127-j5
  if pp!=87 then skip next rule
  j6=127-j6
  if pp!=103 then skip next rule
  j7=127-j7
  if pp!=119 then skip next rule
  j8=127-j8
Outgoing: (none)

_____________________________________________________________
[x] Preset 1: Lights
 Default MIDI OUT ports:  Launchpad (Novation DMS Ltd)

[x] Translator 1.0: LtAll
Incoming: MIDI 90 pp 7F
Rules:
  if pp!=68 then skip next 2 rules
  if h1==0 then qq=90
  if h1==127 then qq=78
  if pp!=84 then skip next 2 rules
  if h2==0 then qq=90
  if h2==127 then qq=78
  if pp!=100 then skip next 2 rules
  if h3==0 then qq=90
  if h3==127 then qq=78
  if pp!=116 then skip next 2 rules
  if h4==0 then qq=90
  if h4==127 then qq=78
  if pp!=69 then skip next 2 rules
  if h5==0 then qq=90
  if h5==127 then qq=78
  if pp!=85 then skip next 2 rules
  if h6==0 then qq=90
  if h6==127 then qq=78
  if pp!=101 then skip next 2 rules
  if h7==0 then qq=90
  if h7==127 then qq=78
  if pp!=117 then skip next 2 rules
  if h8==0 then qq=90
  if h8==127 then qq=78
  if pp!=70 then skip next 2 rules
  if j1==0 then qq=90
  if j1==127 then qq=78
  if pp!=86 then skip next 2 rules
  if j2==0 then qq=90
  if j2==127 then qq=78
  if pp!=102 then skip next 2 rules
  if j3==0 then qq=90
  if j3==127 then qq=78
  if pp!=118 then skip next 2 rules
  if j4==0 then qq=90
  if j4==127 then qq=78
  if pp!=71 then skip next 2 rules
  if j5==0 then qq=90
  if j5==127 then qq=78
  if pp!=87 then skip next 2 rules
  if j6==0 then qq=90
  if j6==127 then qq=78
  if pp!=103 then skip next 2 rules
  if j7==0 then qq=90
  if j7==127 then qq=78
  if pp!=119 then skip next 2 rules
  if j8==0 then qq=90
  if j8==127 then qq=78
Outgoing: MIDI 90 pp qq

_____________________________________________________________
[x] Preset 2: MidiOut
 Default MIDI OUT ports:  Bome's Midi Translator 1 Virtual Out

[x] Translator 2.0: LtAll
Incoming: MIDI 90 pp 7F
Rules:
  if pp!=68 then skip next 2 rules
  if h1==0 then qq=0
  if h1==127 then qq=127
  if pp!=84 then skip next 2 rules
  if h2==0 then qq=0
  if h2==127 then qq=127
  if pp!=100 then skip next 2 rules
  if h3==0 then qq=0
  if h3==127 then qq=127
  if pp!=116 then skip next 2 rules
  if h4==0 then qq=0
  if h4==127 then qq=127
  if pp!=69 then skip next 2 rules
  if h5==0 then qq=0
  if h5==127 then qq=127
  if pp!=85 then skip next 2 rules
  if h6==0 then qq=0
  if h6==127 then qq=127
  if pp!=101 then skip next 2 rules
  if h7==0 then qq=0
  if h7==127 then qq=127
  if pp!=117 then skip next 2 rules
  if h8==0 then qq=0
  if h8==127 then qq=127
  if pp!=70 then skip next 2 rules
  if j1==0 then qq=0
  if j1==127 then qq=127
  if pp!=86 then skip next 2 rules
  if j2==0 then qq=0
  if j2==127 then qq=127
  if pp!=102 then skip next 2 rules
  if j3==0 then qq=0
  if j3==127 then qq=127
  if pp!=118 then skip next 2 rules
  if j4==0 then qq=0
  if j4==127 then qq=127
  if pp!=71 then skip next 2 rules
  if j5==0 then qq=0
  if j5==127 then qq=127
  if pp!=87 then skip next 2 rules
  if j6==0 then qq=0
  if j6==127 then qq=127
  if pp!=103 then skip next 2 rules
  if j7==0 then qq=0
  if j7==127 then qq=127
  if pp!=119 then skip next 2 rules
  if j8==0 then qq=0
  if j8==127 then qq=127
Outgoing: MIDI 90 pp qq

am i on the right track with this?