;==========================================================================================================================; ;================/ Function: MasterRouter.exe /==================================================================; ;===============/ AutoIt: v3.3.14.5 /===================================================================; ;==============/ Date: August 2019 /====================================================================; #NoTrayIcon ;==============================================================================================================; #include #include #include #include #include #include #include _Singleton("MasterRouter.exe", 0) Opt('GUIOnEventMode', 1) Global $hGUI, $idCombo_1, $idLabel_A, $idLabel_B, $idLabel_C, $aInputs Global $sOutString, $hMidiIn, $hMidiOut, $Cb, $Callback_function Local $iIn, $iX, $iOut, $hOpen, $aDevCaps $iIn = (_MidiInGetNumDevs() - 1) If $iIn = -1 Then MsgBox(0, "", "No MIDI input devices were found.") Exit EndIf $iDevIn = -1 For $iX = 0 To $iIn $hOpen = _MidiInOpen($iX) If @error <> 0 Then MsgBox(16, "MIDI In Port # " & $iX, '"MIDI In" Failed to Open:' & @CRLF & "Error Code # - " & @error) Exit EndIf $aDevCaps = _MidiInGetDevCaps($hOpen) _MidiInClose($hOpen) If @error <> 0 Then MsgBox(16, "MIDI In Port # " & $iX, '"MIDI In" failed to Close:' & @CRLF & "Error Code # - " & @error) Exit EndIf If $aDevCaps[3] = "USB Uno MIDI Interface" Or $aDevCaps[3] = "MIDISPORT Uno In" Then $iDevIn = $iX ExitLoop ; "USB Uno MIDI Interface" and "MIDISPORT Uno In" are just the assigned names of EndIf ; the MIDI Interface That I use for my master (main) keyboard. I have two names Next ; here because the system (for some reason) doesn't always assign the same name. If $iDevIn = -1 Then MsgBox(16, "Input", "Unable to access MASTER KEYBOARD input") Exit EndIf $iOut = (_MidiOutGetNumDevs() - 1) If $iOut = -1 Then MsgBox(16, "", "No MIDI output devices were found.") Exit EndIf For $iX = 0 To $iOut $hOpen = _MidiOutOpen($iX) If @error <> 0 Then MsgBox(16, "MIDI Out Port # " & $iX, '"MIDI Out" Failed to Open:' & @CRLF & "Error Code # - " & @error) Exit EndIf $aDevCaps = _MidiOutGetDevCaps($hOpen) _MidiOutClose($hOpen) If @error <> 0 Then MsgBox(16, "MIDI Out Port # " & $iX, '"MIDI Out" failed to Close:' & @CRLF & "Error Code # - " & @error) Exit EndIf If $aDevCaps[3] = "USB Uno MIDI Interface" Then ContinueLoop $sOutString = ($sOutString & "|" & $iX & " " & $aDevCaps[3]) Next $hGUI = GUICreate("MASTER ROUTER", 258, 67, 841, 5, $WS_CAPTION) GUISetBkColor(0x111111) $idCombo_1 = GUICtrlCreateCombo("", 10, 35, 240) GUICtrlSetBkColor($idCombo_1,0x111111) GUICtrlSetFont($idCombo_1, 11, 800) GUICtrlSetColor($idCombo_1, 0xFFFFFF) GUICtrlSetData($idCombo_1, $sOutString) $idLabel_B = GUICtrlCreateLabel("Destination:", 11, 14) GUICtrlSetColor($idLabel_B, 0xFFFFFF) $idButton_1 = GUICtrlCreateButton("Close", 216, 7, 35, 22) GUICtrlSetBkColor($idButton_1, 0xFF1515) GUICtrlSetColor($idButton_1, 0xFFFFFF) GUICtrlSetOnEvent($idButton_1, "Close") $idButton_2 = GUICtrlCreateButton("Connect", 110, 7, 100, 22) GUICtrlSetBkColor($idButton_2,0xC0C0C0) GUICtrlSetOnEvent($idButton_2, "_Func_1") GUISetState(@SW_SHOWNORMAL, $hGUI) While 1 Sleep(100) WEnd Func MidiInProc($MidiIn, $msg, $instance, $Param1, $Param2) EndFunc ;==>MidiInProc Func _Func_1(); "Connect" $iDevOut = StringStripWS(StringLeft(GUICtrlRead($idCombo_1), 2), 8) If $iDevOut <> "" Then $Cb = DllCallbackRegister("MidiInProc", "long", "ptr;int;dword;dword;dword") $hMidiIn = _MidiInOpen($iDevIn, DllCallbackGetPtr($Cb), 0, $Callback_function) $hMidiOut = _MidiOutOpen($iDevOut) _MidiConnect($hMidiIn, $hMidiOut) _MidiInStart($hMidiIn) GUICtrlSetOnEvent($idButton_1, "_Func_2") GUICtrlSetData($idButton_2, "Disconnect") GUICtrlSetBkColor($idButton_2,0xC0C0C0) GUICtrlSetOnEvent($idButton_2, "_Func_2") EndIf EndFunc ;==>_Func_1 Func _Func_2(); "Disconnect" _MidiInStop($hMidiIn) _MidiDisconnect($hMidiIn, $hMidiOut) _MidiInReset($hMidiIn) _MidiInClose($hMidiIn) _MidiOutReset($hMidiOut) _MidiOutClose($hMidiOut) DllCallbackFree($Cb) GUICtrlSetOnEvent($idButton_1, "Close") GUICtrlSetData($idButton_2, "Connect") GUICtrlSetOnEvent($idButton_2, "_Func_1") EndFunc ;==>_Func_2 Func Close() _MidiInStop($hMidiIn) _MidiDisconnect($hMidiIn, $hMidiOut) _MidiInReset($hMidiIn) _MidiInClose($hMidiIn) _MidiOutReset($hMidiOut) _MidiOutClose($hMidiOut) DllCallbackFree($Cb) GUIDelete($hGUI) Exit EndFunc ;==>End Exit