MIDI-OX User Forum (http://www.midiox.com/cgi-bin/yabb/YaBB.pl)
MIDI-OX >> Scripting Questions >> Midi-ox, Live and DJ-ing.
(Message started by: syce on Apr 20th, 2005, 4:22am)

Title: Midi-ox, Live and DJ-ing.
Post by syce on Apr 20th, 2005, 4:22am
Hi,

I'm using Midi-ox for a while now. The midiox software helped me out several times where other programs (like Live) don't behave like I wanted it.
While I use Live as a "DJ-tool" it would be very handy to use "Bend" buttons (or something like that) to get the tempo in sync with the beat.
Live offers the ability to control the tempo with a midi control, so my idea is:

map a MIDI slider to the tempo of Live. Now I want two buttons (one to smoothly subtract let's say the value 10 from the slider value. When I press the second assigned button I want to add the value (10) to the tempo slider.

I think it's simple to put this in a script, but HOW?
Is there anyone out here with any idea? I hope so ;)



Title: Re: Midi-ox, Live and DJ-ing.
Post by dayton on May 27th, 2005, 5:04am
Hi. I don't get in here too much, so I didn't see your question until now.

Yes, you can do that.  I imagine the following:

1.  Map a MIDI-slider to the tempo in LIVE: I don't use Live, but from what you wrote this is probably a function of the Live program, and has to be done before you begin with a vbs-script.  Let us assume that you are using a MIDI-fader which sends CC-message 01 on channel 1 (It could be any controller on any channel).

1a.  You must make sure that the script also sends this.  In the "Sub Sink_MidiInput( ts, port, stat, dat1, dat2)", there has to be a line about sending the incoming values:

mox.OutputMidiMsg -1, stat, dat1, dat2  (this sends any info coming in without changing it; I assume you know all this)

2.  Create a button which smoothly decreases the tempo by ten:  the decrease part is easy the smoothly part is more tricky.  Let's say that pressing middle C on your keyboard in channel 1 is the button.  To jump to the new value, the code would be simple:
if stat=&hB0 and dat1=00 then
    mox.OutputMidiMsg -1, &hB0, 00, dat2
    lastCCvalue=dat2   'to keep the computer aware of what the value is currently
end if
if stat=&h90 and dat1=60 then
    mox.OutputMidiMsg -1, &hB0, 00, lastCCvalue - 10
    lastCCvalue=lastCCvalue - 10  'to keep the computer aware of what the value is currently.  Note, that this would cause a problem the next time you move the MIDI-fader because the tempo would then jump to the value being sent.
end if

So far so good.  A "smooth" transfer requires a change over time, however.  There are basically two ways of doing this in vbs with midiox.  If you are using the sink-method, then the Sub with all of your logical code only gets triggered when a note is triggered.  If you only have to do one thing at a time, then you just have to run a loop:
for i = 0 to 10
 mox.OutputMidiMsg -1, &hB0, 00, lastCCvalue - 1
 lastCCvalue=lastCCvalue - 1
 WScript.Sleep 1000   '(these are milliseconds; this loop would decrease the tempo in 10 seconds)
next i

Unfortunately, this causes the script to sleep for the time required to decrease the tempo, meaning that anything you play in the meantime gets spit out one after the other like a machine-gun after the time is up.

The other method would be to use the polling option in the midiox-scripting.  Instead of triggering a reaction every time a MIDI-message comes in, this is fixed in a continuous loop and checks to see if any messages have come in since the last time the loop started.  I don't know how fast the loop is, but it must be somehow related to interrupt-time.  This causes a readout in the task-manager of 100% CPU-usage, and because I don't use this method, I don't know how and if it would affect other programs running, but I did some experiments a while back, and it should work well enough with your projects (I used the polling-method while running Cubase and Reason at the same time, and had no real problems).  In any case, the script would read something like this:

if stat=&h90 and dat1=60 then
  tempodecreasetoggle=9
end if
if tempodecreasetoggle<>0 and timer>waittime then
  mox.OutputMidiMsg -1, &hB0, 00, lastCCvalue - 1
  lastCCvalue=lastCCvalue - 1
  tempodecreasetoggle=tempodecreasetoggle - 1
  waittime=timer + 1
end if

This way, the tempo gets reduced by 1 everytime the timer says that one second has gone by, and this happens 10 times.  The loop continues, however, allowing other MIDI-events to pass.  The (typical) problem with the computer sending CC-data which has been processed and no longer reflects the actual position of the fader could be addressed with a comparison statement to allow a smooth return to normality:

if stat=&hB0 and dat1=00 then
  if  lastCCvalue<dat2 then
     mox.OutputMidiMsg -1, &hB0, 00, dat2 - (dat2-lastCCvalue) + 2  'because sometimes controllers jump
     lastCCvalue=dat2 - (dat2-lastCCvalue) + 2
  else
     mox.OutputMidiMsg -1, &hB0, 00, dat2
     lastCCvalue=dat2
  end if
end if

Mach's gut,

Dayton

Title: Re: Midi-ox, Live and DJ-ing.
Post by syce on May 27th, 2005, 5:09am
Thanks for your reply, So that will be script writing tonight when i'm back home... ;)
I'll post it here when it's ready



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