Can I send raw bytes to a MIDI device?

Viewed 349

I am getting a stream of real-time MIDI data from a named pipe, one byte at a time.

I would like to forward this data, as it is received, to a MIDI device. I am familiar with WinAPI coding/interop for MIDI in C#.

Unfortunately, the WinAPI function midiOutShortMsg requires that I assemble my bytes into valid MIDI messages first. I'd like to avoid this and simply send the raw bytes as I get them from the pipe.

Is there a WinAPI MIDI function I've overlooked? Or something else in the broader WinAPI that would give me low-level access to a MIDI device such that I can send raw bytes?

Note: I have explored the midiStream set of functions and these present the same problem as above.

Bonus background context...

For those who may be wondering what I'm doing with MIDI data over a named pipe...

I still compose and produce music on a Windows 3.1 PC running Cakewalk Pro and Encore. Just as I did circa 1994. When I say PC I really mean a VirtualBox virtual machine.

The virtual PC has Roland's Serial MIDI driver installed, which provides 2x16 channels of MIDI output and 1x16 channels of MIDI input over a serial port. VirtualBox is so kind as to allow us to talk/listen to virtual serial ports via named pipes. Big pat on the back VirtualBox for implementing such a useful feature.

So in a nutshell: I am receiving MIDI data from a virtual PC, via a named pipe served up by VirtualBox. I would like to forward this data to a real MIDI device on the host PC.

Sample MIDI stream

F5 02 90 3C 7F 40 7F 43 7F 80 3C 00 40 00 43 00

Those familiar with MIDI messages might notice that the F5 02 message is non-standard, this Roland's way of "switching" part groups, in the example above a Roland SC-88 will know that the subsequent data is intended for part group B. If it were F5 01 that would mean part group A.

Also, the data above demonstrates running status, where status bytes can be omitted to save bandwidth. Fun.

As you can see, it would be nice to just send the raw bytes to a MIDI device. But, with the WinAPI, it seems I have to process the bytes into full MIDI messages before sending them. The WinAPI forces you into that box. And that means having to code up a little state machine, to handle running status and sysex and maybe other details I haven't thought of yet. I love Windows but sometimes it makes what should be super easy, super hard.

So I thought I'd ask here, to see if there is a simple way, before I invest time into doing it the hard way.

0 Answers
Related