MIDI-OX User Forum (http://www.midiox.com/cgi-bin/yabb/YaBB.pl)
MIDI-OX >> Scripting Questions >> Midiox script to map expression pedal to kick drum
(Message started by: PenguiN42 on Jan 23rd, 2011, 4:53am)

Title: Midiox script to map expression pedal to kick drum
Post by PenguiN42 on Jan 23rd, 2011, 4:53am
So I've found a few utilities out there that map the sustain pedal to a kick drum hit, but the problem with that is you don't have any velocity control.

So I thought -- wouldn't it be cool to use a volume or expression pedal and deduce the velocity from that, and make a MIDI kick drum out of it?

Below is a VBscript for midi-ox that does just this. Feel free to use and abuse it! I tested it with a Roland EV-5 through an m-audio Axiom 61 into Cakewalk's Session Drummer 3 and it felt pretty good (other than the lack of spring action in the pedal). Here's a test track I recorded with it http://soundcloud.com/ken-taylor/drum-gtr-test-012211

And here's the code:

(Edit: I should probably mention that the code in its current form is very dependent on the rate at which your midi device sends controller updates. I originally tried to make it independent by using timestamps, but that wasn't consistent enough in my tests, so I just put in a fudge factor instead that assumes the device is sending at a constant rate. You can see the commented out timestamp-lasttime and lasttime-lasttime2 in the code below)


' For use with MIDI-OX
' Translates expression pedal hits into bass drum hits with velocity info

option explicit

dim thresh, in_ctrl, out_note

dim v_in_min, v_in_max
dim v_out_min, v_out_max

dim nonlin

thresh = &H50
in_ctrl = 11
out_note = 36
v_in_min = 0
v_in_max = 3.5
v_out_min = 0
v_out_max = &H7F
nonlin = 0.7

dim lasttime, lastpos, lasttime2, lastpos2
dim mox

lasttime = 0
lastpos = 0
lasttime2 = 0
lastpos2 = 0

' Create object
Set mox = WScript.CreateObject("MIDIOX.MOXScript.1", "OnTrigger_")

mox.DivertMidiInput = 1 ' when set, routes all data
mox.FireMidiInput = 1 ' begins input

Do While mox.ShouldExitScript = 0
  WScript.sleep(1)
Loop


mox.FireMidiInput = 0 ' stops MIDI input
mox.DivertMidiInput = 0

' -----------------------------------------------------------
' This is the function that gets called by MIDI-OX
Sub OnTrigger_MidiInput( timestamp, port, status, dat1, dat2)
  dim vel_in1, vel_in2, vel_in, vel_out
 
  if status = &HB0 and dat1 = in_ctrl then
    if (lastpos < thresh) and (dat2 >= thresh) then
      vel_in1 = (dat2-lastpos)/20 '(timestamp-lasttime)
      vel_in2 = (lastpos-lastpos2)/20 '/(lasttime-lasttime2)
      if (vel_in1 > vel_in2) then
        vel_in = vel_in1
      else
        vel_in = vel_in2
      end if
      'vel_in = (vel_in1+vel_in2)/2
     
      vel_in = ((vel_in-v_in_min)^nonlin)/((v_in_max-v_in_min)^nonlin) _
                *(v_in_max-v_in_min) + v_in_min
     
      'MsgBox("threshold crossed, vel = " & vel_in)
      vel_out = ((vel_in-v_in_min)/(v_in_max-v_in_min))*(v_out_max-v_out_min)+v_out_min
      'MsgBox("out vel = " & Int(vel_out))
      'MsgBox("status = " & status)
     
      if(vel_out > v_out_max) then
        vel_out = v_out_max
      end if
     
      if(vel_out < v_out_min) then
        vel_out = v_out_min
      end if
     
      mox.OutputMidiMsg -1, &H90, out_note, Int(vel_out)
      mox.OutputMidiMsg -1, &H90, out_note, 0
    end if
   
    lastpos2 = lastpos
    lasttime2 = lasttime
    lastpos = dat2
    lasttime = timestamp
  else

     ' ship it right back
     mox.OutputMidiMsg -1, status, dat1, dat2
  end if
End Sub




MIDI-OX User Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.