Jump to content

Recommended Posts

Posted

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:

#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

Posted (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 by youknowwho4eva

Giggity

Posted (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 by Uwe
Posted (edited)

  youknowwho4eva said:

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 by TABALtd
Posted

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:

  Reveal hidden contents

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 UDFsProcess 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)

Posted

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:

  Quote

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

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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