Posted: 12th Apr 2005 03:40
We have the windows winmm dll working in Liberty basic for short midi message output. Can someone please post the Darkbasic method of doing the following dll calls?
Liberty Basic example to open dll
struct m, a# as ptr
CallDll #winmm, "midiOutOpen", m as struct, -1 as long, 0 as long, 0 as long, 0 as long, ret as long
hMidiOut=m.a$.struct 'handle to midi device
-1 above controls the port that opens. you should look at one of your midi programs, and see what list of ports it opens, and then pick a number here that matchs that port in the list positon.
-1 is midi mapper. It is not present in windows xp, so just try -1, 1, 2, etc. and eventually you will figure out what number will match what ports you have on your midi interface, and card, etc.
To set what instrument you will use
Pick a number from 1-128 or 0-127 if your keyboard or midi device starts numbering from 0.
voice=15 ' we will set instrument 15
event=192 'command to do instrument change on channel 1, add 1 for
'instrument change on channel 2 etc.
velocity=127 'set to a good value for your midi device. this is
'setting to max velocity, so you will hear it first
'time around
low=(voice*256)+event
hi=velocity*256*256
dwmsg=low+hi
CallDll #winmm, "midiOutShortMsg", hMidiOut as ulong, dwMsg as ulong, ret as ulong.
Ulong means unsigned long number.
To play a note:
event=144 'midi channel 1 , 145 = channel 2 etc.
low=(note*256)+event
velocity=127 'set to max to hear it first time. adjust to desired
'level of velocity
hi=velocity*256*256
dwMsg=low+hi
CallDll #winmm, "midiOutShortMsg",hMidiOut as ulong, dwmsg as ulong, ret as ulong
Then you wait the length of the note.
And then you repeat the above, but set velocity to 0, which will cause the note to turn off. This is an alternate method to use of the midi off command for a note. Either will work and midi files often use either method for shut off of a note. Almost any sequencer around will recognize either method in a midi file, and work ok.
This midi dll also can do sysex messages, but for that you will need to use the MidiOutLongMsg command.
You can find documentation for much of the commands this dll uses at microsoft developers web site.
Do a search on midi, midi sdk, winmm.dll etc, will get you into the right areas.