User Forum    :: Powered by YaBB
  « MIDI-OX User Forum - script to initiate and receieve Midi Sample Dump »
Welcome, Guest. Please Login or Register.
May 9th, 2025, 5:48am


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


   MIDI-OX User Forum
   MIDI-OX
   Scripting Questions
(Moderator: Jamie OConnell)
   script to initiate and receieve Midi Sample Dump
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: script to initiate and receieve Midi Sample Dump  (Read 2595 times)
mercury
New Member
*



MIDI-OX Rules!

   


Posts: 2
script to initiate and receieve Midi Sample Dump
« on: Nov 25th, 2018, 4:44pm »
Quote Quote Modify Modify

Hi,
 
I have managed to hack together a script in Windows PowerShell to send and receive SysEx messages but I'm now scratching my head on how to  expand this to support SDS messages. The issue as I see it may be the handshaking.
 
I haven't figured out how to implement a sink method in PowerShell yet so for now I am simply looking for the  end-of-exclusive byte to break the receive loop. SDS responses will have multiple messages so I need to change things to support that.
 
What I would like to achieve is to issue a command to receive a specific sample and store the result in a variable and eventually export this to a wav file. I have code and some command line programs that will convert a .syx file to .wav so If I can just get the syx format or even the full string that MIDI-OX will receive by default that would get me across the line.
 
FYI, this is a for a project of mine to archive samples from my ancient Peavey DPM SP sample player. So far I have got working code to Load a bank from Disk, pull all the SysEx info for all objects and generate a keymap description for all the presets. Given the proprietary disk format I need to rely on SDS to recover the samples to my PC. Once that is achieved I can then create new sound programs in a virtual sampler such as ESX24.  
 
Obviously the use of PowerShell is my choice but I'll be happy to receive VBScript code for the solution which I can then try and translate.
 
Here is my function that returns either an array of hex values or a concatenated string (with a space delimiter). It expects an array of hex values as input:
 
function Get-SysExResponseMessage{
 param(
  [object]$SysExCommand,
  [switch]$AsText
 )
     
    $EOX = "F7"
 $IsEOX = $false
 
    If($SysExCommand[$SysExCommand.GetUpperBound(0)] -ne $EOX){$SysExCommand += @($EOX)} # Attach missing EOX if required
     
    [string]$SysExString = $SysExCommand -join " "
 
  $MOX.SendSysExString($SysExString)  
  $SysExResponseMessage = ""  
 
  While ($IsEOX -eq $false){
   $MidiResponseMessage = $MOX.GetMidiInput()  
   If ($MidiResponseMessage -ne "") {  
   Write-Host "MSG Receiving...($SysExResponseMessage)" -for cyan
     If (([Int](($MidiResponseMessage -Split ",")[1]) ) -eq 240) { # SysEx, must ask for SysEx string message "&HF0"
      Write-Host "Receiving SysEx Dump" -for green  
      $SysExResponseMessage += $MOX.GetSysExInput()  
      if($SysExResponseMessage -like "*$EOX*"){$IsEOX = $true}  
     }
   }  
  }
   
  If ($AsText -eq $true){
   Return $SysExResponseMessage.Trim()
  }
  else {
   Return $SysExResponseMessage.Trim() -split " "
  }
 }
IP Logged
mercury
New Member
*



MIDI-OX Rules!

   


Posts: 2
Re: script to initiate and receieve Midi Sample Du
« Reply #1 on: Dec 2nd, 2018, 2:35am »
Quote Quote Modify Modify

Success! example script below.
 
I over-thought some of it initially, I should be doing checksums and sending hand-shaking messages but 3 seconds of no more messages does the job for now.  
 
Code:

function Get-SysExResponseMessage{
 param(
  [string]$SysExCommand,
  [switch]$AsText
 )
 
    Write-Host "." -NoNewline -ForegroundColor white # crude progress indicator
 
  $MOX.SendSysExString($SysExCommand)  
   $SysExResponseMessage = ""    
   $TimeoutSeconds = 3
   $LastMessageTime = get-date
   $Continue = $true
   
  While ($Continue -eq $true){
  $MidiResponseMessage = $MOX.GetMidiInput()
   If ($MidiResponseMessage -ne "") {
      $LastMessageTime = get-date
      Write-Host "." -NoNewline -ForegroundColor Green
     If (([Int](($MidiResponseMessage -Split ",")[1]) ) -eq 240) { # SysEx detected, retreive the message
        $SysExResponseMessage += $MOX.GetSysExInput()
     }
  }
  # Check duration of 'No Response'
  if(((Get-date) - $LastMessageTime).totalSeconds -lt $TimeoutSeconds){$Continue = $true}
  else{$Continue = $false} # Break loop
  }
   
   Write-Host "." -ForegroundColor white
   
  If ($AsText -eq $true){
   Return $SysExResponseMessage.Trim()
  }
  else {
   Return $SysExResponseMessage.Trim() -split " "
  }
}
 
# Main
 
$MOX = new-object -ComObject "Midiox.moxscript.1"
$MOX.FireMidiInput = 0
$MOX.DivertMidiInput = 1
 
Write-Host "Get Sample 00" -ForegroundColor Yellow
$Sample00_String = Get-SysExResponseMessage -SysExCommand "F0 7E 7F 03 00 00 F7" -AsText
 
Write-Host "Get Sample 01" -ForegroundColor Yellow
$Sample01_String = Get-SysExResponseMessage -SysExCommand "F0 7E 7F 03 01 00 F7" -AsText
 
# Cleanup, needed in Visual Studio Code
[System.Runtime.InteropServices.Marshal]::ReleaseComObject( $MOX ) | out-null # Closes Midi-OX
[System.GC]::Collect() | out-null     # Note sure if this is required
[System.GC]::WaitForPendingFinalizers | out-null     # Note sure if this is required
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.