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.

carla_host.hpp 15KB

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