Global Const $CALLBACK_NULL = 0 Global Const $CALLBACK_WINDOW = 0x10000 Global Const $CALLBACK_THREAD = 0x20000 Global Const $CALLBACK_FUNCTION = 0x30000 Global Const $CALLBACK_EVENT = 0x50000 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 $MIDICAPS_CACHE = 0x4 Global Const $MIDICAPS_LRVOLUME = 0x20 Global Const $MIDICAPS_STREAM = 0x8 Global Const $MIDICAPS_VOLUME = 0x1 Global Const $MIDIPROP_GET = 0x40000000 Global Const $MIDIPROP_SET = 0x80000000 Global Const $MIDIPROP_TEMPO = 0x2 Global Const $MIDIPROP_TIMEDIV = 0x1 Global Const $MIDISTRM_ERROR = -2 Global Const $MIDI_IO_STATUS = 0x20 Global Const $MIDIMAPPER = -1 Global Const $MAXERRORLENGTH = 128 Global Const $MAXPNAMELEN = 32 Global Const $MIDIPATCHSIZE = 128 Global Const $MIDIERR_BASE = 64 Global Const $MMSYSERR_BASE = 0 Global Const $MMSYSERR_NOERROR = 0 Global Const $MIDIHDR = "ptr lpData; dword dwBufferLength; dword dwBytesRecorded; dword_ptr dwUser; dword dwFlags; int lpNext; dword_ptr reserved; dword dwOffset; dword_ptr dwReserved[4];" Global Const $MIDIINCAPS = "word wMid; word wPid; int vDriverVersion; char szPname[32]; dword dwSupport;" Global Const $MIDIOUTCAPS = "word wMid; word wPid; int vDriverVersion; char szPname[32]; word wTechnology; word wVioces; word wNotes; word wChannelMask; dword dwSupport;" Global Const $MIDIEVENT = "dword dwDeltaTime; dword dwStreamID; dword dwEvent; dword dwParms[];" Global Const $MIDISTRMBUFFVER = "int dwVersion; int dwMid; int dwOEMVersion;" Global Const $MMIOINFO = "int dwFlags; int fccIOProc; int pIOProc; int wErrorRet; int htask; int cchBuffer; string pchBuffer; string pchNext; string pchEndRead; string pchEndWrite; int lBufOffset; int lDiskOffset; int adwInfo; int dwReserved1; int dwReserved2; int hmmio;" Global Const $MMCKINFO = "int ckid; int ckSize; int fccType; int dwDataOffset; int dwFlags;" Global Const $MMTIME = "uint wType; dword ms; dword sample; dword cb; dword ticks; byte hour; byte min; byte sec; byte frame; byte fps; byte dummy; byte pad[2]; dword songptrpos;" Global Const $MIDIPROPTIMEDIV = "dword cbStruct; dword dwTimeDiv;" Global Const $MIDIPROPTEMPO = "dword cbStruct; dword dwTempo;" Global Const $KEYARRAY = "word KEYARRAY[128];" Global Const $PATCHARRAY = "word PATCHARRAY[128];" Global Const $MHDR_DONE = 0x1 Global Const $MHDR_INQUEUE = 0x4 Global Const $MHDR_PREPARED = 0x2 Global Const $MHDR_VALID = 0x7 Global Const $MOD_MIDIPORT = 1 Global Const $MOD_SYNTH = 2 Global Const $MOD_SQSYNTH = 3 Global Const $MOD_FMSYNTH = 4 Global Const $MOD_MAPPER = 5 Global Const $TIME_BYTES = 0x4 Global Const $TIME_MIDI = 0x10 Global Const $TIME_MS = 0x1 Global Const $TIME_ONESHOT = 0 Global Const $TIME_PERIODIC = 1 Global Const $TIME_SAMPLES = 0x2 Global Const $TIME_SMPTE = 0x8 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 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 $MIDIERR_BADOPENMODE = ($MIDIERR_BASE + 6) Global Const $MMSYSERR_ALLOCATED = ($MMSYSERR_BASE + 4) Global Const $MMSYSERR_INVALFLAG = ($MMSYSERR_BASE + 10) Global Const $MMSYSERR_BADDEVICEID = ($MMSYSERR_BASE + 2) Global Const $MMSYSERR_NODRIVER = ($MMSYSERR_BASE + 6) Global Const $MMSYSERR_ERROR = ($MMSYSERR_BASE + 1) Global Const $MMSYSERR_HANDLEBUSY = ($MMSYSERR_BASE + 12) Global Const $MMSYSERR_INVALIDALIAS = ($MMSYSERR_BASE + 13) Global Const $MMSYSERR_LASTERROR = ($MMSYSERR_BASE + 13) Global Const $MMSYSERR_BADERRNUM = ($MMSYSERR_BASE + 9) Global Const $MMSYSERR_INVALPARAM = ($MMSYSERR_BASE + 11) Global Const $MMSYSERR_NOMEM = ($MMSYSERR_BASE + 7) Global Const $MMSYSERR_INVALHANDLE = ($MMSYSERR_BASE + 5) Global Const $MMSYSERR_NOTSUPPORTED = ($MMSYSERR_BASE + 8) Global $MIDI_WinMM_DLL = -1 #cs DllStructure Help ---DllStruct $MIDIHDR--- lpData - Pointer to MIDI data. dwBufferLenght - Size of the buffer. dwBytesRecorded - Actual amount of data in the buffer. This value should be less than or equal to the value given in the dwBufferLength member. dwUser - Custom user data. dwFlags - Flags giving information about the buffer. $MHDR_DONE - Set by the device driver to indicate that it is finished with the buffer and is returning it to the application. $MHDR_INQUEUE - Set by Windows to indicate that the buffer is queued for playback. $MHDR_PREPARED - Set by Windows to indicate that the buffer has been prepared by using the _MidiIn_PrepareHeader or _MidiOut_PrepareHeader function. lpNext - Reserved; do not use. reserved - Reserved; do not use. dwOffset - Offset into the buffer when a callback is performed. (This callback is generated because the $MEVT_F_CALLBACK flag is set in the dwEvent member of the $MIDIEVENT structure.) This offset enables an application to determine which event caused the callback. dwReserved - Reserved; do not use. ---DllStruct $MIDIINCAPS--- wMid - Manufacturer identifier of the device driver for the MIDI input device. Manufacturer identifiers are defined in Manufacturer and Product Identifiers. wPid - Product identifier of the MIDI input device. Product identifiers are defined in Manufacturer and Product Identifiers. vDriverVersion - Version number of the device driver for the MIDI input device. The high-order byte is the major version number, and the low-order byte is the minor version number. szPname - Product name in a null-terminated string. dwSupport - Reserved; must be zero. ---DllStruct $MIDIOUTCAPS--- wMid - Manufacturer identifier of the device driver for the MIDI output device. Manufacturer identifiers are defined in Manufacturer and Product Identifiers. wPid - Product identifier of the MIDI output device. Product identifiers are defined in Manufacturer and Product Identifiers. vDriverVersion - Version number of the device driver for the MIDI output device. The high-order byte is the major version number, and the low-order byte is the minor version number. szPname - Product name in a null-terminated string. wTechnology - Type of the MIDI output device. This value can be one of the following: MOD_MIDIPORT -MIDI hardware port. MOD_SYNTH - Synthesizer. MOD_SQSYNTH - Square wave synthesizer. MOD_FMSYNTH - FM synthesizer. MOD_MAPPER - Microsoft MIDI mapper. MOD_WAVETABLE - Hardware wavetable synthesizer. MOD_SWSYNTH - Software synthesizer. wVoices - Number of voices supported by an internal synthesizer device. If the device is a port, this member is not meaningful and is set to 0. wNotes - Maximum number of simultaneous notes that can be played by an internal synthesizer device. If the device is a port, this member is not meaningful and is set to 0. wChannelMask - Channels that an internal synthesizer device responds to, where the least significant bit refers to channel 0 and the most significant bit to channel 15. Port devices that transmit on all channels set this member to 0xFFFF. dwSupport - Optional functionality supported by the device. It can be one or more of the following: $MIDICAPS_CACHE - Supports patch caching. $MIDICAPS_LRVOLUME - Supports separate left and right volume control. $MIDICAPS_STREAM - Provides direct support for the _MidiStream_Out function. $MIDICAPS_VOLUME - Supports volume control. If a device supports volume changes, the $MIDICAPS_VOLUME flag will be set for the dwSupport member. If a device supports separate volume changes on the left and right channels, both the $MIDICAPS_VOLUME and the $MIDICAPS_LRVOLUME flags will be set for this member. ---DllStruct $MMTIME--- wType - Time format. It can be one of the following values: TIME_BYTES - Current byte offset from beginning of the file. TIME_MIDI - MIDI time. TIME_MS - Time in milliseconds. TIME_SAMPLES - Number of waveform-audio samples. TIME_SMPTE - SMPTE (Society of Motion Picture and Television Engineers) time. TIME_TICKS - Ticks within a MIDI stream. ms - Number of milliseconds. Used when wType is TIME_MS. sample - Number of samples. Used when wType is TIME_SAMPLES. cb - Byte count. Used when wType is TIME_BYTES. ticks - Ticks in MIDI stream. Used when wType is TIME_TICKS. smpte - SMPTE time structure. Used when wType is TIME_SMPTE. songptrpos - Song pointer position. midi - MIDI time structure. Used when wType is $TIME_MIDI. hour -Hours. min - Minutes. sec - Seconds. frame - Frames. fps - Frames per second (24, 25, 29 (30 drop), or 30). dummy - Dummy byte for alignment. pad - Padding. ---DllStruct $MIDIPROPTEMPO--- cbStruct - Length, in bytes, of this structure. This member must be filled in for both the $MIDIPROP_SET and $MIDIPROP_GET operations of the _MidiStream_Property function. dwTempo - Tempo of the stream, in microseconds per quarter note. The tempo is honored only if the time division for the stream is specified in quarter note format. This member is set in a $MIDIPROP_SET operation and is filled on return from a $MIDIPROP_GET operation. ---DllStruct $MIDIPROPTIMEDIV--- cbStruct - Length, in bytes, of this structure. This member must be filled in for both the $MIDIPROP_SET and $MIDIPROP_GET operations of the _MidiStream_Property function. dwTimeDiv - Time division for this stream, in the format specified in the Standard MIDI Files 1.0 specification. The low 16 bits of this DWORD value contain the time division. This member is set in a $MIDIPROP_SET operation and is filled on return from a $MIDIPROP_GET operation. ---DllStruct $PATCHARRAY--- PATCHARRAY is a type used to define an array of MIDI patches. Each element in the array corresponds to a patch with each of the 16 bits representing one of the 16 MIDI channels. Bits are set for each of the channels that use that particular patch. For example, if patch number 0 is used by physical MIDI channels 0 and 8, element 0 of the array should be set to 0x0101. ---DllStruct $KEYARRAY--- KEYARRAY specifies a type used to define an array of keys. Each element in the array corresponds to a key-based percussion patch with each of the 16 bits representing one of the 16 MIDI channels. Bits are set for each of the channels that use that particular patch. For example, if the percussion patch for key number 60 is used by physical MIDI channels 9 and 15, element 60 of the array should be set to 0x8200. #ce DllStruct Help ;================================================ ; Func _Midi_Startup ; The _Midi_Startup function opens the windowsapi dll ; Usage : _Midi_Startup() ; Output : ; Success 1 ; Failure 0 and @error ;================================================ Func _Midi_Startup() If $MIDI_WinMM_DLL = -1 Then $MIDI_WinMM_DLL = DllOpen("winmm.dll") If @error Or Not $MIDI_WinMM_DLL Then Return SetError(1,1,False) Return True EndFunc ;================================================ ; Func _Midi_Shudown ; The _Midi_Shutdown function closes the windowsapi dll ; Usage : _Midi_Shutdown() ; Output : ; Success 1 ; Failure 0 and @error ;================================================ Func _Midi_Shutdown() DllClose($MIDI_WinMM_DLL) If @error Then Return SetError(1,1,0) $MIDI_WinMM_DLL = -1 Return True EndFunc ;================================================ ; Func _Midi_Connect ; The _Midi_Connect function connects a MIDI input device to a MIDI thru or output device, or connects a MIDI thru device to a MIDI output device. ; Usage : _Midi_Connect($hMidi,$hMidiOut,$pReserved = 0) ; $hMidi - Handle to a MIDI input device or a MIDI thru device. (For thru devices, this handle must have been returned by a call to the _MidiOut_Open function.) ; $hMidiOut - Handle to the MIDI output or thru device. ; $pReserved - Reserved; must be NULL. ; Output : ; Success 1 ; Failure 0 and @error ; @error = 1 - Specified input device is already connected to an output device. ; @error = 2 - Specified device handle is invalid. ; @error = 3 - Unknown Error. ; Info : ; After calling this function, the MIDI input device receives event data ; in an $MIM_DATA message whenever a message with the same event data is sent to the output device driver. ; A thru driver is a special form of MIDI output driver. ; The system will allow only one MIDI output device to be connected to a MIDI input device, ; but multiple MIDI output devices can be connected to a MIDI thru device. ; Whenever the given MIDI input device receives event data in an $MIM_DATA message, ; a message with the same event data is sent to the given output device driver (or through the thru driver to the output drivers). ;================================================ Func _Midi_Connect($hMidi,$hMidiOut,$pReserved = 0) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiConnect","int",$hMidi,"int",$hMidiOut,"int",$pReserved) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_NOTREADY Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(2,2,0) Else Return SetError(3,3,0) EndIf EndFunc ; <=== _Midi_Connect ;================================================ ; Func _Midi_Disconnect ; The _Midi_Disconnect function disconnects a MIDI input device from a MIDI thru or output device, or disconnects a MIDI thru device from a MIDI output device. ; Usage : _Midi_Disconnect($hMidi,$hMidiOut,$pReserved = 0) ; $hMidi - Handle to a MIDI input device or a MIDI thru device. ; $hMidiOut - Handle to the MIDI output device to be disconnected. ; $pReserved - Reserved; must be NULL. ; Output : ; Success 1 ; Failure 0 and @error ; @error = 1 - Specified device handle is invalid. ; @error = 2 - Unknown Error. ; Info : ; MIDI input, output, and thru devices can be connected by using the _Midi_Connect function. ; Thereafter, whenever the MIDI input device receives event data in an $MIM_DATA message, ; a message with the same event data is sent to the output device driver (or through the thru driver to the output drivers). ;================================================ Func _Midi_Disconnect($hMidi,$hMidiOut,$pReserved = 0) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiDisconnect","int",$hMidi,"int",$hMidiOut,"int",$pReserved) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _Midi_Disconnect ;================================================ ; Func _MidiIn_AddBuffer ; The _MidiIn_AddBuffer function sends an input buffer to a specified opened MIDI input device. This function is used for system-exclusive messages. ; Usage : _MidiIn_AddBuffer($hMidi,$lpMidiInHdr,$cbMidiInHdr) ; $hMidi - Handle to the MIDI input device. ; $lbMidiInHdr - Pointer to a $MIDIHDR structure that identifies the buffer. ; $cbMidiInHdr - Size, in bytes, of the $MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The buffer pointed to by $lpMidiInHdr is still in the queue. ; @error = 2 - The buffer pointed to by $lpMidiInHdr has not been prepared. ; @error = 3 - The specified device handle is invalid. ; @error = 4 - The specified pointer or structure is invalid. ; @error = 5 - The system is unable to allocate or lock memory. ; @error = 6 - Unknown Error ; Info : ; When the buffer is filled, it is sent back to the application. ; The buffer must be prepared by using the _MidiIn_PrepareHeader function before it is passed to the _MidiIn_AddBuffer function. ;================================================ Func _MidiIn_AddBuffer($hMidi,$lpMidiInHdr,$cbMidiInHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInAddBuffer","int",$hMidi,"ptr",$lpMidiInHdr,"uint",$cbMidiInHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_STILLPLAYING Then Return SetError(1,1,0) ElseIf $aResult[0] = $MIDIERR_UNPREPARED Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(4,4,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(5,5,0) Else Return SetError(6,6,0) EndIf EndFunc ; <=== _MidiIn_AddBuffer ;================================================ ; Func _MidiIn_Close ; The _MidiIn_Close function closes the specified MIDI input device. ; Usage : _MidiIn_Close($hMidi) ; $hMidi - Handle to the MIDI input device. If the function is successful, the handle is no longer valid after the call to this function. ; Output : ; Success Return Value = 1 ; Failure Return Value = 0 and @error ; @error = 1 - Buffers are still in the queue. ; @error = 2 - The specified device handle is invalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error ; Info : ; If there are input buffers that have been sent by using the _MidiIn_AddBuffer function and have not been returned to the application, ; the close operation will fail. To return all pending buffers through the callback function, use the _MidiIn_Reset function. ;================================================ Func _MidiIn_Close($hMidi) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInClose","int",$hMidi) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_STILLPLAYING Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiIn_Close ;================================================ ; Func _MidiIn_GetDevCaps ; The _MidiIn_GetDevCaps function determines the capabilities of a specified MIDI input device. ; Usage : _MidiIn_GetDevCaps($uDeviceID,$lpMidiInCaps,$cbMidiInCaps) ; $uDeviceID - Identifier of the MIDI input device. The device identifier varies from 0 to one less than the number of devices present. This parameter can also be a properly cast device handle. ; $lpMidiInCaps - Pointer to a $MIDIINCAPS structure that is filled with information about the capabilities of the device. ; $cdMideInCaps - Size, in bytes, of the $MIDIINCAPS structure. Only $cbMidiInCaps bytes (or less) of information is copied to the location pointed to by $lpMidiInCaps. ; If $cbMidiInCaps is 0, nothing is copied, and the function returns 1. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device identifier is out of range. ; @error = 2 - The specified pointer or structure is invalid. ; @error = 3 - The driver is not installed. ; @error = 4 - The system is unable to allocate or lock memory. ; @error = 5 - Unknown Error. ; Info : ; To determine the number of MIDI input devices present on the system, use the _MidiIn_GetNumDevs function. ;================================================ Func _MidiIn_GetDevCaps($uDeviceID,$lpMidiInCaps,$cbMidiInCaps) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInGetDevCaps","uint_ptr",$uDeviceID,"ptr",$lpMidiInCaps,"uint",$cbMidiInCaps) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_BADDEVICEID Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NODRIVER Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(4,4,0) Else Return SetError(5,5,0) EndIf EndFunc ; <=== _MidiIn_GetDevCaps ;================================================ ; Func _MidiIn_GetErrorText ; The _MidiIn_GetErrorText function retrieves a textual description for an error identified by the specified error code. ; Usage : _MidiIn_GetErrorText($wError,$lpText,$cchText) ; $wError - Error code. ; $lpText - Pointer to the buffer to be filled with the textual error description. ; $cchText - Length, in characters, of the buffer pointed to by lpText. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified error number is out of range. ; @error = 2 - The specified pointer or structure is invalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ; Info : ; If the textual error description is longer than the specified buffer, ; the description is truncated. The returned error string is always null-terminated. ; If $cchText is 0, nothing is copied, and the function returns 1. ; All error descriptions are less than $MAXERRORLENGTH characters long. ;================================================ Func _MidiIn_GetErrorText($wError,$lpText,$cchText) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInGetErrorText","int",$wError,"ptr",$lpText,"uint",$cchText) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_BADERRNUM Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiIn_GetErrorText ;================================================ ; Func _MidiIn_GetID ; The _MidiIn_GetID function gets the device identifier for the given MIDI input device. ; This function is supported for backward compatibility. New applications can cast a handle of the device rather than retrieving the device identifier. ; Usage : _MidiIn_GetID($hMidiIn,$puDeviceID) ; $hMidiIn - Handle to the MIDI input device. ; $puDeviceID - Pointer to a variable to be filled with the device identifier. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The $hMidiIn parameter specifies an invalid handle. ; @error = 2 - No device driver is present. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ;================================================ Func _MidiIn_GetID($hMidiIn,$puDeviceID) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInGetID","int",$hMidiIn,"ptr",$puDeviceID) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_NODRIVER Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiIn_GetID ;================================================ ; Func _MidiIn_GetNumDevs ; The _MidiIn_GetNumDevs function retrieves the number of MIDI input devices in the system. ; Output : ; Returns the number of MIDI input devices present in the system. A return value of 0 means that there are no devices (not that there is no error). ;================================================ Func _MidiIn_GetNumDevs() Local $aResult = DllCall($MIDI_WinMM_DLL,"uint","midiInGetNumDevs") If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) Return $aResult[0] EndFunc ; <=== _MidiIn_GetNumDevs ;================================================ ; Func _MidiIn_Message ; The _MidiIn_Message function sends a message to the MIDI device driver. ; Usage: _MidiIn_Message($deviceID,$msg,$dw1,$dw2) ; $deviceID - Identifier of the MIDI device that receives the message. You must cast the device ID to the $HMIDIIN handle type. ; If you supply a handle instead of a device ID, the function fails and returns the error code 1. ; $msg - Message to send. ; $dw1 - Message parameter. ; $dw2 - Message parameter. ; Output : ; Returns the value returned by the audio device driver. ; Info : ; This function is used only for driver-specific messages that are not supported by the MIDI API. ;================================================ Func _MidiIn_Message($deviceID,$msg,$dw1,$dw2) Local $aResult = DllCall($MIDI_WinMM_DLL,"dword","midiInGetNumDevs","int",$deviceID,"uint",$msg,"dword_ptr",$dw1,"dword_ptr",$dw2) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOTSUPPORTED Then Return SetError(1,1,0) Else Return $aResult[0] EndIf EndFunc ; <=== _MidiIn_Message ;================================================ ; Func _MidiIn_Open ; The _MidiIn_Open function opens a specified MIDI input device. ; Usage: _MidiIn_Open($lphMidiIn,$uDeviceID,$dwCallback,$dwCallbackInstance,$dwFlags) ; $lpMidiIn - Pointer to an HMIDIIN handle. This location is filled with a handle identifying the opened MIDI input device. ; The handle is used to identify the device in calls to other MIDI input functions. ; $uDeviceID - Identifier of the MIDI input device to be opened. ; $dwCallback - Pointer to a callback function, a thread identifier, or a handle of a window called with information about incoming MIDI messages. For more information on the callback function, see _MidiIn_Proc. ; $dwCallbackInstance - User instance data passed to the callback function. This parameter is not used with window callback functions or threads. ; $dwFlags - Callback flag for opening the device and, optionally, a status flag that helps regulate rapid data transfers. It can be the following values. ; Most applications that use a callback mechanism will specify $CALLBACK_FUNCTION for this parameter. ; $CALLBACK_FUNCTION - The $dwCallback parameter is a callback procedure address. ; $CALLBACK_NULL - There is no callback mechanism. This value is the default setting. ; $CALLBACK_THREAD - The dwCallback parameter is a thread identifier. ; $CALLBACK_WINDOW - The dwCallback parameter is a window handle. ; $MIDI_IO_STATUS - When this parameter also specifies CALLBACK_FUNCTION, MIM_MOREDATA messages are sent to the callback function as well as MIM_DATA messages. ; Or, if this parameter also specifies CALLBACK_WINDOW, MM_MIM_MOREDATA messages are sent to the window as well as MM_MIM_DATA messages. ; This flag does not affect event or thread callbacks. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified resource is already allocated. ; @error = 2 - The specified device identifier is out of range. ; @error = 3 - The flags specified by $dwFlags are invalid. ; @error = 4 - The specified pointer or structure is invalid. ; @error = 5 - The system is unable to allocate or lock memory. ; @error = 6 - Unknown Error. ; Info : ; To determine the number of MIDI input devices present in the system, use the _MidiIn_GetNumDevs function. ; The device identifier specified by wDeviceID varies from zero to one less than the number of devices present. ; If a window or thread is chosen to receive callback information, the following messages are sent to the window procedure ; or thread to indicate the progress of MIDI input: $MM_MIM_OPEN, $MM_MIM_CLOSE, $MM_MIM_DATA, $MM_MIM_LONGDATA, $MM_MIM_ERROR, $MM_MIM_LONGERROR, and $MM_MIM_MOREDATA. ; If a function is chosen to receive callback information, the following messages are sent to the function to indicate the progress of MIDI input: ; $MIM_OPEN, $MIM_CLOSE, $MIM_DATA, $MIM_LONGDATA, $MIM_ERROR, $MIM_LONGERROR, and $MIM_MOREDATA. ;================================================ Func _MidiIn_Open($uDeviceID, $dwCallback, $dwCallbackInstance, $dwFlags = $CALLBACK_NULL) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInOpen","int*", 0,"uint_ptr",$uDeviceID,"dword_ptr",$dwCallback,"dword_ptr",$dwCallbackInstance,"dword",$dwFlags) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) Return $aResult[1] #cs If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_ALLOCATED Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_BADDEVICEID Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALFLAG Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(4,4,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(5,5,0) Else Return SetError(6,6,0) EndIf #ce EndFunc ; <=== _MidiIn_Open ;================================================ ; Func _MidiIn_PrepareHeader ; The _MidiIn_PrepareHeader function prepares a buffer for MIDI input. ; Usage: _MidiIn_PrepareHeader($hMidiIn,$lpMidiInHdr,$cbMidiInHdr) ; $hMidiIn - Handle to the MIDI input device. ; $lpMidiInHdr - Pointer to a $MIDIHDR structure that identifies the buffer to be prepared. ; $cbMidiInHdr - Size, in bytes, of the $MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - The specified address is invalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ; Info : ; Preparing a header that has already been prepared has no effect, and the function returns 1. ; After the header has been prepared, do not modify the buffer. To free the buffer, use the _MidiIn_UnprepareHeader function. ; Before using this function, you must set the $lpData, $dwBufferLength, and $dwFlags members of the $MIDIHDR structure. The $dwFlags member must be set to 0. ;================================================ Func _MidiIn_PrepareHeader($hMidiIn,$lpMidiInHdr,$cbMidiInHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInPrepareHeader","int",$hMidiIn,"int",$lpMidiInHdr,"uint",$cbMidiInHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiIn_PrepareHeader ;================================================ ; Func _MidiIn_Proc ; The _MidiIn_Proc function is the callback function for handling incoming MIDI messages. ; _MidiIn_Proc is a placeholder for the application-supplied function name. ; The address of this function can be specified in the callback-address parameter of the _MidiIn_Open function. ; Usage: _MidiIn_Proc($hMidiIn,$wMsg,$dwInstance,$dwParam1,$dwParam2) ; $hMidiIn - Handle to the MIDI input device. ; $wMsg - MIDI input message. ; $cbMidiInHdr - Instance data supplied with the _MidiIn_Open function. ; $dwParam1 - Message parameter. ; $dwParam2 - Message parameter. ; Info : ; The meaning of the $dwParam1 and $dwParam2 parameters is specific to the message type. For more information, see the topics for messages, such as $MIM_DATA. ; Applications should not call any system-defined functions from inside a callback function, ; except for EnterCriticalSection, LeaveCriticalSection, _MidiOut_LongMsg, _MidiOut_ShortMsg, OutputDebugString, PostMessage, PostThreadMessage, SetEvent, timeGetSystemTime, timeGetTime, timeKillEvent, and timeSetEvent. ;================================================ Func _MidiIn_Proc($hMidiIn,$wMsg,$dwInstance,$dwParam1,$dwParam2) DllCall($MIDI_WinMM_DLL,"int","midiInProc","int",$hMidiIn,"uint",$wMsg,"dword_ptr",$dwInstance,"dword_ptr",$dwParam1,"dword_ptr",$dwParam2) EndFunc ; <=== _MidiIn_Proc ;================================================ ; Func _MidiIn_Reset ; The _MidiIn_Reset function stops input on a given MIDI input device. ; Usage: _MidiIn_Reset($hMidiIn) ; $hMidiIn - Handle to the MIDI input device. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error. ; Info : ; This function returns all pending input buffers to the callback function and sets the $MHDR_DONE flag in the dwFlags member of the $MIDIHDR structure. ;================================================ Func _MidiIn_Reset($hMidiIn) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInReset","int",$hMidiIn) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiIn_Reset ;================================================ ; Func _MidiIn_Start ; The _MidiIn_Start function starts MIDI input on the specified MIDI input device. ; Usage: _MidiIn_Start($hMidiIn) ; $hMidiIn - Handle to the MIDI input device. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error ; Info : ; This function resets the time stamp to zero; time stamp values for subsequently received messages are relative to the time that this function was called. ; All messages except system-exclusive messages are sent directly to the client when they are received. ; System-exclusive messages are placed in the buffers supplied by the _MidiIn_AddBuffer function. ; If there are no buffers in the queue, the system-exclusive data is thrown away without notification to the client and input continues. ; Buffers are returned to the client when they are full, when a complete system-exclusive message has been received, or when the _MidiIn_Reset function is used. ; The dwBytesRecorded member of the $MIDIHDR structure will contain the actual length of data received. ; Calling this function when input is already started has no effect, and the function returns 1. ;================================================ Func _MidiIn_Start($hMidiIn) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInStart","int",$hMidiIn) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiIn_Start ;================================================ ; Func _MidiIn_Stop ; The _MidiIn_Stop function stops MIDI input on the specified MIDI input device. ; Usage: _MidiIn_Stop($hMidiIn) ; $hMidiIn - Handle to the MIDI input device. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error ; Info : ; If there are any system-exclusive messages or stream buffers in the queue, ; the current buffer is marked as done (the dwBytesRecorded member of the $MIDIHDR structure will contain the actual length of data), ; but any empty buffers in the queue remain there and are not marked as done. ; Calling this function when input is not started has no effect, and the function returns 1. ;================================================ Func _MidiIn_Stop($hMidiIn) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInStop","int",$hMidiIn) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiIn_Stop ;================================================ ; Func _MidiIn_UnprepareHeader ; The _MidiIn_UnprepareHeader function cleans up the preparation performed by the _MidiIn_PrepareHeader function. ; Usage: _MidiIn_PrepareHeader($hMidiIn,$lpMidiInHdr,$cbMidiInHdr) ; $hMidiIn - Handle to the MIDI input device. ; $lpMidiInHdr - Pointer to a $MIDIHDR structure that identifies the buffer to be prepared. ; $cbMidiInHdr - Size, in bytes, of the $MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - The specified address is invalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ; Info : ; This function is complementary to _MidiIn_PrepareHeader. You must use this function before freeing the buffer. ; After passing a buffer to the device driver by using the _MidiIn_AddBuffer function, ; you must wait until the driver is finished with the buffer before using _MidiIn_UnprepareHeader. ; Unpreparing a buffer that has not been prepared has no effect, and the function returns 1. ;================================================ Func _MidiIn_UnprepareHeader($hMidiIn,$lpMidiInHdr,$cbMidiInHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiInUnprepareHeader","int",$hMidiIn,"ptr",$lpMidiInHdr,"uint",$cbMidiInHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_STILLPLAYING Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiIn_UnprepareHeader ;================================================ ; Func _MidiOut_CacheDrumPatches ; The _MidiOut_CacheDrumPatches function requests that an internal MIDI synthesizer device preload and cache a specified set of key-based percussion patches. ; Usage: _MidiOut_CacheDrumPatches($hMidiOut,$wPatch,$lpKeyArray,$wFlags) ; $hMidiOut - Handle to the opened MIDI output device. This device should be an internal MIDI synthesizer. This parameter can also be the handle of a MIDI stream, cast to HMIDIOUT. ; $wPatch - Drum patch number that should be used. This parameter should be set to 0 to cache the default drum patch. ; $lpKeyArray - Pointer to a $KEYARRAY array indicating the key numbers of the specified percussion patches to be cached or uncached. ; $wFlags - Options for the cache operation. It can be one of the following flags. ; $MIDI_CACHE_ALL - Caches all of the specified patches. If they cannot all be cached, it caches none, clears the $KEYARRAY array, and returns error 4. ; $MIDI_CACHE_BESTFIT - Caches all of the specified patches. If they cannot all be cached, it caches as many patches as possible, changes the $KEYARRAY array to reflect which patches were cached, and returns error 4. ; $MIDI_CACHE_QUERY - Changes the $KEYARRAY array to indicate which patches are currently cached. ; $MIDI_UNCACHE - Uncaches the specified patches and clears the $KEYARRAY array. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The flag specified by $wFlags is invalid. ; @error = 2 - The specified device handle is invalid. ; @error = 3 - The array pointed to by the $lpKeyArray array is invalid. ; @error = 4 - The device does not have enough memory to cache all of the requested patches. ; @error = 5 - The specified device does not support patch caching. ; @error = 6 - Unknown Error. ; Info : ; Some synthesizers are not capable of keeping all percussion patches loaded simultaneously. Caching patches ensures that the specified patches are available. ; Each element of the $KEYARRAY array represents one of the 128 key-based percussion patches and has bits set for each of the 16 MIDI channels that use the particular patch. ; The least-significant bit represents physical channel 0, and the most-significant bit represents physical channel 15. ; For example, if the patch on key number 60 is used by physical channels 9 and 15, element 60 would be set to 0x8200. ; This function applies only to internal MIDI synthesizer devices. Not all internal synthesizers support patch caching. ; To see if a device supports patch caching, use the $MIDICAPS_CACHE flag to test the dwSupport member of the $MIDIOUTCAPS structure filled by the _MidiOut_GetDevCaps function. ;================================================ Func _MidiOut_CacheDrumPatches($hMidiOut,$wPatch,$lpKeyArray,$wFlags) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutCacheDrumPatches","int",$hMidiOut,"uint",$wPatch,"word",$lpKeyArray,"uint",$wFlags) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALFLAG Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(4,4,0) ElseIf $aResult[0] = $MMSYSERR_NOTSUPPORTED Then Return SetError(5,5,0) Else Return SetError(6,6,0) EndIf EndFunc ; <=== _MidiOut_CacheDrumPatches ;================================================ ; Func _MidiOut_CachePatches ; The _MidiOut_CachePatches function requests that an internal MIDI synthesizer device preload and cache a specified set of patches. ; Usage: _MidiOut_CachePatches($hMidiOut,$wBank,$lpPatchArray,$wFlags) ; $hMidiOut - Handle to the opened MIDI output device. This device must be an internal MIDI synthesizer. This parameter can also be the handle of a MIDI stream, cast to HMIDIOUT. ; $wBank - Bank of patches that should be used. This parameter should be set to 0 to cache the default patch bank. ; $lpKeyArray - Pointer to a $PATCHARRAY array indicating the patches to be cached or uncached. ; $wFlags - Options for the cache operation. It can be one of the following flags. ; $MIDI_CACHE_ALL - Caches all of the specified patches. If they cannot all be cached, it caches none, clears the KEYARRAY array, and returns error 4. ; $MIDI_CACHE_BESTFIT - Caches all of the specified patches. If they cannot all be cached, it caches as many patches as possible, changes the KEYARRAY array to reflect which patches were cached, and returns error 4. ; $MIDI_CACHE_QUERY - Changes the $KEYARRAY array to indicate which patches are currently cached. ; $MIDI_UNCACHE - Uncaches the specified patches and clears the $KEYARRAY array. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The flag specified by $wFlags is invalid. ; @error = 2 - The specified device handle is invalid. ; @error = 3 - The array pointed to by the $lpPatchArray array is invalid. ; @error = 4 - The device does not have enough memory to cache all of the requested patches. ; @error = 5 - The specified device does not support patch caching. ; @error = 6 - Unknown Error. ; Info : ; Some synthesizers are not capable of keeping all patches loaded simultaneously and must load data from disk when they receive MIDI program change messages. ; Caching patches ensures that the specified patches are immediately available. ; Each element of the $PATCHARRAY array represents one of the 128 patches and has bits set for each of the 16 MIDI channels that use the particular patch. ; The least-significant bit represents physical channel 0, and the most-significant bit represents physical channel 15 (0x0F). ; For example, if patch 0 is used by physical channels 0 and 8, element 0 would be set to 0x0101. ; This function applies only to internal MIDI synthesizer devices. Not all internal synthesizers support patch caching. ; To see if a device supports patch caching, use the $MIDICAPS_CACHE flag to test the dwSupport member of the $MIDIOUTCAPS structure filled by the _MidiOut_GetDevCaps function. ;================================================ Func _MidiOut_CachePatches($hMidiOut,$wBank,$lpPatchArray,$wFlags) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutCachePatches","int",$hMidiOut,"uint",$wBank,"word",$lpPatchArray,"uint",$wFlags) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALFLAG Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(4,4,0) ElseIf $aResult[0] = $MMSYSERR_NOTSUPPORTED Then Return SetError(5,5,0) Else Return SetError(6,6,0) EndIf EndFunc ; <=== _MidiOut_CachePatches ;================================================ ; Func _MidiOut_GetDevCaps ; The _MidiOut_GetDevCaps function queries a specified MIDI output device to determine its capabilities. ; Usage : _MidiOut_GetDevCaps($uDeviceID,$lpMidiOutCaps,$cbMidiOutCaps) ; $uDeviceID - Identifier of the MIDI output device. The device identifier specified by this parameter varies from 0 to one less than the number of devices present. ; The $MIDI_MAPPER constant is also a valid device identifier. This parameter can also be a properly cast device handle. ; $lpMidiOutCaps - Pointer to a $MIDIOUTCAPS structure. This structure is filled with information about the capabilities of the device. ; $cbMideOutCaps - Size, in bytes, of the $MIDIOUTCAPS structure. Only $cbMidiOutCaps bytes (or less) of information is copied to the location pointed to by $lpMidiOutCaps. ; If $cbMidiOutCaps is 0, nothing is copied, and the function returns 1. ; Output : ; Success Return Value = 1 ; Failure Return Value = 0 and @error ; @error = 1 - The specified device identifier is out of range. ; @error = 2 - The specified pointer or structure is invalid. ; @error = 3 - The driver is not installed. ; @error = 4 - The system is unable to load mapper string description. ; @error = 5 - Unknown Error. ; Info : ; To determine the number of MIDI output devices present in the system, use the _MidiOut_GetNumDevs function. ;================================================ Func _MidiOut_GetDevCaps($uDeviceID,$lpMidiOutCaps,$cbMidiOutCaps) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutGetDevCaps","int",$uDeviceID,"int",$lpMidiOutCaps,"int",$cbMidiOutCaps) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_BADDEVICEID Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NODRIVER Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(4,4,0) Else Return SetError(5,5,0) EndIf EndFunc ; <=== _MidiOut_GetDevCaps ;================================================ ; Func _MidiOut_GetErrorText ; The _MidiOut_GetErrorText function retrieves a textual description for an error identified by the specified error code. ; Usage : _MidiOut_GetErrorText($mmrError,$lpText,$cchText) ; $mmrError - Error code. ; $lpText - Pointer to the buffer to be filled with the textual error description. ; $cchText - Length, in characters, of the buffer pointed to by $lpText. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified error number is out of range. ; @error = 2 - The specified pointer or structure is invalid. ; @error = 3 - Unknown Error. ; Info : ; If the textual error description is longer than the specified buffer, the description is truncated. ; The returned error string is always null-terminated. If $cchText is 0, nothing is copied, and the function returns 1. ; All error descriptions are less than $MAXERRORLENGTH characters long. ;================================================ Func _MidiOut_GetErrorText($mmrError,$lpText,$cchText) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutGetErrorText","int",$mmrError,"ptr",$lpText,"uint",$cchText) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_BADERRNUM Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) Else Return SetError(3,3,0) EndIf EndFunc ; <=== _MidiOut_GetErrorText ;================================================ ; Func _MidiOut_GetID ; The _MidiOut_GetID function retrieves the device identifier for the given MIDI output device. ; This function is supported for backward compatibility. New applications can cast a handle of the device rather than retrieving the device identifier. ; Usage : _MidiOut_GetID($hMidiOut,$puDeviceID) ; $hMidiOut - Handle to the MIDI Output device. ; $puDeviceID - Pointer to a variable to be filled with the device identifier. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The $hMidiOut parameter specifies an invalid handle. ; @error = 2 - No device driver is present. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ;================================================ Func _MidiOut_GetID($hMidiOut,$puDeviceID) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutGetID","int",$hMidiOut,"ptr",$puDeviceID) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_NODRIVER Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiOut_GetID ;================================================ ; Func _MidiOut_GetNumDevs ; The _MidiOut_GetNumDevs function retrieves the number of MIDI output devices present in the system. ; Output : ; Returns the number of MIDI output devices. A return value of 0 means that there are no devices (not that there is no error). ;================================================ Func _MidiOut_GetNumDevs() Local $aResult = DllCall($MIDI_WinMM_DLL,"uint","midiOutGetNumDevs") If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) Return $aResult[0] EndFunc ; <=== _MidiOut_GetNumDevs ;================================================ ; Func _MidiOut_GetVolume ; The _MidiOut_GetVolume function retrieves the current volume setting of a MIDI output device. ; Usage : _MidiOut_GetVolume($hMidiOut,$lpdwVolume) ; $hMidiOut - Handle to the MIDI Output device. ; $lpdwVolume - Pointer to the location to contain the current volume setting. ; The low-order word of this location 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 the specified location contains the mono volume level. ; Any value set by using the _MidiOut_SetVolume function is returned, regardless of whether the device supports that value. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - The specified pointer or structure is invalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - The function is not supported. ; @error = 5 - Unknown Error. ; Info : ; If a device identifier is used, then the result of the _MidiOut_GetVolume call and the information returned in $lpdwVolume applies to all instances of the device. ; If a device handle is used, then the result and information returned applies only to the instance of the device referenced by the device handle. ; Not all devices support volume control. You can determine whether a device supports volume control by querying the device by using the _MidiOut_GetDevCaps function and specifying the MIDICAPS_VOLUME flag. ; You can also determine whether the device supports volume control on both the left and right channels by querying the device by using the _MidiOut_GetDevCaps function and specifying the MIDICAPS_LRVOLUME flag. ;================================================ Func _MidiOut_GetVolume($hMidiOut,$lpdwVolume) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutGetVolume","int",$hMidiOut,"ptr",$lpdwVolume) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_NOTSUPPORTED Then Return SetError(4,4,0) Else Return SetError(5,5,0) EndIf EndFunc ; <=== _MidiOut_GetVolume ;================================================ ; Func _MidiOut_LongMsg ; The _MidiOut_LongMsg function sends a system-exclusive MIDI message to the specified MIDI output device. ; Usage : _MidiOut_LongMsg($hMidiOut,$lpMidiOutHdr,$cbMidiOutHdr) ; $hMidiOut - Handle to the MIDI output device. This parameter can also be the handle of a MIDI stream cast to HMIDIOUT. ; $lpMidiOutHdr - Pointer to a $MIDIHDR structure that identifies the MIDI buffer. ; $cbMidiOutHdr - Size, in bytes, of the $MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The hardware is busy with other data. ; @error = 2 - The buffer pointed to by $lpMidiOutHdr has not been prepared. ; @error = 3 - The specified device handle is invalid. ; @error = 4 - The specified pointer or structure is invalid. ; @error = 5 - Unknown Error. ; Info : ; Before the buffer is passed to _MidiOut_LongMsg, it must be prepared by using the _MidiOut_PrepareHeader function. The MIDI output device driver determines whether the data is sent synchronously or asynchronously. ;================================================ Func _MidiOut_LongMsg($hMidiOut,$lpMidiOutHdr,$cbMidiOutHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutLongMsg","int",$hMidiOut,"ptr",$lpMidiOutHdr,"uint",$cbMidiOutHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_NOTREADY Then Return SetError(1,1,0) ElseIf $aResult[0] = $MIDIERR_UNPREPARED Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(4,4,0) Else Return SetError(5,5,0) EndIf EndFunc ; <=== _MidiOut_LongMsg ;================================================ ; Func _MidiOut_Message ; The _MidiOut_Message function sends a message to the MIDI device drivers. This function is used only for driver-specific messages that are not supported by the MIDI API. ; Usage : _MidiOut_Message($deviceID,$msg,$dw1,$dw2) ; $deviceID - Identifier of the MIDI device that receives the message. You must cast the device ID to the HMIDIOUT handle type. ; If you supply a handle instead of a device ID, the function fails and returns the MMSYSERR_NOSUPPORT error code. ; $msg - Message to send. ; $dw1 - Message parameter. ; $dw2 - Message parameter. ; Output : ; Success Returns the value returned by the audio device driver. ; Failure Return 0 and @error ; @error = 1 - The specified device is not supported. ; Info : ; Returns the value returned by the audio device driver. ;================================================ Func _MidiOut_Message($deviceID,$msg,$dw1,$dw2) Local $aResult = DllCall($MIDI_WinMM_DLL,"dword","midiOutMessage","int",$deviceID,"uint",$msg,"dword_ptr",$dw1,"dword_ptr",$dw2) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOTSUPPORTED Then Return SetError(1,1,0) Else Return $aResult[0] EndIf EndFunc ; <=== _MidiOut_Message ;================================================ ; Func _MidiOut_Open ; The _MidiOut_Open function opens a MIDI output device for playback. ; Usage: _MidiOut_Open($lphMidiOut,$uDeviceID,$dwCallback,$dwCallbackInstance,$dwFlags) ; $lphMidiOut - Pointer to an HMIDIOUT handle. This location is filled with a handle identifying the opened MIDI output device. ; The handle is used to identify the device in calls to other MIDI output functions. ; $uDeviceID - Identifier of the MIDI output device that is to be opened. ; $dwCallback - Pointer to a callback function, an event handle, a thread identifier, or a handle of a window or thread called during MIDI playback to process messages related to the progress of the playback. ; If no callback is desired, specify 0 for this parameter. For more information on the callback function, see _MidiOut_Proc. ; $dwCallbackInstance - User instance data passed to the callback. This parameter is not used with window callbacks or threads. ; $dwFlags - Callback flag for opening the device. It can be the following values. ; $CALLBACK_EVENT - The dwCallback parameter is an event handle. This callback mechanism is for output only. ; $CALLBACK_FUNCTION - The dwCallback parameter is a callback function address. ; $CALLBACK_NULL - There is no callback mechanism. This value is the default setting. ; $CALLBACK_THREAD - The dwCallback parameter is a thread identifier. ; $CALLBACK_WINDOW - The dwCallback parameter is a window handle. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - No MIDI port was found. This error occurs only when the mapper is opened. ; @error = 2 - The specified resource is already allocated. ; @error = 3 - The specified device identifier is out of range. ; @error = 4 - The specified pointer or structure is invalid. ; @error = 5 - The system is unable to allocate or lock memory. ; @error = 6 - Unknown Error. ; Info : ; To determine the number of MIDI output devices present in the system, use the _MidiOut_GetNumDevs function. ; The device identifier specified by wDeviceID varies from 0 to one less than the number of devices present. $MIDI_MAPPER can also be used as the device identifier. ; If a window or thread is chosen to receive callback information, the following messages are sent to the window procedure or thread to indicate the progress of MIDI output: $MM_MOM_OPEN, $MM_MOM_CLOSE, and $MM_MOM_DONE. ; If a function is chosen to receive callback information, the following messages are sent to the function to indicate the progress of MIDI output: $MOM_OPEN, $MOM_CLOSE, and $MOM_DONE. ;================================================ Func _MidiOut_Open($lphMidiOut,$uDeviceID,$dwCallback,$dwCallbackInstance,$dwFlags = $CALLBACK_NULL) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutOpen","int",$lphMidiOut,"uint_ptr",$uDeviceID,"dword_ptr",$dwCallback,"dword_ptr",$dwCallbackInstance,"dword",$dwFlags) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_NODEVICE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_ALLOCATED Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_BADDEVICEID Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(4,4,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(5,5,0) Else Return SetError(6,6,0) EndIf EndFunc ; <=== _MidiOut_Open ;================================================ ; Func _MidiOut_PrepareHeader ; The _MidiOut_PrepareHeader function prepares a MIDI system-exclusive or stream buffer for output. ; Usage: _MidiOut_PrepareHeader($hMidiOut,$lpMidiOutHdr,$cbMidiOutHdr) ; $hMidiOut - Handle to the MIDI output device. This parameter can also be the handle of a MIDI stream cast to HMIDIOUT. ; $lpMidiOutHdr - Pointer to a $MIDIHDR structure that identifies the buffer to be prepared. ; $cbMidiOutHdr - Size, in bytes, of the $MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is Outvalid. ; @error = 2 - The specified address is Outvalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ; Info : ; A stream buffer cannot be larger than 64K. ; Preparing a header that has already been prepared has no effect, and the function returns 1. ; After the header has been prepared, do not modify the buffer. To free the buffer, use the _MidiOut_UnprepareHeader function. ; Before using this function, you must set the lpData, dwBufferLength, and dwFlags members of the $MIDIHDR structure. The dwFlags member must be set to 0. ;================================================ Func _MidiOut_PrepareHeader($hMidiOut,$lpMidiOutHdr,$cbMidiOutHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutPrepareHeader","int",$hMidiOut,"int",$lpMidiOutHdr,"uint",$cbMidiOutHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiOut_PrepareHeader ;================================================ ; Func _MidiOut_Proc ; The _MidiOut_Proc function is the callback function for handling outgoing MIDI messages. ; _MidiOut_Proc is a placeholder for the application-supplied function name. ; The address of the function can be specified in the callback-address parameter of the _MidiOut_Open function. ; Usage: _MidiOut_Proc($hMidiOut,$wMsg,$dwInstance,$dwParam1,$dwParam2) ; $hMidiOut - Handle to the MIDI Output device. ; $wMsg - MIDI Output message. ; $cbMidiOutHdr - Instance data supplied by using the _MidiOut_Open function. ; $dwParam1 - Message parameter. ; $dwParam2 - Message parameter. ; Info : ; Applications should not call any system-defined functions from inside a callback function, except for : ; EnterCriticalSection, LeaveCriticalSection, _MidiOut_LongMsg, _MidiOut_ShortMsg, OutputDebugString, PostMessage, PostThreadMessage, SetEvent, timeGetSystemTime, timeGetTime, timeKillEvent, and timeSetEvent. ; Calling other wave functions will cause deadlock. ;================================================ Func _MidiOut_Proc($hMidiOut,$wMsg,$dwInstance,$dwParam1,$dwParam2) DllCall($MIDI_WinMM_DLL,"int","midiOutProc","int",$hMidiOut,"uint",$wMsg,"dword_ptr",$dwInstance,"dword_ptr",$dwParam1,"dword_ptr",$dwParam2) EndFunc ; <=== _MidiOut_Proc ;================================================ ; Func _MidiOut_Reset ; The _MidiOut_Reset function turns off all notes on all MIDI channels for the specified MIDI output device. ; Usage: _MidiOut_Reset($hMidiOut) ; $hMidiOut - Handle to the MIDI output device. This parameter can also be the handle of a MIDI stream cast to HMIDIOUT. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is Invalid. ; Info : ; Any pending system-exclusive or stream output buffers are returned to the callback function and the $MHDR_DONE flag is set in the dwFlags member of the $MIDIHDR structure. ; Terminating a system-exclusive message without sending an EOX (end-of-exclusive) byte might cause problems for the receiving device. ; The _MidiOut_Reset function does not send an EOX byte when it terminates a system-exclusive message — applications are responsible for doing this. ; To turn off all notes, a note-off message for each note in each channel is sent. In addition, the sustain controller is turned off for each channel. ;================================================ Func _MidiOut_Reset($hMidiOut) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutReset","int",$hMidiOut) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return 1 EndIf EndFunc ; <=== _MidiOut_Reset ;================================================ ; Func _MidiOut_SetVolume ; The _MidiOut_SetVolume function sets the volume of a MIDI output device. ; Usage: _MidiOut_SetVolume($hMidiOut,$dwVolume) ; $hMidiOut - Handle to an open MIDI output device. This parameter can also contain the handle of a MIDI stream, as long as it is cast to HMIDIOUT. ; This parameter can also be a device identifier. ; $dwVolume - New volume setting. 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. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is Invalid. ; @error = 2 - The system is unable to allocate or lock memory. ; @error = 3 - The function is not supported. ; @error = 4 - Unknown Error. ; Info : ; If a device identifier is used, then the result of the _MidiOut_SetVolume call applies to all instances of the device. ; If a device handle is used, then the result applies only to the instance of the device referenced by the device handle. ; Not all devices support volume changes. You can determine whether a device supports it by querying the device using the _MidiOut_GetDevCaps function and the $MIDICAPS_VOLUME flag. ; You can also determine whether the device supports volume control on both the left and right channels by querying the device using the _MidiOut_GetDevCaps function and the $MIDICAPS_LRVOLUME flag. ; Devices that do not support a full 16 bits of volume-level control use the high-order bits of the requested volume setting. ; For example, a device that supports 4 bits of volume control produces the same volume setting for the following volume-level values: 0x4000, 0x43be, and 0x4fff. ; The _MidiOut_GetVolume function returns the full 16-bit value, as set by _MidiOut_SetVolume, irrespective of the device's capabilities. ; Volume settings are interpreted logarithmically. This means that the perceived increase in volume is the same when increasing the volume level from 0x5000 to 0x6000 as it is from 0x4000 to 0x5000. ;================================================ Func _MidiOut_SetVolume($hMidiOut,$dwVolume) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutSetVolume","int",$hMidiOut,"dword",$dwVolume) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOTSUPPORTED Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiOut_SetVolume ;================================================ ; Func _MidiOut_ShortMsg ; The _MidiOut_ShortMsg function sends a short MIDI message to the specified MIDI output device. ; Usage: _MidiOut_ShortMsg($hMidiOut,$dwMsg) ; $hMidiOut - Handle to the MIDI output device. This parameter can also be the handle of a MIDI stream cast to HMIDIOUT. ; $dwMsg - MIDI message. The message is packed into a DWORD value with the first byte of the message in the low-order byte. The message is packed into this parameter as follows. ; 1. Option - The two MIDI data bytes are optional ; High Word, Low-order - Second byte of MIDI data (Optional) ; Low Word, High-order - First byte of MIDI data (Optional) ; Low Word, Low-order - MIDI status ; 2. Option - Series of messages have the same status byte ; Low Word, High-order - Second byte of MIDI data (Optional) ; Low Word, Low-order - First byte of MIDI data ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The application sent a message without a status byte to a stream handle. ; @error = 2 - The hardware is busy with other data. ; @error = 3 - The specified device handle is invalid. ; @error = 4 - Unknown Error. ; Info : ; This function is used to send any MIDI message except for system-exclusive or stream messages. ; This function might not return until the message has been sent to the output device. ; You can send short messages while streams are playing on the same device (although you cannot use a running status in this case). ;================================================ Func _MidiOut_ShortMsg($hMidiOut,$dwMsg) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutShortMsg","int",$hMidiOut,"dword",$dwMsg) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_BADOPENMODE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MIDIERR_NOTREADY Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiOut_ShortMsg ;================================================ ; Func _MidiOut_UnprepareHeader ; The _MidiOut_UnprepareHeader function cleans up the preparation performed by the _MidiOut_PrepareHeader function. ; Usage: _MidiOut_PrepareHeader($hMidiOut,$lpMidiOutHdr,$cbMidiOutHdr) ; $hMidiOut - Handle to the MIDI output device. This parameter can also be the handle of a MIDI stream cast to HMIDIOUT. ; $lpMidiOutHdr - Pointer to a MIDIHDR structure identifying the buffer to be cleaned up. ; $cbMidiOutHdr - Size, in bytes, of the MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The buffer pointed to by $lpMidiOutHdr is still in the queue. ; @error = 2 - The specified device handle is invalid. ; @error = 3 - The specified pointer or structure is invalid. ; @error = 4 - Unknown Error. ; Info : ; This function is complementary to the _MidiOut_PrepareHeader function. You must call _MidiOut_UnprepareHeader before freeing the buffer. ; After passing a buffer to the device driver with the _MidiOut_LongMsg function, you must wait until the device driver is finished with the buffer before calling _MidiOut_UnprepareHeader. ; Unpreparing a buffer that has not been prepared has no effect, and the function returns 1. ;================================================ Func _MidiOut_UnprepareHeader($hMidiOut,$lpMidiOutHdr,$cbMidiOutHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiOutUnprepareHeader","int",$hMidiOut,"int",$lpMidiOutHdr,"int",$cbMidiOutHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MIDIERR_STILLPLAYING Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiOut_UnprepareHeader ;================================================ ; Func _MidiStream_Close ; The _MidiStream_Close function closes an open MIDI stream. ; Usage: _MidiOut_Close($hStream) ; $hStream - Handle to a MIDI stream, as retrieved by using the _MidiStream_Open function. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error. ;================================================ Func _MidiOut_Close($hStream) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamClose","int",$hStream) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiStream_Close ;================================================ ; Func _MidiStream_Open ; The _MidiStream_Open function opens a MIDI stream for output. By default, the device is opened in paused mode. ; The stream handle retrieved by this function must be used in all subsequent references to the stream. ; Usage: _MidiStream_Open($lphStream,$puDeviceID,$cMidi,$dwCallback,$dwInstance,$fdwOpen) ; $lphStream - Pointer to a variable to contain the stream handle when the function returns. ; $puDeviceID - Pointer to a device identifier. The device is opened on behalf of the stream and closed again when the stream is closed. ; $cMidi - Reserved; must be 1. ; $dwCallback - Pointer to a callback function, an event handle, a thread identifier, or a handle of a window or thread called during MIDI playback to process messages related to the progress of the playback. ; If no callback mechanism is desired, specify 0 for this parameter. ; $dwInstance - Application-specific instance data that is returned to the application with every callback function. ; $fdwOpen - Callback flag for opening the device. One of the following callback flags must be specified. ; $CALLBACK_EVENT - The $dwCallback parameter is an event handle. This callback mechanism is for output only. ; $CALLBACK_FUNCTION - The $dwCallback parameter is a callback procedure address. ; $CALLBACK_NULL - There is no callback mechanism. This is the default setting. ; $CALLBACK_THREAD - The $dwCallback parameter is a thread identifier. ; $CALLBACK_WINDOW - The $dwCallback parameter is a window handle. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device identifier is out of range. ; @error = 2 - The given handle or flags parameter is invalid. ; @error = 3 - The system is unable to allocate or lock memory. ; @error = 4 - Unknown Error. ;================================================ Func _MidiStream_Open($lphStream,$puDeviceID,$cMidi,$dwCallback,$dwInstance,$fdwOpen = $CALLBACK_NULL) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamOpen","ptr",$lphStream,"ptr",$puDeviceID,"dword",$cMidi,"dword_ptr",$dwCallback,"dword_ptr",$dwInstance,"dword",$fdwOpen) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_BADDEVICEID Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(3,3,0) Else Return SetError(4,4,0) EndIf EndFunc ; <=== _MidiStream_Open ;================================================ ; Func _MidiStream_Out ; The _MidiStream_Out function plays or queues a stream (buffer) of MIDI data to a MIDI output device. ; Usage: _MidiStream_Out($hMidiStream,$lpMidiHdr,$cbMidiHdr) ; $hMidiStream - Handle to a MIDI stream. This handle must have been returned by a call to the _MidiStream_Open function. ; This handle identifies the output device. ; $lpMidiHdr - Pointer to a $MIDIHDR structure that identifies the MIDI buffer. ; $cbMidiHdr - Size, in bytes, of the $MIDIHDR structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The system is unable to allocate or lock memory. ; @error = 2 - The output buffer pointed to by $lpMidiHdr is still playing or is queued from a previous call to _MidiStream_Out. ; @error = 3 - The header pointed to by $lpMidiHdr has not been prepared. ; @error = 4 - The specified device handle is invalid. ; @error = 5 - The pointer specified by $lpMidiHdr is invalid. ; @error = 6 - Unknown Error. ; Info : ; Because the _MidiStream_Open function opens the output device in paused mode, ; you must call the _MidiStream_Restart function before you can use _MidiStream_Out to start the playback. ; For the current implementation of this function, the buffer must be smaller than 64K. ; The buffer pointed to by the MIDIHDR structure contains one or more MIDI events, each of which is defined by a MIDIEVENT structure. ;================================================ Func _MidiStream_Out($hMidiStream,$lpMidiHdr,$cbMidiHdr) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamOut","int",$hMidiStream,"ptr",$lpMidiHdr,"uint",$cbMidiHdr) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_NOMEM Then Return SetError(1,1,0) ElseIf $aResult[0] = $MIDIERR_STILLPLAYING Then Return SetError(2,2,0) ElseIf $aResult[0] = $MIDIERR_UNPREPARED Then Return SetError(3,3,0) ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(4,4,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(5,5,0) Else Return SetError(6,6,0) EndIf EndFunc ; <=== _MidiStream_Out ;================================================ ; Func _MidiStream_Pause ; The _MidiStream_Pause function pauses playback of a specified MIDI stream. ; Usage: _MidiStream_Pause($hMidiStream) ; $hMidiStream - Handle to a MIDI stream. This handle must have been returned by a call to the MIDIEVENT function. ; This handle identifies the output device. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error. ; Info : ; The current playback position is saved when playback is paused. To resume playback from the current position, use the _MidiStream_Restart function. ; Calling this function when the output is already paused has no effect, and the function returns 1. ;================================================ Func _MidiStream_Pause($hMidiStream) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamPause","int",$hMidiStream) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiStream_Pause ;================================================ ; Func _MidiStream_Position ; The _MidiStream_Position function retrieves the current position in a MIDI stream. ; Usage: _MidiStream_Position($hMidiStream,$pMidiTime,$cbMidiTime) ; $hMidiStream - Handle to a MIDI stream. This handle must have been returned by a call to the _MidiStream_Open function. This handle identifies the output device. ; $pMidiTime - Pointer to an MMTIME structure. ; $cbMidiTime - Size, in bytes, of the MMTIME structure. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Specified pointer or structure is invalid. ; @error = 3 - Unknown Error. ; Info : ; Before calling _MidiStream_Position, set the wType member of the $MMTIME structure to indicate the time format you desire. ; After calling _MidiStreamPosition, check the wType member to determine if the desired time format is supported. ; If the desired format is not supported, wType will specify an alternative format. ; The position is set to zero when the device is opened or reset. ;================================================ Func _MidiStream_Position($hMidiStream,$pMidiTime,$cbMidiTime) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamPosition","int",$hMidiStream,"ptr",$pMidiTime,"uint",$cbMidiTime) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) Else Return SetError(3,3,0) EndIf EndFunc ; <=== _MidiStream_Position ;================================================ ; Func _MidiStream_Property ; The _MidiStream_Property function sets or retrieves properties of a MIDI data stream associated with a MIDI output device. ; Usage: _MidiStream_Property($hMidi,$lpPropertyData,$dwProperty) ; $hMidiStream - Handle to the MIDI device that the property is associated with. ; $lpPropertyData - Pointer to the property data. ; $cbMidiTime - Flags that specify the action to perform and identify the appropriate property of the MIDI data stream. ; The _MidiStream_Property function requires setting two flags in each use. ; One flag (either $MIDIPROP_GET or $MIDIPROP_SET) specifies an action, and the other identifies a specific property to examine or edit. ; $MIDIPROP_GET - Retrieves the current setting of the given property. ; $MIDIPROP_SET - Sets the given property. ; $MIDIPROP_TEMPO - Retrieves the tempo property. The $lpPropertyData parameter points to a $MIDIPROPTEMPO structure. The current tempo value can be retrieved at any time. ; Output devices set the tempo by inserting MEVT_TEMPO events into the MIDI data. ; $MIDIPROP_TIMEDIV - Specifies the time division property. You can get or set this property. ; The $lpPropertyData parameter points to a $MIDIPROPTIMEDIV structure. This property can be set only when the device is stopped. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified handle is not a stream handle. ; @error = 2 - The given handle or flags parameter is invalid. ; @error = 3 - Unknown Error. ; Info : ; These properties are the default properties defined by the system. Driver writers can implement and document their own properties. ;================================================ Func _MidiStream_Property($hMidi,$lpPropertyData,$dwProperty) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamProperty","int",$hMidi,"ptr",$lpPropertyData,"dword",$dwProperty) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) ElseIf $aResult[0] = $MMSYSERR_INVALPARAM Then Return SetError(2,2,0) Else Return SetError(3,3,0) EndIf EndFunc ; <=== _MidiStream_Property ;================================================ ; Func _MidiStream_Restart ; The _MidiStream_Restart function restarts a paused MIDI stream. ; Usage: _MidiStream_Restart($hMidiStream) ; $hMidiStream - Handle to a MIDI stream. This handle must have been returned by a call to the _MidiStream_Open function. This handle identifies the output device. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error. ; Info : ; Calling this function when the output is not paused has no effect, and the function returns 1. ;================================================ Func _MidiStream_Restart($hMidiStream) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamRestart","int",$hMidiStream) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiStream_Restart ;================================================ ; Func _MidiStream_Stop ; The _MidiStream_Stop function turns off all notes on all MIDI channels for the specified MIDI output device. ; Usage: _MidiStream_Stop($hMidiStream) ; $hMidiStream - Handle to a MIDI stream. This handle must have been returned by a call to the _MidiStream_Open function. This handle identifies the output device. ; Output : ; Success Return 1 ; Failure Return 0 and @error ; @error = 1 - The specified device handle is invalid. ; @error = 2 - Unknown Error. ; Info : ; When you call this function, any pending system-exclusive or stream output buffers are returned to the callback mechanism and the MHDR_DONE bit is set in the dwFlags member of the MIDIHDR structure. ; While the _MidiOut_Reset function turns off all notes, _MidiStream_Stop turns off only those notes that have been turned on by a MIDI note-on message. ;================================================ Func _MidiStream_Stop($hMidiStream) Local $aResult = DllCall($MIDI_WinMM_DLL,"int","midiStreamStop","int",$hMidiStream) If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False) If $aResult[0] = $MMSYSERR_NOERROR Then Return 1 ElseIf $aResult[0] = $MMSYSERR_INVALHANDLE Then Return SetError(1,1,0) Else Return SetError(2,2,0) EndIf EndFunc ; <=== _MidiStream_Stop