Jump to content

MIDI Input


Uwe
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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