Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_Initialisation.h 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /** Initialises Juce's GUI classes.
  21. If you're embedding Juce into an application that uses its own event-loop rather
  22. than using the START_JUCE_APPLICATION macro, call this function before making any
  23. Juce calls, to make sure things are initialised correctly.
  24. Note that if you're creating a Juce DLL for Windows, you may also need to call the
  25. Process::setCurrentModuleInstanceHandle() method.
  26. @see shutdownJuce_GUI()
  27. */
  28. JUCE_API void JUCE_CALLTYPE initialiseJuce_GUI();
  29. /** Clears up any static data being used by Juce's GUI classes.
  30. If you're embedding Juce into an application that uses its own event-loop rather
  31. than using the START_JUCE_APPLICATION macro, call this function in your shutdown
  32. code to clean up any juce objects that might be lying around.
  33. @see initialiseJuce_GUI()
  34. */
  35. JUCE_API void JUCE_CALLTYPE shutdownJuce_GUI();
  36. //==============================================================================
  37. /** A utility object that helps you initialise and shutdown Juce correctly
  38. using an RAII pattern.
  39. When the first instance of this class is created, it calls initialiseJuce_GUI(),
  40. and when the last instance is deleted, it calls shutdownJuce_GUI(), so that you
  41. can easily be sure that as long as at least one instance of the class exists, the
  42. library will be initialised.
  43. This class is particularly handy to use at the beginning of a console app's
  44. main() function, because it'll take care of shutting down whenever you return
  45. from the main() call.
  46. Be careful with your threading though - to be safe, you should always make sure
  47. that these objects are created and deleted on the message thread.
  48. */
  49. class JUCE_API ScopedJuceInitialiser_GUI
  50. {
  51. public:
  52. /** The constructor simply calls initialiseJuce_GUI(). */
  53. ScopedJuceInitialiser_GUI();
  54. /** The destructor simply calls shutdownJuce_GUI(). */
  55. ~ScopedJuceInitialiser_GUI();
  56. };
  57. //==============================================================================
  58. /**
  59. To start a JUCE app, use this macro: START_JUCE_APPLICATION (AppSubClass) where
  60. AppSubClass is the name of a class derived from JUCEApplication or JUCEApplicationBase.
  61. See the JUCEApplication and JUCEApplicationBase class documentation for more details.
  62. */
  63. #ifdef DOXYGEN
  64. #define START_JUCE_APPLICATION(AppClass)
  65. #else
  66. #if JUCE_WINDOWS && ! defined (_CONSOLE)
  67. #define JUCE_MAIN_FUNCTION int __stdcall WinMain (struct HINSTANCE__*, struct HINSTANCE__*, char*, int)
  68. #define JUCE_MAIN_FUNCTION_ARGS
  69. #else
  70. #define JUCE_MAIN_FUNCTION int main (int argc, char* argv[])
  71. #define JUCE_MAIN_FUNCTION_ARGS argc, (const char**) argv
  72. #endif
  73. #if JUCE_IOS
  74. #define JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  75. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \
  76. void* juce_GetIOSCustomDelegateClass() { return nullptr; }
  77. #define JUCE_CREATE_APPLICATION_DEFINE_CUSTOM_DELEGATE(AppClass, DelegateClass) \
  78. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \
  79. void* juce_GetIOSCustomDelegateClass() { return [DelegateClass class]; }
  80. #define JUCE_MAIN_FUNCTION_DEFINITION \
  81. extern "C" JUCE_MAIN_FUNCTION \
  82. { \
  83. juce::JUCEApplicationBase::createInstance = &juce_CreateApplication; \
  84. juce::JUCEApplicationBase::iOSCustomDelegate = juce_GetIOSCustomDelegateClass(); \
  85. return juce::JUCEApplicationBase::main (JUCE_MAIN_FUNCTION_ARGS); \
  86. }
  87. #elif JUCE_ANDROID
  88. #define JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  89. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); }
  90. #define JUCE_MAIN_FUNCTION_DEFINITION
  91. #else
  92. #define JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  93. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); }
  94. #define JUCE_MAIN_FUNCTION_DEFINITION \
  95. extern "C" JUCE_MAIN_FUNCTION \
  96. { \
  97. juce::JUCEApplicationBase::createInstance = &juce_CreateApplication; \
  98. return juce::JUCEApplicationBase::main (JUCE_MAIN_FUNCTION_ARGS); \
  99. }
  100. #endif
  101. #if JucePlugin_Build_Standalone
  102. #if JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP
  103. #define START_JUCE_APPLICATION(AppClass) JUCE_CREATE_APPLICATION_DEFINE(AppClass)
  104. #if JUCE_IOS
  105. #define START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE(AppClass, DelegateClass) JUCE_CREATE_APPLICATION_DEFINE_CUSTOM_DELEGATE(AppClass, DelegateClass)
  106. #endif
  107. #else
  108. #define START_JUCE_APPLICATION(AppClass) static_assert(false, "You are trying to use START_JUCE_APPLICATION in an audio plug-in. Define JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP=1 if you want to use a custom standalone target app.");
  109. #if JUCE_IOS
  110. #define START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE(AppClass, DelegateClass) static_assert(false, "You are trying to use START_JUCE_APPLICATION in an audio plug-in. Define JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP=1 if you want to use a custom standalone target app.");
  111. #endif
  112. #endif
  113. #else
  114. #define START_JUCE_APPLICATION(AppClass) \
  115. JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  116. JUCE_MAIN_FUNCTION_DEFINITION
  117. #if JUCE_IOS
  118. /**
  119. You can instruct JUCE to use a custom iOS app delegate class instaed of JUCE's default
  120. app delegate. For JUCE to work you must pass all messages to JUCE's internal app delegate.
  121. Below is an example of minimal forwarding custom delegate. Note that you are at your own
  122. risk if you decide to use your own delegate an subtle, hard to debug bugs may occur.
  123. @interface MyCustomDelegate : NSObject <UIApplicationDelegate> { NSObject<UIApplicationDelegate>* juceDelegate; } @end
  124. @implementation MyCustomDelegate
  125. -(id) init
  126. {
  127. self = [super init];
  128. juceDelegate = reinterpret_cast<NSObject<UIApplicationDelegate>*> ([[NSClassFromString (@"JuceAppStartupDelegate") alloc] init]);
  129. return self;
  130. }
  131. -(void)dealloc
  132. {
  133. [juceDelegate release];
  134. [super dealloc];
  135. }
  136. - (void)forwardInvocation:(NSInvocation *)anInvocation
  137. {
  138. if (juceDelegate != nullptr && [juceDelegate respondsToSelector:[anInvocation selector]])
  139. [anInvocation invokeWithTarget:juceDelegate];
  140. else
  141. [super forwardInvocation:anInvocation];
  142. }
  143. -(BOOL)respondsToSelector:(SEL)aSelector
  144. {
  145. if (juceDelegate != nullptr && [juceDelegate respondsToSelector:aSelector])
  146. return YES;
  147. return [super respondsToSelector:aSelector];
  148. }
  149. @end
  150. */
  151. #define START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE(AppClass, DelegateClass) \
  152. JUCE_CREATE_APPLICATION_DEFINE_CUSTOM_DELEGATE(AppClass, DelegateClass) \
  153. JUCE_MAIN_FUNCTION_DEFINITION
  154. #endif
  155. #endif
  156. #endif
  157. } // namespace juce