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 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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. @tags{Events}
  49. */
  50. class JUCE_API ScopedJuceInitialiser_GUI final
  51. {
  52. public:
  53. /** The constructor simply calls initialiseJuce_GUI(). */
  54. ScopedJuceInitialiser_GUI();
  55. /** The destructor simply calls shutdownJuce_GUI(). */
  56. ~ScopedJuceInitialiser_GUI();
  57. };
  58. //==============================================================================
  59. /**
  60. To start a JUCE app, use this macro: START_JUCE_APPLICATION (AppSubClass) where
  61. AppSubClass is the name of a class derived from JUCEApplication or JUCEApplicationBase.
  62. See the JUCEApplication and JUCEApplicationBase class documentation for more details.
  63. */
  64. #if DOXYGEN
  65. #define START_JUCE_APPLICATION(AppClass)
  66. #else
  67. #if JUCE_WINDOWS && ! defined (_CONSOLE)
  68. #define JUCE_MAIN_FUNCTION \
  69. JUCE_BEGIN_IGNORE_WARNINGS_MSVC (28251) \
  70. int __stdcall WinMain (struct HINSTANCE__*, struct HINSTANCE__*, char*, int) \
  71. JUCE_END_IGNORE_WARNINGS_MSVC
  72. #define JUCE_MAIN_FUNCTION_ARGS
  73. #else
  74. #define JUCE_MAIN_FUNCTION int main (int argc, char* argv[])
  75. #define JUCE_MAIN_FUNCTION_ARGS argc, (const char**) argv
  76. #endif
  77. #if JUCE_IOS
  78. #define JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  79. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wmissing-prototypes") \
  80. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \
  81. void* juce_GetIOSCustomDelegateClass() { return nullptr; } \
  82. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  83. #define JUCE_CREATE_APPLICATION_DEFINE_CUSTOM_DELEGATE(AppClass, DelegateClass) \
  84. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wmissing-prototypes") \
  85. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); } \
  86. void* juce_GetIOSCustomDelegateClass() { return [DelegateClass class]; } \
  87. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  88. #define JUCE_MAIN_FUNCTION_DEFINITION \
  89. extern "C" JUCE_MAIN_FUNCTION \
  90. { \
  91. juce::JUCEApplicationBase::createInstance = &juce_CreateApplication; \
  92. juce::JUCEApplicationBase::iOSCustomDelegate = juce_GetIOSCustomDelegateClass(); \
  93. return juce::JUCEApplicationBase::main (JUCE_MAIN_FUNCTION_ARGS); \
  94. }
  95. #elif JUCE_ANDROID
  96. #define JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  97. extern "C" juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); }
  98. #define JUCE_MAIN_FUNCTION_DEFINITION
  99. #else
  100. #define JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  101. juce::JUCEApplicationBase* juce_CreateApplication(); \
  102. juce::JUCEApplicationBase* juce_CreateApplication() { return new AppClass(); }
  103. #define JUCE_MAIN_FUNCTION_DEFINITION \
  104. extern "C" JUCE_MAIN_FUNCTION \
  105. { \
  106. juce::JUCEApplicationBase::createInstance = &juce_CreateApplication; \
  107. return juce::JUCEApplicationBase::main (JUCE_MAIN_FUNCTION_ARGS); \
  108. }
  109. #endif
  110. #if JucePlugin_Build_Standalone
  111. #if JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP
  112. #define START_JUCE_APPLICATION(AppClass) JUCE_CREATE_APPLICATION_DEFINE(AppClass)
  113. #if JUCE_IOS
  114. #define START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE(AppClass, DelegateClass) JUCE_CREATE_APPLICATION_DEFINE_CUSTOM_DELEGATE(AppClass, DelegateClass)
  115. #endif
  116. #else
  117. #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.");
  118. #if JUCE_IOS
  119. #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.");
  120. #endif
  121. #endif
  122. #else
  123. #define START_JUCE_APPLICATION(AppClass) \
  124. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wmissing-prototypes") \
  125. JUCE_CREATE_APPLICATION_DEFINE(AppClass) \
  126. JUCE_MAIN_FUNCTION_DEFINITION \
  127. JUCE_END_IGNORE_WARNINGS_GCC_LIKE
  128. #if JUCE_IOS
  129. /**
  130. You can instruct JUCE to use a custom iOS app delegate class instead of JUCE's default
  131. app delegate. For JUCE to work you must pass all messages to JUCE's internal app delegate.
  132. Below is an example of minimal forwarding custom delegate. Note that you are at your own
  133. risk if you decide to use your own delegate and subtle, hard to debug bugs may occur.
  134. @interface MyCustomDelegate : NSObject <UIApplicationDelegate> { NSObject<UIApplicationDelegate>* juceDelegate; } @end
  135. @implementation MyCustomDelegate
  136. -(id) init
  137. {
  138. self = [super init];
  139. juceDelegate = reinterpret_cast<NSObject<UIApplicationDelegate>*> ([[NSClassFromString (@"JuceAppStartupDelegate") alloc] init]);
  140. return self;
  141. }
  142. -(void) dealloc
  143. {
  144. [juceDelegate release];
  145. [super dealloc];
  146. }
  147. - (void) forwardInvocation: (NSInvocation*) anInvocation
  148. {
  149. if (juceDelegate != nullptr && [juceDelegate respondsToSelector: [anInvocation selector]])
  150. [anInvocation invokeWithTarget: juceDelegate];
  151. else
  152. [super forwardInvocation: anInvocation];
  153. }
  154. -(BOOL) respondsToSelector: (SEL) aSelector
  155. {
  156. if (juceDelegate != nullptr && [juceDelegate respondsToSelector: aSelector])
  157. return YES;
  158. return [super respondsToSelector: aSelector];
  159. }
  160. @end
  161. */
  162. #define START_JUCE_APPLICATION_WITH_CUSTOM_DELEGATE(AppClass, DelegateClass) \
  163. JUCE_CREATE_APPLICATION_DEFINE_CUSTOM_DELEGATE(AppClass, DelegateClass) \
  164. JUCE_MAIN_FUNCTION_DEFINITION
  165. #endif
  166. #endif
  167. #endif
  168. } // namespace juce