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_Application.h 7.4KB

9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_APPLICATION_H_INCLUDED
  18. #define JUCE_APPLICATION_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An instance of this class is used to specify initialisation and shutdown
  22. code for the application.
  23. Any application that wants to run an event loop must declare a subclass of
  24. JUCEApplicationBase or JUCEApplication, and implement its various pure virtual
  25. methods.
  26. It then needs to use the START_JUCE_APPLICATION macro somewhere in a CPP file
  27. to declare an instance of this class and generate suitable platform-specific
  28. boilerplate code to launch the app.
  29. Note that this class is derived from JUCEApplicationBase, which contains most
  30. of the useful methods and functionality. This derived class is here simply as
  31. a convenient way to also inherit from an ApplicationCommandTarget, and to implement
  32. default versions of some of the pure virtual base class methods. But you can derive
  33. your app object directly from JUCEApplicationBase if you want to, and by doing so
  34. can avoid having a dependency on the juce_gui_basics module.
  35. e.g. @code
  36. class MyJUCEApp : public JUCEApplication
  37. {
  38. public:
  39. MyJUCEApp() {}
  40. ~MyJUCEApp() {}
  41. void initialise (const String& commandLine) override
  42. {
  43. myMainWindow = new MyApplicationWindow();
  44. myMainWindow->setBounds (100, 100, 400, 500);
  45. myMainWindow->setVisible (true);
  46. }
  47. void shutdown() override
  48. {
  49. myMainWindow = nullptr;
  50. }
  51. const String getApplicationName() override
  52. {
  53. return "Super JUCE-o-matic";
  54. }
  55. const String getApplicationVersion() override
  56. {
  57. return "1.0";
  58. }
  59. private:
  60. ScopedPointer<MyApplicationWindow> myMainWindow;
  61. };
  62. // this generates boilerplate code to launch our app class:
  63. START_JUCE_APPLICATION (MyJUCEApp)
  64. @endcode
  65. @see JUCEApplicationBase, START_JUCE_APPLICATION
  66. */
  67. class JUCE_API JUCEApplication : public JUCEApplicationBase,
  68. public ApplicationCommandTarget
  69. {
  70. public:
  71. //==============================================================================
  72. /** Constructs a JUCE app object.
  73. If subclasses implement a constructor or destructor, they shouldn't call any
  74. JUCE code in there - put your startup/shutdown code in initialise() and
  75. shutdown() instead.
  76. */
  77. JUCEApplication();
  78. /** Destructor.
  79. If subclasses implement a constructor or destructor, they shouldn't call any
  80. JUCE code in there - put your startup/shutdown code in initialise() and
  81. shutdown() instead.
  82. */
  83. ~JUCEApplication();
  84. //==============================================================================
  85. /** Returns the global instance of the application object being run. */
  86. static JUCEApplication* JUCE_CALLTYPE getInstance() noexcept;
  87. //==============================================================================
  88. #if DOXYGEN
  89. /** Returns the application's name. */
  90. virtual const String getApplicationName() = 0;
  91. /** Returns the application's version number. */
  92. virtual const String getApplicationVersion() = 0;
  93. #endif
  94. /** Checks whether multiple instances of the app are allowed.
  95. If you application class returns true for this, more than one instance is
  96. permitted to run (except on OSX where the OS automatically stops you launching
  97. a second instance of an app without explicitly starting it from the command-line).
  98. If it's false, the second instance won't start, but it you will still get a
  99. callback to anotherInstanceStarted() to tell you about this - which
  100. gives you a chance to react to what the user was trying to do.
  101. */
  102. bool moreThanOneInstanceAllowed() override;
  103. /** Indicates that the user has tried to start up another instance of the app.
  104. This will get called even if moreThanOneInstanceAllowed() is false.
  105. */
  106. void anotherInstanceStarted (const String& commandLine) override;
  107. /** Called when the operating system is trying to close the application.
  108. The default implementation of this method is to call quit(), but it may
  109. be overloaded to ignore the request or do some other special behaviour
  110. instead. For example, you might want to offer the user the chance to save
  111. their changes before quitting, and give them the chance to cancel.
  112. If you want to send a quit signal to your app, this is the correct method
  113. to call, because it means that requests that come from the system get handled
  114. in the same way as those from your own application code. So e.g. you'd
  115. call this method from a "quit" item on a menu bar.
  116. */
  117. void systemRequestedQuit() override;
  118. /** This method is called when the application is being put into background mode
  119. by the operating system.
  120. */
  121. void suspended() override;
  122. /** This method is called when the application is being woken from background mode
  123. by the operating system.
  124. */
  125. void resumed() override;
  126. /** If any unhandled exceptions make it through to the message dispatch loop, this
  127. callback will be triggered, in case you want to log them or do some other
  128. type of error-handling.
  129. If the type of exception is derived from the std::exception class, the pointer
  130. passed-in will be valid. If the exception is of unknown type, this pointer
  131. will be null.
  132. */
  133. void unhandledException (const std::exception* e,
  134. const String& sourceFilename,
  135. int lineNumber) override;
  136. //==============================================================================
  137. /** @internal */
  138. ApplicationCommandTarget* getNextCommandTarget() override;
  139. /** @internal */
  140. void getCommandInfo (CommandID, ApplicationCommandInfo&) override;
  141. /** @internal */
  142. void getAllCommands (Array<CommandID>&) override;
  143. /** @internal */
  144. bool perform (const InvocationInfo&) override;
  145. private:
  146. bool initialiseApp() override;
  147. JUCE_DECLARE_NON_COPYABLE (JUCEApplication)
  148. };
  149. #endif // JUCE_APPLICATION_H_INCLUDED