How to use connectTo with ofxAudioUnit

@admsyn
i am using a bunch of different audiounit effects and combine them like this:

filePlayer.connectTo(BandPassFilter).connectTo(PeakLimiter).connectTo(HighShelfFilter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);

but sometimes i want to be able to dis-connect one of the effects; for example remove .connectTo(PeakLimiter) while the app is running.

currently i do this complicated bool checking with an if else like when a certain toggle button was clicked in my main GUI.

    if(bUseBandPass && bUsePeakLimiter && bUseHighShelf){
        filePlayer.connectTo(BandPassFilter).connectTo(PeakLimiter).connectTo(HighShelfFilter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
        
    }else if(bUseBandPass && bUsePeakLimiter && !bUseHighShelf){
          filePlayer.connectTo(BandPassFilter).connectTo(PeakLimiter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
        
    }else if(bUseBandPass && !bUsePeakLimiter && !bUseHighShelf){
        filePlayer.connectTo(BandPassFilter).connectTo(tap).connectTo(DynamicsProcessor).connectTo(fft).connectTo(output);
        
    }else if(!bUseBandPass && bUsePeakLimiter && bUseHighShelf){
        filePlayer.connectTo(PeakLimiter).connectTo(HighShelfFilter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
        
    }else if(!bUseBandPass && !bUsePeakLimiter && bUseHighShelf){
        filePlayer.connectTo(HighShelfFilter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
        
    }else if(!bUseBandPass && bUsePeakLimiter && !bUseHighShelf){
        filePlayer.connectTo(PeakLimiter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
        
    }else if(bUseBandPass && !bUsePeakLimiter && bUseHighShelf){
        filePlayer.connectTo(BandPassFilter).connectTo(HighShelfFilter).connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
    }else{
         filePlayer.connectTo(DynamicsProcessor).connectTo(fft).connectTo(tap).connectTo(output);
    }

ideally i could do
if(bUseBandPass) filePlayer.connectTo(BandPassFilter);
if(bUsePeakLimiter) filePlayer.connectTo(PeakLimiter);
if(bUseHighShelf) filePlayer.connectTo(HighShelfFilter);
filePlayer.connectTo(tap).connectTo(output);
etc

thx

The API isn’t really designed for dynamic reconfiguration of the graph while it’s running. If it’s really necessary you might be better off with the straight AUGraph API, since it keeps track of the entire graph and can coordinate dynamic reconfiguring like that.

It sounds like you could get away with having all your filters in one chain, though, and just enabling / disabling the bypass property per-effect (kAudioUnitProperty_BypassEffect). Documentation for that param is in <AudioUnit/AudioUnitProperties.h> on line 297 on my copy.

thanks that worked

//bUseBandPass is a boolean toggled via my gui

 UInt32 bypassed = !bUseBandPass;
        AudioUnitSetProperty(BandPassFilter.getUnit(), kAudioUnitProperty_BypassEffect, kAudioUnitScope_Global,0,&bypassed,sizeof(bypassed));