Midi. Delete notes that very close to each other.

Topics: Midi, Newbie, Plugin Development
Jul 18, 2012 at 3:26 PM

Hello everybody!

I'm new to VST.NET so i have some dumb questions.

I want to create plugin for Cubase. It's main feature is  to prevent repeated notes. I have USB-MIDI device (electronic drums) that sometimes produce very fast, very near notes (first note is correct, but second note creates some cacophony). Those notes are very close to each other (i think near 30ms or smth like that). I want to create such a plugin that deletes those unnecessary notes. So there are some questions:

1) Is VST.NET can be used for this?

2) How can I use TIME in this? I was reading some docs but I don't understand how to do this. I was wondering to find some Midi-Vst examples (source codes), even delay-example would be good.

Thanks in advance!!!

p.s. english is not my native language = )

Coordinator
Jul 28, 2012 at 8:11 AM

Sorry for the late response (was on vacation).

 

Yes, VST.NET can be used to manipulate Midi messages, although I know that Cubase (and other Steinberg Hosts?) is very particular about what a midi plugin is. Most other hosts should be ok. You should check out the samples (downloads or source code tabs), it comes with a midi mapper plugin that would be a good place to start.

The VstTimeInfo structure can be used to ask the host specific time info. When you make the GetTimeInfo call you specify, what specific time attributes you would like to know and the host reports back (in the VstTimeInfo structure) what properties were actually filled. You need to call the GetTimeInfo method only once in your Process method.

Hope this clears things up a bit. I would suggest you start with the Midi Note Mapper sample and try to load it into your Host. When that works (means that your VST.NET installation is good), try to change the sample code to detect the repeated notes.

Good luck and have fun!
Marc 

Jul 28, 2012 at 5:46 PM
Edited Jul 28, 2012 at 5:49 PM

1)As I understand the main function that I must rewrite myself is "public void Process(VstEventCollection events)" in file "MidiProcessor.cs" ?

2) Where should I initialize the new instance of "VstTimeInfo" class? In the beginning of "Process" function or it must be global?

3)Than for each VstEvent I must call SmpteOffset and use that data to know exactly position (from the begining) of each midi note in the track. Am I right? (I need to know time of each note, to know which of those notes are unwanted)

4) What should I do with unwanted note? I can set it's velocity to zero or there is a better way? Maybe not add into Events my outputEvent?

Coordinator
Jul 29, 2012 at 8:41 AM

1) Yes. This method is called repeatedly by the host (just before it calls the Process method on the AudioProcessor). Each time you get the midi events for a small span of time. So you might need to keep track of the last notes in the collection (with the largest deltaFrames - although most of the time deltaFrames is left zero by the host) in order to be able to detect midi notes that are very close but are in different calls to the Process method. You can use the GetTimeInfo method to get the absolute time of each Process call. You need to call GetTimeInfo only once per 'cycle' - calling it more often usually returns the exact same info.

 

2) Doesn't really matter functionally. But during processing you should avoid memory allocations as much as possible. This is to reduce the chance that the .NET Garbage Collector kicks in and freezes all your threads. So I would suggest you make it a class member and refresh it at the beginning of each call to Process.

 

3) I'm not sure SmpteOffset is filled by each host. Start of with making something that works with your host, then add fallback scenarios for other types of info. There are some fields that are always filled (mandatory for the host - refer to the doc comments), perhaps you could start with those?

 

4) If you receive a note from the host but you do not output it from your plugin back to the host, that note is lost. So if you detect a double note, just don't copy it to the output collection and it is 'erased'.

 

Hope it helps,
Marc