Interesting problem to solve!
Indeed, this is not trivial, but not hard either, once you figure out all the conditions you need to take care of.
For the fun of it, I've implemented it on my Korg NanoKontrol. It should be easy to adapt to other fader boxes.
The most simplest design is this:
- use a global variable g0 to remember the last value of the fader
- use a global variable h0 to remember if a note is currently on (h0 is not equal to zero), or currently off (h0 is 0).
Now, whenever you move the fader, do this:
- calculate the difference of current fader value and last value (g0)
- if the difference is positive, the fader was moved upwards. if the note is not yet started (i.e. h0=0), start the note and set h0 to 1.
- if the difference is negative, the fader was moved downwards. if the note was actually started (i.e. h0 not zero), stop the note and set h0 to 0.
It would be nice to play with different velocity... Right now, it doesn't depend at all where the fader is, all that matters is if you change direction. I leave this to the reader
I've also added a "sharp" button. It just sets variable gs to 1 while the button is pressed. Then, to the note value is always added gs. There is one tricky thing to solve here: what if you move the fader up with sharp button down, then release the button, and move the fader down? It will stop the non-sharp note. To properly stop the sharp note here, the variable h0 is used to store the value of the currently sounding note. When the note is turned off, the value of h0 is used as note value.
Here is the first translator for the first fader:
Code: Select all
Translator 1: Fader Movement 1
Options: stop=false
Incoming: B0 02 pp
Rules:
Label "outgoing note"
tt=64+gs
Label "calculate direction of fader movement in rr"
rr=pp-g0
g0=pp
qq=0
if rr<0 then Goto "NoteOff"
Label "NoteOn"
if h0!=0 then exit rules, skip Outgoing Action
h0=tt
qq=100
exit rules, execute Outgoing Action
Label "NoteOff"
if h0==0 then exit rules, skip Outgoing Action
tt=h0
h0=0
Outgoing: MIDI 90 tt qq
Note: qq holds the velocity for the note to be played.
In order to support multiple notes, just add more translators like this. The incoming action needs to be modified, accordingly, and the assignment of tt in the first rule, too. Plus, all g0 needs to be replaced with g1, and h0 with h1. Here is the full preset:
KorgNanoKontrolAsKeyboard.bmtp -> right-click and choose "Save As...".
It's quite fun!
Florian