Sign in to follow this  
Followers 0
Uwe

MIDI Input

8 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  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

Share this post


Link to post
Share on other sites

Did you enter input MIDI data?

Uwe

Share this post


Link to post
Share on other sites

#4 ·  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

Share this post


Link to post
Share on other sites

Did you enter input MIDI data?

Uwe

I've never used the udf before, what do you mean?


Giggity

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by TABALtd

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0