Randomizer

borister

2009-05-23 02:01:08

Hi,

I was wondering if there is a way to create random midi re-patching. I am trying to create a rig where I can press the same midi key 30 or more times, and it will do something different each time.

Any idea's on how to accomplish this?

florian

2009-05-23 15:25:34

Hi,

we've always planned to add a special random variable or so, but it's not yet in there.

For the time being, you can use the timer to make a random variable. The timer will run infinitely and increase a variable by a fixed amount. Now depending on when you access that variable, it'll always have a different value.

The following preset handles this timer in the first two translator entries. The global variable gr will then always have a different random number.
For the fun of it, the remaining translators will cause all played notes to be mapped to a random note.

Code: Select all

Translator 1: Start random number timer
Options: stop=false
Incoming: Project Opened
Outgoing: Periodic timer "Update Random Number": 5 ms (initial delay: 100 ms)

Translator 2: Make new Random number gr
Options: stop=false
Incoming: On timer "Update Random Number"
Rules: 
  gr=gr+17
  if gr>=50 then gr=gr-50
Outgoing: Periodic timer "Update Random Number": 5 ms (initial delay: 100 ms)

Translator 3: On Note On, play random note
Options: stop=false
Incoming: MIDI 90 pp qq 
Rules: 
  if qq==0 then exit rules, skip Outgoing Action
  pp=ga
  if pp!=0 then exit rules, execute Outgoing Action
  pp=gr+30
  ga=pp
Outgoing: MIDI 90 pp qq 

Translator 4: On Note Off 1, stop the previously started note
Options: stop=false
Incoming: MIDI 90 pp 00 
Rules: 
  if ga==0 then exit rules, skip Outgoing Action
  pp=ga
  ga=0
Outgoing: MIDI 90 pp 00 

Translator 5: On Note Off 2, stop the previously started note
Options: stop=false
Incoming: MIDI 80 pp qq 
Rules: 
  if ga==0 then exit rules, skip Outgoing Action
  pp=ga
  ga=0
Outgoing: MIDI 80 pp qq 
Explanation: the timer increments the variable gr by 17. If it exceeds 50, it is subtracted by 50 (sort of a wrap-around). Using an odd number like 17 ensures that after some time, gr takes all values in the range 0..49. If you need a different range, just replace 50 by a different value.

Then when you press a key (Translator 3), it first checks if it's not a Note Off. We need to handle the case of playing multiple notes at once and re-play the same note. Eventually, we set pp to the random note, plus 30 (because note range 0..49 is very low, by adding 30 we make it note range 30...79). Last, but not least, we remember the currently playing note in ga, so that we can release it when the Note Off message comes in.

The two Note Off variants (one for Note On with velocity 0, the other using the "proper" Note Off MIDI message) will make sure that the random note is released (i.e. set pp to the remembered value in ga), then reset ga to 0.

You can download the preset file here:
http://www.bome.com/midi/translator/sol ... mNote.bmtp
(right-click on it and choose "Save Link As..." or so).

Let me know how it works!
Florian

PS: you will notice that this preset will only work for one note at a time. It would require more rules to track the note number of multiple notes at once.