#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; ==================================================================================================== ; ; ; Tests of the 'Extra' functionality of the new improved (and fixed) MIDI UDF ; ; Author: Ascend4nt ; ==================================================================================================== #include "Array.au3" #include "MIDIFunctions.au3" #include "MIDIConstants.au3" #include #include Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Global $nMidiInDevices = _MidiInGetNumDevs() ConsoleWrite(" Input # Devices: " & $nMidiInDevices & @CRLF) Global $nMidiOutDevices = _MidiOutGetNumDevs() ConsoleWrite(" Output # Devices: " & $nMidiOutDevices & @CRLF) Local $CodeMidiInDev = -1; Local $CodeMidiOutDev = -1; Global $midiInHeaders[10][4] ; [x][0] = Header, [x][1] = ptr to Header ; [x][2] = Buffer, [x][3] = ptr to Buffer If $nMidiInDevices > 0 Then ConsoleWrite("Input devices found: " & @CRLF ) For $i = 0 To $nMidiInDevices - 1 Local $aCaps = _MidiInGetDevCaps($i) ConsoleWrite("Caps Dev #"&$i&": [0] = " & $aCaps[0] & _ ; Manufacturer ID ", [1] = " & $aCaps[1] & _ ; Product ID ", [2] = " & $aCaps[2] & _ ; Driver Version ", [3] = " & $aCaps[3] &@CRLF) ; Name If $aCaps[3] == "CODE" Then $CodeMidiInDev = $i Next EndIf If $nMidiOutDevices > 0 Then ConsoleWrite("Output devices found: " & @CRLF ) For $i = 0 To $nMidiOutDevices - 1 $aCaps = _MidiOutGetDevCaps($i) ConsoleWrite("Caps Dev #"&$i&": [0] = " & $aCaps[0] & _ ; Manufacturer ID ", [1] = " & $aCaps[1] & _ ; Product ID ", [2] = " & $aCaps[2] & _ ; Driver Version ", [3] = " & $aCaps[3] & _ ; Name ", [4] = " & $aCaps[4] & _ ; If 1, then 'MOD_MIDIPORT' or MIDI Hardware Port ", [5] = " & $aCaps[5] & _ ; # of Voices (0 for Hardware Ports) ", [6] = " & $aCaps[6] & _ ; # Simultaneous Notes (0 for Hardware Ports) ", [7] = " & $aCaps[7] & _ ; Channel mask (= 0xFFFF = all 16 ports) ", [8] = " & $aCaps[8] &@CRLF) ; Optional Functionality If $aCaps[3] == "CODE" Then $CodeMidiOutDev = $i Next EndIf ;PRESET CHANGE C0 00-63 (Preset: 0-99) ;---------------- EQ Section -------------------------------------------- Global Const $MARSHALL_CODE_GAIN = 0x46 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_BASS = 0x47 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_MIDDLE = 0x48 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_TREBLE = 0x49 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_VOLUME = 0x4A ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_GATE_THRESHOLD = 0x53 ; 00-64 (0.0 - 10.0) ;---------------- Button Controls ----------------------------------- Global Const $MARSHALL_CODE_PREFX_ONOFF = 0x4B ; 00=Off, 01=On Global Const $MARSHALL_CODE_PREAMP_ONOFF = 0x51 ; 00=Off, 01=On Global Const $MARSHALL_CODE_MOD_ONOFF = 0x55 ; 00=Off, 01=On Global Const $MARSHALL_CODE_DELAY_ONOFF = 0x67 ; 00=Off, 01=On Global Const $MARSHALL_CODE_REVERB_ONOFF = 0x6C ; 00=Off, 01=On Global Const $MARSHALL_CODE_POWERAMP_ONOFF = 0x72 ; 00=Off, 01=On Global Const $MARSHALL_CODE_CAB_ONOFF = 0x74 ; 00=Off, 01=On ;---------------- CABINETS ----------------------------------- Global Const $MARSHALL_CODE_CAB_TYPE = 0x75 ; 00-07 Global Const $MARSHALL_CODE_CAB_1960 = 0x00 Global Const $MARSHALL_CODE_CAB_1960V = 0x01 Global Const $MARSHALL_CODE_CAB_1960AX = 0x02 Global Const $MARSHALL_CODE_CAB_1960HW = 0x03 Global Const $MARSHALL_CODE_CAB_1936 = 0x04 Global Const $MARSHALL_CODE_CAB_1936V = 0x05 Global Const $MARSHALL_CODE_CAB_1912 = 0x06 Global Const $MARSHALL_CODE_CAB_1974CX = 0x07 ;---------------- Power Amps ----------------------------------- Global Const $MARSHALL_CODE_POWERAMP_TYPE = 0x73 ; 00-03 Global Const $MARSHALL_CODE_POWERAMP_CM100 = 0x00 ; Classic Marshall 100W Global Const $MARSHALL_CODE_POWERAMP_VM30 = 0x01 ; Vintage Marshall 30W Global Const $MARSHALL_CODE_POWERAMP_BCLA = 0x02 ; British Class A Global Const $MARSHALL_CODE_POWERAMP_ACAB = 0x03 ; American Class A/B Global Const $MARSHALL_CODE_POWERAMP_PRES = 0x76 ; Presence 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_POWERAMP_RES = 0x77 ; Resonance 00-64 (0.0 - 10.0) ;---------------- Reverb ----------------------------------- Global Const $MARSHALL_CODE_REVERB_TYPE = 0x6D ; 00-03 Global Const $MARSHALL_CODE_REVERB_ROOM = 0x00 Global Const $MARSHALL_CODE_REVERB_HALL = 0x01 Global Const $MARSHALL_CODE_REVERB_SPRING = 0x02 Global Const $MARSHALL_CODE_REVERB_STADIUM = 0x03 Global Const $MARSHALL_CODE_REVERB_DECAY = 0x6E ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_REVERB_PREDELAY = 0x6F ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_REVERB_TONE = 0x70 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_REVERB_LEVEL = 0x71 ; 00-64 (0.0 - 10.0) ;---------------- Delay ----------------------------------------- Global Const $MARSHALL_CODE_DELAY_TYPE = 0x68 ; 00-03 Global Const $MARSHALL_CODE_DELAY_STUDIO = 0x00 Global Const $MARSHALL_CODE_DELAY_VINTAGE = 0x01 Global Const $MARSHALL_CODE_DELAY_MULTI = 0x02 Global Const $MARSHALL_CODE_DELAY_REVERSE = 0x03 Global Const $MARSHALL_CODE_DELAY_TIME_MSB = 0x1F ; 00-1F ( 0ms - 31ms multiplied by 128 ) Global Const $MARSHALL_CODE_DELAY_TIME_LSB = 0x3F ; 00-7F ( 0ms - 255ms, added to the above ) Global Const $MARSHALL_CODE_DELAY_TIME_MAX = 4000 ; 4000 = = 0x1F20 Global Const $MARSHALL_CODE_DELAY_FEEDBACK = 0x69 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_DELAY_FREQUENCY = 0x6A ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_DELAY_AGE = 0x6A ; For Vintage Delay Only(0.0 - 10.0) Global Const $MARSHALL_CODE_DELAY_PATTERN = 0x6A ; For Multi Delay Only (00 - 03) Global Const $MARSHALL_CODE_DELAY_LEVEL = 0x6B ; 00-64 (0.0 - 10.0) ;---------------- Modulation ----------------------------------------- Global Const $MARSHALL_CODE_MOD_TYPE = 0x56 ; 00-03 Global Const $MARSHALL_CODE_MOD_CHORUS = 0x00 Global Const $MARSHALL_CODE_MOD_FLANGER = 0x01 Global Const $MARSHALL_CODE_MOD_PHASER = 0x02 Global Const $MARSHALL_CODE_MOD_TREMOLO = 0x03 Global Const $MARSHALL_CODE_MOD_MODE = 0x5A ; 00 - 01 Global Const $MARSHALL_CODE_MOD_MODE_CLS = 0x00 ; Classic (for Chorus & Phaser) Global Const $MARSHALL_CODE_MOD_MODE_VIB = 0x01 ; Vibrato (for Chorus & Phaser) Global Const $MARSHALL_CODE_MOD_MODE_JET = 0x00 ; Jet Flanger Global Const $MARSHALL_CODE_MOD_MODE_MET = 0x01 ; Metallic Flanger Global Const $MARSHALL_CODE_MOD_MODE_VLV = 0x00 ; Valve (Tremolo) Global Const $MARSHALL_CODE_MOD_MODE_SQR = 0x01 ; Square (Tremolo) Global Const $MARSHALL_CODE_MOD_SPEED = 0x57 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_MOD_DEPTH = 0x59 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_MOD_TONE = 0x66 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_MOD_REGEN = 0x66 ; 00-64 (0.0 - 10.0) - For Flanger & Phaser only Global Const $MARSHALL_CODE_MOD_SKEW = 0x66 ; 00-64 (-50 - +50) - For Tremolo only ;---------------- Pre-Amps ----------------------------------------- Global Const $MARSHALL_CODE_PREAMP_TYPE = 0x52 ; 00-0E Global Const $MARSHALL_CODE_PRE_CLN_JTM45 = 0x00 Global Const $MARSHALL_CODE_PRE_CLN_DSL = 0x01 Global Const $MARSHALL_CODE_PRE_CLN_USA = 0x02 Global Const $MARSHALL_CODE_PRE_CLN_JVM = 0x03 Global Const $MARSHALL_CODE_PRE_CLN_ACCOUST = 0x04 Global Const $MARSHALL_CODE_PRE_CRN_BLUESB = 0x05 Global Const $MARSHALL_CODE_PRE_CRN_PLEXI = 0x06 Global Const $MARSHALL_CODE_PRE_CRN_USA = 0x07 Global Const $MARSHALL_CODE_PRE_CRN_JCM800 = 0x08 Global Const $MARSHALL_CODE_PRE_CRN_50UK = 0x09 Global Const $MARSHALL_CODE_PRE_OD_JVM = 0x0A Global Const $MARSHALL_CODE_PRE_OD_DSL = 0x0B Global Const $MARSHALL_CODE_PRE_OD_USA = 0x0C Global Const $MARSHALL_CODE_PRE_OD_JUBILEE = 0x0D Global Const $MARSHALL_CODE_PRE_NATURAL = 0x0E ;---------------- Pre FX ----------------------------------------- Global Const $MARSHALL_CODE_PFX_TYPE = 0x4C ; 00-04 Global Const $MARSHALL_CODE_PFX_COMPRESSOR = 0x00 Global Const $MARSHALL_CODE_PFX_DISTORTION = 0x01 Global Const $MARSHALL_CODE_PFX_AUTOWAH = 0x02 Global Const $MARSHALL_CODE_PFX_PITCHSHIFT = 0x03 Global Const $MARSHALL_CODE_PFX_COM_TONE = 0x4D ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_COM_RATIO = 0x4E ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_COM_COMP = 0x4F ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_COM_LEVEL = 0x50 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_DIS_MODE = 0x4D ; 00-02 (00: GUV, 01: ODR, 02: DIS) Global Const $MARSHALL_CODE_PFX_DIS_DRIVE = 0x4E ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_DIS_TONE = 0x4F ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_DIS_LEVEL = 0x50 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_WAH_MODE = 0x4D ; 00-01 ( 00: ENV, 01: LFO ) Global Const $MARSHALL_CODE_PFX_WAH_FREQ = 0x4E ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_WAH_SENS = 0x4F ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_WAH_RES = 0x50 ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_PSH_SEMI = 0x4D ; 00-18 (-12 - +12) Global Const $MARSHALL_CODE_PFX_PSH_FINE = 0x4E ; 00-64 (-50 - +50) Global Const $MARSHALL_CODE_PFX_PSH_REGEN = 0x4F ; 00-64 (0.0 - 10.0) Global Const $MARSHALL_CODE_PFX_PSH_MIX = 0x50 ; 00-64 (0.0 - 10.0) If $CodeMidiInDev = -1 OR $CodeMidiOutDev = -1 Then Exit Global $hGui = GUICreate("Midi In Example", 1000, 420) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $cCombo = GUICtrlCreateCombo("", 10, 10, 400, 20) ;Global $cButton_Start = GUICtrlCreateButton("Start", 420, 10, 80, 20) ;GUICtrlSetOnEvent(-1, "_Midi_Start") Global $cButton_Stop = GUICtrlCreateButton("Stop", 510, 10, 80, 20) GUICtrlSetOnEvent(-1, "_Midi_Stop") GUICtrlCreateLabel("MIM_DATA", 10, 40, 100, 20) Global $cEdit_Data = GUICtrlCreateEdit("", 10, 60, 485, 350) GUICtrlCreateLabel("MIM_LONGDATA", 505, 40, 100, 20) Global $cEdit_LongData = GUICtrlCreateEdit("", 505, 60, 485, 350) GUISetState() Global $hMidiIn = _MidiInOpen( $CodeMidiInDev, $hGui, 0, BitOR($MIDI_Callback_Window, $MIDI_IO_STATUS) ) If @error Then ConsoleWrite("_MidiInOpen error:"& @error & ", @extended = " & @extended & @CRLF) Exit EndIf for $hdr = 0 to 9 Local $Buffer_Length = 1024 ; create a 1K buffer and store it, as well as a pointer to it in our structure $midiInHeaders[ $hdr ][2] = DllStructCreate("byte BufferData[" & $Buffer_Length & "];") $midiInHeaders[ $hdr ][3] = DllStructGetPtr( $midiInHeaders[ $hdr ][3] ) ; create a MidiInHeader Local $MIDIHDR = "STRUCT; long_ptr lpData;dword dwBufferLength;dword dwBytesRecorded;dword_ptr dwUser;dword dwFlags; long_ptr lpNext;dword_ptr reserved;dword dwOffset;dword_ptr dpres[4]; ENDSTRUCT" $midiInHeaders[ $hdr ][0] = DllStructCreate( $MIDIHDR ) $midiInHeaders[ $hdr ][1] = DllStructGetPtr( $midiInHeaders[ $hdr ][0] ) ; fill data in Header DllStructSetData( $midiInHeaders[ $hdr ][0] , "lpData", $midiInHeaders[ $hdr ][3] ) ; pointer to buffer DllStructSetData( $midiInHeaders[ $hdr ][0] , "dwBufferLength", $Buffer_Length) ; lengeth DllStructSetData( $midiInHeaders[ $hdr ][0] , "dwFlags", 0 ) ; Add buffers to the MidiIn port Local $aRet = DllCall($g_MIDI_hWinMMDLL, "long", "midiInPrepareHeader", "handle", $hMidiIn, "long_ptr", $midiInHeaders[ $hdr ][1] , "uint", DllStructGetSize( $midiInHeaders[ $hdr ][0] ) ) Local $aRet = DllCall($g_MIDI_hWinMMDLL, "long", "midiInAddBuffer", "handle", $hMidiIn, "long_ptr", $midiInHeaders[ $hdr ][1] , "uint", DllStructGetSize( $midiInHeaders[ $hdr ][0] ) ) Next For $N = 950 To 990 GUIRegisterMsg( $N, "_MyMidiWinProc" ) ; making sure I'm not missing a message Next ;GUIRegisterMsg($MM_MIM_CLOSE, "_MyMidiWinProc") ;GUIRegisterMsg($MM_MIM_DATA, "_MyMidiWinProc") ;GUIRegisterMsg($MM_MIM_ERROR, "_MyMidiWinProc") ;GUIRegisterMsg($MM_MIM_LONGDATA, "_MyMidiWinProc") ;GUIRegisterMsg($MM_MIM_LONGERROR, "_MyMidiWinProc") ;GUIRegisterMsg($MM_MIM_MOREDATA, "_MyMidiWinProc") ;GUIRegisterMsg($MM_MIM_OPEN, "_MyMidiWinProc") Local $aRet = DllCall($g_MIDI_hWinMMDLL, "long", "midiInStart", "handle", $hMidiIn) While Sleep(10) WEnd Func _ProcessLongData($pData, $iBytes) Local $tGetData = DllStructCreate("byte[" & $iBytes & "];", $pData) GUICtrlSetData($cEdit_LongData, DllStructGetData($tGetData, 1) & @CRLF, 1) EndFunc ;==>_ProcessLongData Func _ProcessData($iMidiMessage) Local $iLoWord = _WinAPI_LoWord($iMidiMessage) Local $iHiWord = _WinAPI_HiWord($iMidiMessage) Local $bStatus = BitAND($iLoWord, 0xFF) ;LoByte Local $bData1 = BitShift($iLoWord, 8) ;HiByte Local $bData2 = BitAND($iHiWord, 0xFF) ;LoByte Local $Chan = BitAND($bStatus, 0xF) Local $MidiMsg = BitShift($bStatus, 4) GUICtrlSetData($cEdit_Data, "StatusByte: " & $bStatus & @TAB & "DataByte1: " & $bData1 & @TAB & "DataByte2: " & $bData2 & @CRLF, 1) Switch $MidiMsg Case 0x8 ; Note Off GUICtrlSetData($cEdit_Data, @TAB & "NoteOff: MidiChannel: " & $Chan & @TAB & "NoteNumber: " & $bData1 & @TAB & "Velocity: " & $bData2 & @CRLF, 1) Case 0x9 ; Note On GUICtrlSetData($cEdit_Data, @TAB & "NoteOn: MidiChannel: " & $Chan & @TAB & "NoteNumber: " & $bData1 & @TAB & "Velocity: " & $bData2 & @CRLF, 1) Case 0xA ; Polyphonic aftertouch GUICtrlSetData($cEdit_Data, @TAB & "Polyphonic aftertouch: MidiChannel: " & $Chan & @TAB & "NoteNumber: " & $bData1 & @TAB & "Poly Pressure: " & $bData2 & @CRLF, 1) Case 0xB ; Control Change GUICtrlSetData($cEdit_Data, @TAB & "Control Change: MidiChannel: " & $Chan & @TAB & "Controller: " & $bData1 & @TAB & "Value: " & $bData2 & @CRLF, 1) Case 0xC ; Program Change GUICtrlSetData($cEdit_Data, @TAB & "Program Change: MidiChannel: " & $Chan & @TAB & "Programm: " & $bData1 & @CRLF, 1) Case 0xD ; Channel aftertouch GUICtrlSetData($cEdit_Data, @TAB & "Channel aftertouch: MidiChannel: " & $Chan & @TAB & "Aftertouch : " & $bData1 & @CRLF, 1) Case 0xE ; Pitch Bend GUICtrlSetData($cEdit_Data, @TAB & "Pitch Bend: MidiChannel: " & $Chan & @TAB & "LSB: " & $bData1 & @TAB & "MSB: " & $bData2 & @CRLF, 1) EndSwitch EndFunc ;==>_ProcessData Func _MyMidiWinProc($hWnd, $iMsg, $wParam, $lParam) ConsoleWrite( $hWnd & "-" & $iMsg & "-" & $wParam & "-" & $lParam ) Switch $iMsg Case $MIM_OPEN ConsoleWrite("> MIM_OPEN" & @CRLF) Case $MIM_CLOSE ;hMidi Handle ab jetzt ungültig ConsoleWrite("> MIM_CLOSE" & @CRLF) $hMidiIn = 0 Case $MIM_DATA ; Normale Midi MSG ConsoleWrite("> MIM_DATA" & @CRLF) _ProcessData($lParam) Case $MIM_MOREDATA ConsoleWrite("> MIM_MOREDATA" & @CRLF) Case $MM_MIM_LONGDATA ConsoleWrite("> MIM_LONGDATA" & @CRLF) Local $tMidiHDR = DllStructCreate($MIDIHDR, $lParam) Local $iBytesRecorded = DllStructGetData($tMidiHDR, "dwBytesRecorded") ConsoleWrite("+ LONGDATA IN: " & $iBytesRecorded & " bytes" & @CRLF) _ProcessLongData(DllStructGetData($tMidiHDR, "lpData"), $iBytesRecorded) _MidiInAddBuffer($hMidiIn, $lParam) ; put the buffer back Case $MIM_ERROR ConsoleWrite("> MIM_ERROR" & @CRLF) Case $MIM_LONGERROR ConsoleWrite("> MIM_LONGERROR" & @CRLF) _MidiInAddBuffer($hMidiIn, $lParam) EndSwitch EndFunc ;==>_MyMidiWinProc Func _Exit() Exit EndFunc ;==>_Exit Func _Midi_Stop() _MidiInReset($hMidiIn) _MidiInStop($hMidiIn) For $hdr = 0 to 9 Local $aRet = DllCall($g_MIDI_hWinMMDLL, "long", "midiInUnprepareHeader", "handle", $hMidiIn, "long_ptr", $midiInHeaders[ $hdr ][1] , "uint", DllStructGetSize( $midiInHeaders[ $hdr ][0] ) ) Next EndFunc