Basic plugin preprocessor directives

There are some preprocessor directives in the Basic Plugin template, especially in the PluginProcessor.cpp. A lot of them helpful to understand the code but I wonder where they are intitially set. Am I supposed to set them somewhere if I want to use/alter them?

Also, in the AudioProcessor constructor there’s a preprocessor directive right before the colon for member initialization. I find that odd, where do I put my own member initializations in this case? It looks a bit messy to me… :slightly_smiling_face:

NewProjectAudioProcessor::NewProjectAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  juce::AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
                     #endif
                       )
#endif

The Projucer will manage those macros for you, you don’t need to change their value yourself. You can change them in the project settings window of the Projucer.

Personally, I always go through and remove all these as I’d rather edit those settings in code than in the Projucer - it’s a lot cleaner.

1 Like


you’d put your own stuff here

That assumes JucePlugin_PreferredChannelConfigurations is true (or that the extra members you want to initialise only need to be initialised if it’s true).

If you wanted them to be initialised regardless of whether that property is true or not, you’d need something like:

NewProjectAudioProcessor::NewProjectAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  juce::AudioChannelSet::stereo(), true)
                      #endif
                       .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
                     #endif
                       )
#else
    : AudioProcessor()
#endif
    , m_myMember {123}
    , m_anotherMember (321}

I agree with @ImJimmi, you know what you are building and what your default channel configuration will be, so get rid of all the stuff between #ifndef JucePlugin_PreferredChannelConfigurations and #endif in favour of the actual setting. Same for the block around isBusesLayoutSupported().

That macro hell was helpful when doing most things in Projucer, but the trend is to do things in code (and cmake), so every macro less is great.

The default template could be decluttered nowadays.

1 Like

Yes, I feel it’s kind of cluttered to, especially the one in the member initializer is really ugly and as ImJimmi noted will risk not being compiled unless even more directives are added.

So, if I remove these directives and use my own code instead how do I know these preprocessor literals are not used in the predefined classes I haven’t written myself? I mean, is there a risk I get unknown results if it’s assumed they are used in PluginProcessor.cpp but I have removed them?

Furthermore, how do I know which settings in Projucer relies on preprocessor directives like this? If I am to remove them I would need to keep track of which settings in Projucer are rendered “useless” to keep things in order.