User Forum    :: Powered by YaBB
  « MIDI-OX User Forum - Receiving Sysex »
Welcome, Guest. Please Login or Register.
Sep 9th, 2024, 2:22am


Home Home Help Help Search Search Members Members Login Login Register Register


   MIDI-OX User Forum
   MIDI-OX
   Scripting Questions
(Moderator: Jamie OConnell)
   Receiving Sysex
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Receiving Sysex  (Read 6615 times)
RickRepsher
New Member
*





   


Posts: 5
Receiving Sysex
« on: Jun 20th, 2005, 7:01am »
Quote Quote Modify Modify

I am trying to receive sysex data from a Nord Lead.  So far sending messages is not a problem.  This is the vba code I have been working with, but I always get a null back from the midiox instance.
 
' Global declaration
Dim WithEvents MWire As MIDIOXLib.MoxScript
 
Sub GetSysEx
    Dim strMsg As String
    Dim vStatus As Variant
    Dim strData As String
     
    MWire.FireMidiInput = 1
 
    ' Sysex to tell Nord to send patch data
    strMsg = "F0 33 7F 09 30 04 00 F7"
    MWire.SendSysExString strMsg
 
    strMsg = MWire.GetMidiInputRaw()
    vStatus = strMsg And &HF0
    If vStatus = &HF0 Then
   strData = MWire.GetSysExInput()
    End If
     
    If strData <> "" Then
   ConvertStringToByteArray strData
    Else
   MsgBox "NoData!"
    End If
End Sub
 
IP Logged
Jamie OConnell
Administrator
*****






   
WWW Email

Gender: male
Posts: 2027
Re: Receiving Sysex
« Reply #1 on: Jun 20th, 2005, 11:45am »
Quote Quote Modify Modify

I think with 'FireMidiInput' and 'WithEvents' you need to write a connection point sink routine.  In any case for polling, you'll have to implement a Loop: the MIDI input data will not be immediately available, and you'll have to keep checking until it is, and keep checking until you get all of it.  This is why the example code has a loop that is only terminated by the user.
« Last Edit: Jun 20th, 2005, 11:51am by Jamie OConnell » IP Logged

--Jamie
Music is its own reward.

RickRepsher
New Member
*





   


Posts: 5
Re: Receiving Sysex
« Reply #2 on: Jun 21st, 2005, 7:05am »
Quote Quote Modify Modify

Huh??
 
Which example code?  I have gone through the documentation looking for just such an example.  Personally, I would have thought that this is a question asked all the time, and something that would have been included in the docs.
 
Thanks,
 
Rick
IP Logged
Jamie OConnell
Administrator
*****






   
WWW Email

Gender: male
Posts: 2027
Re: Receiving Sysex
« Reply #3 on: Jun 22nd, 2005, 3:03am »
Quote Quote Modify Modify

Installed with MIDI-OX are several Windows Script Host examples.  They are in the WSH folder below the MIDIOX install folder (default: C:\Program Files\MIDIOX\WSH).
 
Here is the VB polling example:
 

' MIDIOX Test
option explicit
 
dim mox
dim str, strWrk
dim n, ii, nInst
dim bGo
dim chan, stat, dat1, dat2
dim msg, msgstr, strSysEx
dim A
 
' Wsh version
Str = Wscript.Name & " ver. " & Wscript.Version
MsgBox str
 
' Create object
Set mox = WScript.CreateObject("Midiox.MoxScript.1")  
 
str = "MIDI-OX"
n = mox.InstanceNumber
If n > 0 Then
  str = str & ":" & CStr( n )
Else
  MsgBox "No Instances"
End If
 
str = str & " " & mox.GetAppVersion
str = str & " of " & mox.InstanceCount
MsgBox str
 
 
' *** Try out our MIDI Input loop
mox.FireMidiInput = 0
 
str = "Enter MIDI Input Loop?" & vbCrLf & "(Exit Script from MIDI-OX)"
If vbYes = MsgBox( str, vbYesNo + vbQuestion, "MIDI Notes"  ) Then
   If vbYes = MsgBox( "Divert MIDI Input?", vbYesNo + vbQuestion, "MIDI Notes"  ) Then
      mox.DivertMidiInput = 1
   Else
      mox.DivertMidiInput = 0
   End If
 
   Do While mox.ShouldExitScript = 0
      ' First try raw Input
      msg = mox.GetMidiInputRaw()      
      If msg <> 0 Then
         stat = msg And &h000000FF
 
         If (stat = &hF0) Then ' SysEx, must ask for SysEx string message
              strSysEx = mox.GetSysExInput()
              mox.SendSysExString strSysEx
         Else
            msg  = msg \ 256       ' pull off stat
            dat1 = msg And &h0000007F
            msg  = msg \ 256
            dat2 = msg And &h0000007F        
            mox.OutputMidiMsg -1, stat, dat1, dat2                    
         End If
      End If
 
      ' Now try the string format
      msgStr = mox.GetMidiInput()      
      If msgStr <> "" Then
         A = Split( msgStr, ",", -1, vbTextCompare )
         stat = Int(A(2))
 
         If (stat = &hF0) Then ' SysEx, must ask for SysEx string message
             strSysEx = mox.GetSysExInput()
             mox.SendSysExString strSysEx  
         Else
            dat1 = Int(A(3))
            dat2 = Int(A(4))
            mox.OutputMidiMsg -1, stat, dat1, dat2                    
         End If
      End If
   Loop
 
   mox.DivertMidiInput = 0
End If
 
MsgBox "End Demo"
 
Set str    = nothing
Set strWrk = nothing
Set mox    = nothing
 
' Exit Point
'------------------------------------------
 
« Last Edit: Jun 22nd, 2005, 3:04am by Jamie OConnell » IP Logged

--Jamie
Music is its own reward.

RickRepsher
New Member
*





   


Posts: 5
Re: Receiving Sysex
« Reply #4 on: Jun 22nd, 2005, 6:50am »
Quote Quote Modify Modify

Jamie,
 
Ok, I didn't see the examples, only the documentation.
 
I still have a couple of questions.  
 
1) Where is the loop "terminated by the user"?  
2) In the following code:
     strSysEx = mox.GetSysExInput()  
     mox.SendSysExString strSysEx  
Is strSysEx the entire message, or just one byte?  Are you resending the message and if so, why.  Just for the example?
 
Thanks again
 
Rick
IP Logged
Jamie OConnell
Administrator
*****






   
WWW Email

Gender: male
Posts: 2027
Re: Receiving Sysex
« Reply #5 on: Jun 22nd, 2005, 5:16pm »
Quote Quote Modify Modify

1) The loop starts here:
 

. . .
str = "Enter MIDI Input Loop?" & vbCrLf & "(Exit Script from MIDI-OX)"  
If vbYes = MsgBox( str, vbYesNo + vbQuestion, "MIDI Notes"  ) Then  
   If vbYes = MsgBox( "Divert MIDI Input?", vbYesNo + vbQuestion, "MIDI Notes"  ) Then  
      mox.DivertMidiInput = 1  
   Else  
      mox.DivertMidiInput = 0  
   End If  
 
   Do While mox.ShouldExitScript = 0  
      ' First try raw Input
   . . .

 
2) It is the entire message received so far.  It is sent just as an example, although you might want to echo it anyway, especially if it's not something you want to handle.
 
« Last Edit: Jun 22nd, 2005, 5:16pm by Jamie OConnell » IP Logged

--Jamie
Music is its own reward.

RickRepsher
New Member
*





   


Posts: 5
Re: Receiving Sysex
« Reply #6 on: Jun 23rd, 2005, 8:54am »
Quote Quote Modify Modify

I obviously still don't understand what is supposed to be happening here.  If I open MidiOx in the "stand alone mode" and go to the sysex view, and enter the following string in the sysex view command window  
 
F0 33 7F 09 31 00 00 F7
 
and then do a send/receive, I get data back in the display window (data that I would expect to see.)
 
But...
 
If I run the following piece of code (which is pretty much copied from the example), I get the following values as I step through the procedure.
 
strMsg = "0, 240, 0, 0, 0"
lngStstus = 0
 
After multiple loops through, there are only null values in those variables, and we have never seen an &HF0, although the "stand alone" method definitly returns one (in the first byte.)
 
I DO have an &HF0 in arr_strTemp(1) (zero based...)
 
 
Code:
'>>>>>>>>>>
Dim strSysEx As String
Dim strMsg As String
Dim arr_strTemp() As String
 
Dim lngStatus As Long
 
MWire.FireMidiInput = 0
MWire.DivertMidiInput = 1
 
strSysEx = "F0 33 7F 09 31 00 00 F7"
MWire.SendSysExString strSysEx
 
strSysEx = ""
 
Do While MWire.ShouldExitScript = 0
    strMsg = MWire.GetMidiInput()
    If strMsg <> "" Then
   arr_strTemp = Split(strMsg, ",", -1, vbTextCompare)
   lngStatus = Int(arr_strTemp(2))
 
   If (lngStatus = &HF0) Then ' SysEx, must ask for SysEx string message
  strSysEx = MWire.GetSysExInput()
   End If
    End If
Loop
 
MWire.DivertMidiInput = 0
'<<<<<<<<<<
IP Logged
Jamie OConnell
Administrator
*****






   
WWW Email

Gender: male
Posts: 2027
Re: Receiving Sysex
« Reply #7 on: Jun 25th, 2005, 12:33pm »
Quote Quote Modify Modify

I wouldn't be surprised if single-stepping through would affect the results as you're probably missing input that way.  You might try the Connection point sink model, which gets triggered when there is data to collect.  Again though, single-stepping through a real-time MIDI program may drop or skip data.  Instead, you might want to put in some kind of TRACE or reporting statements to see what's happening.  The 'sink' example is in MOXScriptDemo.vbs.
IP Logged

--Jamie
Music is its own reward.

RickRepsher
New Member
*





   


Posts: 5
Re: Receiving Sysex
« Reply #8 on: Jun 29th, 2005, 11:52am »
Quote Quote Modify Modify

Jamie,
 
First off, thanks for all the help so far.  I have done some VBS and VBA programming, but my issues have been how I need to interact with the MIDIOX com model.
 
With that said... when I looked at the status message and noticed that I had an $HF0 in the second byte, I changed my code to this:
 
lngStatus = Int(arr_strTemp(1))
 
Being zero based, I got the correct status message, and I was able to grab the incoming sysex data.
 
Everything is smooth as silk...
 
Now I just need to play some more to get the feel of the rest of the model.
 
Thanks again.
 
RR
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »


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