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.

169 lines
6.7KB

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