title: Can I send raw bytes to a MIDI device?
body: <p>I am getting a stream of real-time MIDI data from a named pipe, one byte at a time.</p>
  <p>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#.</p>
  <p>Unfortunately, the WinAPI function <a href="https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-midioutshortmsg" rel="nofollow noreferrer">midiOutShortMsg</a> 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.</p>
  <p>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?</p>
  <p>Note: I have explored the <a href="https://docs.microsoft.com/en-us/windows/win32/multimedia/stream-buffers" rel="nofollow noreferrer">midiStream</a> set of functions and these present the same problem as above.</p>
  <h3>Bonus background context...</h3>
  <p><em>For those who may be wondering what I'm doing with MIDI data over a named pipe...</em></p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p><strong>Sample MIDI stream</strong></p>
  <p><code>F5 02   90 3C 7F   40 7F   43 7F   80 3C 00   40 00   43 00</code></p>
  <p>Those familiar with MIDI messages might notice that the <code>F5 02</code> message is non-standard, this Roland's way of &quot;switching&quot; part groups, in the example above a Roland SC-88 will know that the subsequent data is intended for <em>part group B</em>. If it were <code>F5 01</code> that would mean <em>part group A</em>.</p>
  <p>Also, the data above demonstrates running status, where status bytes can be omitted to save bandwidth. Fun.</p>
  <p>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.</p>
  <p>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.</p>