Which indexes to use in AudioProcessorGraph::addConnection?

How do I use AudioProcessorGraph::addConnection?

I’ve successfully made a working graph of: midi-input -> VST-instrument -> audio-output

I now want to add an effect: midi-input -> VST-instrument -> effect -> audio-output

When I connect the instrument-node to the effect-node, which source and destination channel indexes should I use? I suppose that it depends on the plugins themselves and how many output and input channels they each have. But how do I find this out, and then get the channel-indexes for them?

I can see that the AudioProcessor class has getNumInputChannels() and getNumOutputChannels(). Should I use these? And if I do, how do I get the channel indexes for them? For example:

  • The instrument has midi input and stereo output
  • The effect has stereo input and stereo output

What are the indexes for the instrument’s output? What are the indexes for the effect’s inputs and outputs? Is it the case that addConnection is always connecting the source node’s outputs to the destination node’s inputs, and the indexes are just zero-based indexes up to the number of channels? So for stereo connections would it always be:
graph.addConnection(sourceID, 0, destinationID, 0)
graph.addConnection(sourceID, 1, destinationID, 1)

Sorry if this is a stupid question… but it’s confusing me at the moment!

thanks,
Richard

If you’re creating connections related to MIDI, the source and destination channels are to be juce::AudioProcessorGraph::midiChannelIndex - always.

For audio on the other hand, the “channel-indexes” associate as follows: 0 for Left channel, 1 for Right channel, and so on. How you want to go about connecting stuff together is up to you… You can certainly utilize juce::AudioProcessor::getNumInputChannels() and juce::AudioProcessor::getNumOutputChannels() if you wanted to.

You’ve multiple options, but you could use whatever the minimum number of channels there are between the nodes, and go from there. (ie: Connect src left channel to dest left channel, etc…) If you try to create a connection that isn’t logical, such as where the channel index is beyond what either source and destination processor supports, the juce::AudioProcessorGraph::addConnection() method will just return false.

Thank you… I’ve got my instrument and effect nicely connected up now!

The thing that I had been confused about was whether there were separate indexes for input and output channels. For example, I had wondered whether input-left=0, input-right=1, output-left=2, output-right=3 or something like that.

But addConnection is being more helpful than that, and is hooking up the zero-based outputs from the source to the zero-based inputs on the destination. I had thought that things were more confusing than they were.