How to handle MIDI with MidiProcessor

Topics: Audio, Getting Started, Midi, My, Newbie, Plugin Development, VST.NET Framework
Jun 5, 2014 at 6:40 PM
Edited Jun 5, 2014 at 6:43 PM
I just started using VST.NET and I finally have a plugin that loads. However, I am a huge n00b to MIDI/VST and no matter how long I stare at MidiProcessor.cs I cannot figure out where I am supposed to convert the MIDI notes into actual audio output.

So, for specificity, the real question is, where do I put my code to output audio and how do I hook it up to the MIDI input?

Thanks for your time, everybody. :)

EDIT 0: Looked a little closer at DummyAudioProcessor.Process() and found where I stick my noise generating code, but still can't figure out how to make it respond to MIDI.
Jun 5, 2014 at 6:50 PM
By the VST SDK specifications, you put your audio code in ProcessReplace and your Midi code in ProcessEvents. I can't go into the specific way Vst.Net handles it but the general principle is that you get a queue of Events which contains Midi and Vst events in ProcessEvents and an Input and Output buffer for audio in ProcessReplace.
Jun 11, 2014 at 1:00 AM
YuryK wrote:
By the VST SDK specifications, you put your audio code in ProcessReplace and your Midi code in ProcessEvents. I can't go into the specific way Vst.Net handles it but the general principle is that you get a queue of Events which contains Midi and Vst events in ProcessEvents and an Input and Output buffer for audio in ProcessReplace.
That's a nice response, but I'm afraid it's not helpful. Like I said, I have had no previous experience with the VST SDK or any sort of MIDI software code. I need to know how to handle the MIDI in -- wait, sorry. That response is helpful. Now I know at least where to put the code, but I don't know how to turn the MIDI into note frequencies and such.

So thanks for that response. :D ProcessReplace and ProcessEvents. Fantastic. :D

So what's a simple way to implement ProcessEvents?
Coordinator
Jun 11, 2014 at 6:30 AM
(MidiProcessor)ProcessEvents is called right before (AudioProcessor)Process and it is handed the midi events for that time-slice or cycle. If you wish to generate a note from the midi information you need to build an oscillator or trigger ROM samples.

It sounds like the idea you have for the plugin is a bit over you head. I would suggest you first get acquainted with the parts of a VST plugin (MIDI, oscillator etc) to give yourself a better understanding.

For MIDI may I suggest my MIDI.NET project (https://midinet.codeplex.com/) and for oscillators you may find Leslie Stanford's C# Synth toolkit (http://www.codeproject.com/Articles/19618/C-Synth-Toolkit-Part-I and http://www.codeproject.com/Articles/19621/C-Synth-Toolkit-Part-II).
Jun 11, 2014 at 12:47 PM
Edited Jun 11, 2014 at 1:09 PM
I don't know how to turn the MIDI into note frequencies and such.
  • I used a lookup table with pre-calculated frequencies mapping.
So what's a simple way to implement ProcessEvents?
  • ProcessEvents have already been implemented for you by the Vst.Net SDK.
Compared to audio DSP, Midi is very easy to grasp. It's just a messaging system based on (outdated) traditional music theory. Look up the Midi specs to decipher the meaning of the message and you're pretty much done with it. What you do with those messages is outside the range of Midi and Vst.Net. The framework supply you a queue of those message in a standard format (MIDI or VST events) inside the ProcessEvents function.

To quote Mark I also get the feeling you are 'a bit over your head'. I don't know your level of expertise in DSP but I don't think it's accurate to say you can turn Midi into note frequencies. Midi is a message system so it's better to focus on specific message when talking about Midi. Likewise frequencies don't equate to a note in the sense of traditionnal music theory so it's better to look at it simply as a the number of cycle of a waveform per second (hertz).

A midi 'note on/off' message will contain the note constant in it's payload. You then map that value to a frequency which you use to tune an oscillator. This is a minimal synthesizer, you'd want to add at least an amplifier (attenuator), an enveloppe and a filter to get something usefull out of it. The note on/off message would be used to fire the enveloppe and tune the oscillator. The enveloppe would be used to control the amplifier. There are whole books written on DSP and the mathematics involved can be very daunting. It's my opinion that by the time you are able to write a basic synthesizer, learning Midi would be a non issue.