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.1KB

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