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.

385 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 preferPluginBridges;
  62. bool preferUIBridges;
  63. bool preventBadBehaviour;
  64. bool showLogs;
  65. bool showPluginBridges;
  66. bool showWineBridges;
  67. bool uiBridgesTimeout;
  68. bool uisAlwaysOnTop;
  69. // settings
  70. QString pathBinaries;
  71. QString pathResources;
  72. CarlaHost();
  73. signals:
  74. void SignalTerminate();
  75. void SignalSave();
  76. // Engine stuff
  77. void EngineStartedCallback(uint, int, int, uint, float, QString);
  78. void EngineStoppedCallback();
  79. private:
  80. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaHost)
  81. };
  82. //---------------------------------------------------------------------------------------------------------------------
  83. // Host Window
  84. class CarlaHostWindow : public QMainWindow,
  85. public PluginEditParentMeta
  86. {
  87. Q_OBJECT
  88. public:
  89. //-----------------------------------------------------------------------------------------------------------------
  90. CarlaHostWindow(CarlaHost& host, const bool withCanvas, QWidget* const parent = nullptr);
  91. ~CarlaHostWindow() override;
  92. private:
  93. struct PrivateData;
  94. PrivateData* const self;
  95. protected:
  96. //-----------------------------------------------------------------------------------------------------------------
  97. // Plugin Editor Parent
  98. void editDialogVisibilityChanged(int pluginId, bool visible) override;
  99. void editDialogPluginHintsChanged(int pluginId, int hints) override;
  100. void editDialogParameterValueChanged(int pluginId, int parameterId, float value) override;
  101. void editDialogProgramChanged(int pluginId, int index) override;
  102. void editDialogMidiProgramChanged(int pluginId, int index) override;
  103. void editDialogNotePressed(int pluginId, int note) override;
  104. void editDialogNoteReleased(int pluginId, int note) override;
  105. void editDialogMidiActivityChanged(int pluginId, bool onOff) override;
  106. //-----------------------------------------------------------------------------------------------------------------
  107. // show/hide event
  108. void showEvent(QShowEvent* event) override;
  109. void hideEvent(QHideEvent* event) override;
  110. //-----------------------------------------------------------------------------------------------------------------
  111. // resize event
  112. void resizeEvent(QResizeEvent* event) override;
  113. //-----------------------------------------------------------------------------------------------------------------
  114. // timer event
  115. void timerEvent(QTimerEvent* event) override;
  116. //-----------------------------------------------------------------------------------------------------------------
  117. // color/style change event
  118. void changeEvent(QEvent* event) override;
  119. //-----------------------------------------------------------------------------------------------------------------
  120. // close event
  121. void closeEvent(QCloseEvent* event) override;
  122. private slots:
  123. //-----------------------------------------------------------------------------------------------------------------
  124. // Files (menu actions)
  125. void slot_fileNew();
  126. void slot_fileOpen();
  127. void slot_fileSave(bool saveAs = false);
  128. void slot_fileSaveAs();
  129. void slot_loadProjectNow();
  130. //-----------------------------------------------------------------------------------------------------------------
  131. // Engine (menu actions)
  132. void slot_engineStart();
  133. bool slot_engineStop(bool forced = false);
  134. void slot_engineConfig();
  135. bool slot_engineStopTryAgain();
  136. //-----------------------------------------------------------------------------------------------------------------
  137. // Engine (host callbacks)
  138. void slot_handleEngineStartedCallback(uint pluginCount, int processMode, int transportMode, uint bufferSize, float sampleRate, QString driverName);
  139. void slot_handleEngineStoppedCallback();
  140. void slot_handleTransportModeChangedCallback(int transportMode, QString transportExtra);
  141. void slot_handleBufferSizeChangedCallback(int newBufferSize);
  142. void slot_handleSampleRateChangedCallback(double newSampleRate);
  143. void slot_handleCancelableActionCallback(int pluginId, bool started, QString action);
  144. void slot_canlableActionBoxClicked();
  145. void slot_handleProjectLoadFinishedCallback();
  146. //-----------------------------------------------------------------------------------------------------------------
  147. // Plugins (menu actions)
  148. void slot_favoritePluginAdd();
  149. void slot_showPluginActionsMenu();
  150. void slot_pluginAdd();
  151. void slot_confirmRemoveAll();
  152. void slot_jackAppAdd();
  153. //-----------------------------------------------------------------------------------------------------------------
  154. // Plugins (macros)
  155. void slot_pluginsEnable();
  156. void slot_pluginsDisable();
  157. void slot_pluginsVolume100();
  158. void slot_pluginsMute();
  159. void slot_pluginsWet100();
  160. void slot_pluginsBypass();
  161. void slot_pluginsCenter();
  162. void slot_pluginsCompact();
  163. void slot_pluginsExpand();
  164. //-----------------------------------------------------------------------------------------------------------------
  165. // Plugins (host callbacks)
  166. void slot_handlePluginAddedCallback(int pluginId, QString pluginName);
  167. void slot_handlePluginRemovedCallback(int pluginId);
  168. //-----------------------------------------------------------------------------------------------------------------
  169. // Canvas (menu actions)
  170. void slot_canvasShowInternal();
  171. void slot_canvasShowExternal();
  172. void slot_canvasArrange();
  173. void slot_canvasRefresh();
  174. void slot_canvasZoomFit();
  175. void slot_canvasZoomIn();
  176. void slot_canvasZoomOut();
  177. void slot_canvasZoomReset();
  178. void slot_canvasSaveImage();
  179. //-----------------------------------------------------------------------------------------------------------------
  180. // Canvas (canvas callbacks)
  181. void slot_canvasItemMoved(int group_id, int split_mode, QPointF pos);
  182. void slot_canvasSelectionChanged();
  183. void slot_canvasScaleChanged(double scale);
  184. void slot_canvasPluginSelected(QList<void*> pluginList);
  185. //-----------------------------------------------------------------------------------------------------------------
  186. // Canvas (host callbacks)
  187. void slot_handlePatchbayClientAddedCallback(int clientId, int clientIcon, int pluginId, QString clientName);
  188. void slot_handlePatchbayClientRemovedCallback(int clientId);
  189. void slot_handlePatchbayClientRenamedCallback(int clientId, QString newClientName);
  190. void slot_handlePatchbayClientDataChangedCallback(int clientId, int clientIcon, int pluginId);
  191. void slot_handlePatchbayPortAddedCallback(int clientId, int portId, int portFlags, int portGroupId, QString portName);
  192. void slot_handlePatchbayPortRemovedCallback(int groupId, int portId);
  193. void slot_handlePatchbayPortChangedCallback(int groupId, int portId, int portFlags, int portGroupId, QString newPortName);
  194. void slot_handlePatchbayPortGroupAddedCallback(int groupId, int portId, int portGroupId, QString newPortName);
  195. void slot_handlePatchbayPortGroupRemovedCallback(int groupId, int portId);
  196. void slot_handlePatchbayPortGroupChangedCallback(int groupId, int portId, int portGroupId, QString newPortName);
  197. void slot_handlePatchbayConnectionAddedCallback(int connectionId, int groupOutId, int portOutId, int groupInId, int portInId);
  198. void slot_handlePatchbayConnectionRemovedCallback(int connectionId, int portOutId, int portInId);
  199. //-----------------------------------------------------------------------------------------------------------------
  200. // Settings (helpers)
  201. void slot_restoreCanvasScrollbarValues();
  202. //-----------------------------------------------------------------------------------------------------------------
  203. // Settings (menu actions)
  204. void slot_showSidePanel(bool yesNo);
  205. void slot_showToolbar(bool yesNo);
  206. void slot_showCanvasMeters(bool yesNo);
  207. void slot_showCanvasKeyboard(bool yesNo);
  208. void slot_configureCarla();
  209. //-----------------------------------------------------------------------------------------------------------------
  210. // About (menu actions)
  211. void slot_aboutCarla();
  212. void slot_aboutJuce();
  213. void slot_aboutQt();
  214. //-----------------------------------------------------------------------------------------------------------------
  215. // Disk (menu actions)
  216. void slot_diskFolderChanged(int index);
  217. void slot_diskFolderAdd();
  218. void slot_diskFolderRemove();
  219. void slot_fileTreeDoubleClicked(QModelIndex* modelIndex);
  220. //-----------------------------------------------------------------------------------------------------------------
  221. // Transport (menu actions)
  222. void slot_transportPlayPause(bool toggled);
  223. void slot_transportStop();
  224. void slot_transportBackwards();
  225. void slot_transportBpmChanged(qreal newValue);
  226. void slot_transportForwards();
  227. void slot_transportJackEnabled(bool clicked);
  228. void slot_transportLinkEnabled(bool clicked);
  229. //-----------------------------------------------------------------------------------------------------------------
  230. // Other
  231. void slot_xrunClear();
  232. //-----------------------------------------------------------------------------------------------------------------
  233. // Canvas scrollbars
  234. void slot_horizontalScrollBarChanged(int value);
  235. void slot_verticalScrollBarChanged(int value);
  236. //-----------------------------------------------------------------------------------------------------------------
  237. // Canvas keyboard
  238. void slot_noteOn(int note);
  239. void slot_noteOff(int note);
  240. //-----------------------------------------------------------------------------------------------------------------
  241. // Canvas keyboard (host callbacks)
  242. void slot_handleNoteOnCallback(int pluginId, int channel, int note, int velocity);
  243. void slot_handleNoteOffCallback(int pluginId, int channel, int note);
  244. //-----------------------------------------------------------------------------------------------------------------
  245. void slot_handleUpdateCallback(int pluginId);
  246. //-----------------------------------------------------------------------------------------------------------------
  247. // MiniCanvas stuff
  248. void slot_miniCanvasCheckAll();
  249. void slot_miniCanvasCheckSize();
  250. void slot_miniCanvasMoved(qreal xp, qreal yp);
  251. //-----------------------------------------------------------------------------------------------------------------
  252. // Misc
  253. void slot_tabChanged(int index);
  254. void slot_handleReloadAllCallback(int pluginId);
  255. //-----------------------------------------------------------------------------------------------------------------
  256. void slot_handleNSMCallback(int opcode, int valueInt, QString valueStr);
  257. //-----------------------------------------------------------------------------------------------------------------
  258. void slot_handleDebugCallback(int pluginId, int value1, int value2, int value3, float valuef, QString valueStr);
  259. void slot_handleInfoCallback(QString info);
  260. void slot_handleErrorCallback(QString error);
  261. void slot_handleQuitCallback();
  262. void slot_handleInlineDisplayRedrawCallback(int pluginId);
  263. //-----------------------------------------------------------------------------------------------------------------
  264. void slot_handleSIGUSR1();
  265. void slot_handleSIGTERM();
  266. //-----------------------------------------------------------------------------------------------------------------
  267. private:
  268. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaHostWindow)
  269. };
  270. //---------------------------------------------------------------------------------------------------------------------
  271. // Init host
  272. CarlaHost& initHost(const QString initName, const bool isControl, const bool isPlugin, const bool failError);
  273. //---------------------------------------------------------------------------------------------------------------------
  274. // Load host settings
  275. void loadHostSettings(CarlaHost& host);
  276. //---------------------------------------------------------------------------------------------------------------------
  277. // Set host settings
  278. void setHostSettings(const CarlaHost& host);
  279. //---------------------------------------------------------------------------------------------------------------------
  280. // Set Engine settings according to carla preferences. Returns selected audio driver.
  281. QString setEngineSettings(CarlaHost& host);
  282. //---------------------------------------------------------------------------------------------------------------------
  283. // Run Carla without showing UI
  284. void runHostWithoutUI(CarlaHost& host);
  285. //---------------------------------------------------------------------------------------------------------------------
  286. #endif // CARLA_HOST_HPP_INCLUDED