I do a bit of live streaming. It’s a pretty fun hobby, and gets me talking to groups of people on a semi-regular basis, which is a great skill for any developer to have. One of the things I like to do while streaming is to play sound bit, or specific songs, during the stream; generally little quips or things like “Ain’t nobody got time for that”.
Additionally, I have a home recording studio, as a hobbyist musician, I have tons of random hardware laying around.
I want to create a new app, to work with those components, so I can blast off songs, playlists, sound clips, and or change scenes in my OBS application.
MIDI is a light weight binary protocol of messages, just like about every other protocol out there, which is good news for me, I have written tons of network layers. Each message consists of a status byte (the type) and two data bytes (the parameters). Pretty straight forward for most of our cases. The tricky part is how to actually connect and receive data from this stream.
There are only a few native methods that I really care about in this first part of the implementation, and they are all in the Winmm.dll.
There are more, however, these are the main ones I want to start with. One really nice place to start is on pinvoke.net, for example:
http://pinvoke.net/default.aspx/winmm.waveInGetNumDevs will show me the declarations specific to the method, as well as declarations of specific structures I will need to implement to communicate with the library.
So how do I get started in making my magic goodness?
- Name it something cool, like Stream Companion (always go with your gut)
- Create a new solution with a console application and a class library
- Implement all of the native methods
- Wrap the native methods with .Net types for object lifetimes (don’t leak those pointers)
- Enumerate all the MIDI devices
- Choose a MIDI device
- Console Write all of the MIDI events in real time
Now to get started, except let’s try something new, instead of me posting a butt load of code, going through all of the lines in this blog, I think I am going to try to live stream the first step and see how it goes! Coding live can’t go that horribly wrong can it?
Subscribe to my YouTube channel, and I will schedule up the Live Event there, don’t worry, if you miss it, I will post a follow up blog post with a link to the video.
The code, like always, will be provided open source on my GitHub.