The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

160 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include <JuceHeader.h>
  19. #include "UI/MainHostWindow.h"
  20. #include "Plugins/InternalPlugins.h"
  21. #if ! (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU)
  22. #error "If you're building the audio plugin host, you probably want to enable VST and/or AU support"
  23. #endif
  24. //==============================================================================
  25. class PluginHostApp : public JUCEApplication,
  26. private AsyncUpdater
  27. {
  28. public:
  29. PluginHostApp() {}
  30. void initialise (const String&) override
  31. {
  32. // initialise our settings file..
  33. PropertiesFile::Options options;
  34. options.applicationName = "Juce Audio Plugin Host";
  35. options.filenameSuffix = "settings";
  36. options.osxLibrarySubFolder = "Preferences";
  37. appProperties.reset (new ApplicationProperties());
  38. appProperties->setStorageParameters (options);
  39. mainWindow.reset (new MainHostWindow());
  40. mainWindow->setUsingNativeTitleBar (true);
  41. commandManager.registerAllCommandsForTarget (this);
  42. commandManager.registerAllCommandsForTarget (mainWindow.get());
  43. mainWindow->menuItemsChanged();
  44. // Important note! We're going to use an async update here so that if we need
  45. // to re-open a file and instantiate some plugins, it will happen AFTER this
  46. // initialisation method has returned.
  47. // On Windows this probably won't make a difference, but on OSX there's a subtle event loop
  48. // issue that can happen if a plugin runs one of those irritating modal dialogs while it's
  49. // being loaded. If that happens inside this method, the OSX event loop seems to be in some
  50. // kind of special "initialisation" mode and things get confused. But if we load the plugin
  51. // later when the normal event loop is running, everything's fine.
  52. triggerAsyncUpdate();
  53. }
  54. void handleAsyncUpdate() override
  55. {
  56. File fileToOpen;
  57. #if JUCE_ANDROID || JUCE_IOS
  58. fileToOpen = PluginGraph::getDefaultGraphDocumentOnMobile();
  59. #else
  60. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  61. {
  62. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  63. if (fileToOpen.existsAsFile())
  64. break;
  65. }
  66. #endif
  67. if (! fileToOpen.existsAsFile())
  68. {
  69. RecentlyOpenedFilesList recentFiles;
  70. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  71. if (recentFiles.getNumFiles() > 0)
  72. fileToOpen = recentFiles.getFile (0);
  73. }
  74. if (fileToOpen.existsAsFile())
  75. if (auto* graph = mainWindow->graphHolder.get())
  76. if (auto* ioGraph = graph->graph.get())
  77. ioGraph->loadFrom (fileToOpen, true);
  78. }
  79. void shutdown() override
  80. {
  81. mainWindow = nullptr;
  82. appProperties = nullptr;
  83. LookAndFeel::setDefaultLookAndFeel (nullptr);
  84. }
  85. void suspended() override
  86. {
  87. #if JUCE_ANDROID || JUCE_IOS
  88. if (auto graph = mainWindow->graphHolder.get())
  89. if (auto ioGraph = graph->graph.get())
  90. ioGraph->saveDocument (PluginGraph::getDefaultGraphDocumentOnMobile());
  91. #endif
  92. }
  93. void systemRequestedQuit() override
  94. {
  95. if (mainWindow != nullptr)
  96. mainWindow->tryToQuitApplication();
  97. else
  98. JUCEApplicationBase::quit();
  99. }
  100. bool backButtonPressed() override
  101. {
  102. if (mainWindow->graphHolder != nullptr)
  103. mainWindow->graphHolder->hideLastSidePanel();
  104. return true;
  105. }
  106. const String getApplicationName() override { return "Juce Plug-In Host"; }
  107. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  108. bool moreThanOneInstanceAllowed() override { return true; }
  109. ApplicationCommandManager commandManager;
  110. std::unique_ptr<ApplicationProperties> appProperties;
  111. private:
  112. std::unique_ptr<MainHostWindow> mainWindow;
  113. };
  114. static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
  115. ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
  116. ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
  117. bool isOnTouchDevice()
  118. {
  119. static bool isTouch = Desktop::getInstance().getMainMouseSource().isTouch();
  120. return isTouch;
  121. }
  122. // This kicks the whole thing off..
  123. START_JUCE_APPLICATION (PluginHostApp)