Jump to content

Recommended Posts

Posted (edited)

If anyone is interested here is my version of this UDF.

The MIDI Stream section -- wow -- I'm not able to complete with my current AutoIt level. But I have taken it very far though. Maybe someone with knowledge of structs could lend a hand?

Tested on Windows 7 Professional x64.

Examples.au3

#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d
#AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%"
#AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3"
#AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe"
#AutoIt3Wrapper_UseX64=n

Switch @CPUArch
    Case "X86"
        #AutoIt3Wrapper_UseX64=n
    Case "X64"
        #AutoIt3Wrapper_UseX64=y
EndSwitch

#include "MIDI UDF.au3"

; Stream Example ----------------------------------------------------------------------------------------------------------
Global $return = _midiStreamOpen()
_printErr(@error, @extended)

Global Const $handle = $return

$return = _midiStreamRestart($handle)
_printErr(@error, @extended)

$return = _midiStreamProperty_SetTimeDiv($handle, 96)
_printErr(@error, @extended)

$return = _midiStreamOut($handle, $C_OCTAVEUP_NOTEON)
_printErr(@error, @extended)

$return = _midiStreamRestart($handle)
_printErr(@error, @extended)

Sleep(1000)

$return = _midiStreamPosition($handle)
_printErr(@error, @extended)

$return = _midiStreamPause($handle)
_printErr(@error, @extended)

$return = _midiStreamStop($handle)
_printErr(@error, @extended)

$return = _midiStreamClose($handle)
_printErr(@error, @extended)

; -------------------------------------------------------------------------------------------------------------------------

Global Const $open = _midiOutOpen()

_MidiOutSetVolume(65536)

ConsoleWrite(_MidiOutGetVolume() & @LF)

For $i = 27 To 87
    _MidiOutShortMsg($open, 0x99 + ($i * 256) + (127 * 0x10000)) ; Drums Bitch!
    Sleep(200)
Next

; -------------------------------------------------------------------------------------------------------------------------

; THE FOLLOWING IS AN EXAMPLE ON HOW TO USE THE CONSTANTS...
; PIECE - 12 VARIATIONS (K.265,Ah! vous dirai-je maman) THEME
; Composer : Wolfgang Amadeus Mozart
; Resequenced by Eynstyne

For $i = 1 To 2
    _midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $CBASS_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $C_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $E_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $C_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $F_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $C_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $E_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $C_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $D_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $B_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $C_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $A_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $FBASS_NOTEON)
    Sleep(500)
    _midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $GBASS_NOTEON)
    Sleep(300)
    _midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
    Sleep(175)
    _midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
    _midioutshortmsg($open, $CBASS_NOTEON)
    Sleep(1000)
    _midioutshortmsg($open, $CBASS_NOTEOFF)
Next

_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
Sleep(500)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $D_NOTEON)
Sleep(500)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
Sleep(500)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(500)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
Sleep(500)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $B_NOTEON)
Sleep(500)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $G_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $G_NOTEON)
Sleep(500)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $D_NOTEON)
Sleep(500)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $G_NOTEON)
Sleep(500)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(400)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)

Sleep(50)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
Sleep(50)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
Sleep(50)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
Sleep(250)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $D_NOTEON)
Sleep(150)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
Sleep(500)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $B_NOTEON)
Sleep(500)
_midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $CBASS_NOTEON)
Sleep(500)
_midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(500)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $F_NOTEON)
Sleep(500)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
Sleep(500)
_midioutshortmsg($open, $G_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(500)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $D_NOTEON)
Sleep(500)
_midioutshortmsg($open, $F_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $B_NOTEON)
Sleep(500)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $C_NOTEON)
Sleep(500)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $A_NOTEON)
Sleep(500)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $FBASS_NOTEON)
Sleep(400)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
Sleep(50)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
Sleep(50)
_midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
Sleep(50)
_midioutshortmsg($open, $D_OCTAVEUP_NOTEON)
Sleep(250)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
Sleep(150)
_midioutshortmsg($open, $C_OCTAVEUP_NOTEON)
_midioutshortmsg($open, $CBASS_NOTEON)
Sleep(1000)

_MidiOutClose($open)

Func _printErr(Const $error, Const $extended)
    If Not $error Then
        If IsArray($return) Then
            _ArrayDisplay($return)
        Else
            ConsoleWrite("$return: " & $return & @LF)
        EndIf
    ElseIf $error = 1 Then
        ConsoleWrite($return & ": " & $extended & @LF)
    ElseIf $error = 2 Then
        ConsoleWrite("DllCall : " & $error & @LF)
    EndIf
EndFunc

MIDI UDF.au3

#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d
#AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%"
#AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3"
#AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe"
#AutoIt3Wrapper_UseX64=n

Switch @CPUArch
    Case "X86"
        #AutoIt3Wrapper_UseX64=n
    Case "X64"
        #AutoIt3Wrapper_UseX64=y
EndSwitch

#include <Array.au3>
#include <WinAPI.au3>
#include "MIDI Constants.au3"
#include "MIDI Stream.au3"

;======================
;Midi UDFs by Eynstyne
;See Example in Comments
;======================

Global $winmm_dll

;=======================================================
;Retrieves the number of Midi Output devices which exist
;Parameters - None
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _midiOutGetNumDevs()
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutGetNumDevs")
    If Not @error Then Return $ret[0]
EndFunc   ;==>_midiOutGetNumDevs

;=======================================================
;Retrieves the number of Midi Input devices which exist
;Parameters - None
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _midiInGetNumDevs(Const $ReturnErrorAsString = 0) ;Working
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInGetNumDevs")
    If Not @error Then Return $ret[0]
EndFunc   ;==>_midiInGetNumDevs

;=======================================================
;Retrieves a MIDI handle and Opens the Device
;Parameters(Optional) - Device ID, Window Callback, instance, flags
;Author  : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _midiOutOpen(Const $device_id = 0, Const $callback = 0, Const $instance = 0, Const $flags = 0)
    $winmm_dll = DllOpen("winmm.dll")

    Local Const $h_midiout = DllStructCreate("handle")

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutOpen", _
                                "ptr"  , DllStructGetPtr($h_midiout), _
                                "uint" , $device_id, _
                                "dword", $callback, _
                                "dword", $instance, _
                                "dword", $flags)

    Switch $ret[0]
        Case 1 To 20
            SetError(1, $ret[0])
        Case Else
            Return DllStructGetData($h_midiout, 1)
    EndSwitch
EndFunc   ;==>_midiOutOpen

;=======================================================
;Retrieves a MIDI handle and Opens the Device
;Parameters(Optional) - Device ID, Window Callback, instance, flags
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _midiInOpen(Const $device_id = $MM_MIDI_MAPPER, Const $callback = 0, Const $instance = 0, Const $flags = 0)
    Local Const $h_midiin = DllStructGetPtr(DllStructCreate("dword"))

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInOpen", _
                                "ptr" , $h_midiin, _
                                "int" , $device_id, _
                                "long", $callback, _
                                "long", $instance, _
                                "long", $flags)

    Switch $ret[0]
        Case 1 To 20
            SetError(1, $ret[0])
        Case Else
            Return DllStructGetData($h_midiin, 1)
    EndSwitch
EndFunc   ;==>_midiInOpen

;=======================================================
;Sets the Mixer Volume for MIDI
;Parameters - Volume (0 - 131070)
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutSetVolume(Const $volume, Const $device_id = $MM_MIDI_MAPPER)
    Local $_volume

    If $volume < 0 Then
        $_volume = 0
    Elseif $volume > 131070 Then
        $_volume = 131070
    Else
        $_volume = $volume
    EndIf

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutSetVolume", _
                                "uint" , $device_id, _
                                "dword", $_volume)

    Switch $ret[0]
        Case 1 To 20
            SetError(1, $ret[0])
        Case Else
            Return $ret[0]
    EndSwitch
EndFunc   ;==>_MidiOutSetVolume

;=======================================================
;Gets the Mixer Volume for MIDI
;Parameters - None
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutGetVolume($device_id = $MM_MIDI_MAPPER)
    Local Const $volume = DllStructCreate("ushort")

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutGetVolume", _
                                "long", $device_id, _
                                "ptr", DllStructGetPtr($volume))
    Switch $ret[0]
        Case 1 To 20
            SetError(1, $ret[0])
        Case Else
            Return DllStructGetData($volume, 1)
    EndSwitch
EndFunc   ;==>_MidiOutGetVolume

;=======================================================
;Resets MIDI Output/Input
;Parameters - MidiHandle
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutReset($hmidiout)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutReset", "handle", $hmidiout)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiOutReset

Func _MidiInReset($hmidiin)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInReset", "handle", $hmidiin)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiInReset

;=======================================================
;Starts Midi Input
;Parameters - MidiHandle
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiInStart($hmidiin)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInStart", "handle", $hmidiin)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiInStart

;=======================================================
;Stops Midi Input
;Parameters - MidiHandle
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiInStop($hmidiin)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInStop", "handle", $hmidiin)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiInStop

;=======================================================
;Closes Midi Output/Input devices
;Parameters - MidiHandle
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutClose($hmidiout)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutClose", "handle", $hmidiout)
    DllClose($winmm_dll)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiOutClose

Func _MidiInClose($hmidiin)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInClose", "handle", $hmidiin)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiInClose

;=======================================================
;Cache Drum Patches for Output
;Parameters - MidiHandle,Patch,Keynumber,Flag
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutCacheDrumPatches($hmidiout, $Patch, $keynumber, $flags = 0)
    Local Const $struct = DllStructCreate("short")
    Local Const $keyarray = _ArrayCreate($keynumber)
    DllStructSetData($struct, 1, $keynumber)

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutCacheDrumPatches", "handle", $hmidiout, "int", $Patch, "ptr", DllStructGetPtr($struct), "int", $flags)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiOutCacheDrumPatches

;=======================================================
;Caches MIDI Patches
;Parameters - MidiHandle, Bank, PatchNumber, Flags
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutCachePatches($hmidiout, $bank, $patchnumber, $flags = 0)
    Local Const $struct = DllStructCreate("short")
    Local Const $patcharray = _ArrayCreate($patchnumber)
    DllStructSetData($struct, 1, $patchnumber)

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutCachePatches", "handle", $hmidiout, "int", $bank, "ptr", DllStructGetPtr($struct), "int", $flags)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiOutCachePatches


;=======================================================
;Gets MIDI DeviceID
;Parameters - MidiHandle
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiInGetID($hmidiin)
    Local Const $struct = DllStructCreate("uint")
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInGetID", "handle", $hmidiin, "ptr", DllStructGetPtr($struct))

    If Not @error Then
        Return DllStructGetData($struct, 1)
    EndIf
EndFunc   ;==>_MidiInGetID


Func _MidiOutGetID($hmidiout)
    Local Const $struct = DllStructCreate("uint")
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInGetID", "handle", $hmidiout, "ptr", DllStructGetPtr($struct))

    If Not @error Then
        Return DllStructGetData($struct, 1)
    EndIf
EndFunc   ;==>_MidiOutGetID

;=======================================================
;Translates Error codes into Plaintext
;Parameters - Error number
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiInGetErrorText($error)
    Local Const $struct = DllStructCreate("char[128]")
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInGetErrorText", "int", $error, "ptr", DllStructGetPtr($struct), "int", 999)
    MsgBox(0, '', DllStructGetData($struct, 1))
EndFunc   ;==>_MidiInGetErrorText

Func _MidiOutGetErrorText($error)
    Local Const $struct = DllStructCreate("char[128]")
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutGetErrorText", "int", $error, "ptr", DllStructGetPtr($struct), "int", 999)
    MsgBox(0, '', DllStructGetData($struct, 1))
EndFunc   ;==>_MidiOutGetErrorText

;=======================================================
;MIDI Message Send Function
;Parameters - Message as Hexcode or Constant
;Author : Eynstyne
;Library : Microsoft winmm.dll
;=======================================================
Func _MidiOutShortMsg(Const $device_id, Const $msg)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutShortMsg", "uint", $device_id, "dword", $msg)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiOutShortMsg

Func _MidiOutLongMsg($hmidiout, $data, $bufferlength, $bytesrecorded, $user, $flags, $next, $getmmsyserr = 0)
    Local Const $struct = DllStructCreate("char[128];udword;udword;udword;udword;ushort;ushort")
    DllStructSetData($struct, 1, $data)
    DllStructSetData($struct, 2, $bufferlength)
    DllStructSetData($struct, 3, $bytesrecorded)
    DllStructSetData($struct, 4, $user)
    DllStructSetData($struct, 5, $flags)
    DllStructSetData($struct, 6, $next)
    DllStructSetData($struct, 7, 0)

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInPrepareHeader", "handle", $hmidiout, "ptr", DllStructGetPtr($struct), "long", 999)

    If Not @error Then
        If $getmmsyserr = 1 Then
            Return $ret[0]
        ElseIf $getmmsyserr <> 1 Then
            Local Const $array = _ArrayCreate($hmidiout, DllStructGetData($struct, 1), DllStructGetData($struct, 2), DllStructGetData($struct, 3), DllStructGetData($struct, 4), DllStructGetData($struct, 5), DllStructGetData($struct, 6), DllStructGetData($struct, 7))
            Return $array
        EndIf
    EndIf
EndFunc   ;==>_MidiOutLongMsg

;=======================================================
;Get the Capabilities of the MIDI Device
;Parameters - DeviceID
;Author : Eynstyne
;Library : Microsoft winmm.dll
;First Value - Manufacturer ID
;Second Value - Product ID
;Third Value - Driver Version
;Fourth Value - Driver Name
;Fifth Value - Type of Device
;Sixth Value - Voices
;Seventh Value - Notes
;eighth Value - Channel Mask
;Ninth Value - Capabilities
;=======================================================
Func _MidiOutGetDevCaps(Const $deviceid = $MM_MIDI_MAPPER, Const $getmmsyserr = 0)
    Local Const $midi_out_caps = DllStructCreate("ushort;ushort;uint;char[32];ushort;ushort;ushort;ushort;uint")

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutGetDevCapsA", _
                                "uint", $deviceid, _
                                "ptr" , DllStructGetPtr($midi_out_caps), _
                                "uint", DllStructGetSize($midi_out_caps))

    Switch $ret[0]
        Case 1 To 20
            SetError(1, $ret[0])
        Case Else
            Switch $getmmsyserr
                Case 1
                    Return $ret[0]
                Case Else
                    Return _ArrayCreate(DllStructGetData($midi_out_caps, 1), _
                                        DllStructGetData($midi_out_caps, 2), _
                                        DllStructGetData($midi_out_caps, 3), _
                                        DllStructGetData($midi_out_caps, 4), _
                                        DllStructGetData($midi_out_caps, 5), _
                                        DllStructGetData($midi_out_caps, 6), _
                                        DllStructGetData($midi_out_caps, 7), _
                                        DllStructGetData($midi_out_caps, 8), _
                                        DllStructGetData($midi_out_caps, 9))
            EndSwitch
    EndSwitch
EndFunc   ;==>_MidiOutGetDevCaps

;=======================================================
;Get the Capabilities of the MIDI Device Input
;Parameters - DeviceID
;Author : Eynstyne
;Library : Microsoft winmm.dll
;First Value - Manufacturer ID
;Second Value - Product ID
;Third Value - Driver Version
;Fourth Value - Driver Name
;=======================================================
Func _MidiInGetDevCaps($deviceid = 0, $getmmsyserr = 0)
    Local Const $struct = DllStructCreate("ushort;ushort;uint;char[128]")

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInGetDevCapsA", "long", $deviceid, "ptr", DllStructGetPtr($struct), "int", 999)

    If Not @error Then
        If $getmmsyserr = 1 Then
            Return $ret[0]
        ElseIf $getmmsyserr <> 1 Then
            Local Const $array = _ArrayCreate(DllStructGetData($struct, 1), DllStructGetData($struct, 2), DllStructGetData($struct, 3), DllStructGetData($struct, 4))
            Return $array
        EndIf
    EndIf
EndFunc   ;==>_MidiInGetDevCaps

;========================================================
;Connect/Disconnect the MIDI Device to Application Source
; / Dest.
;Parameters - MidiHandleIn, MidiHandleOut
;Author: Eynstyne
;Library : Microsoft winmm.dll
;========================================================
Func _MidiConnect($hmidiin, $hmidiout)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiConnect", "handle", $hmidiin, "handle", $hmidiout, "int", 0)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiConnect

Func _MidiDisconnect($hmidiin, $hmidiout)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiDisconnect", "handle", $hmidiin, "handle", $hmidiout, "int", 0)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiDisconnect

;========================================================
;Prepare/Unprepare the MIDI header
;Parameters - MidiInHandle,Data,Bufferlength,
; BytesRecorded,User,Flags,Next,Getmmsystemerror
;Author:Eynstyne
;Library:Microsoft winmm.dll
;========================================================
Func _MidiInPrepareHeader($hmidiin, $data, $bufferlength, $bytesrecorded, $user, $flags, $next, $getmmsyserr = 0)
    Local Const $struct = DllStructCreate("char[128];udword;udword;udword;udword;ushort;ushort")
    DllStructSetData($struct, 1, $data)
    DllStructSetData($struct, 2, $bufferlength)
    DllStructSetData($struct, 3, $bytesrecorded)
    DllStructSetData($struct, 4, $user)
    DllStructSetData($struct, 5, $flags)
    DllStructSetData($struct, 6, $next)
    DllStructSetData($struct, 7, 0)

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInPrepareHeader", "handle", $hmidiin, "ptr", DllStructGetPtr($struct), "long", 999)

    If Not @error Then
        If $getmmsyserr = 1 Then
            Return $ret[0]
        ElseIf $getmmsyserr <> 1 Then
            Local Const $array = _ArrayCreate($hmidiin, DllStructGetData($struct, 1), DllStructGetData($struct, 2), DllStructGetData($struct, 3), DllStructGetData($struct, 4), DllStructGetData($struct, 5), DllStructGetData($struct, 6), DllStructGetData($struct, 7))
            Return $array
        EndIf
    EndIf
EndFunc   ;==>_MidiInPrepareHeader

Func _MidiInUnprepareHeader($hmidiin, $data, $bufferlength, $bytesrecorded, $user, $flags, $next, $getmmsyserr = 0)
    Local Const $struct = DllStructCreate("char[128];udword;udword;udword;udword;ushort;ushort")
    DllStructSetData($struct, 1, $data)
    DllStructSetData($struct, 2, $bufferlength)
    DllStructSetData($struct, 3, $bytesrecorded)
    DllStructSetData($struct, 4, $user)
    DllStructSetData($struct, 5, $flags)
    DllStructSetData($struct, 6, $next)
    DllStructSetData($struct, 7, 0)

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInUnprepareHeader", "handle", $hmidiin, "ptr", DllStructGetPtr($struct), "long", 999)

    If Not @error Then
        If $getmmsyserr = 1 Then
            Return $ret[0]
        ElseIf $getmmsyserr <> 1 Then
            Local Const $array = _ArrayCreate($hmidiin, DllStructGetData($struct, 1), DllStructGetData($struct, 2), DllStructGetData($struct, 3), DllStructGetData($struct, 4), DllStructGetData($struct, 5), DllStructGetData($struct, 6), DllStructGetData($struct, 7))
            Return $array
        EndIf
    EndIf
EndFunc   ;==>_MidiInUnprepareHeader

;========================================================
;Add buffer to Midi Header
;Parameters - MidiInHandle,Data,Bufferlength,
; BytesRecorded,User,Flags,Next,Getmmsystemerror
;Author:Eynstyne
;Library:Microsoft winmm.dll
;========================================================
Func _MidiInAddBuffer($hmidiin, $data, $bufferlength, $bytesrecorded, $user, $flags, $next, $getmmsyserr = 0)
    Local Const $struct = DllStructCreate("char[128];udword;udword;udword;udword;ushort;ushort")

    DllStructSetData($struct, 1, $data)
    DllStructSetData($struct, 2, $bufferlength)
    DllStructSetData($struct, 3, $bytesrecorded)
    DllStructSetData($struct, 4, $user)
    DllStructSetData($struct, 5, $flags)
    DllStructSetData($struct, 6, $next)
    DllStructSetData($struct, 7, 0)

    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInAddBuffer", "handle", $hmidiin, "ptr", DllStructGetPtr($struct), "long", 999)

    If Not @error Then
        If $getmmsyserr = 1 Then
            Return $ret[0]
        ElseIf $getmmsyserr <> 1 Then
            Local Const $array = _ArrayCreate($hmidiin, DllStructGetData($struct, 1), DllStructGetData($struct, 2), DllStructGetData($struct, 3), DllStructGetData($struct, 4), DllStructGetData($struct, 5), DllStructGetData($struct, 6), DllStructGetData($struct, 7))
            Return $array
        EndIf
    EndIf
EndFunc   ;==>_MidiInAddBuffer

;========================================================
;Sends Internal MIDI Info to Input / Output device
;Parameters - MidiInHandle,message, parameter1, parameter2
;Author:Eynstyne
;Library:Microsoft winmm.dll
;========================================================
Func _MidiInMessage($hmidiin, $msg, $dw1 = 0, $dw2 = 0)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiInMessage", "handle", $hmidiin, "long", $msg, "long", $dw1, "long", $dw2)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiInMessage

Func _MidiOutMessage($hmidiout, $msg, $dw1 = 0, $dw2 = 0)
    Local Const $ret = DllCall($winmm_dll, $MMRESULT, "midiOutMessage", "handle", $hmidiout, "long", $msg, "long", $dw1, "long", $dw2)
    If Not @error Then Return $ret[0]
EndFunc   ;==>_MidiOutMessage

MIDI Constants.au3

Global Const $MMRESULT = "uint"

Global Const $MEVT_F_SHORT = 0
Global Const $MEVT_SHORTMSG = 0

Global Const $MHDR_DONE     = 1
Global Const $MHDR_PREPARED = 2
Global Const $MHDR_INQUEUE  = 4
Global Const $MHDR_ISSTRM   = 8

Global Const $CALLBACK_NULL     = 0
Global Const $CALLBACK_Window   = 0x10000000
Global Const $CALLBACK_thread   = 0x20000000
Global Const $CALLBACK_FUNCTION = 0x30000000
Global Const $CALLBACK_EVENT    = 0x50000000

Global Const $TIME_MS   = 1
Global Const $TIME_SAMPLES = 2
Global Const $TIME_BYTES   = 4
Global Const $TIME_SMPTE   = 8
Global Const $TIME_MIDI = 16
Global Const $TIME_TICKS   = 32

Global Const $MMSYSERR_BASE         = 0
Global Const $MMSYSERR_NOERROR      = 0
Global Const $MMSYSERR_ERROR        = $MMSYSERR_BASE + 1
Global Const $MMSYSERR_BADDEVICEID  = $MMSYSERR_BASE + 2
Global Const $MMSYSERR_NOTENABLED   = $MMSYSERR_BASE + 3
Global Const $MMSYSERR_ALLOCATED    = $MMSYSERR_BASE + 4
Global Const $MMSYSERR_INVALHANDLE  = $MMSYSERR_BASE + 5
Global Const $MMSYSERR_NODRIVER     = $MMSYSERR_BASE + 6
Global Const $MMSYSERR_NOMEM        = $MMSYSERR_BASE + 7
Global Const $MMSYSERR_NOTSUPPORTED = $MMSYSERR_BASE + 8
Global Const $MMSYSERR_BADERRNUM    = $MMSYSERR_BASE + 9
Global Const $MMSYSERR_INVALFLAG    = $MMSYSERR_BASE + 10
Global Const $MMSYSERR_INVALPARAM   = $MMSYSERR_BASE + 11
Global Const $MMSYSERR_HANDLEBUSY   = $MMSYSERR_BASE + 12
Global Const $MMSYSERR_INVALIDALIAS = $MMSYSERR_BASE + 13
Global Const $MMSYSERR_BADDB        = $MMSYSERR_BASE + 14
Global Const $MMSYSERR_KEYNOTFOUND  = $MMSYSERR_BASE + 15
Global Const $MMSYSERR_READERROR    = $MMSYSERR_BASE + 16
Global Const $MMSYSERR_WRITEERROR   = $MMSYSERR_BASE + 17
Global Const $MMSYSERR_DELETEERROR  = $MMSYSERR_BASE + 18
Global Const $MMSYSERR_VALNOTFOUND  = $MMSYSERR_BASE + 19
Global Const $MMSYSERR_NODRIVERCB   = $MMSYSERR_BASE + 20
Global Const $MMSYSERR_LASTERROR    = $MMSYSERR_BASE + 20

Global Const $MIDI_CACHE_ALL    = 1
Global Const $MIDI_CACHE_BESTFIT = 2
Global Const $MIDI_CACHE_QUERY   = 3
Global Const $MIDI_UNCACHE      = 4
Global Const $MIDI_CACHE_VALID   = ( $MIDI_CACHE_ALL Or $MIDI_CACHE_BESTFIT Or $MIDI_CACHE_QUERY Or $MIDI_UNCACHE )
Global Const $MIDI_IO_STATUS = 0x20
Global Const $MIDICAPS_CACHE    = 0x4
Global Const $MIDICAPS_LRVOLUME = 0x20
Global Const $MIDICAPS_STREAM   = 0x8
Global Const $MIDICAPS_VOLUME   = 0x1
Global Const $MIDIERR_BASE      = 64
Global Const $MIDIERR_UNPREPARED   = $MIDIERR_BASE + 0
Global Const $MIDIERR_STILLPLAYING = $MIDIERR_BASE + 1
Global Const $MIDIERR_NOMAP     = $MIDIERR_BASE + 2
Global Const $MIDIERR_NOTREADY  = $MIDIERR_BASE + 3
Global Const $MIDIERR_NODEVICE  = $MIDIERR_BASE + 4
Global Const $MIDIERR_INVALIDSETUP = $MIDIERR_BASE + 5
Global Const $MIDIERR_LASTERROR = $MIDIERR_BASE + 5
Global Const $MIDIPROP_SET  = 0x80000000
Global Const $MIDIPROP_GET  = 0x40000000
Global Const $MIDIPROP_TIMEDIV = 1
Global Const $MIDIPROP_TEMPO   = 2
Global Const $MIDISTRM_ERROR = -2
Global Const $MM_MPU401_MIDIOUT = 10
Global Const $MM_MPU401_MIDIIN  = 11
Global Const $MM_MIDI_MAPPER = -1
Global Const $MIDIPATCHSIZE = 128

Global Const $MM_MIM_CLOSE  = 0x3c2
Global Const $MM_MIM_DATA   = 0x3c3
Global Const $MM_MIM_ERROR  = 0x3c5
Global Const $MM_MIM_LONGDATA  = 0x3c4
Global Const $MM_MIM_LONGERROR = 0x3c6
Global Const $MM_MIM_MOREDATA  = 0x3cc
Global Const $MM_MIM_OPEN   = 0x3c1
Global Const $MM_MOM_CLOSE      = 0x3c8
Global Const $MM_MOM_DONE       = 0x3c9
Global Const $MM_MOM_OPEN       = 0x3c7
Global Const $MM_MOM_POSITIONCB = 0x3ca

Global Const $MIM_CLOSE     = $MM_MIM_CLOSE
Global Const $MIM_DATA      = $MM_MIM_DATA
Global Const $MIM_ERROR     = $MM_MIM_ERROR
Global Const $MIM_LONGDATA   = $MM_MIM_LONGDATA
Global Const $MIM_LONGERROR  = $MM_MIM_LONGERROR
Global Const $MIM_MOREDATA   = $MM_MIM_MOREDATA
Global Const $MIM_OPEN      = $MM_MIM_OPEN
Global Const $MOM_CLOSE     = $MM_MOM_CLOSE
Global Const $MOM_DONE      = $MM_MOM_DONE
Global Const $MOM_OPEN      = $MM_MOM_OPEN
Global Const $MOM_POSITIONCB = $MM_MOM_POSITIONCB

;Midi Notes
;==========

Global Const $ABASS_OCTAVEDOWN16_NOTEON     = 0x00401590;1
Global Const $ASHARPBASS_OCTAVEDOWN16_NOTEON = 0x00401690;2
Global Const $BBASS_OCTAVEDOWN16_NOTEON     = 0x00401790;3
Global Const $CBASS_OCTAVEDOWN8_NOTEON      = 0x00401890;4
Global Const $CSHARPBASS_OCTAVEDOWN8_NOTEON  = 0x00401990;5
Global Const $DBASS_OCTAVEDOWN8_NOTEON      = 0x00401A90;6
Global Const $DSHARPBASS_OCTAVEDOWN8_NOTEON  = 0x00401B90;7
Global Const $EBASS_OCTAVEDOWN8_NOTEON      = 0x00401C90;8
Global Const $FBASS_OCTAVEDOWN8_NOTEON      = 0x00401D90;9
Global Const $FSHARPBASS_OCTAVEDOWN8_NOTEON  = 0x00401E90;10
Global Const $GBASS_OCTAVEDOWN8_NOTEON      = 0x00401F90;11
Global Const $GSHARPBASS_OCTAVEDOWN8_NOTEON  = 0x00402090;12
Global Const $ABASS_OCTAVEDOWN8_NOTEON      = 0x00402190;13
Global Const $ASHARPBASS_OCTAVEDOWN8_NOTEON  = 0x00402290;14
Global Const $BBASS_OCTAVEDOWN_NOTEON       = 0x00402390;15
Global Const $CBASS_OCTAVEDOWN_NOTEON       = 0x00402490;16
Global Const $CSHARPBASS_OCTAVEDOWN_NOTEON   = 0x00402590;17
Global Const $DBASS_OCTAVEDOWN_NOTEON       = 0x00402690;18
Global Const $DSHARPBASS_OCTAVEDOWN_NOTEON   = 0x00402790;19
Global Const $EBASS_OCTAVEDOWN_NOTEON       = 0x00402890;20
Global Const $FBASS_OCTAVEDOWN_NOTEON       = 0x00402990;21
Global Const $FSHARPBASS_OCTAVEDOWN_NOTEON   = 0x00402A90;22
Global Const $GBASS_OCTAVEDOWN_NOTEON       = 0x00402B90;23
Global Const $GSHARPBASS_OCTAVEDOWN_NOTEON   = 0x00402C90;24
Global Const $ABASS_OCTAVEDOWN_NOTEON       = 0x00402D90;25
Global Const $ASHARPBASS_OCTAVEDOWN_NOTEON   = 0x00402E90;26
Global Const $BBASS_NOTEON      = 0x00402F90;27
Global Const $CBASS_NOTEON      = 0x00403090;28
Global Const $CSHARPBASS_NOTEON = 0x00403190;29
Global Const $DBASS_NOTEON      = 0x00403290;30
Global Const $DSHARPBASS_NOTEON = 0x00403390;31
Global Const $EBASS_NOTEON      = 0x00403490;32
Global Const $FBASS_NOTEON      = 0x00403590;33
Global Const $FSHARPBASS_NOTEON = 0x00403690;34
Global Const $GBASS_NOTEON      = 0x00403790;35
Global Const $GSHARPBASS_NOTEON = 0x00403890;36
Global Const $ABASS_NOTEON      = 0x00403990;37
Global Const $ASHARPBASS_NOTEON = 0x00403A90;38
Global Const $B_NOTEON          = 0x00403B90;39
Global Const $C_NOTEON          = 0x00403C90;40 - Middle C
Global Const $CSHARP_NOTEON     = 0x00403D90;41
Global Const $D_NOTEON          = 0x00403E90;42
Global Const $DSHARP_NOTEON     = 0x00403F90;43
Global Const $E_NOTEON          = 0x00404090;44
Global Const $F_NOTEON          = 0x00404190;45
Global Const $FSHARP_NOTEON     = 0x00404290;46
Global Const $G_NOTEON          = 0x00404390;47
Global Const $GSHARP_NOTEON     = 0x00404490;48
Global Const $A_NOTEON          = 0x00404590;49
Global Const $ASHARP_NOTEON     = 0x00404690;50
Global Const $B_OCTAVE_NOTEON   = 0x00404790;51
Global Const $C_OCTAVEUP_NOTEON = 0x00404890;52
Global Const $CSHARP_OCTAVEUP_NOTEON = 0x00404990;53
Global Const $D_OCTAVEUP_NOTEON = 0x00404A90;54
Global Const $DSHARP_OCTAVEUP_NOTEON = 0x00404B90;55
Global Const $E_OCTAVEUP_NOTEON = 0x00404C90;56
Global Const $F_OCTAVEUP_NOTEON = 0x00404D90;57
Global Const $FSHARP_OCTAVEUP_NOTEON = 0x00404E90;58
Global Const $G_OCTAVEUP_NOTEON = 0x00404F90;59
Global Const $GSHARP_OCTAVEUP_NOTEON = 0x00405090;60
Global Const $A_OCTAVEUP_NOTEON = 0x00405190;61
Global Const $ASHARP_OCTAVEUP_NOTEON = 0x00405290;62
Global Const $B_OCTAVEUP_NOTEON = 0x00405390;63
Global Const $C_OCTAVEUP8_NOTEON = 0x00405490;64
Global Const $CSHARP_OCTAVEUP8_NOTEON = 0x00405590;65
Global Const $D_OCTAVEUP8_NOTEON = 0x00405690;66
Global Const $DSHARP_OCTAVEUP8_NOTEON = 0x00405790;67
Global Const $E_OCTAVEUP8_NOTEON = 0x00405890;68
Global Const $F_OCTAVEUP8_NOTEON = 0x00405990;69
Global Const $FSHARP_OCTAVEUP8_NOTEON = 0x00405A90;70
Global Const $G_OCTAVEUP8_NOTEON = 0x00405B90;71
Global Const $GSHARP_OCTAVEUP8_NOTEON = 0x00405C90;72
Global Const $A_OCTAVEUP8_NOTEON = 0x00405D90;73
Global Const $ASHARP_OCTAVEUP8_NOTEON = 0x00405E90;74
Global Const $B_OCTAVEUP8_NOTEON = 0x00405F90;75
Global Const $C_OCTAVEUP16_NOTEON = 0x00406090;76
Global Const $CSHARP_OCTAVEUP16_NOTEON = 0x00406190;77
Global Const $D_OCTAVEUP16_NOTEON = 0x00406290;78
Global Const $DSHARP_OCTAVEUP16_NOTEON = 0x00406390;79
Global Const $E_OCTAVEUP16_NOTEON = 0x00406490;80
Global Const $F_OCTAVEUP16_NOTEON = 0x00406590;81
Global Const $FSHARP_OCTAVEUP16_NOTEON = 0x00406690; 82
Global Const $G_OCTAVEUP16_NOTEON = 0x00406790; 83
Global Const $GSHARP_OCTAVEUP16_NOTEON = 0x00406890; 84
Global Const $A_OCTAVEUP16_NOTEON = 0x00406990 ;85
Global Const $ASHARP_OCTAVEUP16_NOTEON = 0x00406A90 ;86
Global Const $B_OCTAVEUP16_NOTEON = 0x00406B90 ;87
Global Const $C_OCTAVEUP32_NOTEON = 0x00406C90 ;88

;Turn Off the Notes

Global Const $ABASS_OCTAVEDOWN16_NOTEOFF = 0x00001590;1
Global Const $ASHARPBASS_OCTAVEDOWN16_NOTEOFF = 0x00001690;2
Global Const $BBASS_OCTAVEDOWN16_NOTEOFF = 0x00001790;3
Global Const $CBASS_OCTAVEDOWN8_NOTEOFF = 0x00001890;4
Global Const $CSHARPBASS_OCTAVEDOWN8_NOTEOFF = 0x00001990;5
Global Const $DBASS_OCTAVEDOWN8_NOTEOFF = 0x00001A90;6
Global Const $DSHARPBASS_OCTAVEDOWN8_NOTEOFF = 0x00001B90;7
Global Const $EBASS_OCTAVEDOWN8_NOTEOFF = 0x00001C90;8
Global Const $FBASS_OCTAVEDOWN8_NOTEOFF = 0x00001D90;9
Global Const $FSHARPBASS_OCTAVEDOWN8_NOTEOFF = 0x00001E90;10
Global Const $GBASS_OCTAVEDOWN8_NOTEOFF = 0x00001F90;11
Global Const $GSHARPBASS_OCTAVEDOWN8_NOTEOFF = 0x00002090;12
Global Const $ABASS_OCTAVEDOWN8_NOTEOFF = 0x00002190;13
Global Const $ASHARPBASS_OCTAVEDOWN8_NOTEOFF = 0x00002290;14
Global Const $BBASS_OCTAVEDOWN_NOTEOFF = 0x00002390;15
Global Const $CBASS_OCTAVEDOWN_NOTEOFF = 0x00002490;16
Global Const $CSHARPBASS_OCTAVEDOWN_NOTEOFF = 0x00002590;17
Global Const $DBASS_OCTAVEDOWN_NOTEOFF = 0x00002690;18
Global Const $DSHARPBASS_OCTAVEDOWN_NOTEOFF = 0x00002790;19
Global Const $EBASS_OCTAVEDOWN_NOTEOFF = 0x00002890;20
Global Const $FBASS_OCTAVEDOWN_NOTEOFF = 0x00002990;21
Global Const $FSHARPBASS_OCTAVEDOWN_NOTEOFF = 0x00002A90;22
Global Const $GBASS_OCTAVEDOWN_NOTEOFF = 0x00002B90;23
Global Const $GSHARPBASS_OCTAVEDOWN_NOTEOFF = 0x00002C90;24
Global Const $ABASS_OCTAVEDOWN_NOTEOFF = 0x00002D90;25
Global Const $ASHARPBASS_OCTAVEDOWN_NOTEOFF = 0x00002E90;26
Global Const $BBASS_NOTEOFF = 0x00002F90;27
Global Const $CBASS_NOTEOFF = 0x00003090;28
Global Const $CSHARPBASS_NOTEOFF = 0x00003190;29
Global Const $DBASS_NOTEOFF = 0x00003290;30
Global Const $DSHARPBASS_NOTEOFF = 0x00003390;31
Global Const $EBASS_NOTEOFF = 0x00003490;32
Global Const $FBASS_NOTEOFF = 0x00003590;33
Global Const $FSHARPBASS_NOTEOFF = 0x00003690;34
Global Const $GBASS_NOTEOFF = 0x00003790;35
Global Const $GSHARPBASS_NOTEOFF = 0x00003890;36
Global Const $ABASS_NOTEOFF = 0x00003990;37
Global Const $ASHARPBASS_NOTEOFF = 0x00003A90;38
Global Const $B_NOTEOFF = 0x00003B90;39
Global Const $C_NOTEOFF = 0x00003C90;00 - Middle C
Global Const $CSHARP_NOTEOFF = 0x00003D90;41
Global Const $D_NOTEOFF = 0x00003E90;42
Global Const $DSHARP_NOTEOFF = 0x00003F90;43
Global Const $E_NOTEOFF = 0x0004090;44
Global Const $F_NOTEOFF = 0x00004190;45
Global Const $FSHARP_NOTEOFF = 0x00004290;46
Global Const $G_NOTEOFF = 0x00004390;47
Global Const $GSHARP_NOTEOFF = 0x00004490;48
Global Const $A_NOTEOFF = 0x00004590;49
Global Const $ASHARP_NOTEOFF = 0x00004690;50
Global Const $B_OCTAVE_NOTEOFF = 0x00004790;51
Global Const $C_OCTAVEUP_NOTEOFF = 0x00004890;52
Global Const $CSHARP_OCTAVEUP_NOTEOFF = 0x00004990;53
Global Const $D_OCTAVEUP_NOTEOFF = 0x00004A90;54
Global Const $DSHARP_OCTAVEUP_NOTEOFF = 0x00004B90;55
Global Const $E_OCTAVEUP_NOTEOFF = 0x00004C90;56
Global Const $F_OCTAVEUP_NOTEOFF = 0x00004D90;57
Global Const $FSHARP_OCTAVEUP_NOTEOFF = 0x00004E90;58
Global Const $G_OCTAVEUP_NOTEOFF = 0x00004F90;59
Global Const $GSHARP_OCTAVEUP_NOTEOFF = 0x00005090;60
Global Const $A_OCTAVEUP_NOTEOFF = 0x00005190;61
Global Const $ASHARP_OCTAVEUP_NOTEOFF = 0x00005290;62
Global Const $B_OCTAVEUP_NOTEOFF = 0x00005390;63
Global Const $C_OCTAVEUP8_NOTEOFF = 0x00005490;64
Global Const $CSHARP_OCTAVEUP8_NOTEOFF = 0x00005590;65
Global Const $D_OCTAVEUP8_NOTEOFF = 0x00005690;66
Global Const $DSHARP_OCTAVEUP8_NOTEOFF = 0x00005790;67
Global Const $E_OCTAVEUP8_NOTEOFF = 0x00005890;68
Global Const $F_OCTAVEUP8_NOTEOFF = 0x00005990;69
Global Const $FSHARP_OCTAVEUP8_NOTEOFF = 0x00005A90;70
Global Const $G_OCTAVEUP8_NOTEOFF = 0x00005B90;71
Global Const $GSHARP_OCTAVEUP8_NOTEOFF = 0x00005C90;72
Global Const $A_OCTAVEUP8_NOTEOFF = 0x00005D90;73
Global Const $ASHARP_OCTAVEUP8_NOTEOFF = 0x00005E90;74
Global Const $B_OCTAVEUP8_NOTEOFF = 0x00005F90;75
Global Const $C_OCTAVEUP16_NOTEOFF = 0x00006090;76
Global Const $CSHARP_OCTAVEUP16_NOTEOFF = 0x00006190;77
Global Const $D_OCTAVEUP16_NOTEOFF = 0x00006290;78
Global Const $DSHARP_OCTAVEUP16_NOTEOFF = 0x00006390;79
Global Const $E_OCTAVEUP16_NOTEOFF = 0x00006490;80
Global Const $F_OCTAVEUP16_NOTEOFF = 0x00006590;81
Global Const $FSHARP_OCTAVEUP16_NOTEOFF = 0x00006690; 82
Global Const $G_OCTAVEUP16_NOTEOFF = 0x00006790; 83
Global Const $GSHARP_OCTAVEUP16_NOTEOFF = 0x00006890; 84
Global Const $A_OCTAVEUP16_NOTEOFF = 0x00006990 ;85
Global Const $ASHARP_OCTAVEUP16_NOTEOFF = 0x00006A90 ;86
Global Const $B_OCTAVEUP16_NOTEOFF = 0x00006B90 ;87
Global Const $C_OCTAVEUP32_NOTEOFF = 0x00006C90 ;88

;Instruments
#cs Grand Piano;0
    Bright Piano;1
    Electric Grand Piano;2
    Honky-Tonk Piano;3
    Electric piano 1; 4
    Electric Piano 2; 5
    Harpsichord;    6
    Clavinet;   7
    Celesta;    8
    Glockenspiel;   9
    Music Box;  10
    Vibraphone;     11
    Marimba;    12
    Xylophone;  13
    Tubular bells;  14
    Dulcimer;   15
    Drawbar Organ;  16
    Percussive Organ;   17
    Rock Organ;     18
    Church Organ;   19
    Reed Organ;     20
    Accordion;  21
    Harmonica;  22
    Tango Accordion;    23
    Nylon String Guitar;    24
    Steel String Guitar;    25
    Jazz Guitar;    26
    Clean Electric Guitar;  27
    Muted Electric Guitar;  28
    Overdrive Guitar;   29
    Distortion Guitar;  30
    Guitar Harmonics;   31
    Accoustic Bass;     32
    Fingered Bass;  33
    Picked Bass;    34
    Fretless Bass;  35
    Slap Bass 1;    36
    Slap Bass 2;    37
    Synth Bass 1;   38
    Synth Bass 2;   39
    Violin;     40
    Viola;  41
    Cello;  42
    Contrabass;     43
    Tremolo Strings;    44
    Pizzicato Strings; 45
    Orchestral Harp;    46
    Timpani;    47
    String Ensemble 1;  48
    String Ensemble 2; 49
    Synth Strings 1;    50
    Synth Strings 2;    51
    Choir ahh;  52
    Choir oohh;     53
    Synth Voice;    54
    Orchestral Hit;     55
    Trumpet;    56
    Trombone; 57
    Tuba;   58
    Muted Trumpet;  59
    French Horn;    60
    Brass Section;  61
    Synth Brass 1;  62
    Synth Brass 2;  63
    Soprano Sax;    64
    Alto Sax;   65
    Tenor Sax;  66
    Baritone Sax;   67
    Oboe;   68
    English Horn;   69
    Bassoon;    70
    Clarinet;   71
    Piccolo;    72
    Flute;  73
    Recorder;   74
    Pan flute;  75
    Blown Bottle;   76
    Shakuhachi;     77
    Whistle;    78
    Ocarina;    79
    Square Wave;    80
    Sawtooth Wave;  81
    Caliope;    82
    Chiff;  83
    Charang;    84
    Voice;  85
    Fifths;     86
    Bass & Lead;    87
    New Age;    88
    Warm;   89
    PolySynth;  90
    Choir;  91
    Bowed;  92
    Metallic; 93
    Halo;   94
    Sweep;  95
    FX: Rain;96
    FX: Soundtrack;97
    FX: Crystal;98
    FX: Atmosphere;99
    FX: Brightness;100
    FX: Goblins;101
    FX: Echo Drops;102
    FX: Star Theme;103
    Sitar;104
    Banjo;105
    Shamisen;106
    Koto;107
    Kalimba;108
    Bagpipe;109
    Fiddle;110
    Shanai;111
    Tinkle bell;112
    Agogo;113
    Steel Drums;114
    Woodblock;115
    Taiko Drum;116
    Melodic Tom;117
    Synth Drum;118
    Reverse Cymbal;119
    Guitar Fret Noise;120
    Breath Noise;121
    Seashore;122
    Bird Tweet;123
    Telephone Ring;124
    Helicopter;125
    Applause;126
    Gunshot;127

    Drums
    =====
#ce Range from 27 - 87

MIDI Stream.au3

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamOut( Const $hmidiStream , Const $event , Const $time = 0 , Const $user = 0 )
    Local Const $midi_event = DllStructCreate( "dword;dword;byte" )

    DllStructSetData( $midi_event , 1 , $time  )
    DllStructSetData( $midi_event , 2 , 0   )
;~  DllStructSetData( $midi_event , 3 , $event )
    DllStructSetData( $midi_event , 3 , BitOR( BitShift( BitOR( $MEVT_F_SHORT , $MEVT_SHORTMSG ) , -24 ) , BitAND( $event , 0x00FFFFFF ) ) )
;~  DllStructSetData( $midi_event , 3 , $MEVT_F_SHORT Or BitShift( $MEVT_SHORTMSG , -24 ) Or BitAND( $event , 0x00FFFFFF ) )
;~  DllStructSetData( $midi_event , 3 , BitAND( BitShift( $event , 24 ) , 0x00FFFFFF ) )

    Local Const $midi_hdr = _midiOutPrepareHeader( $hmidiStream , $midi_event )

    If @error Then MsgBox( 32 , @error , @extended )

    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamOut"               , _
                                            "handle"  , $hmidiStream                , _
                                            "ptr"   , DllStructGetPtr( $midi_hdr  ) , _
                                            "uint"  , DllStructGetSize( $midi_hdr ) )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamOut" )
            Case 0
                Return $ret[ 0 ]
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiOutPrepareHeader( Const $hmidiStream , Const $midi_event )
    Local Const $_midi_hdr = DllStructCreate( "byte[37];dword;dword;dword_ptr;dword;dword_ptr;dword_ptr;dword;dword_ptr[4]" )

    DllStructSetData( $_midi_hdr , 1 , String( DllStructGetPtr(  $midi_event ) ) )
    DllStructSetData( $_midi_hdr , 2 , DllStructGetSize( $midi_event ) )
    DllStructSetData( $_midi_hdr , 3 , DllStructGetSize( $midi_event ) )
    DllStructSetData( $_midi_hdr , 4 , 0 )
    DllStructSetData( $_midi_hdr , 5 , 0 )
    DllStructSetData( $_midi_hdr , 8 , 0 )

    Local Const $header = DllCall( "WinMM.dll" , $MMRESULT , "midiOutPrepareHeader"     , _
                                                 "handle"  , $hmidiStream               , _
                                                 "str*" , String( DllStructGetPtr( $_midi_hdr ) ) , _
                                                 "uint" , DllStructGetSize( $_midi_hdr ) )

    If Not @error Then
        Switch $header[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $header[ 0 ] , "midiOutPrepareHeader" )
            Case 0
                Return $_midi_hdr
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamClose( Const $hmidiStream )
    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamClose" , "handle" , $hmidiStream )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamClose" )
            Case 0
                Return $ret[ 0 ]
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamOpen( Const $callback = 0 , Const $instance = 0 , Const $fdwopen = $CALLBACK_EVENT)
    Local Const $stream = DllStructCreate( "handle" )

    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamOpen" , _
                                "ptr"   , DllStructGetPtr( $stream ) , _
                                "uint*" , $MM_MIDI_MAPPER , _
                                "dword" , 1 , _
                                "dword_ptr" , $callback , _
                                "dword_ptr" , $instance , _
                                "dword" , $fdwopen )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamOpen" )
            Case 0
                Return DllStructGetData( $stream , 1 )
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamPause( Const $hmidiStream )
    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamPause" , "handle" , $hmidiStream )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamPause" )
            Case 0
                Return $ret[ 0 ]
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamPosition( Const $hmidiStream )
    Local Const $mmtime = DllStructCreate( "uint;dword" )

    DllStructSetData( $mmtime , 1 , $TIME_MIDI )

    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamPosition" , _
                                "handle" , $hmidiStream , _
                                "ptr"   , DllStructGetPtr( $mmtime ) , _
                                "uint"   , DllStructGetSize( $mmtime ) )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamPosition" )
            Case 0
                Return DllStructGetData( $mmtime , 2 )
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamRestart( Const $hmidiStream )
    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamRestart" , "handle" , $hmidiStream )

    If Not @error Then
        Switch $ret[ 0]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamRestart" )
            Case 0
                Return $ret[ 0 ]
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamStop( Const $hmidiStream )
    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamStop" , "handle" , $hmidiStream )

    If Not @error Then
        Switch $ret[ 0]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamStop" )
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamProperty_SetTimeDiv( Const $hmidiStream , Const $time_div )
    Local Const $midiprop_timediv = DllStructCreate( "dword;byte[1024]" )

    DllStructSetData( $midiprop_timediv , 1 , DllStructGetSize( $midiprop_timediv ) )
    DllStructSetData( $midiprop_timediv , 2 , $time_div )

    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamProperty" , _
                                "handle" , $hmidiStream , _
                                "str*"  , _WinAPI_StringFromGUID( DllStructGetPtr( $midiprop_timediv ) ) , _
                                "dword"  , BitOR( $MIDIPROP_SET , $MIDIPROP_TIMEDIV ) )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamProperty" )
            Case 0
                Return DllStructGetData( $midiprop_timediv , 2 )
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------

Func _midiStreamProperty_GetTimeDiv( Const $hmidiStream )
    Local Const $midiprop_timediv = DllStructCreate( "dword;lpbyte" )

    DllStructSetData( $midiprop_timediv , 1 , DllStructGetSize( $midiprop_timediv ) )

    Local Const $ret = DllCall( "WinMM.dll" , $MMRESULT , "midiStreamProperty" , _
                                "handle" , $hmidiStream , _
                                "ptr"   , DllStructGetPtr( $midiprop_timediv ) , _
                                "dword"  , $MIDIPROP_GET Or $MIDIPROP_TIMEDIV )

    If Not @error Then
        Switch $ret[ 0 ]
            Case 1 To 20
                Return SetError( 1 , $ret[ 0 ] , "midiStreamProperty" )
            Case 0
                Return DllStructGetData( $midiprop_timediv , 2 )
        EndSwitch
    Else
        SetError( 2 , @error )
    EndIf
EndFunc

; ----------------------------------------------------------------------------------------------------------
Edited by LaCastiglione
Posted (edited)

@LaCastiglione, That's a nice example.

IS THIS A MICROSOFT BUG?

For years I didn't know that Windows Media Player was setting midi volume to zero, without any warning or indication. This happens when you exit Windows Media player after playing a midi file, and it is a mystery to me why Microsoft chose to do that.

Now with these UDFs I am experiencing a different problem. When I set the volume with the function _MidiOutSetVolume(), I find that the SW Synth balance has been set to the far left and the midi sound only comes out of one speaker. I have run several tests to confirm that it is not the speaker. Either it is a Microsoft bug, or it is a problem with the UDFs. Both Ascendant's and LaCastiglione's UDF have exactly the same effect.

Could someone please try setting the midi volume using _MidiOutSetVolume() and then check if the SW Synth balance has been set to the far left. Either run one of the examples (first setting the volume) and listen to the sound coming out of each speaker, or just run the function and check the master volume control. While I'm thinking this may be a Microsoft related bug, a possible solution would be to set the midi balance, but I'm not sure how long it would take me to figure that out. Perhaps someone can suggest a simple fix.

Edited by czardas
Posted (edited)

The volume is a 2-part value, each part is 16-bits wide but it is combined into a 32-bit value and passed onto the mixer that way. Perhaps that is what you're missing.

So given $iLVolume and $iRVolume, this should set the Left/Right mix to the middle (or just one whole channel in mono MIDI out):

; Set to approximately half (max is 65535)
$iLVolume=32768
$iRVolume=32768
$iMixVolume=BitOr(BitAND($iLVolume,0xFFFF),BitShift(BitAND($iRVolume,0xFFFF),-16))
_MidiOutSetVolume($iMixVolume)

Sorry that I haven't been around.. I will fix that incorrect constant value you mentioned czardas (copied and pasted that section from whoever else's code) when I get a chance to check the other values also.

*edit: 5/19/2011 - fixed version uploaded. See my post on page 3

Edited by Ascend4nt
Posted

The volume is a 2-part value, each part is 16-bits wide but it is combined into a 32-bit value and passed onto the mixer that way. Perhaps that is what you're missing.

Thanks! I'll test it out properly tomorrow, but I think it's working fine now. Much appreciated. :unsure:
Posted

Here you got! a extract from a song... :unsure:

;~ Extract of the song "Wait For Sleep" writen by Dream Theater
#include <MIDI UDF.au3>
$t = 180
$open = _midiOutOpen()
;---------------------------UNA SOLA MANO------------------------------
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
 _midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
 _midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
 _midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP16_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP16_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
;---------------------------REPITE CON SEGUNDA MANO------------------------------
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
 _midioutshortmsg($open, $B_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
 _midioutshortmsg($open, $EBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
 _midioutshortmsg($open, $B_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
 _midioutshortmsg($open, $EBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
 _midioutshortmsg($open, $B_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
 _midioutshortmsg($open, $EBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP16_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP16_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $CBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $ABASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $CBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $ABASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $ABASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $BBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
sleep(1000)
_MidiOutClose($open)
Posted

This is from MSDN: The low-order word contains the left-channel volume setting, and the high-order word contains the right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence. If a device does not support both left and right volume control, the low-order word of dwVolume specifies the mono volume level, and the high-order word is ignored.

I can't find a way to manually set the volume and balance of my midi device.

Posted (edited)

#include <MIDI UDF.au3>
hotkeyset("p","_play")
Guicreate("midi test")
$button1 = Guictrlcreatebutton("test",50,50,50,50)
Guisetstate()
While 1
    $msj = Guigetmsg()
    switch $msj
        case -3
            Exit
        case $button1
            _play()
    EndSwitch
WEnd
func _play()
;~ Extract of the song "Wait For Sleep" writen by Dream Theater
$t = 180
$open = _midiOutOpen()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $open = ' & $open & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
;---------------------------UNA SOLA MANO------------------------------
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
 _midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
 _midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
 _midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP16_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP16_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
;---------------------------REPITE CON SEGUNDA MANO------------------------------
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
 _midioutshortmsg($open, $B_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
 _midioutshortmsg($open, $EBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
 _midioutshortmsg($open, $B_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
 _midioutshortmsg($open, $EBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
 _midioutshortmsg($open, $B_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
 _midioutshortmsg($open, $EBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP16_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP16_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $CBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $GBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $ABASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $CBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $ABASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $E_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $C_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $ABASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $G_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $FSHARP_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $E_OCTAVEUP8_NOTEON)
_midioutshortmsg($open, $BBASS_NOTEON)
sleep($t)
_midioutshortmsg($open, $B_OCTAVEUP_NOTEON)
sleep($t)
_midioutshortmsg($open, $D_OCTAVEUP8_NOTEON)
sleep($t)
_midioutshortmsg($open, $A_OCTAVEUP_NOTEON)
sleep($t)
sleep(1000)
_MidiOutClose($open)
EndFunc

look at this... i don´t know the errors codes... how can i use the hotkey to re reporduce the midi, when this is already open??

Edited by monoscout999
Posted (edited)

monoscout999

One of the problems I find with using the Sleep function is that it pauses the whole script. This makes it difficult to interrupt a process, for example by clicking a GUI control. There are some possible ways to get around this, but I think the easiest thing to do is to avoid using the Sleep function altogether. Using Hotkeys isn't my prefered choice.

Looking at alternative ways to encode the notes was on my list of things to do. Here is what I have so far, but it will undoubtedly need some changes. The following script is an example of using TimerDiff as an alternative to Sleep. Each note has two additional attributes : Delay in milliseconds before the note is played and the duration of the note in milliseconds (stored in the array $aMyTune).

#include <MidiOutLite.au3>
#include <Array.au3>

_Main()

Func _Main()
    Local $GUI = Guicreate("midi test")
    Local $button = Guictrlcreatebutton("GO",50,50,50,50)
    Guisetstate()

    Local $aMyTune[16][3] = _ ; [Delay, Midi Note Number, Duration = positive intefger or -1]
    [[0,39,-1], _   ; Do
    [0,36,-1], _
    [0,48,-1], _
    [200,41,200], _ ; Re
    [200,43,50], _  ; Mi
    [200,44,50], _  ; Fa
    [200,46,800], _ ; So
    [0,32,800], _
    [0,50,800], _
    [0,53,800], _
    [200,48,100], _ ; La
    [200,50,400], _ ; Si
    [400,51,-1], _  ; Do
    [0,27,-1], _
    [0,43,-1], _
    [0,46,-1]]

    Local $iCurrentlyPlaying = 0, $aTemp = _ConvertToMidiStream($aMyTune)
    Local $open, $iTimer, $iProgress, $iTimeOut = 1000
    While 1
        $msg = GUIGetMsg()
        switch $msg
            case -3
                Exit
            case $button
                If $iCurrentlyPlaying = 0 Then
                    $open = _MidiOutOpen()
                    _MidiOutShortMsg($open,256 * 0 + 192)
                    $iProgress = 0
                    $iCurrentlyPlaying = 1
                    GUICtrlSetData($button, "STOP")
                    $iTimer = TimerInit()
                Else
                    _MidiOutclose($open)
                    GUICtrlSetData($button, "GO")
                    $iCurrentlyPlaying = 0
                EndIf
            EndSwitch

        If ($iCurrentlyPlaying = 1) And ($iProgress > UBound($aTemp) -1) Then
            $iCurrentlyPlaying = 2
            $iTimer = TimerInit()
        EndIf
        If ($iCurrentlyPlaying = 1) And (TimerDiff($iTimer) >= $aTemp[$iProgress][0]) And ($iProgress <= UBound($aTemp) -1) Then
            _PlayMidiSequence($open, $aTemp, $iProgress)
            $iTimer = TimerInit()
        EndIf
        If $iCurrentlyPlaying = 2 And TimerDiff($iTimer) >= $iTimeOut Then
            _MidiOutclose($open)
            GUICtrlSetData($button, "GO")
            $iCurrentlyPlaying = 0
        EndIf
    WEnd
EndFunc

Func _ConvertToMidiStream($aInit)
    Local $iLimit = UBound($aInit) -1
    Local $iCount = 0
    For $i = 1 To $iLimit
        If $aInit[$i][2] <> 0 Then
            $aInit[$i][0] += $aInit[$i -1][0] ; Calculate the start time for every note.
        Else
            Return SetError (1,0,0) ; Duration must not be zero, but a value of -1 is allowed.
        EndIf
    Next
    $aStopped = $aInit

    Local $iCount = 0 ; Count midi messages which do not need to be sent.
    For $i = 0 To $iLimit
        If $aInit[$i][2] <> -1 Then
            $aStopped[$i][0] += $aInit[$i][2] ; Calculate the stop time for every note.
        Else
            $aStopped[$i][0] = -1
            $iCount +=1
        EndIf
    Next

    Local $aTemp[2*($iLimit +1) -$iCount][3]

    $iCount = 0
    For $i = 0 To $iLimit
        If $aStopped[$i][0] <> -1 Then
            $aTemp[$iCount][0] = $aStopped[$i][0] *10 ; Stopping notes first is the logical order.
            $aTemp[$iCount][1] = $aStopped[$i][1]
            $aTemp[$iCount][2] = 1 ; Indicates the note will be stopped.
            $iCount += 1
        EndIf
    Next
    $aStopped = 0 ; No longer needed.

    For $i = 0 To $iLimit
        $aTemp[$iCount][0] = $aInit[$i][0] *10 +1 ;
        $aTemp[$iCount][1] = $aInit[$i][1]
        $aTemp[$iCount][2] = 0 ; Indicates the note will be played.
        $iCount += 1
    Next
    $aInit = 0 ; No longer needed.

    _ArraySort($aTemp) ; Places Midi messages in the correct order.

    $iLimit = $iCount - 1
    For $i = 0 To $iLimit
        If $aTemp[$i][2] = 0 Then $aTemp[$i][0] -= 1
        $aTemp[$i][0] /= 10
        $aTemp[$i][1] = $MIDINOTE[ $aTemp[$i][1] ][ $aTemp[$i][2] ]
    Next

    Local $aStream[$iLimit +1][2]
    For $i = 0 To $iLimit
        For $j = 0 To 1
            $aStream[$i][$j] = $aTemp[$i][$j]
        Next
    Next
    $aTemp = 0

    Local $iRealTime
    For $i = 0 To $iLimit -1
        $iRealTime = $aStream[$i][0]
        For $j = $i +1 To $iLimit
            If $aStream[$j][0] = $iRealTime Then
                $aStream[$j][0] = 0 ; Delay in miliseconds before sending the message.
                $i += 1
            Else
                ExitLoop
            EndIf
        Next
    Next

    For $i = $iLimit To 1 Step -1
        If $aStream[$i][0] <> 0 Then
            $iRealTime = $aStream[$i][0]
            For $j = $i -1 To 0 Step -1
                If $aStream[$j][0] <> 0 Then
                    $aStream[$i][0] -= $aStream[$j][0] ; Delay in miliseconds before sending the message.
                    ExitLoop
                EndIf
            Next
        EndIf
    Next
    ;_ArrayDisplay($aTemp)
    Return $aStream
EndFunc

Func _PlayMidiSequence($open, $aTemp, ByRef $iProgress)
    _MidiOutshortmsg($open, $aTemp[$iProgress][1] )
    $iProgress += 1
    If UBound ($aTemp) > $iProgress And $aTemp[$iProgress][0] = 0 Then
        _PlayMidiSequence($open, $aTemp, $iProgress)
    EndIf
EndFunc

To run this example you will need the file MidiOutLite.au3 (Also work in progress)

I wish to play chords as well as single notes. With this way of encoding the music I can give a note a delay of zero seconds, although there will always be a very tiny delay. If you listen to the example, you will hear that some of the notes are stopped early while others are allowed to continue ringing. So there is a little more control over the music. Hopefully I will find time to look deeper into how midi works and find better solutions.

Edited by czardas
  • 3 weeks later...
Posted (edited)

Hello !

Sorry for my english but :

I'm using autoit for send midi to audiomulch. I'm using command line with sendmidi.exe ( http://public.sreal.com:8000/~div/midi-utilities/ )

Example :

ShellExecute("sendmidi.exe","--out "& $port & " --control-change "& $channel & " " & $number & " " & $value ,@ScriptDir,"", @SW_HIDE )

It's possible to use this UDF for that ?

Thanks !

http://autoitscript.fr/forum/viewtopic.php?f=3&t=5332

___________________

Bonjours, j'utilise autoit pour envoyer des informations en midi à audiomulch, j'utilise sendmidi.exe en ligne de commande ( http://public.sreal.com:8000/~div/midi-utilities/ )

ShellExecute("sendmidi.exe","--out "& $port & " --control-change "& $channel & " " & $number & " " & $value ,@ScriptDir,"", @SW_HIDE )

Es-ce possible de faire pareil avec cet UDF ?

Merci !

http://autoitscript.fr/forum/viewtopic.php?f=3&t=5332

Edited by SurPriseS
Posted

I guess it could.

I don't see why not.

Unless it would need the streaming functions.

Then I would say no because those are incomplete and shall remain so until such time as someone with more knowledge than me comes along or until I gain the required knowledge myself (ha).

  • 2 months later...
Posted (edited)

I am trying to use this udf now, it looks great!

I found the function to send a note out, but i can't find the function where i am looking for.

For my launchpad i can set some leds, to set them you need to send 3 value's for example:

Hex version B0h, 00h, 00h.

Decimal version 176, 0, 0.

To reset the pad

To set the leds i need to send this:

Hex version 90h, Key, Velocity.

Decimal version 144, Key, Velocity.

Where key is my key and velocity the led number 0 to 2

Can i send this with this udf?

hope you can help me a little.

I have found more udf versions, the original version recognizes my launchpad all other versions are telling me i do not have any midi devices connected.

Edited by Erik.

I little problem, hard to find and fix

  • 2 weeks later...
Posted

Hi to everyone, I've been reading with interest this topic since I'm long looking for a way to send midi instructions to a keyboard. I've tried to use midi udf and examples but it doesn't seem to work for me.

I've use autoit for a few months and (even not expert) I'm kinda familiar with it...

Most part of the functions are working, but i can't send anything to the midi internal device. It just doesn't sound (no error messages).

I've tried both with XP Pro e Windows 7 32.

Any idea?

Thanks!

  • 1 year later...
Posted

Is there a function in this midiUDF to convert binary midi to/from human readable text?

It would make editing a midi file a lot easier.

Has anyone got any ideas if this adaptation is even possible?

mehomic

Posted (edited)

Is there a function in this midiUDF to convert binary midi to/from human readable text?

It would make editing a midi file a lot easier.

Has anyone got any ideas if this adaptation is even possible?

mehomic

I tried to figure this one out several years ago. Midi is not intended to be read by humans. For music scripts you might want to look at LillyPond. I haven't really tried it and I'm unsure what it can do (the script might be just for notation - but it will give you an idea what's involved). I intend to write something like this in approximately a years time. I doubt I will be able to do it any faster than that. Midi itself has some issues I'm not happy with. Forced time signatures is one of them.

LillyPond Example

Edited by czardas
  • 3 months later...
Posted

Anyone get the "Drum Notes" to work 35-82? I thought they would be on "Music Box" Instrument (Ch 10), but this isn't working.

Oh, never mind, here is da codez:

$n=0x00402399;Acoustic Bass Drum
$n=0x00402499;Bass Drum 1
$n=0x00402599;Side Stick
$n=0x00402699;Acoustic Snare
$n=0x00402799;Hand Clap
$n=0x00402899;Electric Snare
$n=0x00402999;Low Floor Tom
$n=0x00402A99;Closed Hi-Hat
$n=0x00402B99;High Floor Tom
$n=0x00402C99;Pedal Hi-Hat
$n=0x00402D99;Low Tom
$n=0x00402E99;Open Hi-Hat
$n=0x00402F99;Low-Mid Tom
$n=0x00403099;Hi-Mid Tom
$n=0x00403199;Crash Cymbal 1
$n=0x00403299;High Tom
$n=0x00403399;Ride Cymbal 1
$n=0x00403499;Chinese Cymbal
$n=0x00403599;Ride Bell
$n=0x00403699;Tambourine
$n=0x00403799;Splash Cymbal
$n=0x00403899;Cowbell
$n=0x00403999;Crash Symbol 2
$n=0x00403A99;Vibraslap
$n=0x00403B99;Ride Cymbal 2
$n=0x00403C99;Hi Bongo
$n=0x00403D99;Low Bongo
$n=0x00403E99;Mute Hi Conga
$n=0x00403F99;Open Hi Conga
$n=0x00404099;Low Conga
$n=0x00404199;High Timbale
$n=0x00404299;Low Timbale
$n=0x00404399;High Agogo
$n=0x00404499;Low Agogo
$n=0x00404599;Cabasa
$n=0x00404699;Maracas
$n=0x00404799;Short Whistle
$n=0x00404899;Long Whistle
$n=0x00404999;Short Guiro
$n=0x00404A99;Long Guiro
$n=0x00404B99;Claves
$n=0x00404C99;Hi Wood Block
$n=0x00404D99;Low Wood Block
$n=0x00404E99;Mute Cuica
$n=0x00404F99;Open Cuica
$n=0x00405099;Mute Triangle
$n=0x00405199;Open Triangle
$n=0x00405299;Shaker

Doesn't matter what instrument you have on currently, and I assume that 0x0000??99 will stop the 'percussion note'.

Posted (edited)

Anyone get the "Drum Notes" to work 35-82? I thought they would be on "Music Box" Instrument (Ch 10), but this isn't working.

Oh, never mind, here is da codez:

...

Doesn't matter what instrument you have on currently, and I assume that 0x0000??99 will stop the 'percussion note'.

 

Nice, Mark!  I hadn't thought about it until now, but the channels are obviously handled in the low 4-bits (nibble) of the message.  Logically, since channels are numbered 1-16, the lower nibble would represent these by subtracting 1 (yielding values 0-15 or 0x00 - 0x0F).  By using 0x09 for the channel, you are effectively telling it to play the desired notes on Channel 10.

This should allow setting instruments and sending sounds individually for all 16 channels by just adding 0 through 15 to the functions (NoteOn, NoteOff, Play, SetInstrument).  I'm gonna have to experiment, but I think this should effectively work.  If so, we'll just need to add that optional parameter to the functions, add constants for the instruments, and optionally PercussionOn/Off functions)..

*edit: Turns out I was right.  But more importantly, looks like the note-off messages were coded as velocity = 0 messages.  I'm getting info from the MIDI Message Table.  Looks like a number of things need to be rewritten here..

Edited by Ascend4nt
Posted (edited)

So I've messed around since figuring out how the bits are supposed to be arranged according to the MIDI Message Table I had linked to earlier, and managed to fix the NoteOn, NoteOff, and setInstrument functions, as well as bring a few new functions into the fold:

PercussionOn()   ; Turns on a Percussion instrument at a given velocity
PercussionOff()  ; Turns off a Percussion instrument
AllNotesOff()    ; Turns off all notes on a given channel
PitchBend()      ; Pitch-bends all the notes on a given channel

I haven't worked on fixing the constants in the MidiUDF yet, but as of right now this example should give you a good idea of what's capable - multi-channel multi-instrument mixed-velocity sounds with some percussive instruments, and pitch bending!

Here's the script in its current form:

See >post # 81 for the current version

Edited by Ascend4nt
Posted (edited)

So I've messed around since figuring out how the bits are supposed to be arranged according to the MIDI Message Table I had linked to earlier, and managed to fix the NoteOn, NoteOff, and setInstrument functions, as well as bring a few new functions into the fold:

 

I'll be studying this. If you've solved the channel mystery, you are a superstar. Everything in my mus++ is set up for when this day arrives - setting separate channels represented the final hurdle for me. Thanks for all the great work here. :D

At last I will also be able to add accents and dynamics. It's interesting to note that you need not be limited to 16 instruments because each channel is capable of playing multiple instruments simultaneously - an exploit  which is not in the manual.

Edited by czardas

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...