Author Topic: get all midi events in midi message format or in a array of byte format  (Read 166 times)

johnvantelli

  • Posts: 68
hi, I'm trying to send all midi events to a midiout device.
I set a sync with:

Code: [Select]
BASS_ChannelSetSync(fStream,  BASS_SYNC_MIDI_EVENT, 0,  @_MySyncProc, self);
and in _MySyncProc I would like to use

Code: [Select]
midiOutShortMsg(DeviceHandle, AMessage);
now my question is:
How can I convert the "data" syncproc parameter in a MIDI RAW message?



Ian @ un4seen

  • Administrator
  • Posts: 24730
The "data" handling will depend on the type of event. It should be fairly straightforward for standard MIDI events (but not for sysex), and could look something like this:

Code: [Select]
void CALLBACK MidiEventSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
DWORD chan = (data >> 16) && 0xff;
DWORD event = data >> 24;
DWORD param = data & 0xffff;
DWORD midimsg;

if (event == MIDI_EVENT_NOTE)
midimsg = 0x90 | chan | (param << 8);
else if (event == MIDI_EVENT_PROGRAM)
midimsg = 0xc0 | chan | (param << 8);
else if (event == MIDI_EVENT_VOLUME)
midimsg = 0xb0 | chan | (7 << 8) | (param << 16);
else if (event == MIDI_EVENT_PAN)
midimsg = 0xb0 | chan | (10 << 8) | (param << 16);
// handle rest of events here...
else
return; // ignore other events

midiOutShortMsg(DeviceHandle, midimsg);
}

An example of similar event processing can be found in the BASS_VST source code:

   https://github.com/r10s/BASS_VST/blob/master/source/bass_vst_impl.cpp#L2202

johnvantelli

  • Posts: 68
Thank you Ian,
it is very useful...
« Last Edit: 31 Aug '22 - 14:23 by johnvantelli »