Getting channel config and OnActivate()


I’m trying to understand at what point a plugin has access to the i/o channel configuration, which has left me fairly confused about the OnActivate() function.

(Context is that I’m working on a plugin where a number of params are per-channel, i.e. there’s an independent instance of the param for each output channel. The plugin should accept a range of i/o configurations, so needs to get the number of input and output channels in order to set up the right number of params and their controls.)

I found a post of Oli’s which says “A plug-in’s I/O are not yet connected in the plug-in constructor. You can override IPlugProcessor::OnActivate() to do something when the I/O connections are known.”

From this, I concluded that I’d need to move most of my setup code into OnActivate. I inserted print statements to report the output of NInChansConnected() and NOutChansConnected(), trying to understand when OnActivate () is called.

Running in AULab, in the plugin constructor, the channel config reported is as Oli says: inputs = 0, outputs = 0.

Then OnActivate() is called, and also reports inputs = 0, outputs = 0.

Then OnActivate is called a second time (why?). Now, NInChansConnected = 2 (which is correct), NOutChansConnected = 0 (which isn’t)

On quitting the app, OnActivate runs again, this time correctly reporting inputs = 2, outputs = 2.

I’d be grateful for a). an explanation of what OnActivate() is doing, and/or b). suggestions as to the right way to get the channel config!

OnActivate is typically called by the DAW when the plugin is “turned on/off” in the DAW plugin window - but not always. Sometimes Reset() is called and/or OnActivate is called when the transport starts/stops. I started making a list one time of what DAWs call what but it was overcome by other events.

I have made it a habit - right or wrong, but so far it’s been working - to use both OnReset() and OnActivate() to set up the plugin, get the current sample rate, clear buffers, etc.

I then check the plugin I/O configuration in the Process() block before the For() loop using “IsChannelConnected(kInput/kOutput, 1)”, etc. which is correct most of the time. Some DAWs, like Cubase, connect to all available pins of a plugin even if that plugin is being used on a mono track - so you have to be prepared for almost any situation and do lots of testing!

Many thanks for this, and apologies for the slow response!

I suppose it’s reassuring that I’m not the only one confused by this. (I was going to link to an older post comparing OnActivate() and OnReset() before realising that it was yours :slight_smile: )

Anyway, I’ll try calling both methods as you suggest. (In my case I think any check in ProcessBlock will be too late.)