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.

371 lines
14KB

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