The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

217 lines
8.6KB

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