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.

149 lines
5.3KB

  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. #include <JuceHeader.h>
  14. #include "UI/MainHostWindow.h"
  15. #include "Plugins/InternalPlugins.h"
  16. #if ! (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU)
  17. #error "If you're building the audio plugin host, you probably want to enable VST and/or AU support"
  18. #endif
  19. //==============================================================================
  20. class PluginHostApp : public JUCEApplication,
  21. private AsyncUpdater
  22. {
  23. public:
  24. PluginHostApp() {}
  25. void initialise (const String&) override
  26. {
  27. // initialise our settings file..
  28. PropertiesFile::Options options;
  29. options.applicationName = "Juce Audio Plugin Host";
  30. options.filenameSuffix = "settings";
  31. options.osxLibrarySubFolder = "Preferences";
  32. appProperties.reset (new ApplicationProperties());
  33. appProperties->setStorageParameters (options);
  34. mainWindow.reset (new MainHostWindow());
  35. mainWindow->setUsingNativeTitleBar (true);
  36. commandManager.registerAllCommandsForTarget (this);
  37. commandManager.registerAllCommandsForTarget (mainWindow.get());
  38. mainWindow->menuItemsChanged();
  39. // Important note! We're going to use an async update here so that if we need
  40. // to re-open a file and instantiate some plugins, it will happen AFTER this
  41. // initialisation method has returned.
  42. // On Windows this probably won't make a difference, but on OSX there's a subtle event loop
  43. // issue that can happen if a plugin runs one of those irritating modal dialogs while it's
  44. // being loaded. If that happens inside this method, the OSX event loop seems to be in some
  45. // kind of special "initialisation" mode and things get confused. But if we load the plugin
  46. // later when the normal event loop is running, everything's fine.
  47. triggerAsyncUpdate();
  48. }
  49. void handleAsyncUpdate() override
  50. {
  51. File fileToOpen;
  52. #if JUCE_ANDROID || JUCE_IOS
  53. fileToOpen = PluginGraph::getDefaultGraphDocumentOnMobile();
  54. #else
  55. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  56. {
  57. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  58. if (fileToOpen.existsAsFile())
  59. break;
  60. }
  61. #endif
  62. if (! fileToOpen.existsAsFile())
  63. {
  64. RecentlyOpenedFilesList recentFiles;
  65. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  66. if (recentFiles.getNumFiles() > 0)
  67. fileToOpen = recentFiles.getFile (0);
  68. }
  69. if (fileToOpen.existsAsFile())
  70. if (auto* graph = mainWindow->graphHolder.get())
  71. if (auto* ioGraph = graph->graph.get())
  72. ioGraph->loadFrom (fileToOpen, true);
  73. }
  74. void shutdown() override
  75. {
  76. mainWindow = nullptr;
  77. appProperties = nullptr;
  78. LookAndFeel::setDefaultLookAndFeel (nullptr);
  79. }
  80. void suspended() override
  81. {
  82. #if JUCE_ANDROID || JUCE_IOS
  83. if (auto graph = mainWindow->graphHolder.get())
  84. if (auto ioGraph = graph->graph.get())
  85. ioGraph->saveDocument (PluginGraph::getDefaultGraphDocumentOnMobile());
  86. #endif
  87. }
  88. void systemRequestedQuit() override
  89. {
  90. if (mainWindow != nullptr)
  91. mainWindow->tryToQuitApplication();
  92. else
  93. JUCEApplicationBase::quit();
  94. }
  95. bool backButtonPressed() override
  96. {
  97. if (mainWindow->graphHolder != nullptr)
  98. mainWindow->graphHolder->hideLastSidePanel();
  99. return true;
  100. }
  101. const String getApplicationName() override { return "Juce Plug-In Host"; }
  102. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  103. bool moreThanOneInstanceAllowed() override { return true; }
  104. ApplicationCommandManager commandManager;
  105. std::unique_ptr<ApplicationProperties> appProperties;
  106. private:
  107. std::unique_ptr<MainHostWindow> mainWindow;
  108. };
  109. static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
  110. ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
  111. ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
  112. bool isOnTouchDevice() { return Desktop::getInstance().getMainMouseSource().isTouch(); }
  113. // This kicks the whole thing off..
  114. START_JUCE_APPLICATION (PluginHostApp)