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.

205 lines
8.0KB

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