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.

386 lines
15KB

  1. /*
  2. * Carla plugin host
  3. * Copyright (C) 2011-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_HOST_HPP_INCLUDED
  18. #define CARLA_HOST_HPP_INCLUDED
  19. //---------------------------------------------------------------------------------------------------------------------
  20. // Imports (Global)
  21. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  22. # pragma GCC diagnostic push
  23. # pragma GCC diagnostic ignored "-Wconversion"
  24. # pragma GCC diagnostic ignored "-Weffc++"
  25. # pragma GCC diagnostic ignored "-Wsign-conversion"
  26. #endif
  27. #include <QtWidgets/QMainWindow>
  28. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  29. # pragma GCC diagnostic pop
  30. #endif
  31. //---------------------------------------------------------------------------------------------------------------------
  32. // Imports (Custom)
  33. #include "carla_shared.hpp"
  34. #include "carla_widgets.hpp"
  35. #include "CarlaBackend.h"
  36. #include "CarlaJuceUtils.hpp"
  37. CARLA_BACKEND_USE_NAMESPACE;
  38. //---------------------------------------------------------------------------------------------------------------------
  39. class CarlaHost : public QObject
  40. {
  41. Q_OBJECT
  42. public:
  43. // info about this host object
  44. bool isControl;
  45. bool isPlugin;
  46. bool isRemote;
  47. bool nsmOK;
  48. // settings
  49. EngineProcessMode processMode;
  50. EngineTransportMode transportMode;
  51. QCarlaString transportExtra;
  52. EngineProcessMode nextProcessMode;
  53. bool processModeForced;
  54. QCarlaString audioDriverForced;
  55. // settings
  56. bool experimental;
  57. bool exportLV2;
  58. bool forceStereo;
  59. bool manageUIs;
  60. uint maxParameters;
  61. bool resetXruns;
  62. bool preferPluginBridges;
  63. bool preferUIBridges;
  64. bool preventBadBehaviour;
  65. bool showLogs;
  66. bool showPluginBridges;
  67. bool showWineBridges;
  68. bool uiBridgesTimeout;
  69. bool uisAlwaysOnTop;
  70. // settings
  71. QString pathBinaries;
  72. QString pathResources;
  73. CarlaHost();
  74. signals:
  75. void SignalTerminate();
  76. void SignalSave();
  77. // Engine stuff
  78. void EngineStartedCallback(uint, int, int, uint, float, QString);
  79. void EngineStoppedCallback();
  80. private:
  81. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaHost)
  82. };
  83. //---------------------------------------------------------------------------------------------------------------------
  84. // Host Window
  85. class CarlaHostWindow : public QMainWindow,
  86. public PluginEditParentMeta
  87. {
  88. Q_OBJECT
  89. public:
  90. //-----------------------------------------------------------------------------------------------------------------
  91. CarlaHostWindow(CarlaHost& host, const bool withCanvas, QWidget* const parent = nullptr);
  92. ~CarlaHostWindow() override;
  93. private:
  94. struct PrivateData;
  95. PrivateData* const self;
  96. protected:
  97. //-----------------------------------------------------------------------------------------------------------------
  98. // Plugin Editor Parent
  99. void editDialogVisibilityChanged(int pluginId, bool visible) override;
  100. void editDialogPluginHintsChanged(int pluginId, int hints) override;
  101. void editDialogParameterValueChanged(int pluginId, int parameterId, float value) override;
  102. void editDialogProgramChanged(int pluginId, int index) override;
  103. void editDialogMidiProgramChanged(int pluginId, int index) override;
  104. void editDialogNotePressed(int pluginId, int note) override;
  105. void editDialogNoteReleased(int pluginId, int note) override;
  106. void editDialogMidiActivityChanged(int pluginId, bool onOff) override;
  107. //-----------------------------------------------------------------------------------------------------------------
  108. // show/hide event
  109. void showEvent(QShowEvent* event) override;
  110. void hideEvent(QHideEvent* event) override;
  111. //-----------------------------------------------------------------------------------------------------------------
  112. // resize event
  113. void resizeEvent(QResizeEvent* event) override;
  114. //-----------------------------------------------------------------------------------------------------------------
  115. // timer event
  116. void timerEvent(QTimerEvent* event) override;
  117. //-----------------------------------------------------------------------------------------------------------------
  118. // color/style change event
  119. void changeEvent(QEvent* event) override;
  120. //-----------------------------------------------------------------------------------------------------------------
  121. // close event
  122. void closeEvent(QCloseEvent* event) override;
  123. private slots:
  124. //-----------------------------------------------------------------------------------------------------------------
  125. // Files (menu actions)
  126. void slot_fileNew();
  127. void slot_fileOpen();
  128. void slot_fileSave(bool saveAs = false);
  129. void slot_fileSaveAs();
  130. void slot_loadProjectNow();
  131. //-----------------------------------------------------------------------------------------------------------------
  132. // Engine (menu actions)
  133. void slot_engineStart();
  134. bool slot_engineStop(bool forced = false);
  135. void slot_engineConfig();
  136. bool slot_engineStopTryAgain();
  137. //-----------------------------------------------------------------------------------------------------------------
  138. // Engine (host callbacks)
  139. void slot_handleEngineStartedCallback(uint pluginCount, int processMode, int transportMode, uint bufferSize, float sampleRate, QString driverName);
  140. void slot_handleEngineStoppedCallback();
  141. void slot_handleTransportModeChangedCallback(int transportMode, QString transportExtra);
  142. void slot_handleBufferSizeChangedCallback(int newBufferSize);
  143. void slot_handleSampleRateChangedCallback(double newSampleRate);
  144. void slot_handleCancelableActionCallback(int pluginId, bool started, QString action);
  145. void slot_canlableActionBoxClicked();
  146. void slot_handleProjectLoadFinishedCallback();
  147. //-----------------------------------------------------------------------------------------------------------------
  148. // Plugins (menu actions)
  149. void slot_favoritePluginAdd();
  150. void slot_showPluginActionsMenu();
  151. void slot_pluginAdd();
  152. void slot_confirmRemoveAll();
  153. void slot_jackAppAdd();
  154. //-----------------------------------------------------------------------------------------------------------------
  155. // Plugins (macros)
  156. void slot_pluginsEnable();
  157. void slot_pluginsDisable();
  158. void slot_pluginsVolume100();
  159. void slot_pluginsMute();
  160. void slot_pluginsWet100();
  161. void slot_pluginsBypass();
  162. void slot_pluginsCenter();
  163. void slot_pluginsCompact();
  164. void slot_pluginsExpand();
  165. //-----------------------------------------------------------------------------------------------------------------
  166. // Plugins (host callbacks)
  167. void slot_handlePluginAddedCallback(int pluginId, QString pluginName);
  168. void slot_handlePluginRemovedCallback(int pluginId);
  169. //-----------------------------------------------------------------------------------------------------------------
  170. // Canvas (menu actions)
  171. void slot_canvasShowInternal();
  172. void slot_canvasShowExternal();
  173. void slot_canvasArrange();
  174. void slot_canvasRefresh();
  175. void slot_canvasZoomFit();
  176. void slot_canvasZoomIn();
  177. void slot_canvasZoomOut();
  178. void slot_canvasZoomReset();
  179. void slot_canvasSaveImage();
  180. //-----------------------------------------------------------------------------------------------------------------
  181. // Canvas (canvas callbacks)
  182. void slot_canvasItemMoved(int group_id, int split_mode, QPointF pos);
  183. void slot_canvasSelectionChanged();
  184. void slot_canvasScaleChanged(double scale);
  185. void slot_canvasPluginSelected(QList<void*> pluginList);
  186. //-----------------------------------------------------------------------------------------------------------------
  187. // Canvas (host callbacks)
  188. void slot_handlePatchbayClientAddedCallback(int clientId, int clientIcon, int pluginId, QString clientName);
  189. void slot_handlePatchbayClientRemovedCallback(int clientId);
  190. void slot_handlePatchbayClientRenamedCallback(int clientId, QString newClientName);
  191. void slot_handlePatchbayClientDataChangedCallback(int clientId, int clientIcon, int pluginId);
  192. void slot_handlePatchbayPortAddedCallback(int clientId, int portId, int portFlags, int portGroupId, QString portName);
  193. void slot_handlePatchbayPortRemovedCallback(int groupId, int portId);
  194. void slot_handlePatchbayPortChangedCallback(int groupId, int portId, int portFlags, int portGroupId, QString newPortName);
  195. void slot_handlePatchbayPortGroupAddedCallback(int groupId, int portId, int portGroupId, QString newPortName);
  196. void slot_handlePatchbayPortGroupRemovedCallback(int groupId, int portId);
  197. void slot_handlePatchbayPortGroupChangedCallback(int groupId, int portId, int portGroupId, QString newPortName);
  198. void slot_handlePatchbayConnectionAddedCallback(int connectionId, int groupOutId, int portOutId, int groupInId, int portInId);
  199. void slot_handlePatchbayConnectionRemovedCallback(int connectionId, int portOutId, int portInId);
  200. //-----------------------------------------------------------------------------------------------------------------
  201. // Settings (helpers)
  202. void slot_restoreCanvasScrollbarValues();
  203. //-----------------------------------------------------------------------------------------------------------------
  204. // Settings (menu actions)
  205. void slot_showSidePanel(bool yesNo);
  206. void slot_showToolbar(bool yesNo);
  207. void slot_showCanvasMeters(bool yesNo);
  208. void slot_showCanvasKeyboard(bool yesNo);
  209. void slot_configureCarla();
  210. //-----------------------------------------------------------------------------------------------------------------
  211. // About (menu actions)
  212. void slot_aboutCarla();
  213. void slot_aboutJuce();
  214. void slot_aboutQt();
  215. //-----------------------------------------------------------------------------------------------------------------
  216. // Disk (menu actions)
  217. void slot_diskFolderChanged(int index);
  218. void slot_diskFolderAdd();
  219. void slot_diskFolderRemove();
  220. void slot_fileTreeDoubleClicked(QModelIndex* modelIndex);
  221. //-----------------------------------------------------------------------------------------------------------------
  222. // Transport (menu actions)
  223. void slot_transportPlayPause(bool toggled);
  224. void slot_transportStop();
  225. void slot_transportBackwards();
  226. void slot_transportBpmChanged(qreal newValue);
  227. void slot_transportForwards();
  228. void slot_transportJackEnabled(bool clicked);
  229. void slot_transportLinkEnabled(bool clicked);
  230. //-----------------------------------------------------------------------------------------------------------------
  231. // Other
  232. void slot_xrunClear();
  233. //-----------------------------------------------------------------------------------------------------------------
  234. // Canvas scrollbars
  235. void slot_horizontalScrollBarChanged(int value);
  236. void slot_verticalScrollBarChanged(int value);
  237. //-----------------------------------------------------------------------------------------------------------------
  238. // Canvas keyboard
  239. void slot_noteOn(int note);
  240. void slot_noteOff(int note);
  241. //-----------------------------------------------------------------------------------------------------------------
  242. // Canvas keyboard (host callbacks)
  243. void slot_handleNoteOnCallback(int pluginId, int channel, int note, int velocity);
  244. void slot_handleNoteOffCallback(int pluginId, int channel, int note);
  245. //-----------------------------------------------------------------------------------------------------------------
  246. void slot_handleUpdateCallback(int pluginId);
  247. //-----------------------------------------------------------------------------------------------------------------
  248. // MiniCanvas stuff
  249. void slot_miniCanvasCheckAll();
  250. void slot_miniCanvasCheckSize();
  251. void slot_miniCanvasMoved(qreal xp, qreal yp);
  252. //-----------------------------------------------------------------------------------------------------------------
  253. // Misc
  254. void slot_tabChanged(int index);
  255. void slot_handleReloadAllCallback(int pluginId);
  256. //-----------------------------------------------------------------------------------------------------------------
  257. void slot_handleNSMCallback(int opcode, int valueInt, QString valueStr);
  258. //-----------------------------------------------------------------------------------------------------------------
  259. void slot_handleDebugCallback(int pluginId, int value1, int value2, int value3, float valuef, QString valueStr);
  260. void slot_handleInfoCallback(QString info);
  261. void slot_handleErrorCallback(QString error);
  262. void slot_handleQuitCallback();
  263. void slot_handleInlineDisplayRedrawCallback(int pluginId);
  264. //-----------------------------------------------------------------------------------------------------------------
  265. void slot_handleSIGUSR1();
  266. void slot_handleSIGTERM();
  267. //-----------------------------------------------------------------------------------------------------------------
  268. private:
  269. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaHostWindow)
  270. };
  271. //---------------------------------------------------------------------------------------------------------------------
  272. // Init host
  273. CarlaHost& initHost(const QString initName, const bool isControl, const bool isPlugin, const bool failError);
  274. //---------------------------------------------------------------------------------------------------------------------
  275. // Load host settings
  276. void loadHostSettings(CarlaHost& host);
  277. //---------------------------------------------------------------------------------------------------------------------
  278. // Set host settings
  279. void setHostSettings(const CarlaHost& host);
  280. //---------------------------------------------------------------------------------------------------------------------
  281. // Set Engine settings according to carla preferences. Returns selected audio driver.
  282. QString setEngineSettings(CarlaHost& host);
  283. //---------------------------------------------------------------------------------------------------------------------
  284. // Run Carla without showing UI
  285. void runHostWithoutUI(CarlaHost& host);
  286. //---------------------------------------------------------------------------------------------------------------------
  287. #endif // CARLA_HOST_HPP_INCLUDED