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.
I think you need to do the check at run time. The AudioProcessor has the public member wrapperType to check that.
Try #ifdef instead of #if
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.
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.
I managed to get it working thusly :
- remove the code that has the conditional checks form the Shared Code target
- add that same code to each plugin target
- 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.
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
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?
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…
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
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.
You’re right, I’ll get that fixed.
I seem to be having the opposite problem (Xcode 10.0); JUCE_STANDALONE_APPLICATION
is always true, as is JucePlugin_Build_Standalone
. I’ve double checked in the Preprocessor Macros section of the VST target and its 0
. I wonder if AppConfig.h is overriding the Xcode Preprocessor Macros section?
I tested this by manually adding a preprocessor macro to the “Standalone Plugin” target in Xcode, which worked as expected.
Just for the records, if a check at runtime is an option, there is the static JUCEApplicationBase::isStandaloneApp()…
and you have seen Jules’ reply?
Thanks, I saw that, and I am using #if
. I might be able to use the runtime check but its for setting channel configuration so I think better suited to compile time.
Here’s what I did…
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
if (JUCEApplicationBase::isStandaloneApp())
return new MyAudioProcessor (true);
return new MyAudioProcessor();
}
and have two MyAudioProcessor constructors for the different channel configs.
Rail