Tuesday, October 28, 2014

Fun - MIDI Controller

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.

dkl7d

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?

  1. Name it something cool, like Stream Companion (always go with your gut)
  2. Create a new solution with a console application and a class library
  3. Implement all of the native methods
  4. Wrap the native methods with .Net types for object lifetimes (don’t leak those pointers)
  5. Enumerate all the MIDI devices
  6. Choose a MIDI device
  7. 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.

7 comments:

RADRaze2KX said...

The world is waiting, Tom Anderson... We want Midi to OBS Control...

Tom Anderson said...

Sorry about the delay, it is coming!!!

genmce said...

I would love to see this.
I have an apc40 and a launchpad, this could be great.
What approach?
I was thinking about using autohotkey to convert the midi to keypress.

strikeDM said...

Is it still coming? I need this

Tom Anderson said...

Yes, still planning on this, just all about the timing with other projects and work :(

strikeDM said...

Any ETA?

Fredrik Sætre said...

The suspense is killing me. Looking forward to this. Willing to pay money even.