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