MIDI-OX User Forum (http://www.midiox.com/cgi-bin/yabb/YaBB.pl)
MIDI-OX >> Scripting Questions >> handling sysex & note data in one script
(Message started by: msalmon on Nov 22nd, 2009, 7:19pm)

Title: handling sysex & note data in one script
Post by msalmon on Nov 22nd, 2009, 7:19pm
hi folks

i've been working on a vbscript to interface between my Allen & Heath ZEDR16 mixer to my DAW (Samplitude). The only issue I'm having is that data is not getting to my Sink_MidiInput() function. It IS getting to Sink_SysExInput and I've gotten my first feature working in fact.

For background I want to do 2 things in 1 script

1. convert MMC data to Note data, since my DAW transport doesn't do MMC. I have this completed, it wasn't hard

2. receive midi-note data from buttons, and convert them in multiples of 1-n depending on the setting of a bank select button. The 1-8 and bank select buttons all send Midi note on/off and I plan to write some logic to handle this within a function.


Some notes on what I've done to debug while working on the MidiInput mystery:
- tried every config I could think of in midi-ox Midi Devices settings. Right now I have:
       MidiInput = ZEDR16
       Output=MIDIYoke.1
       Port mapping: Out to MIDI Yoke.1 :- ZED, MIDI-OX Events
       Port map objects: channels, system, zed, MIDI-OX events

- When pressing a Midi note button, in Monitor Input I see the notes coming in as expected.
TIMESTAMP IN PORT STATUS DATA1 DATA2 CHAN NOTE EVENT    
00002EFF  10  --     9F    07    7F   16  G -1 Note On  
00002F6D  10  --     8F    07    00   16  G -1 Note Off  

- Again when pressing the same notes, in Midi Port Activity I see:
   Input Ports: 10) ZED Channel 16 red light blinks when pressing the button. Also when pressing MMC keys the SX right light flashes
- setting each possible value of the FireMidiInput and DivertMidiInput.

- parsing the MidiRaw and MidiString data in a Do/While loop (in this case I get the sysex data, but midi note data never comes through).

- In MIDIOX\WSH\MOXScriptDemo.vbs I added 2 debug statements to follow the execution logic
'------------------------------------------
   ' This NEVER gets called when I press a mixing board button
   Sub Sink_MidiInput( ts, port, stat, dat1, dat2)
      msgbox "Midi input"      
   End Sub

   ' This DOES get called when I press a key that produces MMC
   Sub Sink_SysExInput( strSysEx )
      msgbox "sysexinput"      
  End Sub
'------------------------------------------


Summary:
- is it a config of midi-ox that I have messed so that only sysex is processed?
- is it something else in my code? I can paste the various code I've written but if someone has an example that works with call-back sink functions for midi-data and sysex that would be music appreciated


For details on the midi data that the mixer sends and the buttons please see the below link
http://www.allen-heath.co.uk/zed/dl/ZED_R16_MIDI_implementation.pdf :)[/b][b][/b][b][/b][b]

Title: Re: handling sysex & note data in one script
Post by msalmon on Nov 26th, 2009, 9:10pm
I tried my korg electribe also to see if I could get it to send midi data. Again as above sysex worked, but note data didnt get to the script (though again it shows up in the midi input monitor)

Title: Re: handling sysex & note data in one script
Post by Jamie OConnell on Nov 27th, 2009, 11:23pm
--- From the Help --------------

The first thing to do when you want to communicate with MIDI-OX is to create an object. You can use the WScript object to both create an object and identify a prefix for a connection point sink. The sink will be called by MIDI-OX whenever MIDI data is available.

Example:

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


This statement creates an object and tells WScript to generate calls to a method named OnTrigger_MidiInput(). System Exclusive data will trigger an OnTrigger_SysExInput(). You create a subroutine in your script with that name to receive MIDI data. Data will not actually start flowing until you set the FireMidiInput property.

CreateObject() will launch a MIDI-OX instance if none is running, or attach to the oldest running instance if any are running. However, instances are not reused: once a script has been attached to an instance and then closed, another script will not attach to this instance.

mox.FireMidiInput = 1 ' begins input

-------------------------------------

You obviously got the SysEx part working.  1) What does your object creation look like?  2) Are you calling 'FireMidiInput'?

Title: Re: handling sysex & note data in one script
Post by msalmon on Nov 28th, 2009, 9:51pm
My object create code looks just like yours except for the second parameter which is "Sink_" to match the prefix of my callback methods. Also I previously tested setting the firemidiinput value to 0 and 1 without diference in behavior.

Thanks
Ms


Title: Re: handling sysex & note data in one script
Post by Jamie OConnell on Nov 29th, 2009, 3:29pm

Quote:
Also I previously tested setting the firemidiinput value to 0 and 1 without diference in behavior.  


If that's the case, then somehow that statement is not being executed, because it MIDI Input will not be called until after the "FireMidiInput" property has been set on the object.  The property is case sensitive (as is all code).  BTW, I wouldn't recommend Message Boxes as debugging aids in time critical routines -- instead use some sort of tracing.

Perhaps you can post your actual code, and people may be able to see where the problem lies.


Title: Re: handling sysex & note data in one script
Post by msalmon on Nov 30th, 2009, 12:01pm
Here's the script called mmc.vbs. I run it by simply double-clicking it in windows explorer which launches midi-ox:
============================================
********************************************
============================================


option explicit

dim mox
dim str, str2, strWrk, Tstamp, port
dim chan, stat, dat1, dat2
dim msg, msgstr, strPos
dim A
dim bankLength, bankFlag
dim running
bankLength = 3
bankFlag = 1
running = true
' Wsh version
Str = Wscript.Name & " ver. " & Wscript.Version
' Create object
Set mox = WScript.CreateObject("MIDIOX.MOXScript.1", "Sink_")  
mox.DivertMidiInput = 1
mox.FireMidiInput = 1

strWrk = "Sys MidiIn: " & mox.GetFirstSysMidiInDev
Do while strWrk <> ""
  str = str & vbCrLf & "  " & strWrk
  strWrk = mox.GetNextSysMidiInDev
Loop

strWrk = "Open midiDevices: " & mox.GetFirstOpenMidiInDev
Do while strWrk <> ""
  str2 = str2 & vbCrLf & "  " & strWrk
  strWrk = mox.GetNextOpenMidiInDev
Loop

MsgBox "Looping" & vbCrLf & Str & vbCrLf & str2

' Cleanup and exit MidiOx
mox.DivertMidiInput = 0
mox.ShutdownAtEnd = True

Set str    = nothing
Set strWrk = nothing
Set mox    = nothing
' Exit Point

' getting called
Sub Sink_SysExInput(strSysEx)
   dim strSysExmod
   strSysExmod = mid(strSysEx,13,2)

   Select Case A
       ' STOP BUTTON - send CC 0x55
       Case "01"            
           mox.OutputMidiMsg -1, &h95, &hFA, &h7F
           mox.OutputMidiMsg -1, &h95, &hFA, &h00
       ' PLAY BUTTON
       Case "02"
           mox.OutputMidiMsg -1, &h95, &hFC, &h7F
           mox.OutputMidiMsg -1, &h95, &hFC, &h00
      ' FFWD
       Case "04"
           mox.OutputMidiMsg -1, &h95, &hFD, &h7F
           mox.OutputMidiMsg -1, &h95, &hFD, &h00
       ' REWIND
       Case "05"
           mox.OutputMidiMsg -1, &h95, &hFE, &h7F
           mox.OutputMidiMsg -1, &h95, &hFE, &h00
       'REC
       Case "06"
           mox.OutputMidiMsg -1, &h95, &hFF, &h7F
           mox.OutputMidiMsg -1, &h95, &hFF, &h00
       Case Else mox.SendSysExString strSysEx
   End Select  
End Sub

' not getting called
Sub Sink_MidiInput (timestamp, status, channel, data1, data2)
  mox.OutputMidiMsg 16, status, data1, data2
End Sub

Title: Re: handling sysex & note data in one script
Post by Jamie OConnell on Nov 30th, 2009, 10:23pm

Quote:
mox.OutputMidiMsg 16, status, data1, data2


The first parameter to OutputMidiMsg() is the port# with -1 meaning all ports.  You are specifying #16.  Do you have 17 open MIDI ports?  How many are reported in your script? If not, put -1 or a number of an open port.

Status without the channel will always specify channel 1 (0).  To re-combine them you can do: status + chan.

Try moving your divert and fire statements until right before your MsgBox exit block:

-----------------

mox.DivertMidiInput = 1
mox.FireMidiInput = 1
MsgBox "Looping" & vbCrLf & Str & vbCrLf & str2

-------------------------------------------------

you can test them too:

mox.FireMidiInput = 1 ' begin firing MIDI events
If mox.FireMidiInput = 0 Then
  MsgBox "Input will not cause trigger -- are input devices open?"
End If
MsgBox "Looping" & vbCrLf & Str & vbCrLf & str2

---------------------------------------

Finally, Does the vanilla MOXScriptDemo.vbs work for you as written?





Title: Re: handling sysex & note data in one script
Post by msalmon on Dec 1st, 2009, 11:05am
Ok I figured it out, it wasn't a script issue it was a setup issue :)

For some reason I mis-interpreted the MIDI Filter window as a positive filter, e.g. it asks "Display SysEx messages" made me think erroneously that for each checkbox it would pass the data through. I think that was day 1 I found that, and checked everything on the filter page to match. I was going through everything in the app setup and now have the data getting to both sink_ functions.

thanks a lot for the support and time, now I get to have some fun...
ms

Title: Re: handling sysex & note data in one script
Post by Jamie OConnell on Dec 1st, 2009, 5:50pm
Excellent - Glad to hear it!



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