Page 1 of 1

Enter decimal number for program change

Posted: Fri Jan 22, 2010 9:30 am
by florian
A user asked us by email:
I want to be able to use a USB Numeric Keypad to output numbers 00--64, via the following procedure in MTP Pro:
1. Input first digit (0--9), multiply it by 10, and store as X
2. Input second digit (0--9), store as Y, and add X+Y=ZZ
3. Wait for ENTER to be pressed
4. Press ENTER to Output Midi Prog Change CF ZZ (Ch16)

This is similar to entering a preset number (00--64), and then transmitting the midi message only when you press ENTER.

Re: Enter decimal number for program change

Posted: Fri Jan 22, 2010 9:53 am
by florian
To do this, you need "keystroke" as Incoming action. Currently (Jan 2010), it is only available in the Windows version.

You need to define 11 translators, for each digit one, plus one for the ENTER key.
We remember the last digit in the global variable g0, the before-last digit in g1, and the before-before-last entered digit in g2. Also, we remember the number of digits entered in gc (for "count").

When the user presses the ENTER key, we evaluate as follows:
if gc is 0, do not do anything -- the user hasn't entered any digits.
if gc is 1, the user only entered one digit, use g0 as the program change number.
if gc is 2, the user entered two digits, use g1*10 + g0 as the program change number
otherwise, the user entered three digits, use g1*100+g1*10+g0 as the program change number.

Code: Select all

Translator 0: digit 0
Options: stop=false
Incoming: Keystroke: Num 0
Rules: 
  g2=g1
  g1=g0
  g0=0
  gc=gc+1
Outgoing: (none)

Translator 1: digit 1
Options: stop=false
Incoming: Keystroke: Num 1
Rules: 
  g2=g1
  g1=g0
  g0=1
  gc=gc+1
Outgoing: (none)

[.......]

Translator 9: digit 9
Options: stop=false
Incoming: Keystroke: Num 9
Rules: 
  g2=g1
  g1=g0
  g0=9
  gc=gc+1
Outgoing: (none)

Translator 10: ENTER
Options: stop=false
Incoming: Keystroke: Num Enter
Rules: 
  pp=g0
  qq=gc
  gc=0
  if qq==0 then exit rules, skip Outgoing Action
  g1=g1*10
  g2=g2*100
  if qq>1 then pp=pp+g1
  if qq>2 then pp=pp+g2
  Label "number too large, assume 2-digit number"
  if pp>127 then pp=pp-g2
Outgoing: MIDI C0 pp 
The preset is attached as a download.
Florian

Re: Enter decimal number for program change

Posted: Mon Feb 22, 2010 12:07 pm
by Peter Nicholson
:D
Hi Bome Team
Many thanks for your help.
The programme runs perfectly, and the project is in regular use.

Re: Enter decimal number for program change

Posted: Mon Jan 25, 2016 1:36 am
by i@mJONNY
quick q which hopefully someone will be able to see and answer...

is this ^^^ *10 necessary?

Can't I just pass a single variable, a 2-digit number (00-99) for a Program Change?

Re: Enter decimal number for program change

Posted: Thu Jan 28, 2016 12:25 pm
by florian
of course you can just send a program change with any variable. But here, the trick is to enter the program on a numpad. If you enter "NUM 3" and then "NUM 1", the program to switch to is 31, i.e. (3 * 10) + 1. That's why the *10 is necessary in THIS setup.
Hope that makes sense,
Florian

Re: Enter decimal number for program change

Posted: Tue Feb 02, 2016 6:22 pm
by i@mJONNY
perfect sense, many thanks Florian :)

OK, I was thinking of trying to implement this in AHK, but maybe MBT has the power...

Can this idea (numpad entry) be further extended, with a control-prefix key to dictate which operation is performed?

Off the top of my head, I can imagine (for current synth of active track in Reaper) p 1 0 for a ProgramChange to patch10 (or 11, dependent on baseIndex), P - 5 0 (if case-sensitive and negatives) to pan left 50, F1 + 1 0 to increment 'fx1' (cutoff-parameter, for example) by 10...

few bits in here! hope it makes sense

Re: Enter decimal number for program change

Posted: Wed Feb 24, 2016 12:50 am
by florian
Hi, sorry for the late reply. You can certainly extend the example to work with other key combinations and prefixes. Takes a bit of tweaking, but definitely possible.
Feel free to post your created preset! Or if you get stuck, let us know!
Thanks,
Florian