In inVeSTigations part 2, we looked at how we can load VST instruments using the vst~ object to load VST audio plug-ins in Max, and how to format and send MIDI messages to a virtual synth.
In this tutorial, we'll look at a new message to the vst object that lets us load plug-ins without interrupting our audio, and take a look at a novel way to mix the outputs of several VST plug-ins.
Here's a patch that will be familiar if you've looked at inVeSTigations part 1. It's an example of a basic patch we use to host a VST plug-in, minus the things we added that would allow us to access parameters and programs on the plug-in. In fact, this patch uses two identical sets of the same basic patch, and adds a slider, some new logic, and a Message box that contains a message we haven't used before - the disable message.
The disable message, when followed by a number other than zero, stops any further processing by the currently loaded plug-in and outputs a zero signal. As you might guess, the message disable 0 enables pro-cessing for the plug-in. The message is pretty useful for a couple of reasons:
- We can use the message to completely "turn off" the plug-in, and save some CPU cycles
- Since the VST plug-in outputs a zero signal, we can load new plug-ins without interrupting our audio
Here's a part of our new patch that will let us use an hslider to enable/disable one of the two plug-ins hosted by the two vst~ objects:
Let's take a look at this part of the patch in a little detail. The hslider object outputs its usual 0-127 values when we move the slider back and forth, and sends that number to a select object with the arguments 0 and 127. Anytime the slider is all the way to the left, a bang will be sent out the left outlet. When the slider is all the way to the right, a bang message is sent out the second outlet. For any other slider setting, a bang is sent out the right outlet.
I've added some button objects to the patch so you can move the slider back and forth and see for yourself what's happening for yourself.
The bang messages trigger a set of messages that are sent on to a change object. This is an incredibly useful Max object that should become a part of your working environment. The object is easy to understand: when a new number is sent to a change object, it will be sent out the left outlet only if it is different from the last value received (the object also works with floating point values, too - you just give the object a floating point number as an argument, e.g, change 0.). Using the object in this part of the patch means that any time any value is sent to the change object other than a 0 or 127, nothing will happen. If the slider is all the way to the left, a 1 will be sent to the Message box reading disable $1 above the second vst~ object, and the resulting disable 1 message will turn off the plug-in hosted by the second vst~ object. Similarly, moving the slider all the way to the right will turn off the first vst~ object.
We're using the change object here as a way of filtering out unneccessary messages (duplicate messages output by the selct object, in this case). It's always a good idea to think about whether or not you can "thin" a data stream of controller messages - especially when you're working with something like the vst~ object, which can host some pretty CPU-intensive plug-ins. Every little bit helps, and the change object is a big help, indeed.
We can also use the hslider for another purpose, too - we can use it to crossfade the amount of audio output from the plug-ins hosted by the two vst~ objects. It's perfect, really - when the slider is at 0, the second plug-in is turned off anyway, and the first plug-in is turned off they the slider is set at 127. So we can combine crossfading with turning plug-ins on and off (for easy loading). Here's how we do it:
Using the zmap object is old hat for inVeSTigations readers: it takes the outptut from the hslider object and converts it to a floating point value range of 0.-1.0.
We want to set the output amplitudes for to two different plug-ins to match what our disable message to the vst~ object is doing: when the output amplitude from the first plug-in is 0., the other output should be 1.0, and vice versa. The expr object takes a floating point input value (as indicated by the $f1 argument to the object), subtracts it from 1.0, and outputs a floating point value. We can then route those values to the *~ objects (the "volume controls") for the left and right channel outputs of the vst~ objects.
And there you have it - a nifty solution that allows you to mix the outputs of multiple VST plug-ins and and to be able to "turn off" a vst~ object so that you can load a new plug-in.
You can find a zip file containins the patches in this article here.
The next inVeSTIgation will look at some reorganization and good patch hygiene, add some of the interesting VST hosting features we've seen in previous inVeSTigations, and double our pleasure.