Convert Note On to Fade In (and note off to Fade Out)

florian

2006-11-06 15:28:07

Hi, a user requested how the following conversion can be done with Midi Translator:
When I press down a key on my keyboard, I want the notes on that channel to slowly fade in. When I release the note, all notes are slowly faded out. Is that possible?
This is easily possible with Midi Translator Pro: use timers to do the fade in and fade out:

Code: Select all

Translator 1: Note On / set timer to increase controller
Incoming: 90 pp qq
Rules:
  IF qq=0 THEN exit Rules, skip Outgoing Action
  gb = 1
Outgoing: Start Timer "Fader", infinite repeat
          initial delay: 0, repeat delay: 50 milliseconds

Translator 2: Note Off / set timer to decrease controller
Incoming: 90 pp 00
Rules:
  gb = -1
Outgoing: Start Timer "Fader", infinite repeat
          initial delay: 0, repeat delay: 50 milliseconds

Translator 3: Do the fade
General: Stop Processing: unchecked
Incoming: Timer "Fader"
Rules:
  ga = ga + gb
  IF ga<=-1 THEN exit Rules, skip Outgoing Action
  IF ga>=128 THEN exit Rules, skip Outgoing Action
Outgoing: MIDI B0 07 ga

Translator 4: Stop fade
Incoming: Timer "Fader"
Rules:
  IF ga<=-1 THEN exit Rules, execute Outgoing Action
  IF ga>=128 THEN exit Rules, execute Outgoing Action
  exit Rules, skip Translator
Outgoing: Stop Timer "Fader"
Explanation:

ga is a variable with the current fade value. "gb" is a variable with the value by how much ga should be increased/decreased every 50 milliseconds.

Now when you press down the key on the keyboard, the first Translator is triggered, setting gb to 1 (i.e. the control value ga is increased by 1 every 50 millis), and the timer is started, which will trigger the timer called "Fade" every 50 milliseconds.

Now every 50 milliseconds, the 3rd translator is triggered. It will increase the ga variable by gb (meaning by 1 in the example) and send out a controller MIDI message with ga as value (in the example, chanel volume message 0x07 is sent). The rules prevent this message to be sent when the ga variable is too high (128) or too low (-1).

The last Translator stops the timer when the ga variable has reached its maximum or minimum.

You can make the fade faster (slower) by decreasing (increasing) the repeat time of 50 milliseconds, and/or by increasing the step size of gb (e.g. 2 and +2).

Florian

florian

2006-11-06 15:52:18

The user asked for fine-grained control:
note on with soft velocity : slowly fade cc in. More hard velocity = quickly fade in
note off with soft velocity release: slowly fade cc out. More hard velocity release = quickly fade out.
I mean that the velocity control the speed of the fades.
For e.g:
A note on velocity 3, gives, a fade volume in (or other cc), with a speed 500ms
A note on velocity 64, gives a fade volume in (or other cc), with a speed 250ms
A .......>>............127, gives .....................>>................, with a speed 10ms
A note off release velocity 127, gives a fade out cc, with instantaneously fade out response and
a note off release velocity 64, gives a fade out cc, with a speed 200ms and
a slowly note off release velocity like 4 or 1, gives a fade out cc speed, like 500ms.
I know that note off velocity = 0 but some synths make real note off velocity release 0-127
Please tell me how it's possible in Bome Trans.
I need real note off with real note velocity release.
It's possible?
First of all, in order to support the real Note Off message, insert this Translator between Translator 2 and Translator 3:

Code: Select all

Translator 2b: Note Off 2 / set timer to decrease controller
Incoming: 80 pp qq
Rules:
  gb = -1
Outgoing: Start Timer "Fader", infinite repeat
          initial delay: 0, repeat delay: 50 milliseconds
Currently, the timer's delay cannot be set to a variable. I've added this to the feature request list. So the only option you have for an adaptive speed of the fade is to
1) use different values for the increase/decrease variable gb, and increase the range of the gb variable
or
2) set up different Translators for each different value of the delay

I'll present here a solution for 1) -- download at bottom:

Code: Select all

Translator 1: Note On / output Note On message with full velocity
Incoming: 90 pp qq
General: Stop Processing: unchecked
Rules:
  IF qq>0 THEN qq = 127
Outgoing: MIDI 90 pp qq
This optional Translator will output all Note On messages to the MIDI device with full velocity. The velocity will control the speed of the fade, not the final volume. If you don't need the Note On message passed on to the MIDI device, uncheck the Active checkbox.

Code: Select all

Translator 2: Note On / set timer to increase controller
Incoming: 90 pp qq
General: Stop Processing: unchecked
Rules:
  IF qq=0 THEN exit Rules, skip Outgoing Action
  gb = qq
Outgoing: Start Timer "Fader", infinite repeat
          initial delay: 0, repeat delay: 50 milliseconds
This translator reacts on all Note On messages, i.e. the velocity parameter is greater than 0. The second rule will set the global variable gb to the current velocity. gb is the amount by which the volume of the fade is increased every 50 milliseconds. To increase the resolution, gb is stored as 4 times the actual amount that is increased every 50 milliseconds (see Translator 6 for this scaling). The Outgoing Action will start a timer that will trigger the corresponding Translators every 50 milliseconds.

Code: Select all

Translator 3: Note Off / default fade out
Incoming: 90 pp 00
General: Stop Processing: unchecked
Rules:
  IF gb > 0 THEN gb = -1 * gb
  IF gb = 0 THEN gb = -20
Outgoing: Start Timer "Fader", infinite repeat
          initial delay: 0, repeat delay: 50 milliseconds
This Translator handles releasing a key by a Note On message with velocity 0. This will cause a default fade out, i.e. it will fade out with the same speed as it was faded in. For this, the increase variable's sign is switched, done by multiplying gb with -1.
For safety, if gb happens to be 0, gb is set to an arbitrary negative value. It is important that gb is non-zero: otherwise the timer would never increase/decrease the current fade and the timer would run endlessly without ever doing anything. As for the 2nd Translator, the Outgoing Action will start a timer that will trigger the corresponding Translators every 50 milliseconds.

Code: Select all

Translator 4: Note Off / set timer to decrease controller
General: Stop Processing: unchecked
Incoming: 80 pp qq
Rules:
  IF qq=0 THEN qq = 1
  gb = -1 * qq
Outgoing: Start Timer "Fader", infinite repeat
          initial delay: 0, repeat delay: 50 milliseconds
This Translator handles the Note Off message with variable note off velocity (passed in the variable qq). Just as for Note On, the velocity is used to set the variable that decreases the current fade volume. To make it negative (for decrease), qq is multiplied with -1. Also here, the Outgoing Action will start a timer that will trigger the corresponding Translators every 50 milliseconds.

Code: Select all

Translator 5: Note Off / output Note Off message
Incoming: 80 pp qq
Outgoing: MIDI 80 pp qq
This simple Translator will just output any Note Off message so that the MIDI device will receive the Note Off. As for Translator 1, this is optional.

Code: Select all

Translator 6: Do the fade
General: Stop Processing: unchecked
Incoming: Timer "Fader"
Rules:
  qq = gb / 4
  ga = ga + qq
  IF ga<=0 THEN ga = 0
  IF ga>=127 THEN ga = 127
Outgoing: MIDI B0 07 ga
This is the core fade Translator: It is triggered by the "Fader" timer. First, a local variable qq is used to scale the current increase/decrease value gb by 4 -- like this the gb value has a much wider range. Then the current fade volume level ga is increased (or decreased) by the value of qq.
The current fade value is capped by 0 and 127 so that it will not be outside the range of MIDI controllers.
Finally, the MIDI Channel Volume controller message is sent, with ga as controller value.

Code: Select all

Translator 7: Stop fade
Incoming: Timer "Fader"
Rules:
  IF ga<=0 THEN exit Rules, execute Outgoing Action
  IF ga>=127 THEN exit Rules, execute Outgoing Action
  exit Rules, skip Translator
Outgoing: Kill Timer "Fader"

The last Translator checks the current fade volume level ga whenever the timer is triggered. If ga has reached its end level (i.e. 0 or 127), the timer is killed -- the fade is finished.

You can download this preset here:
http://www.bome.com/midi/translator/sol ... adeIn.bmtp

Enjoy!
Florian

florian

2009-05-30 00:27:31

Update: as of version 1.6.0 and later, timer delay and repetition count can be set to a variable.
Florian