Re: Using callback functions


Richard Russell
 

--- In bb4w@..., "Richard" <yahoo@...> wrote:
This simple program demonstrates the callback function in action.
Another version listed below, including calls to midiInStart and midiInStop. Incidentally, in the group's Files area since January 2006 (nearly five years!) is the program MIDIIN.BBC which, pre-dating the CALLBACK library, does it using assembler code:

http://groups.yahoo.com/group/bb4w/files/Multimedia/MIDIIN.BBC

Richard.

REM!WC Windows Constants
MIM_CLOSE = &3C2
MIM_DATA = &3C3
MIM_ERROR = &3C5
MIM_LONGDATA = &3C4
MIM_LONGERROR = &3C6
MIM_MOREDATA = &3CC
MIM_OPEN = &3C1
_CALLBACK_FUNCTION = &30000

INSTALL @lib$+"CALLBACK" : REM Must be v3.2 or later

SYS FN_syscalls("midiInOpen"), ^hMidiIn%, 0, &#92;
&#92; FN_callback(FNmidiInProc(), 5), 0, _CALLBACK_FUNCTION
IF FN_sysresult ERROR 0, "Could not open MIDI input"

SYS FN_syscalls("midiInStart"), hMidiIn%
IF FN_sysresult ERROR 0, "Could not start MIDI input"

Abort% = FALSE
ON CLOSE Abort% = TRUE : RETURN
ON ERROR Abort% = TRUE : SYS "MessageBox", @hwnd%, REPORT$, 0, 0

REPEAT
WAIT 0
UNTIL Abort%

SYS FN_syscalls("midiInStop"), hMidiIn%
IF FN_sysresult ERROR 0, "Could not stop MIDI input"

SYS FN_syscalls("midiInClose"), hMidiIn%
IF FN_sysresult ERROR 0, "Could not close MIDI input"

QUIT

DEF FNmidiInProc(hMidiIn%, wMsg%, dwInstance%, dwParam1%, dwParam2%)
CASE wMsg% OF
WHEN MIM_OPEN:
PRINT "MIDI opening"
WHEN MIM_CLOSE:
PRINT "MIDI closing"
WHEN MIM_DATA:
PRINT "MIDI data received"
OTHERWISE:
PRINT "Another MIDI message received"
ENDCASE
= 0

Join bb4w@groups.io to automatically receive all group messages.