Uwe Posted February 19, 2009 Posted February 19, 2009 Hi, first I want to thank eynstyne, the author of the midi udf. I spent some time figuring out how MIDI input works. It works somehow, but crashes without the sleep function in line 16. Here is the code: expandcollapse popup#include <midiudf.au3> HotKeySet("{Esc}", "Escape") Global $key[100] global $zero[100] for $i=0 to 99 $Zero[$i]=0 Next $key=$zero $cb = DLLCallbackRegister ("MIDIInProc", "long", "ptr;int;dword;dword;dword") $midi_in = _midiInOpen (0,DllCallbackGetPtr($cb),0,$callback_function) _midiinreset($midi_in) _midiinstart($midi_in) While true sleep(100) for $i=36 to 96 if $key[$i]<>0 Then consolewrite ($i) if $key[$i]=1 then consolewrite (" on" & @CRLF) if $key[$i]=-1 then consolewrite (" off" & @CRLF) $key[$i]=0 EndIf Next WEnd Func MidiInProc($midi, $msg,$instance,$Param1,$Param2) if $param1>255 then $mm=$Param1 $n=BitAND($mm,0x00ff00)/256 $on=BitAND($mm,0x000090)/16 if $on=9 then $key[$n]=1 endif if $on=8 Then $key[$n]=-1 EndIf EndIf Return EndFunc func Escape() _midiinstop($midi_in) sleep(100) _midiinclose($midi_in) sleep(100) DllCallbackFree($cb) $finish=True EndFunc Any idea? Uwe
youknowwho4eva Posted February 19, 2009 Posted February 19, 2009 (edited) I'm lost as to what your question is. I took out the sleep worked just fine still. The hot key doesn't work though with or without the sleep. Edit: typo Edited February 19, 2009 by youknowwho4eva Giggity
Uwe Posted February 19, 2009 Author Posted February 19, 2009 (edited) It crashes on 2 PCs without the sleep, or if it is too short. But only when I send MIDI data (play the keyboard) Edited February 19, 2009 by Uwe
youknowwho4eva Posted February 19, 2009 Posted February 19, 2009 Did you enter input MIDI data? UweI've never used the udf before, what do you mean? Giggity
TABALtd Posted February 19, 2009 Posted February 19, 2009 (edited) I've never used the udf before, what do you mean?You have to connect a keyboard to your MIDI In port and play some notes to see how the script crashes. Edited February 19, 2009 by TABALtd
Ascend4nt Posted February 19, 2009 Posted February 19, 2009 According to MSDN, the variables passed to the MidiInProc are: void CALLBACK MidiInProc( HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 ); Although the size *should* match, this one line really should read: $cb = DLLCallbackRegister ("MIDIInProc", "long", "ptr;int;ptr;ptr;ptr") Also, Returning with 'Return 0' usually indicates that the system is to continue processing the message, though I'm not certain how it works for MIDI callbacks. just some thoughts.. A My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Uwe Posted February 20, 2009 Author Posted February 20, 2009 Thank you for your advice, I tried it. But: when I replace dword with ptr, it doesn't work at all. I tried dword* and wparam, works too. After receiving some MIDI input, it throws an exception or the script ends with error messages like: 74 off 72 on 72 off 71 on C:\Programme\NSIS\MIDI\MIDIInput\midiin.au3 (17) : ==> Variable used without being declared.: if $key[$i]<>0 Then if $key[$i]^ ERROR
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now