MIDI Fade Out with timer and rules

florian

2010-06-07 11:20:49

Hi, here's a way how to solve the problem of a smooth fade out with Midi Translator:

Assume you have a button that sends MIDI 90 40 7F when pressed. You want this button to trigger the fade out. The fade out is executed by sending a CC#7. Then you can use these translators:

Code: Select all

Translator 0: Button: Trigger timer
Options: stop=false
Incoming: MIDI 90 40 7F
Rules: Initialize Fade Value
  g0=128
Outgoing: Timer 128 times "Fade Out": 50 ms (initial delay: 50 ms)

Translator 1: On Timer: Send CC
Options: stop=false
Incoming: On timer "Fade Out"
Rules: Decrement g0 before sending the CC
  g0=g0-1
Outgoing: MIDI B0 07 g0 
This is a slow fadeout (128*50ms = 6.4 seconds). Lower the timer times to make a faster fade out.

Florian

kurtr2

2013-10-17 03:06:23

AWESOME!!!!!!!!!


very cool!


thanks!!!

kurtr2

2013-10-17 04:05:21

trying to make another preset that this switches to that will FADE BACK UP to initial value when triggered by same midi button: like a "Fade out/Fade in" button.

can you say: g0=whatever it is at the moment, and then set a timer that does this: g0=g0+1 until g0=110 ?


thx,
k

DvlsAdvct

2013-10-19 03:33:14

Hi kurtr2

Do you want to be able to stop the timer or instead just have it start at 0 and go back up?

kurtr2

2013-10-19 13:41:47

I did it: press midi button 127 and a fadeout starts, press it again and it stops the fadeout timer and initiates a fade in timer with g0=g0+1 (fade-in)...it works.

what i couldnt do was have the fadeout start from wherever the volume was during the fadeout timer. i had to set g0 at 110 for the start of the fadeout. otherwise g0 would never have an initial value. i tried using another button to reset the definition of g0, but that didnt seem to work....

metastatik

2013-10-20 05:23:00

If I understand you correctly, you want a single button to toggle between fading in and fading out with the range of the fade as 0 – 110. Correct? If so, you don’t need multiple presets, you just need to use another global variable to determine the direction to fade (in or out). Assuming that you want to start with a fade in, the translators you need would look something like the following.

This translator will be triggered when the project is opened and will initialize your global variables. After creating it, you need to reload the project in order for the variables to be initialized.

Code: Select all

Translator 0.0: Initialize Variables
Options: stop=false
Incoming: Project Opened
Rules: 
  g0=0
  g1=-1
Outgoing: (none)
This translator will kill the timer and toggle the direction (either 1 for fade in or -1 for fade out) of the fade.

Code: Select all

Translator 0.1: Kill Timer - Toggle direction (g1)
Options: stop=false
Incoming: MIDI 90 40 7F 
Rules: 
  oo=g1
  g1=1
  if oo==1 then g1=-1
Outgoing: Kill timer "Send CC"
This translator will trigger the timer and set how many times it needs to repeat (oo) in order to reach the target value (either 0 or 110). In the case of the fade in, the number of times is equal to 110 minus the value of g0. In the case of the fade out, the number of times is simply the value of g0.

Code: Select all

Translator 0.2: Trigger Timer
Options: stop=false
Incoming: MIDI 90 40 7F 
Rules: 
  Label "Calculate distance from target value"
  oo=g0
  if g1==1 then oo=110-g0
Outgoing: Timer oo times "Send CC": 50 ms (initial delay: 50 ms)
This is the timer translator and is similar to before, but uses the direction variable (g1) to either increment or decrement the value of g0.

Code: Select all

Translator 0.3: Send CC
Options: stop=false
Incoming: On timer "Send CC"
Rules: 
  g0=g0+g1
Outgoing: MIDI B0 07 g0
FYI, if you want to start with the fade out, in the first translator, initialize g0 to 110 and g1 to 1.

kurtr2

2013-10-27 20:38:05

On your preset above, what do the midi incoming triggers represent? two different buttons?

thanks, going to try now....

k

metastatik

2013-10-27 23:28:45

Sorry, that was a typo. The incoming message for translators 0.1 and 0.2 should be the same so they're both triggered by the same MIDI message. You can replace the message in the example (90 40 7F) with whichever MIDI message you want to use.