VST plugin - how to enable MIDI messages receiving?
-
- KVRer
- 11 posts since 20 Jan, 2011
Hi,
I am working on a pitch shifting VST 2.4 plugin. So far I have the plugin working with the amount of pitch shift as a param. Almost everything important is going on in processReplacing. Now I am supposed to enable changing of the amount of pitch shift by MIDI controller. I should read the note on/off events and decide the amout of shift as a difference between the frequency that is coming in from mic and a note that is being played on a MIDI controller.
Now what I am not able to figure out is how to enable receiving MIDI messages with keeping the plugin as an audio effect not MIDI instrument... Can someone please help me?
Thank you,
Mithali.
I am working on a pitch shifting VST 2.4 plugin. So far I have the plugin working with the amount of pitch shift as a param. Almost everything important is going on in processReplacing. Now I am supposed to enable changing of the amount of pitch shift by MIDI controller. I should read the note on/off events and decide the amout of shift as a difference between the frequency that is coming in from mic and a note that is being played on a MIDI controller.
Now what I am not able to figure out is how to enable receiving MIDI messages with keeping the plugin as an audio effect not MIDI instrument... Can someone please help me?
Thank you,
Mithali.
-
- KVRAF
- 2460 posts since 3 Oct, 2002 from SF CA USA NA Earth
If I remember right, by definition, if a VST plugin is to receive MIDI from the host, it has to be an instrument. There's no prohibition in the VST spec against an instrument having audio inputs as well (I've written one), but many VST hosts suffer from a terrible deficit of imagination and don't offer that kind of routing.mithali wrote:Now what I am not able to figure out is how to enable receiving MIDI messages with keeping the plugin as an audio effect not MIDI instrument...
Since you can run arbitrary code in a plugin, of course, you can go directly to the OS's MIDI I/O API, but that's platform-specific and doesn't easily allow a single MIDI interface to talk to both the host (for other instrument plugins) and your plugin.
-
- KVRAF
- 1940 posts since 16 Aug, 2004 from Vienna, Austria
Actually, there's no such definition. There are some other things that govern the MIDI stuff.Borogove wrote:If I remember right, by definition, if a VST plugin is to receive MIDI from the host, it has to be an instrument.
To tell the host that it can send and receive MIDI, canDo() has to include the following:
Code: Select all
VstInt32 <yourPlugIn>::canDo (char* text)
{
if ((!strcmp (text, "sendVstEvents")) ||
(!strcmp (text, "receiveVstEvents")) ||
(!strcmp (text, "sendVstMidiEvent")) ||
(!strcmp (text, "receiveVstMidiEvent")))
return 1;Code: Select all
DECLARE_VST_DEPRECATED (wantEvents)();Still... it depends on the host whether it respects the PlugIn's ideas. There are quite some that stubbornly refuse to pass MIDI events to anything that is no synth. And, as it has to be, it's nearly the identical set of hosts that don't send audio input to PlugIns that are synths. You just can't please them all, I guess...
-
- KVRist
- 150 posts since 6 Mar, 2008
This should get you started for the MIDI event processing:
Code: Select all
VstInt32 AGain::processEvents (VstEvents* ev)
{
VstMidiEvent * vstMidiEvent;
for (VstInt32 i = 0; i < ev->numEvents; i++){
if (ev->events[i]->type == kVstMidiType) {
vstMidiEvent = (VstMidiEvent *)ev->events[i];
//Do your magic here with vstMidiEvent
}
}
delete vstMidiEvent;
return 1;
}-
- KVRer
- Topic Starter
- 11 posts since 20 Jan, 2011
Hi guys!
thank you very much, it works:) So far I tried it only in Ableton and I had to put this effect of mine on audio track, then create new MIDI track and reroute it as an input to my effect.. so it is not really user friendly, but I am happy it works at all!:)
M.
thank you very much, it works:) So far I tried it only in Ableton and I had to put this effect of mine on audio track, then create new MIDI track and reroute it as an input to my effect.. so it is not really user friendly, but I am happy it works at all!:)
M.
-
- KVRian
- 522 posts since 19 Jul, 2007 from Netherlands
yeahtuna wrote:This should get you started for the MIDI event processing:Code: Select all
VstInt32 AGain::processEvents (VstEvents* ev) { VstMidiEvent * vstMidiEvent; for (VstInt32 i = 0; i < ev->numEvents; i++){ if (ev->events[i]->type == kVstMidiType) { vstMidiEvent = (VstMidiEvent *)ev->events[i]; //Do your magic here with vstMidiEvent } } delete vstMidiEvent; return 1; }
WTF: You should delete the event!? As a consumer of the events the host allocated? What if more plugins receive this MIDI? And what about the VstEvents structure? Do you delete that as well?
It was my understanding that the allocated events were kept in memory until the next call to processEvents...
- KVRAF
- 12615 posts since 7 Dec, 2004
it's not legal to call such functions from the constructor, you must call them from resume().
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
No, you shouldn't. That's wrong.obiwanjacobi wrote: WTF: You should delete the event!?
- KVRAF
- 12615 posts since 7 Dec, 2004
actually calling your own version of delete (which is by the way, a function) may cause a crash just when trying to handle the object. the host may have used malloc. it may use an aligned new. it may have pre-allocated memory which it assigns for events. (in essence, doing it's own memory management)
you can't even safely delete objects allocated by another thread or process, even when you think you're "sure" you know what method allocated the memory.
always allow the code which allocated to do the deletion.
for full safety, always put the allocate() and deallocate() functions into the same source file, such as myclass.cpp.
if you allocate in the source, but delete in the header this case may appear:
the global new operator may be overloaded for alignment before the header myclass.h is included. you allocate in myclass.cpp which is unaligned, but you simply place a delete [] pointer; in myclass.h deallocate(). the overloaded new gets called, but the overloaded delete is not called.
that's an extreme case. i'd be perfectly comfortable taking that risk in my own code because i'd know if i were using an overload of new/delete. you need to be aware of these things though.
you can't even safely delete objects allocated by another thread or process, even when you think you're "sure" you know what method allocated the memory.
always allow the code which allocated to do the deletion.
for full safety, always put the allocate() and deallocate() functions into the same source file, such as myclass.cpp.
if you allocate in the source, but delete in the header this case may appear:
the global new operator may be overloaded for alignment before the header myclass.h is included. you allocate in myclass.cpp which is unaligned, but you simply place a delete [] pointer; in myclass.h deallocate(). the overloaded new gets called, but the overloaded delete is not called.
that's an extreme case. i'd be perfectly comfortable taking that risk in my own code because i'd know if i were using an overload of new/delete. you need to be aware of these things though.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
I think yeahtuna just doesn't quite understand that he's being passed a pointer to an existing structure.
As AD says, if you didn't allocate it, you don't delete it.
As AD says, if you didn't allocate it, you don't delete it.
-
- KVRist
- 150 posts since 6 Mar, 2008
-
- KVRer
- 9 posts since 26 Apr, 2010
I've spent many hours fussing with some of the samples from the VST3 SDK. Does anyone have experience with MIDI input and output from VSTis in VST3? I'm trying to code a MIDI thru bus that simple echoes MIDI received by the VSTi directly out its output.
Thanks (potentially) in advance
Thanks (potentially) in advance


