[SOLVED] Standalone plugin conditional compilation

standalone

#1

I have run into problems that I’m really not sure about how to solve.
Throughout my code I want some things to work differently if my plugin is standalone, I thought it would be a case of wrapping with #if JUCE_STANDALONE_APPLICATION but that seems to always evaluate false in XCode 9.2
I tried even adding JUCE_STANDALONE_APPLICATION=1 to the preprocessor macros and it still not working, so I’m wondering if I have misunderstood something fundamental about how to achieve slightly different behaviour in standalone as opposed to AU/VST in a host.


#2

I think you need to do the check at run time. The AudioProcessor has the public member wrapperType to check that.


#3

Try #ifdef instead of #if


#4

But it doesn’t help if the check is going to be done in the “shared code” portion of the project…That is compiled only once and then just linked in for the builds with the various wrappers.


#5

OK, this was one of the things that I was going to investigate. I was wondering if I could move the relevant items out of the shared code into each target, and if that would then build those bits 4 times (VST/3/AU/Standalone). But it sounds like runtime check for which environment might be easier.


#6

I managed to get it working thusly :

  1. remove the code that has the conditional checks form the Shared Code target
  2. add that same code to each plugin target
  3. add JUCE_STANDALONE_APPLICATION=1 to the preprocessor macros

Point 3 really shouldn’t have been necessary, but my guess is it’s because this section of code in AppConfig.h is appearing before any of the defines it relies on :

#ifndef    JUCE_STANDALONE_APPLICATION
 #if defined(JucePlugin_Name) && defined(JucePlugin_Build_Standalone)
  #define  JUCE_STANDALONE_APPLICATION JucePlugin_Build_Standalone
 #else
  #define  JUCE_STANDALONE_APPLICATION 0
 #endif
#endif

It would be incredibly useful if the Projucer had some way to choose under which target any given source file is compiled, because as soon as I re-save from there I will lose any of those edits I’ve made as detailed above. Unless of course I’ve missed this somewhere.


#7

This is a bit OT but if you’re testing juce definitions, never use #ifdef. Always use #if.

We treat our macros as tri-state: undefined means “default”, 1 means true, and 0 means false. #ifdef will return true if the value is actually 0


#8

I had meant to mention that #ifdef JUCE_STANDALONE_APPLICATION would evaluate true regardless, thanks for pointing that out.
Was my thinking correct about point 3 above, that because JucePlugin_Name is not yet defined JUCE_STANDALONE_APPLICATION is always going to be assigned 0?
I’m guessing the Projucer change would be a bit too specific for plugins and likely something that won’t be added? :wink:


#9

The JucePlugin_Name is defined in your generated AppConfig.h, which is the first header included in the JuceHeader.h, that comes usually first in all your files, so I can’t see how JucePlugin_Name would end up undefined…


#10

In my generated AppConfig.h the JUCE_STANDALONE_APPLICATION define is on line 290, where as JucePlugin_Name is defined on line 324. I’m using Projucer 5.3.2 (not compiling myself or anything).
I expect that I am misunderstanding something, but certainly as my AppConfig.h is generated by the Projucer and used in my code, JUCE_STANDALONE_APPLICATION always evaluates false.

Here’s an AppConfig.h as from a fresh audio plugin generated by my Projucer : https://pastebin.com/CbwMquR6


#11

Sorry, that was my bad, I missed that part when I skimmed through the AppConfig.h…
You are totally right, it needs to be the other way round.


#12

You’re right, I’ll get that fixed.