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.

2994 lines
115KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2018 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. import json
  23. if config_UseQt5:
  24. from PyQt5.QtCore import qCritical, QEventLoop, QFileInfo, QModelIndex, QPointF, QTimer
  25. from PyQt5.QtGui import QImage, QPalette
  26. from PyQt5.QtWidgets import QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QMainWindow
  27. else:
  28. from PyQt4.QtCore import qCritical, QEventLoop, QFileInfo, QModelIndex, QPointF, QTimer
  29. from PyQt4.QtGui import QImage, QPalette
  30. from PyQt4.QtGui import QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QMainWindow
  31. # ------------------------------------------------------------------------------------------------------------
  32. # Imports (Custom)
  33. import patchcanvas
  34. import ui_carla_host
  35. from carla_app import *
  36. from carla_database import *
  37. from carla_settings import *
  38. from carla_utils import *
  39. from carla_widgets import *
  40. from widgets.digitalpeakmeter import DigitalPeakMeter
  41. from widgets.pixmapkeyboard import PixmapKeyboardHArea
  42. # ------------------------------------------------------------------------------------------------------------
  43. # Try Import OpenGL
  44. try:
  45. if config_UseQt5:
  46. from PyQt5.QtOpenGL import QGLWidget
  47. else:
  48. from PyQt4.QtOpenGL import QGLWidget
  49. hasGL = True
  50. except:
  51. hasGL = False
  52. # ------------------------------------------------------------------------------------------------------------
  53. # Safe exception hook, needed for PyQt5
  54. def sys_excepthook(typ, value, tback):
  55. return sys.__excepthook__(typ, value, tback)
  56. # ------------------------------------------------------------------------------------------------------------
  57. # Session Management support
  58. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  59. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  60. NSM_URL = os.getenv("NSM_URL")
  61. # ------------------------------------------------------------------------------------------------------------
  62. # Small print helper
  63. def processMode2Str(processMode):
  64. if processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  65. return "Single client"
  66. if processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  67. return "Multi client"
  68. if processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  69. return "Continuous Rack"
  70. if processMode == ENGINE_PROCESS_MODE_PATCHBAY:
  71. return "Patchbay"
  72. if processMode == ENGINE_PROCESS_MODE_BRIDGE:
  73. return "Bridge"
  74. return "Unknown"
  75. # ------------------------------------------------------------------------------------------------------------
  76. # Carla Print class
  77. class CarlaPrint:
  78. def __init__(self, err):
  79. self.err = err
  80. def flush(self):
  81. gCarla.utils.fflush(self.err)
  82. def write(self, string):
  83. gCarla.utils.fputs(self.err, string)
  84. # ------------------------------------------------------------------------------------------------------------
  85. # Host Window
  86. class HostWindow(QMainWindow):
  87. #class HostWindow(QMainWindow, PluginEditParentMeta, metaclass=PyQtMetaClass):
  88. # signals
  89. SIGTERM = pyqtSignal()
  90. SIGUSR1 = pyqtSignal()
  91. # CustomActions
  92. CUSTOM_ACTION_NONE = 0
  93. CUSTOM_ACTION_APP_CLOSE = 1
  94. CUSTOM_ACTION_PROJECT_LOAD = 2
  95. # --------------------------------------------------------------------------------------------------------
  96. def __init__(self, host, withCanvas, parent=None):
  97. QMainWindow.__init__(self, parent)
  98. self.host = host
  99. self.ui = ui_carla_host.Ui_CarlaHostW()
  100. self.ui.setupUi(self)
  101. gCarla.gui = self
  102. if False:
  103. # kdevelop likes this :)
  104. host = CarlaHostNull()
  105. self.host = host
  106. self._true = c_char_p("true".encode("utf-8"))
  107. self.fParentOrSelf = parent or self
  108. # ----------------------------------------------------------------------------------------------------
  109. # Internal stuff
  110. self.fIdleTimerFast = 0
  111. self.fIdleTimerSlow = 0
  112. self.fLadspaRdfNeedsUpdate = True
  113. self.fLadspaRdfList = []
  114. self.fPluginCount = 0
  115. self.fPluginList = []
  116. self.fProjectFilename = ""
  117. self.fIsProjectLoading = False
  118. self.fCurrentlyRemovingAllPlugins = False
  119. self.fLastTransportBPM = 0.0
  120. self.fLastTransportFrame = 0
  121. self.fLastTransportState = False
  122. self.fSampleRate = 0.0
  123. if MACOS:
  124. self.fMacClosingHelper = True
  125. # run a custom action after engine is properly closed
  126. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  127. # first attempt of auto-start engine doesn't show an error
  128. self.fFirstEngineInit = True
  129. # to be filled with key-value pairs of current settings
  130. self.fSavedSettings = {}
  131. if host.isControl:
  132. self.fClientName = "Carla-Control"
  133. self.fSessionManagerName = "Control"
  134. elif host.isPlugin:
  135. self.fClientName = "Carla-Plugin"
  136. self.fSessionManagerName = "Plugin"
  137. elif LADISH_APP_NAME:
  138. self.fClientName = LADISH_APP_NAME
  139. self.fSessionManagerName = "LADISH"
  140. elif NSM_URL and host.nsmOK:
  141. self.fClientName = "Carla.tmp"
  142. self.fSessionManagerName = "Non Session Manager TMP"
  143. else:
  144. self.fClientName = CARLA_CLIENT_NAME or "Carla"
  145. self.fSessionManagerName = ""
  146. # ----------------------------------------------------------------------------------------------------
  147. # Internal stuff (patchbay)
  148. self.fExportImage = QImage()
  149. self.fPeaksCleared = True
  150. self.fExternalPatchbay = False
  151. self.fSelectedPlugins = []
  152. self.fCanvasWidth = 0
  153. self.fCanvasHeight = 0
  154. self.fMiniCanvasUpdateTimeout = 0
  155. self.fWithCanvas = withCanvas
  156. # ----------------------------------------------------------------------------------------------------
  157. # Set up GUI (engine stopped)
  158. if self.host.isPlugin or self.host.isControl:
  159. self.ui.act_file_save.setVisible(False)
  160. self.ui.act_engine_start.setEnabled(False)
  161. self.ui.act_engine_start.setVisible(False)
  162. self.ui.act_engine_stop.setEnabled(False)
  163. self.ui.act_engine_stop.setVisible(False)
  164. self.ui.menu_Engine.setEnabled(False)
  165. self.ui.menu_Engine.setVisible(False)
  166. self.ui.menu_Engine.menuAction().setVisible(False)
  167. self.ui.tabWidget.removeTab(2)
  168. if self.host.isControl:
  169. self.ui.act_file_new.setVisible(False)
  170. self.ui.act_file_open.setVisible(False)
  171. self.ui.act_file_save.setVisible(False)
  172. self.ui.act_file_save_as.setVisible(False)
  173. self.ui.act_plugin_add.setVisible(False)
  174. self.ui.act_plugin_add2.setVisible(False)
  175. self.ui.act_plugin_remove_all.setVisible(False)
  176. self.ui.act_add_jack.setVisible(False)
  177. self.ui.menu_Plugin.setEnabled(False)
  178. self.ui.menu_Plugin.setVisible(False)
  179. self.ui.menu_Plugin.menuAction().setVisible(False)
  180. else:
  181. self.ui.act_file_save_as.setText(self.tr("Export as..."))
  182. else:
  183. self.ui.act_engine_start.setEnabled(True)
  184. if WINDOWS:
  185. self.ui.tabWidget.removeTab(2)
  186. if not self.host.isControl:
  187. self.ui.act_file_connect.setEnabled(False)
  188. self.ui.act_file_connect.setVisible(False)
  189. self.ui.act_file_refresh.setEnabled(False)
  190. self.ui.act_file_refresh.setVisible(False)
  191. if self.fSessionManagerName and not self.host.isPlugin:
  192. self.ui.act_file_new.setEnabled(False)
  193. self.ui.act_file_open.setEnabled(False)
  194. self.ui.act_file_save.setEnabled(False)
  195. self.ui.act_file_save_as.setEnabled(False)
  196. self.ui.act_engine_stop.setEnabled(False)
  197. self.ui.act_plugin_remove_all.setEnabled(False)
  198. self.ui.act_canvas_show_internal.setChecked(False)
  199. self.ui.act_canvas_show_internal.setVisible(False)
  200. self.ui.act_canvas_show_external.setChecked(False)
  201. self.ui.act_canvas_show_external.setVisible(False)
  202. self.ui.menu_PluginMacros.setEnabled(False)
  203. self.ui.menu_Canvas.setEnabled(False)
  204. self.ui.dockWidgetTitleBar = QWidget(self)
  205. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  206. if not withCanvas:
  207. self.ui.act_canvas_show_internal.setVisible(False)
  208. self.ui.act_canvas_show_external.setVisible(False)
  209. self.ui.act_canvas_arrange.setVisible(False)
  210. self.ui.act_canvas_refresh.setVisible(False)
  211. self.ui.act_canvas_save_image.setVisible(False)
  212. self.ui.act_canvas_zoom_100.setVisible(False)
  213. self.ui.act_canvas_zoom_fit.setVisible(False)
  214. self.ui.act_canvas_zoom_in.setVisible(False)
  215. self.ui.act_canvas_zoom_out.setVisible(False)
  216. self.ui.act_settings_show_meters.setVisible(False)
  217. self.ui.act_settings_show_keyboard.setVisible(False)
  218. self.ui.menu_Canvas_Zoom.setEnabled(False)
  219. self.ui.menu_Canvas_Zoom.setVisible(False)
  220. self.ui.menu_Canvas_Zoom.menuAction().setVisible(False)
  221. self.ui.menu_Canvas.setEnabled(False)
  222. self.ui.menu_Canvas.setVisible(False)
  223. self.ui.menu_Canvas.menuAction().setVisible(False)
  224. self.ui.miniCanvasPreview.hide()
  225. self.ui.tabWidget.removeTab(1)
  226. if WINDOWS:
  227. self.ui.tabWidget.tabBar().hide()
  228. if host.isControl:
  229. self.ui.dockWidget.hide()
  230. # ----------------------------------------------------------------------------------------------------
  231. # Set up GUI (disk)
  232. exts = gCarla.utils.get_supported_file_extensions()
  233. self.fDirModel = QFileSystemModel(self)
  234. self.fDirModel.setRootPath(HOME)
  235. self.fDirModel.setNameFilters(tuple(("*." + i) for i in exts))
  236. self.ui.fileTreeView.setModel(self.fDirModel)
  237. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  238. self.ui.fileTreeView.setColumnHidden(1, True)
  239. self.ui.fileTreeView.setColumnHidden(2, True)
  240. self.ui.fileTreeView.setColumnHidden(3, True)
  241. self.ui.fileTreeView.setHeaderHidden(True)
  242. # ----------------------------------------------------------------------------------------------------
  243. # Set up GUI (transport)
  244. fontMetrics = QFontMetrics(self.ui.l_transport_bbt.font())
  245. minValueWidth = fontMetrics.width("000|00|0000")
  246. minLabelWidth = fontMetrics.width(self.ui.label_transport_frame.text())
  247. labelTimeWidth = fontMetrics.width(self.ui.label_transport_time.text())
  248. labelBBTWidth = fontMetrics.width(self.ui.label_transport_bbt.text())
  249. if minLabelWidth < labelTimeWidth:
  250. minLabelWidth = labelTimeWidth
  251. if minLabelWidth < labelBBTWidth:
  252. minLabelWidth = labelBBTWidth
  253. self.ui.label_transport_frame.setMinimumWidth(minLabelWidth + 3)
  254. self.ui.label_transport_time.setMinimumWidth(minLabelWidth + 3)
  255. self.ui.label_transport_bbt.setMinimumWidth(minLabelWidth + 3)
  256. self.ui.l_transport_bbt.setMinimumWidth(minValueWidth + 3)
  257. self.ui.l_transport_frame.setMinimumWidth(minValueWidth + 3)
  258. self.ui.l_transport_time.setMinimumWidth(minValueWidth + 3)
  259. if host.isControl or host.isPlugin:
  260. self.ui.b_transport_play.setEnabled(False)
  261. self.ui.b_transport_stop.setEnabled(False)
  262. self.ui.b_transport_backwards.setEnabled(False)
  263. self.ui.b_transport_forwards.setEnabled(False)
  264. self.ui.group_transport_controls.setEnabled(False)
  265. self.ui.group_transport_controls.setVisible(False)
  266. self.ui.cb_transport_link.setEnabled(False)
  267. self.ui.cb_transport_link.setVisible(False)
  268. self.ui.cb_transport_jack.setEnabled(False)
  269. self.ui.cb_transport_jack.setVisible(False)
  270. self.ui.dsb_transport_bpm.setEnabled(False)
  271. self.ui.dsb_transport_bpm.setReadOnly(True)
  272. self.ui.w_transport.setEnabled(False)
  273. # ----------------------------------------------------------------------------------------------------
  274. # Set up GUI (rack)
  275. self.ui.listWidget.setHostAndParent(self.host, self)
  276. sb = self.ui.listWidget.verticalScrollBar()
  277. self.ui.rackScrollBar.setMinimum(sb.minimum())
  278. self.ui.rackScrollBar.setMaximum(sb.maximum())
  279. self.ui.rackScrollBar.setValue(sb.value())
  280. sb.rangeChanged.connect(self.ui.rackScrollBar.setRange)
  281. sb.valueChanged.connect(self.ui.rackScrollBar.setValue)
  282. self.ui.rackScrollBar.rangeChanged.connect(sb.setRange)
  283. self.ui.rackScrollBar.valueChanged.connect(sb.setValue)
  284. self.ui.rack.setStyleSheet("""
  285. QLabel#pad_left {
  286. background-image: url(:/bitmaps/rack_padding_left.png);
  287. background-repeat: repeat-y;
  288. }
  289. QLabel#pad_right {
  290. background-image: url(:/bitmaps/rack_padding_right.png);
  291. background-repeat: repeat-y;
  292. }
  293. CarlaRackList#CarlaRackList {
  294. background-color: black;
  295. }
  296. """)
  297. # ----------------------------------------------------------------------------------------------------
  298. # Set up GUI (patchbay)
  299. self.ui.peak_in.setChannelCount(2)
  300. self.ui.peak_in.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  301. self.ui.peak_in.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  302. self.ui.peak_in.setFixedWidth(25)
  303. self.ui.peak_out.setChannelCount(2)
  304. self.ui.peak_out.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  305. self.ui.peak_out.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  306. self.ui.peak_out.setFixedWidth(25)
  307. self.ui.scrollArea = PixmapKeyboardHArea(self.ui.patchbay)
  308. self.ui.keyboard = self.ui.scrollArea.keyboard
  309. self.ui.patchbay.layout().addWidget(self.ui.scrollArea, 1, 0, 1, 0)
  310. self.ui.scrollArea.setEnabled(False)
  311. self.ui.miniCanvasPreview.setRealParent(self)
  312. # ----------------------------------------------------------------------------------------------------
  313. # Set up GUI (special stuff for Mac OS)
  314. if MACOS:
  315. self.ui.act_file_quit.setMenuRole(QAction.QuitRole)
  316. self.ui.act_settings_configure.setMenuRole(QAction.PreferencesRole)
  317. self.ui.act_help_about.setMenuRole(QAction.AboutRole)
  318. self.ui.act_help_about_qt.setMenuRole(QAction.AboutQtRole)
  319. self.ui.menu_Settings.setTitle("Panels")
  320. self.ui.menu_Help.menuAction().setVisible(False)
  321. # ----------------------------------------------------------------------------------------------------
  322. # Load Settings
  323. self.loadSettings(True)
  324. # ----------------------------------------------------------------------------------------------------
  325. # Set-up Canvas
  326. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  327. self.ui.graphicsView.setScene(self.scene)
  328. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, bool(self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  329. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  330. self.ui.glView = QGLWidget(self)
  331. self.ui.graphicsView.setViewport(self.ui.glView)
  332. self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  333. self.setupCanvas()
  334. # ----------------------------------------------------------------------------------------------------
  335. # Connect actions to functions
  336. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  337. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  338. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  339. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  340. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  341. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  342. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  343. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  344. self.ui.act_plugin_remove_all.triggered.connect(self.slot_confirmRemoveAll)
  345. self.ui.act_add_jack.triggered.connect(self.slot_jackAppAdd)
  346. self.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  347. self.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  348. self.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  349. self.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  350. self.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  351. self.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  352. self.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  353. self.ui.act_plugins_compact.triggered.connect(self.slot_pluginsCompact)
  354. self.ui.act_plugins_expand.triggered.connect(self.slot_pluginsExpand)
  355. self.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  356. self.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  357. self.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  358. self.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  359. self.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  360. self.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  361. self.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  362. self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  363. self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  364. self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  365. self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  366. self.ui.act_settings_show_toolbar.toggled.connect(self.slot_showToolbar)
  367. self.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  368. self.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  369. self.ui.act_settings_show_side_panel.toggled.connect(self.slot_showSidePanel)
  370. self.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  371. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  372. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  373. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  374. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  375. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  376. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  377. self.ui.b_transport_play.clicked.connect(self.slot_transportPlayPause)
  378. self.ui.b_transport_stop.clicked.connect(self.slot_transportStop)
  379. self.ui.b_transport_backwards.clicked.connect(self.slot_transportBackwards)
  380. self.ui.b_transport_forwards.clicked.connect(self.slot_transportForwards)
  381. self.ui.dsb_transport_bpm.valueChanged.connect(self.slot_transportBpmChanged)
  382. self.ui.cb_transport_jack.clicked.connect(self.slot_transportJackEnabled)
  383. self.ui.cb_transport_link.clicked.connect(self.slot_transportLinkEnabled)
  384. self.ui.listWidget.customContextMenuRequested.connect(self.showPluginActionsMenu)
  385. self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  386. self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  387. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  388. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  389. self.ui.miniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  390. self.ui.tabWidget.currentChanged.connect(self.slot_tabChanged)
  391. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  392. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  393. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  394. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  395. self.SIGTERM.connect(self.slot_handleSIGTERM)
  396. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  397. host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  398. host.TransportModeChangedCallback.connect(self.slot_handleTransportModeChangedCallback)
  399. host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  400. host.ProjectLoadFinishedCallback.connect(self.slot_handleProjectLoadFinishedCallback)
  401. host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  402. host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  403. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  404. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  405. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  406. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  407. host.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  408. host.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  409. host.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  410. host.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  411. host.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  412. host.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  413. host.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  414. host.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  415. host.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  416. host.NSMCallback.connect(self.slot_handleNSMCallback)
  417. host.DebugCallback.connect(self.slot_handleDebugCallback)
  418. host.InfoCallback.connect(self.slot_handleInfoCallback)
  419. host.ErrorCallback.connect(self.slot_handleErrorCallback)
  420. host.QuitCallback.connect(self.slot_handleQuitCallback)
  421. # ----------------------------------------------------------------------------------------------------
  422. # Final setup
  423. self.ui.text_logs.clear()
  424. self.setProperWindowTitle()
  425. # Disable non-supported features
  426. features = gCarla.utils.get_supported_features()
  427. if "link" not in features:
  428. self.ui.cb_transport_link.setEnabled(False)
  429. self.ui.cb_transport_link.setVisible(False)
  430. # Plugin needs to have timers always running so it receives messages
  431. if self.host.isPlugin or self.host.isRemote:
  432. self.startTimers()
  433. # Qt needs this so it properly creates & resizes the canvas
  434. self.ui.tabWidget.blockSignals(True)
  435. self.ui.tabWidget.setCurrentIndex(1)
  436. self.ui.tabWidget.setCurrentIndex(0)
  437. self.ui.tabWidget.blockSignals(False)
  438. # Start in patchbay tab if using forced patchbay mode
  439. if host.processModeForced and host.processMode == ENGINE_PROCESS_MODE_PATCHBAY and not host.isControl:
  440. self.ui.tabWidget.setCurrentIndex(1)
  441. # Load initial project file if set
  442. if not (self.host.isControl or self.host.isPlugin):
  443. projectFile = getInitialProjectFile(QApplication.instance())
  444. if projectFile:
  445. self.loadProjectLater(projectFile)
  446. # For NSM we wait for the open message
  447. if NSM_URL and host.nsmOK:
  448. host.nsm_ready(-1)
  449. return
  450. QTimer.singleShot(0, self.slot_engineStart)
  451. # --------------------------------------------------------------------------------------------------------
  452. # Setup
  453. def compactPlugin(self, pluginId):
  454. if pluginId > self.fPluginCount:
  455. return
  456. pitem = self.fPluginList[pluginId]
  457. if pitem is None:
  458. return
  459. pitem.recreateWidget(True)
  460. def changePluginColor(self, pluginId, color, colorStr):
  461. if pluginId > self.fPluginCount:
  462. return
  463. pitem = self.fPluginList[pluginId]
  464. if pitem is None:
  465. return
  466. self.host.set_custom_data(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaColor", colorStr)
  467. pitem.recreateWidget(newColor = color)
  468. def changePluginSkin(self, pluginId, skin):
  469. if pluginId > self.fPluginCount:
  470. return
  471. pitem = self.fPluginList[pluginId]
  472. if pitem is None:
  473. return
  474. self.host.set_custom_data(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkin", skin)
  475. pitem.recreateWidget(newSkin = skin)
  476. def switchPlugins(self, pluginIdA, pluginIdB):
  477. if pluginIdA == pluginIdB:
  478. return
  479. if pluginIdA < 0 or pluginIdB < 0:
  480. return
  481. if pluginIdA >= self.fPluginCount or pluginIdB >= self.fPluginCount:
  482. return
  483. self.host.switch_plugins(pluginIdA, pluginIdB)
  484. itemA = self.fPluginList[pluginIdA]
  485. compactA = itemA.isCompacted()
  486. guiShownA = itemA.isGuiShown()
  487. itemB = self.fPluginList[pluginIdB]
  488. compactB = itemB.isCompacted()
  489. guiShownB = itemB.isGuiShown()
  490. itemA.setPluginId(pluginIdA)
  491. itemA.recreateWidget2(compactB, guiShownB)
  492. itemB.setPluginId(pluginIdB)
  493. itemB.recreateWidget2(compactA, guiShownA)
  494. self.slot_canvasRefresh()
  495. def setLoadRDFsNeeded(self):
  496. self.fLadspaRdfNeedsUpdate = True
  497. def setProperWindowTitle(self):
  498. title = self.fClientName
  499. if self.fProjectFilename and not self.host.nsmOK:
  500. title += " - %s" % os.path.basename(self.fProjectFilename)
  501. if self.fSessionManagerName:
  502. title += " (%s)" % self.fSessionManagerName
  503. self.setWindowTitle(title)
  504. # --------------------------------------------------------------------------------------------------------
  505. # Files
  506. def makeExtraFilename(self):
  507. return self.fProjectFilename.rsplit(".",1)[0]+".json"
  508. def loadProjectNow(self):
  509. if not self.fProjectFilename:
  510. return qCritical("ERROR: loading project without filename set")
  511. if self.host.nsmOK and not os.path.exists(self.fProjectFilename):
  512. return
  513. self.projectLoadingStarted()
  514. self.fIsProjectLoading = True
  515. self.host.load_project(self.fProjectFilename)
  516. # Project finished loading is sent by engine
  517. def loadProjectLater(self, filename):
  518. self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
  519. self.setProperWindowTitle()
  520. QTimer.singleShot(1, self.slot_loadProjectNow)
  521. def saveProjectNow(self):
  522. if not self.fProjectFilename:
  523. return qCritical("ERROR: saving project without filename set")
  524. self.host.save_project(self.fProjectFilename)
  525. with open(self.makeExtraFilename(), 'w') as fh:
  526. json.dump({
  527. 'canvas': patchcanvas.saveGroupPositions(),
  528. }, fh)
  529. def projectLoadingStarted(self):
  530. self.ui.rack.setEnabled(False)
  531. self.ui.graphicsView.setEnabled(False)
  532. def projectLoadingFinished(self):
  533. self.ui.rack.setEnabled(True)
  534. self.ui.graphicsView.setEnabled(True)
  535. QTimer.singleShot(1000, self.slot_canvasRefresh)
  536. extrafile = self.makeExtraFilename()
  537. if not os.path.exists(extrafile):
  538. return
  539. try:
  540. with open(extrafile, "r") as fh:
  541. canvasdata = json.load(fh)['canvas']
  542. except:
  543. return
  544. patchcanvas.restoreGroupPositions(canvasdata)
  545. # --------------------------------------------------------------------------------------------------------
  546. # Files (menu actions)
  547. @pyqtSlot()
  548. def slot_fileNew(self):
  549. if self.fPluginCount > 0 and QMessageBox.question(self, self.tr("New File"),
  550. self.tr("Plugins that are currently loaded will be removed. Are you sure?"),
  551. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  552. return
  553. self.pluginRemoveAll()
  554. self.fProjectFilename = ""
  555. self.setProperWindowTitle()
  556. @pyqtSlot()
  557. def slot_fileOpen(self):
  558. fileFilter = self.tr("Carla Project File (*.carxp);;Carla Preset File (*.carxs)")
  559. filename = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  560. if config_UseQt5:
  561. filename = filename[0]
  562. if not filename:
  563. return
  564. newFile = True
  565. if self.fPluginCount > 0:
  566. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  567. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  568. newFile = (ask == QMessageBox.Yes)
  569. if newFile:
  570. self.pluginRemoveAll()
  571. self.fProjectFilename = filename
  572. self.setProperWindowTitle()
  573. self.loadProjectNow()
  574. else:
  575. filenameOld = self.fProjectFilename
  576. self.fProjectFilename = filename
  577. self.loadProjectNow()
  578. self.fProjectFilename = filenameOld
  579. @pyqtSlot()
  580. def slot_fileSave(self, saveAs=False):
  581. if self.fProjectFilename and not saveAs:
  582. return self.saveProjectNow()
  583. fileFilter = self.tr("Carla Project File (*.carxp)")
  584. filename = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  585. if config_UseQt5:
  586. filename = filename[0]
  587. if not filename:
  588. return
  589. if not filename.lower().endswith(".carxp"):
  590. filename += ".carxp"
  591. if self.fProjectFilename != filename:
  592. self.fProjectFilename = filename
  593. self.setProperWindowTitle()
  594. self.saveProjectNow()
  595. @pyqtSlot()
  596. def slot_fileSaveAs(self):
  597. self.slot_fileSave(True)
  598. @pyqtSlot()
  599. def slot_loadProjectNow(self):
  600. self.loadProjectNow()
  601. # --------------------------------------------------------------------------------------------------------
  602. # Engine (menu actions)
  603. @pyqtSlot()
  604. def slot_engineStart(self):
  605. audioDriver = setEngineSettings(self.host)
  606. firstInit = self.fFirstEngineInit
  607. self.fFirstEngineInit = False
  608. self.ui.text_logs.appendPlainText("======= Starting engine =======")
  609. if self.host.engine_init(audioDriver, self.fClientName):
  610. if firstInit and not (self.host.isControl or self.host.isPlugin):
  611. settings = QSettings()
  612. lastBpm = settings.value("LastBPM", 120.0, type=float)
  613. del settings
  614. self.host.transport_bpm(lastBpm)
  615. return
  616. elif firstInit:
  617. self.ui.text_logs.appendPlainText("Failed to start engine on first try, ignored")
  618. return
  619. audioError = self.host.get_last_error()
  620. if audioError:
  621. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  622. else:
  623. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  624. @pyqtSlot()
  625. def slot_engineStop(self, forced = False):
  626. self.ui.text_logs.appendPlainText("======= Stopping engine =======")
  627. if self.fPluginCount == 0:
  628. self.engineStopFinal()
  629. return True
  630. if not forced:
  631. ask = QMessageBox.question(self, self.tr("Warning"), self.tr("There are still some plugins loaded, you need to remove them to stop the engine.\n"
  632. "Do you want to do this now?"),
  633. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  634. if ask != QMessageBox.Yes:
  635. return False
  636. return self.slot_engineStopTryAgain()
  637. @pyqtSlot()
  638. def slot_engineStopTryAgain(self):
  639. if self.host.is_engine_running() and not self.host.set_engine_about_to_close():
  640. QTimer.singleShot(0, self.slot_engineStopTryAgain)
  641. return False
  642. self.engineStopFinal()
  643. return True
  644. def engineStopFinal(self):
  645. self.killTimers()
  646. self.removeAllPlugins()
  647. if self.host.is_engine_running():
  648. self.host.remove_all_plugins()
  649. if not self.host.engine_close():
  650. self.ui.text_logs.appendPlainText("Failed to stop engine, error was:")
  651. self.ui.text_logs.appendPlainText(self.host.get_last_error())
  652. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  653. self.close()
  654. elif self.fCustomStopAction == self.CUSTOM_ACTION_PROJECT_LOAD:
  655. self.slot_engineStart()
  656. self.loadProjectNow()
  657. self.host.nsm_ready(2) # open
  658. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  659. # --------------------------------------------------------------------------------------------------------
  660. # Engine (host callbacks)
  661. @pyqtSlot(int, int, float, str)
  662. def slot_handleEngineStartedCallback(self, processMode, transportMode, sampleRate, driverName):
  663. self.fSampleRate = sampleRate
  664. self.ui.menu_PluginMacros.setEnabled(True)
  665. self.ui.menu_Canvas.setEnabled(True)
  666. self.ui.w_transport.setEnabled(True)
  667. self.ui.act_canvas_show_internal.blockSignals(True)
  668. self.ui.act_canvas_show_external.blockSignals(True)
  669. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and not (self.host.isControl or self.host.isPlugin):
  670. self.ui.act_canvas_show_internal.setChecked(True)
  671. self.ui.act_canvas_show_internal.setVisible(True)
  672. self.ui.act_canvas_show_external.setChecked(False)
  673. self.ui.act_canvas_show_external.setVisible(True)
  674. else:
  675. self.ui.act_canvas_show_internal.setChecked(False)
  676. self.ui.act_canvas_show_internal.setVisible(False)
  677. self.ui.act_canvas_show_external.setChecked(False)
  678. self.ui.act_canvas_show_external.setVisible(False)
  679. self.ui.act_canvas_show_internal.blockSignals(False)
  680. self.ui.act_canvas_show_external.blockSignals(False)
  681. if not (self.host.isControl or self.host.isPlugin):
  682. canSave = (self.fProjectFilename and os.path.exists(self.fProjectFilename)) or not self.fSessionManagerName
  683. self.ui.act_file_save.setEnabled(canSave)
  684. self.ui.act_engine_start.setEnabled(False)
  685. self.ui.act_engine_stop.setEnabled(True)
  686. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  687. if self.host.isPlugin or not self.fSessionManagerName:
  688. self.ui.act_file_open.setEnabled(True)
  689. self.ui.act_file_save_as.setEnabled(True)
  690. self.refreshTransport(True)
  691. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  692. self.ui.cb_transport_jack.setEnabled(driverName == "JACK" and processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  693. if self.ui.cb_transport_link.isEnabled():
  694. self.ui.cb_transport_link.setChecked(":link:" in self.host.transportExtra)
  695. self.startTimers()
  696. self.ui.text_logs.appendPlainText("======= Engine started ========")
  697. self.ui.text_logs.appendPlainText("Carla engine started, details:")
  698. self.ui.text_logs.appendPlainText(" Driver name: %s" % driverName)
  699. self.ui.text_logs.appendPlainText(" Sample rate: %.1f" % sampleRate)
  700. self.ui.text_logs.appendPlainText(" Process mode: %s" % processMode2Str(processMode))
  701. @pyqtSlot()
  702. def slot_handleEngineStoppedCallback(self):
  703. self.ui.text_logs.appendPlainText("======= Engine stopped ========")
  704. patchcanvas.clear()
  705. self.killTimers()
  706. # just in case
  707. self.removeAllPlugins()
  708. self.ui.menu_PluginMacros.setEnabled(False)
  709. self.ui.menu_Canvas.setEnabled(False)
  710. self.ui.w_transport.setEnabled(False)
  711. if not (self.host.isControl or self.host.isPlugin):
  712. self.ui.act_file_save.setEnabled(False)
  713. self.ui.act_engine_start.setEnabled(True)
  714. self.ui.act_engine_stop.setEnabled(False)
  715. if self.host.isPlugin or not self.fSessionManagerName:
  716. self.ui.act_file_open.setEnabled(False)
  717. self.ui.act_file_save_as.setEnabled(False)
  718. @pyqtSlot(int, str)
  719. def slot_handleTransportModeChangedCallback(self, transportMode, transportExtra):
  720. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  721. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  722. self.ui.cb_transport_link.setChecked(":link:" in transportExtra)
  723. @pyqtSlot(float)
  724. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  725. self.fSampleRate = newSampleRate
  726. self.refreshTransport(True)
  727. @pyqtSlot()
  728. def slot_handleProjectLoadFinishedCallback(self):
  729. self.fIsProjectLoading = False
  730. self.projectLoadingFinished()
  731. # --------------------------------------------------------------------------------------------------------
  732. # Plugins
  733. def removeAllPlugins(self):
  734. self.ui.act_plugin_remove_all.setEnabled(False)
  735. patchcanvas.handleAllPluginsRemoved()
  736. while self.ui.listWidget.takeItem(0):
  737. pass
  738. self.clearSideStuff()
  739. for pitem in self.fPluginList:
  740. if pitem is None:
  741. continue
  742. pitem.close()
  743. del pitem
  744. self.fPluginCount = 0
  745. self.fPluginList = []
  746. # --------------------------------------------------------------------------------------------------------
  747. # Plugins (menu actions)
  748. def showAddPluginDialog(self):
  749. dialog = PluginDatabaseW(self.fParentOrSelf, self.host)
  750. if not dialog.exec_():
  751. return
  752. if not self.host.is_engine_running():
  753. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  754. return
  755. btype = dialog.fRetPlugin['build']
  756. ptype = dialog.fRetPlugin['type']
  757. filename = dialog.fRetPlugin['filename']
  758. label = dialog.fRetPlugin['label']
  759. uniqueId = dialog.fRetPlugin['uniqueId']
  760. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  761. return (btype, ptype, filename, label, uniqueId, extraPtr)
  762. def showAddJackAppDialog(self):
  763. dialog = JackApplicationW(self.fParentOrSelf, self.host)
  764. if not dialog.exec_():
  765. return
  766. if not self.host.is_engine_running():
  767. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  768. return
  769. return dialog.getCommandAndFlags()
  770. @pyqtSlot()
  771. def showPluginActionsMenu(self):
  772. menu = QMenu(self)
  773. if config_UseQt5:
  774. menu.addSection("Plugins")
  775. else:
  776. # fake section
  777. act = menu.addAction(" Plugins")
  778. font = act.font()
  779. font.setBold(True)
  780. act.setFont(font)
  781. act.setEnabled(False)
  782. menu.addSeparator()
  783. menu.addAction(self.ui.act_plugin_add)
  784. menu.addAction(self.ui.act_plugin_remove_all)
  785. if config_UseQt5:
  786. menu.addSection("All plugins (macros)")
  787. else:
  788. # fake space
  789. act = menu.addAction(" ")
  790. font = act.font()
  791. font.setBold(True)
  792. font.setPointSize(font.pointSize()/2)
  793. act.setEnabled(False)
  794. # fake section
  795. act = menu.addAction(" All plugins (macros)")
  796. font = act.font()
  797. font.setBold(True)
  798. act.setFont(font)
  799. act.setEnabled(False)
  800. menu.addSeparator()
  801. menu.addAction(self.ui.act_plugins_enable)
  802. menu.addAction(self.ui.act_plugins_disable)
  803. menu.addSeparator()
  804. menu.addAction(self.ui.act_plugins_volume100)
  805. menu.addAction(self.ui.act_plugins_mute)
  806. menu.addSeparator()
  807. menu.addAction(self.ui.act_plugins_wet100)
  808. menu.addAction(self.ui.act_plugins_bypass)
  809. menu.addSeparator()
  810. menu.addAction(self.ui.act_plugins_center)
  811. menu.addSeparator()
  812. menu.addAction(self.ui.act_plugins_compact)
  813. menu.addAction(self.ui.act_plugins_expand)
  814. menu.exec_(QCursor.pos())
  815. @pyqtSlot()
  816. def slot_pluginAdd(self):
  817. data = self.showAddPluginDialog()
  818. if data is None:
  819. return
  820. btype, ptype, filename, label, uniqueId, extraPtr = data
  821. if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0):
  822. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  823. @pyqtSlot()
  824. def slot_confirmRemoveAll(self):
  825. if self.fPluginCount == 0:
  826. return
  827. if QMessageBox.question(self, self.tr("Remove All"),
  828. self.tr("Are you sure you want to remove all plugins?"),
  829. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  830. return
  831. self.pluginRemoveAll()
  832. def pluginRemoveAll(self):
  833. if self.fPluginCount == 0:
  834. return
  835. # FIXME - this is not working
  836. # removing a plugin causes flicker, the rack-list becomes empty for some time
  837. # this breaks the remove-all animation, so don't bother using it
  838. if False and not self.host.isPlugin:
  839. self.projectLoadingStarted()
  840. app = QApplication.instance()
  841. app.processEvents()
  842. for i in reversed(range(self.fPluginCount)):
  843. self.host.remove_plugin(i)
  844. app.processEvents()
  845. self.projectLoadingFinished()
  846. self.fCurrentlyRemovingAllPlugins = True
  847. ok = self.host.remove_all_plugins()
  848. self.fCurrentlyRemovingAllPlugins = False
  849. if ok:
  850. self.removeAllPlugins()
  851. else:
  852. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  853. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  854. self.fCurrentlyRemovingAllPlugins = False
  855. @pyqtSlot()
  856. def slot_jackAppAdd(self):
  857. data = self.showAddJackAppDialog()
  858. if data is None:
  859. return
  860. filename, name, label = data
  861. if not filename:
  862. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Cannot add jack application"),
  863. self.tr("command is empty"), QMessageBox.Ok, QMessageBox.Ok)
  864. return
  865. if not self.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, filename, name, label, 0, None, 0x0):
  866. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"),
  867. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  868. # --------------------------------------------------------------------------------------------------------
  869. # Plugins (macros)
  870. @pyqtSlot()
  871. def slot_pluginsEnable(self):
  872. if not self.host.is_engine_running():
  873. return
  874. for pitem in self.fPluginList:
  875. if pitem is None:
  876. break
  877. pitem.getWidget().setActive(True, True, True)
  878. @pyqtSlot()
  879. def slot_pluginsDisable(self):
  880. if not self.host.is_engine_running():
  881. return
  882. for pitem in self.fPluginList:
  883. if pitem is None:
  884. break
  885. pitem.getWidget().setActive(False, True, True)
  886. @pyqtSlot()
  887. def slot_pluginsVolume100(self):
  888. if not self.host.is_engine_running():
  889. return
  890. for pitem in self.fPluginList:
  891. if pitem is None:
  892. break
  893. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  894. @pyqtSlot()
  895. def slot_pluginsMute(self):
  896. if not self.host.is_engine_running():
  897. return
  898. for pitem in self.fPluginList:
  899. if pitem is None:
  900. break
  901. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  902. @pyqtSlot()
  903. def slot_pluginsWet100(self):
  904. if not self.host.is_engine_running():
  905. return
  906. for pitem in self.fPluginList:
  907. if pitem is None:
  908. break
  909. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  910. @pyqtSlot()
  911. def slot_pluginsBypass(self):
  912. if not self.host.is_engine_running():
  913. return
  914. for pitem in self.fPluginList:
  915. if pitem is None:
  916. break
  917. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  918. @pyqtSlot()
  919. def slot_pluginsCenter(self):
  920. if not self.host.is_engine_running():
  921. return
  922. for pitem in self.fPluginList:
  923. if pitem is None:
  924. break
  925. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  926. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  927. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  928. @pyqtSlot()
  929. def slot_pluginsCompact(self):
  930. for pitem in self.fPluginList:
  931. if pitem is None:
  932. break
  933. pitem.compact()
  934. @pyqtSlot()
  935. def slot_pluginsExpand(self):
  936. for pitem in self.fPluginList:
  937. if pitem is None:
  938. break
  939. pitem.expand()
  940. # --------------------------------------------------------------------------------------------------------
  941. # Plugins (host callbacks)
  942. @pyqtSlot(int, str)
  943. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  944. pitem = self.ui.listWidget.createItem(pluginId)
  945. self.fPluginList.append(pitem)
  946. self.fPluginCount += 1
  947. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  948. @pyqtSlot(int)
  949. def slot_handlePluginRemovedCallback(self, pluginId):
  950. patchcanvas.handlePluginRemoved(pluginId)
  951. if pluginId in self.fSelectedPlugins:
  952. self.clearSideStuff()
  953. pitem = self.getPluginItem(pluginId)
  954. self.fPluginCount -= 1
  955. self.fPluginList.pop(pluginId)
  956. self.ui.listWidget.takeItem(pluginId)
  957. if pitem is not None:
  958. pitem.close()
  959. del pitem
  960. # push all plugins 1 slot back
  961. for i in range(pluginId, self.fPluginCount):
  962. pitem = self.fPluginList[i]
  963. pitem.setPluginId(i)
  964. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  965. # --------------------------------------------------------------------------------------------------------
  966. # Canvas
  967. def clearSideStuff(self):
  968. self.scene.clearSelection()
  969. self.fSelectedPlugins = []
  970. self.ui.keyboard.allNotesOff(False)
  971. self.ui.scrollArea.setEnabled(False)
  972. self.fPeaksCleared = True
  973. self.ui.peak_in.displayMeter(1, 0.0, True)
  974. self.ui.peak_in.displayMeter(2, 0.0, True)
  975. self.ui.peak_out.displayMeter(1, 0.0, True)
  976. self.ui.peak_out.displayMeter(2, 0.0, True)
  977. def setupCanvas(self):
  978. pOptions = patchcanvas.options_t()
  979. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  980. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  981. pOptions.auto_select_items = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS]
  982. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  983. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  984. if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY]:
  985. pOptions.eyecandy = patchcanvas.EYECANDY_FULL
  986. elif self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]:
  987. pOptions.eyecandy = patchcanvas.EYECANDY_SMALL
  988. else:
  989. pOptions.eyecandy = patchcanvas.EYECANDY_NONE
  990. pFeatures = patchcanvas.features_t()
  991. pFeatures.group_info = False
  992. pFeatures.group_rename = False
  993. pFeatures.port_info = False
  994. pFeatures.port_rename = False
  995. pFeatures.handle_group_pos = True
  996. patchcanvas.setOptions(pOptions)
  997. patchcanvas.setFeatures(pFeatures)
  998. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  999. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  1000. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  1001. self.fCanvasWidth = int(tryCanvasSize[0])
  1002. self.fCanvasHeight = int(tryCanvasSize[1])
  1003. else:
  1004. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  1005. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  1006. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  1007. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  1008. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  1009. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  1010. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  1011. def updateCanvasInitialPos(self):
  1012. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  1013. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  1014. patchcanvas.setInitialPos(x, y)
  1015. def updateMiniCanvasLater(self):
  1016. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  1017. # --------------------------------------------------------------------------------------------------------
  1018. # Canvas (menu actions)
  1019. @pyqtSlot()
  1020. def slot_canvasShowInternal(self):
  1021. self.fExternalPatchbay = False
  1022. self.ui.act_canvas_show_internal.blockSignals(True)
  1023. self.ui.act_canvas_show_external.blockSignals(True)
  1024. self.ui.act_canvas_show_internal.setChecked(True)
  1025. self.ui.act_canvas_show_external.setChecked(False)
  1026. self.ui.act_canvas_show_internal.blockSignals(False)
  1027. self.ui.act_canvas_show_external.blockSignals(False)
  1028. self.slot_canvasRefresh()
  1029. @pyqtSlot()
  1030. def slot_canvasShowExternal(self):
  1031. self.fExternalPatchbay = True
  1032. self.ui.act_canvas_show_internal.blockSignals(True)
  1033. self.ui.act_canvas_show_external.blockSignals(True)
  1034. self.ui.act_canvas_show_internal.setChecked(False)
  1035. self.ui.act_canvas_show_external.setChecked(True)
  1036. self.ui.act_canvas_show_internal.blockSignals(False)
  1037. self.ui.act_canvas_show_external.blockSignals(False)
  1038. self.slot_canvasRefresh()
  1039. @pyqtSlot()
  1040. def slot_canvasArrange(self):
  1041. patchcanvas.arrange()
  1042. @pyqtSlot()
  1043. def slot_canvasRefresh(self):
  1044. patchcanvas.clear()
  1045. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and (self.host.isControl or self.host.isPlugin):
  1046. return
  1047. if self.host.is_engine_running():
  1048. self.host.patchbay_refresh(self.fExternalPatchbay)
  1049. self.updateMiniCanvasLater()
  1050. @pyqtSlot()
  1051. def slot_canvasZoomFit(self):
  1052. self.scene.zoom_fit()
  1053. @pyqtSlot()
  1054. def slot_canvasZoomIn(self):
  1055. self.scene.zoom_in()
  1056. @pyqtSlot()
  1057. def slot_canvasZoomOut(self):
  1058. self.scene.zoom_out()
  1059. @pyqtSlot()
  1060. def slot_canvasZoomReset(self):
  1061. self.scene.zoom_reset()
  1062. @pyqtSlot()
  1063. def slot_canvasSaveImage(self):
  1064. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  1065. if config_UseQt5:
  1066. newPath = newPath[0]
  1067. if not newPath:
  1068. return
  1069. self.scene.clearSelection()
  1070. if newPath.lower().endswith((".jpg", ".jpeg")):
  1071. imgFormat = "JPG"
  1072. elif newPath.lower().endswith((".png",)):
  1073. imgFormat = "PNG"
  1074. else:
  1075. # File-dialog may not auto-add the extension
  1076. imgFormat = "PNG"
  1077. newPath += ".png"
  1078. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  1079. painter = QPainter(self.fExportImage)
  1080. painter.save()
  1081. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  1082. painter.setRenderHint(QPainter.TextAntialiasing)
  1083. self.scene.render(painter)
  1084. self.fExportImage.save(newPath, imgFormat, 100)
  1085. painter.restore()
  1086. # --------------------------------------------------------------------------------------------------------
  1087. # Canvas (canvas callbacks)
  1088. @pyqtSlot(int, int, QPointF)
  1089. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  1090. self.updateMiniCanvasLater()
  1091. @pyqtSlot(float)
  1092. def slot_canvasScaleChanged(self, scale):
  1093. self.ui.miniCanvasPreview.setViewScale(scale)
  1094. @pyqtSlot(list)
  1095. def slot_canvasPluginSelected(self, pluginList):
  1096. self.ui.keyboard.allNotesOff(False)
  1097. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  1098. self.fSelectedPlugins = pluginList
  1099. # --------------------------------------------------------------------------------------------------------
  1100. # Canvas (host callbacks)
  1101. @pyqtSlot(int, int, int, str)
  1102. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  1103. pcSplit = patchcanvas.SPLIT_UNDEF
  1104. pcIcon = patchcanvas.ICON_APPLICATION
  1105. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1106. pcIcon = patchcanvas.ICON_PLUGIN
  1107. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1108. pcIcon = patchcanvas.ICON_HARDWARE
  1109. elif clientIcon == PATCHBAY_ICON_CARLA:
  1110. pass
  1111. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1112. pcIcon = patchcanvas.ICON_DISTRHO
  1113. elif clientIcon == PATCHBAY_ICON_FILE:
  1114. pcIcon = patchcanvas.ICON_FILE
  1115. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  1116. self.updateMiniCanvasLater()
  1117. if pluginId < 0:
  1118. return
  1119. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1120. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1121. return
  1122. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1123. hasCustomUI = False
  1124. else:
  1125. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1126. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1127. @pyqtSlot(int)
  1128. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  1129. patchcanvas.removeGroup(clientId)
  1130. self.updateMiniCanvasLater()
  1131. @pyqtSlot(int, str)
  1132. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  1133. patchcanvas.renameGroup(clientId, newClientName)
  1134. self.updateMiniCanvasLater()
  1135. @pyqtSlot(int, int, int)
  1136. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  1137. pcIcon = patchcanvas.ICON_APPLICATION
  1138. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1139. pcIcon = patchcanvas.ICON_PLUGIN
  1140. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1141. pcIcon = patchcanvas.ICON_HARDWARE
  1142. elif clientIcon == PATCHBAY_ICON_CARLA:
  1143. pass
  1144. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1145. pcIcon = patchcanvas.ICON_DISTRHO
  1146. elif clientIcon == PATCHBAY_ICON_FILE:
  1147. pcIcon = patchcanvas.ICON_FILE
  1148. patchcanvas.setGroupIcon(clientId, pcIcon)
  1149. self.updateMiniCanvasLater()
  1150. if pluginId < 0:
  1151. return
  1152. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1153. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1154. return
  1155. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1156. hasCustomUI = False
  1157. else:
  1158. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1159. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1160. @pyqtSlot(int, int, int, str)
  1161. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  1162. if portFlags & PATCHBAY_PORT_IS_INPUT:
  1163. portMode = patchcanvas.PORT_MODE_INPUT
  1164. else:
  1165. portMode = patchcanvas.PORT_MODE_OUTPUT
  1166. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  1167. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1168. isAlternate = False
  1169. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  1170. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1171. isAlternate = True
  1172. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  1173. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  1174. isAlternate = False
  1175. else:
  1176. portType = patchcanvas.PORT_TYPE_NULL
  1177. isAlternate = False
  1178. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  1179. self.updateMiniCanvasLater()
  1180. @pyqtSlot(int, int)
  1181. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  1182. patchcanvas.removePort(groupId, portId)
  1183. self.updateMiniCanvasLater()
  1184. @pyqtSlot(int, int, str)
  1185. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  1186. patchcanvas.renamePort(groupId, portId, newPortName)
  1187. self.updateMiniCanvasLater()
  1188. @pyqtSlot(int, int, int, int, int)
  1189. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  1190. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  1191. self.updateMiniCanvasLater()
  1192. @pyqtSlot(int, int, int)
  1193. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  1194. patchcanvas.disconnectPorts(connectionId)
  1195. self.updateMiniCanvasLater()
  1196. # --------------------------------------------------------------------------------------------------------
  1197. # Settings
  1198. def saveSettings(self):
  1199. settings = QSettings()
  1200. settings.setValue("Geometry", self.saveGeometry())
  1201. settings.setValue("ShowToolbar", self.ui.toolBar.isEnabled())
  1202. settings.setValue("ShowSidePanel", self.ui.dockWidget.isEnabled())
  1203. diskFolders = []
  1204. for i in range(self.ui.cb_disk.count()):
  1205. diskFolders.append(self.ui.cb_disk.itemData(i))
  1206. settings.setValue("DiskFolders", diskFolders)
  1207. settings.setValue("LastBPM", self.fLastTransportBPM)
  1208. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  1209. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  1210. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1211. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1212. settings.setValue(CARLA_KEY_ENGINE_TRANSPORT_MODE, self.host.transportMode)
  1213. settings.setValue(CARLA_KEY_ENGINE_TRANSPORT_EXTRA, self.host.transportExtra)
  1214. def loadSettings(self, firstTime):
  1215. settings = QSettings()
  1216. if firstTime:
  1217. self.restoreGeometry(settings.value("Geometry", b""))
  1218. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1219. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1220. self.ui.toolBar.setEnabled(showToolbar)
  1221. self.ui.toolBar.setVisible(showToolbar)
  1222. #if settings.contains("SplitterState"):
  1223. #self.ui.splitter.restoreState(settings.value("SplitterState", b""))
  1224. #else:
  1225. #self.ui.splitter.setSizes([210, 99999])
  1226. showSidePanel = settings.value("ShowSidePanel", True, type=bool)
  1227. self.ui.act_settings_show_side_panel.setChecked(showSidePanel)
  1228. self.ui.dockWidget.setEnabled(showSidePanel)
  1229. self.ui.dockWidget.setVisible(showSidePanel)
  1230. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  1231. self.ui.cb_disk.setItemData(0, HOME)
  1232. for i in range(len(diskFolders)):
  1233. if i == 0: continue
  1234. folder = diskFolders[i]
  1235. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1236. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  1237. # self.setUnifiedTitleAndToolBarOnMac(True)
  1238. showMeters = settings.value("ShowMeters", True, type=bool)
  1239. self.ui.act_settings_show_meters.setChecked(showMeters)
  1240. self.ui.peak_in.setVisible(showMeters)
  1241. self.ui.peak_out.setVisible(showMeters)
  1242. showKeyboard = settings.value("ShowKeyboard", True, type=bool)
  1243. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  1244. self.ui.scrollArea.setVisible(showKeyboard)
  1245. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  1246. # TODO - complete this
  1247. self.fSavedSettings = {
  1248. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  1249. CARLA_KEY_MAIN_CONFIRM_EXIT: settings.value(CARLA_KEY_MAIN_CONFIRM_EXIT, CARLA_DEFAULT_MAIN_CONFIRM_EXIT, type=bool),
  1250. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  1251. CARLA_KEY_MAIN_EXPERIMENTAL: settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool),
  1252. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  1253. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  1254. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  1255. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS: settings.value(CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS, CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS, type=bool),
  1256. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  1257. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=bool),
  1258. CARLA_KEY_CANVAS_FANCY_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_FANCY_EYE_CANDY, CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY, type=bool),
  1259. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  1260. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  1261. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  1262. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  1263. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black"),
  1264. }
  1265. settings = QSettings("falkTX", "Carla2")
  1266. if self.host.experimental and not self.host.isControl:
  1267. self.ui.act_add_jack.setVisible(settings.value(CARLA_KEY_EXPERIMENTAL_JACK_APPS,
  1268. CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS, type=bool))
  1269. else:
  1270. self.ui.act_add_jack.setVisible(False)
  1271. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY] else 0
  1272. setEngineSettings(self.host)
  1273. self.restartTimersIfNeeded()
  1274. # --------------------------------------------------------------------------------------------------------
  1275. # Settings (helpers)
  1276. def enableTransport(self, enabled):
  1277. self.ui.group_transport_controls.setEnabled(enabled)
  1278. self.ui.group_transport_settings.setEnabled(enabled)
  1279. @pyqtSlot()
  1280. def slot_restoreCanvasScrollbarValues(self):
  1281. settings = QSettings()
  1282. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  1283. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  1284. # --------------------------------------------------------------------------------------------------------
  1285. # Settings (menu actions)
  1286. @pyqtSlot(bool)
  1287. def slot_showSidePanel(self, yesNo):
  1288. self.ui.dockWidget.setEnabled(yesNo)
  1289. self.ui.dockWidget.setVisible(yesNo)
  1290. @pyqtSlot(bool)
  1291. def slot_showToolbar(self, yesNo):
  1292. self.ui.toolBar.setEnabled(yesNo)
  1293. self.ui.toolBar.setVisible(yesNo)
  1294. @pyqtSlot(bool)
  1295. def slot_showCanvasMeters(self, yesNo):
  1296. self.ui.peak_in.setVisible(yesNo)
  1297. self.ui.peak_out.setVisible(yesNo)
  1298. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1299. @pyqtSlot(bool)
  1300. def slot_showCanvasKeyboard(self, yesNo):
  1301. self.ui.scrollArea.setVisible(yesNo)
  1302. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1303. @pyqtSlot()
  1304. def slot_configureCarla(self):
  1305. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1306. if not dialog.exec_():
  1307. return
  1308. self.loadSettings(False)
  1309. patchcanvas.clear()
  1310. self.setupCanvas()
  1311. self.slot_miniCanvasCheckAll()
  1312. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1313. pass
  1314. elif self.host.is_engine_running():
  1315. self.host.patchbay_refresh(self.fExternalPatchbay)
  1316. # --------------------------------------------------------------------------------------------------------
  1317. # About (menu actions)
  1318. @pyqtSlot()
  1319. def slot_aboutCarla(self):
  1320. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1321. @pyqtSlot()
  1322. def slot_aboutQt(self):
  1323. QApplication.instance().aboutQt()
  1324. # --------------------------------------------------------------------------------------------------------
  1325. # Disk (menu actions)
  1326. @pyqtSlot(int)
  1327. def slot_diskFolderChanged(self, index):
  1328. if index < 0:
  1329. return
  1330. elif index == 0:
  1331. filename = HOME
  1332. self.ui.b_disk_remove.setEnabled(False)
  1333. else:
  1334. filename = self.ui.cb_disk.itemData(index)
  1335. self.ui.b_disk_remove.setEnabled(True)
  1336. self.fDirModel.setRootPath(filename)
  1337. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1338. @pyqtSlot()
  1339. def slot_diskFolderAdd(self):
  1340. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1341. if newPath:
  1342. if newPath[-1] == os.sep:
  1343. newPath = newPath[:-1]
  1344. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1345. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1346. self.ui.b_disk_remove.setEnabled(True)
  1347. @pyqtSlot()
  1348. def slot_diskFolderRemove(self):
  1349. index = self.ui.cb_disk.currentIndex()
  1350. if index <= 0:
  1351. return
  1352. self.ui.cb_disk.removeItem(index)
  1353. if self.ui.cb_disk.currentIndex() == 0:
  1354. self.ui.b_disk_remove.setEnabled(False)
  1355. @pyqtSlot(QModelIndex)
  1356. def slot_fileTreeDoubleClicked(self, modelIndex):
  1357. filename = self.fDirModel.filePath(modelIndex)
  1358. if not self.ui.listWidget.isDragUrlValid(filename):
  1359. return
  1360. if not self.host.load_file(filename):
  1361. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1362. self.tr("Failed to load file"),
  1363. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1364. # --------------------------------------------------------------------------------------------------------
  1365. # Transport
  1366. def refreshTransport(self, forced = False):
  1367. if not self.isVisible():
  1368. return
  1369. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  1370. return
  1371. timeInfo = self.host.get_transport_info()
  1372. playing = timeInfo['playing']
  1373. frame = timeInfo['frame']
  1374. bpm = timeInfo['bpm']
  1375. if playing != self.fLastTransportState or forced:
  1376. if playing:
  1377. icon = getIcon("media-playback-pause")
  1378. self.ui.b_transport_play.setChecked(True)
  1379. self.ui.b_transport_play.setIcon(icon)
  1380. #self.ui.b_transport_play.setText(self.tr("&Pause"))
  1381. else:
  1382. icon = getIcon("media-playback-start")
  1383. self.ui.b_transport_play.setChecked(False)
  1384. self.ui.b_transport_play.setIcon(icon)
  1385. #self.ui.b_play.setText(self.tr("&Play"))
  1386. self.fLastTransportState = playing
  1387. if frame != self.fLastTransportFrame or forced:
  1388. self.fLastTransportFrame = frame
  1389. time = frame / self.fSampleRate
  1390. secs = time % 60
  1391. mins = (time / 60) % 60
  1392. hrs = (time / 3600) % 60
  1393. self.ui.l_transport_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  1394. frame1 = frame % 1000
  1395. frame2 = (frame / 1000) % 1000
  1396. frame3 = (frame / 1000000) % 1000
  1397. self.ui.l_transport_frame.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  1398. bar = timeInfo['bar']
  1399. beat = timeInfo['beat']
  1400. tick = timeInfo['tick']
  1401. self.ui.l_transport_bbt.setText("%03i|%02i|%04i" % (bar, beat, tick))
  1402. if bpm != self.fLastTransportBPM or forced:
  1403. self.fLastTransportBPM = bpm
  1404. if bpm > 0.0:
  1405. self.ui.dsb_transport_bpm.blockSignals(True)
  1406. self.ui.dsb_transport_bpm.setValue(bpm)
  1407. self.ui.dsb_transport_bpm.blockSignals(False)
  1408. self.ui.dsb_transport_bpm.setStyleSheet("")
  1409. else:
  1410. self.ui.dsb_transport_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  1411. # --------------------------------------------------------------------------------------------------------
  1412. # Transport (menu actions)
  1413. @pyqtSlot(bool)
  1414. def slot_transportPlayPause(self, toggled):
  1415. if self.host.isPlugin or not self.host.is_engine_running():
  1416. return
  1417. if toggled:
  1418. self.host.transport_play()
  1419. else:
  1420. self.host.transport_pause()
  1421. self.refreshTransport()
  1422. @pyqtSlot()
  1423. def slot_transportStop(self):
  1424. if self.host.isPlugin or not self.host.is_engine_running():
  1425. return
  1426. self.host.transport_pause()
  1427. self.host.transport_relocate(0)
  1428. self.refreshTransport()
  1429. @pyqtSlot()
  1430. def slot_transportBackwards(self):
  1431. if self.host.isPlugin or not self.host.is_engine_running():
  1432. return
  1433. newFrame = self.host.get_current_transport_frame() - 100000
  1434. if newFrame < 0:
  1435. newFrame = 0
  1436. self.host.transport_relocate(newFrame)
  1437. @pyqtSlot(float)
  1438. def slot_transportBpmChanged(self, newValue):
  1439. self.host.transport_bpm(newValue)
  1440. @pyqtSlot()
  1441. def slot_transportForwards(self):
  1442. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  1443. return
  1444. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  1445. self.host.transport_relocate(newFrame)
  1446. @pyqtSlot(bool)
  1447. def slot_transportJackEnabled(self, clicked):
  1448. if not self.host.is_engine_running():
  1449. return
  1450. self.host.transportMode = ENGINE_TRANSPORT_MODE_JACK if clicked else ENGINE_TRANSPORT_MODE_INTERNAL
  1451. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE,
  1452. self.host.transportMode,
  1453. self.host.transportExtra)
  1454. @pyqtSlot(bool)
  1455. def slot_transportLinkEnabled(self, clicked):
  1456. if not self.host.is_engine_running():
  1457. return
  1458. extra = ":link:" if clicked else ""
  1459. self.host.transportExtra = extra
  1460. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE,
  1461. self.host.transportMode,
  1462. self.host.transportExtra)
  1463. # --------------------------------------------------------------------------------------------------------
  1464. # Canvas scrollbars
  1465. @pyqtSlot(int)
  1466. def slot_horizontalScrollBarChanged(self, value):
  1467. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1468. if maximum == 0:
  1469. xp = 0
  1470. else:
  1471. xp = float(value) / maximum
  1472. self.ui.miniCanvasPreview.setViewPosX(xp)
  1473. self.updateCanvasInitialPos()
  1474. @pyqtSlot(int)
  1475. def slot_verticalScrollBarChanged(self, value):
  1476. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1477. if maximum == 0:
  1478. yp = 0
  1479. else:
  1480. yp = float(value) / maximum
  1481. self.ui.miniCanvasPreview.setViewPosY(yp)
  1482. self.updateCanvasInitialPos()
  1483. # --------------------------------------------------------------------------------------------------------
  1484. # Canvas keyboard
  1485. @pyqtSlot(int)
  1486. def slot_noteOn(self, note):
  1487. for pluginId in self.fSelectedPlugins:
  1488. self.host.send_midi_note(pluginId, 0, note, 100)
  1489. pedit = self.getPluginEditDialog(pluginId)
  1490. pedit.noteOn(0, note, 100)
  1491. @pyqtSlot(int)
  1492. def slot_noteOff(self, note):
  1493. for pluginId in self.fSelectedPlugins:
  1494. self.host.send_midi_note(pluginId, 0, note, 0)
  1495. pedit = self.getPluginEditDialog(pluginId)
  1496. pedit.noteOff(0, note)
  1497. # --------------------------------------------------------------------------------------------------------
  1498. # Canvas keyboard (host callbacks)
  1499. @pyqtSlot(int, int, int, int)
  1500. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1501. if pluginId in self.fSelectedPlugins:
  1502. self.ui.keyboard.sendNoteOn(note, False)
  1503. @pyqtSlot(int, int, int)
  1504. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1505. if pluginId in self.fSelectedPlugins:
  1506. self.ui.keyboard.sendNoteOff(note, False)
  1507. # --------------------------------------------------------------------------------------------------------
  1508. @pyqtSlot(int)
  1509. def slot_handleUpdateCallback(self, pluginId):
  1510. pitem = self.getPluginItem(pluginId)
  1511. if pitem is None:
  1512. return
  1513. wasCompacted = pitem.isCompacted()
  1514. isCompacted = wasCompacted
  1515. check = self.host.get_custom_data_value(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkinIsCompacted")
  1516. if not check:
  1517. return
  1518. isCompacted = bool(check == "true")
  1519. if wasCompacted == isCompacted:
  1520. return
  1521. pitem.recreateWidget(True)
  1522. # --------------------------------------------------------------------------------------------------------
  1523. # MiniCanvas stuff
  1524. @pyqtSlot()
  1525. def slot_miniCanvasCheckAll(self):
  1526. self.slot_miniCanvasCheckSize()
  1527. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1528. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1529. @pyqtSlot()
  1530. def slot_miniCanvasCheckSize(self):
  1531. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1532. return
  1533. currentIndex = self.ui.tabWidget.currentIndex()
  1534. if currentIndex == 1:
  1535. width = self.ui.graphicsView.width()
  1536. height = self.ui.graphicsView.height()
  1537. else:
  1538. self.ui.tabWidget.blockSignals(True)
  1539. self.ui.tabWidget.setCurrentIndex(1)
  1540. width = self.ui.graphicsView.width()
  1541. height = self.ui.graphicsView.height()
  1542. self.ui.tabWidget.setCurrentIndex(currentIndex)
  1543. self.ui.tabWidget.blockSignals(False)
  1544. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1545. @pyqtSlot(float, float)
  1546. def slot_miniCanvasMoved(self, xp, yp):
  1547. hsb = self.ui.graphicsView.horizontalScrollBar()
  1548. vsb = self.ui.graphicsView.verticalScrollBar()
  1549. hsb.setValue(xp * hsb.maximum())
  1550. vsb.setValue(yp * vsb.maximum())
  1551. self.updateCanvasInitialPos()
  1552. # --------------------------------------------------------------------------------------------------------
  1553. # Timers
  1554. def startTimers(self):
  1555. if self.fIdleTimerFast == 0:
  1556. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1557. if self.fIdleTimerSlow == 0:
  1558. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1559. def restartTimersIfNeeded(self):
  1560. if self.fIdleTimerFast != 0:
  1561. self.killTimer(self.fIdleTimerFast)
  1562. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1563. if self.fIdleTimerSlow != 0:
  1564. self.killTimer(self.fIdleTimerSlow)
  1565. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1566. def killTimers(self):
  1567. if self.fIdleTimerFast != 0:
  1568. self.killTimer(self.fIdleTimerFast)
  1569. self.fIdleTimerFast = 0
  1570. if self.fIdleTimerSlow != 0:
  1571. self.killTimer(self.fIdleTimerSlow)
  1572. self.fIdleTimerSlow = 0
  1573. # --------------------------------------------------------------------------------------------------------
  1574. # Misc
  1575. @pyqtSlot(int)
  1576. def slot_tabChanged(self, index):
  1577. if index != 1:
  1578. return
  1579. self.ui.graphicsView.setFocus()
  1580. @pyqtSlot(int)
  1581. def slot_handleReloadAllCallback(self, pluginId):
  1582. if pluginId >= self.fPluginCount:
  1583. return
  1584. pitem = self.fPluginList[pluginId]
  1585. if pitem is None:
  1586. return
  1587. pitem.recreateWidget()
  1588. # --------------------------------------------------------------------------------------------------------
  1589. @pyqtSlot(int, int, str)
  1590. def slot_handleNSMCallback(self, value1, value2, valueStr):
  1591. # Error
  1592. if value1 == 0:
  1593. pass
  1594. # Reply
  1595. elif value1 == 1:
  1596. self.fFirstEngineInit = False
  1597. self.fSessionManagerName = valueStr
  1598. self.setProperWindowTitle()
  1599. # Open
  1600. elif value1 == 2:
  1601. self.fClientName = os.path.basename(valueStr)
  1602. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1603. self.setProperWindowTitle()
  1604. self.fCustomStopAction = self.CUSTOM_ACTION_PROJECT_LOAD
  1605. self.slot_engineStop(True)
  1606. return
  1607. # Save
  1608. elif value1 == 3:
  1609. self.saveProjectNow()
  1610. # Session is Loaded
  1611. elif value1 == 4:
  1612. pass
  1613. # Show Optional Gui
  1614. elif value1 == 5:
  1615. self.show()
  1616. # Hide Optional Gui
  1617. elif value1 == 6:
  1618. self.hide()
  1619. self.host.nsm_ready(value1)
  1620. # --------------------------------------------------------------------------------------------------------
  1621. def fixLogText(self, text):
  1622. return text.replace("\x1b[30;1m", "").replace("\x1b[31m", "").replace("\x1b[0m", "")
  1623. @pyqtSlot(int, int, int, float, str)
  1624. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1625. self.ui.text_logs.appendPlainText(self.fixLogText(valueStr))
  1626. @pyqtSlot(str)
  1627. def slot_handleInfoCallback(self, info):
  1628. QMessageBox.information(self, "Information", info)
  1629. @pyqtSlot(str)
  1630. def slot_handleErrorCallback(self, error):
  1631. QMessageBox.critical(self, "Error", error)
  1632. @pyqtSlot()
  1633. def slot_handleQuitCallback(self):
  1634. pass # TODO
  1635. # --------------------------------------------------------------------------------------------------------
  1636. @pyqtSlot()
  1637. def slot_handleSIGUSR1(self):
  1638. print("Got SIGUSR1 -> Saving project now")
  1639. self.slot_fileSave()
  1640. @pyqtSlot()
  1641. def slot_handleSIGTERM(self):
  1642. print("Got SIGTERM -> Closing now")
  1643. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1644. self.slot_engineStop(True)
  1645. # --------------------------------------------------------------------------------------------------------
  1646. # Internal stuff
  1647. def getExtraPtr(self, plugin):
  1648. ptype = plugin['type']
  1649. if ptype == PLUGIN_LADSPA:
  1650. uniqueId = plugin['uniqueId']
  1651. self.maybeLoadRDFs()
  1652. for rdfItem in self.fLadspaRdfList:
  1653. if rdfItem.UniqueID == uniqueId:
  1654. return pointer(rdfItem)
  1655. elif ptype == PLUGIN_SF2:
  1656. if plugin['name'].lower().endswith(" (16 outputs)"):
  1657. return self._true
  1658. return None
  1659. def maybeLoadRDFs(self):
  1660. if not self.fLadspaRdfNeedsUpdate:
  1661. return
  1662. self.fLadspaRdfNeedsUpdate = False
  1663. self.fLadspaRdfList = []
  1664. if not haveLRDF:
  1665. return
  1666. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1667. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1668. if os.path.exists(frLadspaFile):
  1669. frLadspa = open(frLadspaFile, 'r')
  1670. try:
  1671. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1672. except:
  1673. pass
  1674. frLadspa.close()
  1675. # --------------------------------------------------------------------------------------------------------
  1676. def getPluginCount(self):
  1677. return self.fPluginCount
  1678. def getPluginItem(self, pluginId):
  1679. if pluginId >= self.fPluginCount:
  1680. return None
  1681. pitem = self.fPluginList[pluginId]
  1682. if pitem is None:
  1683. return None
  1684. #if False:
  1685. #return CarlaRackItem(self, 0, False)
  1686. return pitem
  1687. def getPluginEditDialog(self, pluginId):
  1688. if pluginId >= self.fPluginCount:
  1689. return None
  1690. pitem = self.fPluginList[pluginId]
  1691. if pitem is None:
  1692. return None
  1693. if False:
  1694. return PluginEdit(self, self.host, 0)
  1695. return pitem.getEditDialog()
  1696. def getPluginSlotWidget(self, pluginId):
  1697. if pluginId >= self.fPluginCount:
  1698. return None
  1699. pitem = self.fPluginList[pluginId]
  1700. if pitem is None:
  1701. return None
  1702. #if False:
  1703. #return AbstractPluginSlot()
  1704. return pitem.getWidget()
  1705. # --------------------------------------------------------------------------------------------------------
  1706. def waitForPendingEvents(self):
  1707. pass
  1708. # --------------------------------------------------------------------------------------------------------
  1709. # show/hide event
  1710. def showEvent(self, event):
  1711. self.refreshTransport(True)
  1712. QMainWindow.showEvent(self, event)
  1713. # set our gui as parent for all plugins UIs
  1714. if self.host.manageUIs and not (self.host.isControl or self.host.isPlugin):
  1715. if MACOS:
  1716. nsViewPtr = int(self.winId())
  1717. winIdStr = "%x" % gCarla.utils.cocoa_get_window(nsViewPtr)
  1718. else:
  1719. winIdStr = "%x" % int(self.winId())
  1720. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1721. def hideEvent(self, event):
  1722. # disable parent
  1723. if not (self.host.isControl or self.host.isPlugin):
  1724. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1725. QMainWindow.hideEvent(self, event)
  1726. # --------------------------------------------------------------------------------------------------------
  1727. # resize event
  1728. def fixCanvasPreviewSize(self):
  1729. self.ui.patchbay.resize(self.ui.rack.size())
  1730. self.slot_miniCanvasCheckSize()
  1731. def resizeEvent(self, event):
  1732. QMainWindow.resizeEvent(self, event)
  1733. if self.ui.tabWidget.currentIndex() != 1:
  1734. size = self.ui.rack.size()
  1735. self.ui.patchbay.resize(size)
  1736. self.slot_miniCanvasCheckSize()
  1737. # --------------------------------------------------------------------------------------------------------
  1738. # timer event
  1739. def idleFast(self):
  1740. self.host.engine_idle()
  1741. self.refreshTransport()
  1742. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1743. return
  1744. for pitem in self.fPluginList:
  1745. if pitem is None:
  1746. break
  1747. pitem.getWidget().idleFast()
  1748. for pluginId in self.fSelectedPlugins:
  1749. self.fPeaksCleared = False
  1750. if self.ui.peak_in.isVisible():
  1751. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1752. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1753. if self.ui.peak_out.isVisible():
  1754. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1755. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1756. return
  1757. if self.fPeaksCleared:
  1758. return
  1759. self.fPeaksCleared = True
  1760. self.ui.peak_in.displayMeter(1, 0.0, True)
  1761. self.ui.peak_in.displayMeter(2, 0.0, True)
  1762. self.ui.peak_out.displayMeter(1, 0.0, True)
  1763. self.ui.peak_out.displayMeter(2, 0.0, True)
  1764. def idleSlow(self):
  1765. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1766. return
  1767. for pitem in self.fPluginList:
  1768. if pitem is None:
  1769. break
  1770. pitem.getWidget().idleSlow()
  1771. def timerEvent(self, event):
  1772. if event.timerId() == self.fIdleTimerFast:
  1773. self.idleFast()
  1774. elif event.timerId() == self.fIdleTimerSlow:
  1775. self.idleSlow()
  1776. QMainWindow.timerEvent(self, event)
  1777. # --------------------------------------------------------------------------------------------------------
  1778. # paint event
  1779. #def paintEvent(self, event):
  1780. #QMainWindow.paintEvent(self, event)
  1781. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1782. #return
  1783. #painter = QPainter(self)
  1784. #painter.setBrush(QColor(36, 36, 36))
  1785. #painter.setPen(QColor(62, 62, 62))
  1786. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1787. # --------------------------------------------------------------------------------------------------------
  1788. # close event
  1789. def shouldIgnoreClose(self):
  1790. if self.host.isControl or self.host.isPlugin:
  1791. return False
  1792. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  1793. return False
  1794. if self.fSavedSettings[CARLA_KEY_MAIN_CONFIRM_EXIT]:
  1795. return QMessageBox.question(self, self.tr("Quit"),
  1796. self.tr("Are you sure you want to quit Carla?"),
  1797. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No
  1798. return False
  1799. def closeEvent(self, event):
  1800. if self.shouldIgnoreClose():
  1801. event.ignore()
  1802. return
  1803. if MACOS and self.fMacClosingHelper and not (self.host.isControl or self.host.isPlugin):
  1804. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1805. self.fMacClosingHelper = False
  1806. event.ignore()
  1807. for i in reversed(range(self.fPluginCount)):
  1808. self.host.show_custom_ui(i, False)
  1809. QTimer.singleShot(100, self.close)
  1810. return
  1811. self.killTimers()
  1812. self.saveSettings()
  1813. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  1814. if not self.slot_engineStop(True):
  1815. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1816. event.ignore()
  1817. return
  1818. QMainWindow.closeEvent(self, event)
  1819. # ------------------------------------------------------------------------------------------------
  1820. # Canvas callback
  1821. def canvasCallback(action, value1, value2, valueStr):
  1822. host = gCarla.gui.host
  1823. if action == patchcanvas.ACTION_GROUP_INFO:
  1824. pass
  1825. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1826. pass
  1827. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1828. groupId = value1
  1829. patchcanvas.splitGroup(groupId)
  1830. gCarla.gui.updateMiniCanvasLater()
  1831. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1832. groupId = value1
  1833. patchcanvas.joinGroup(groupId)
  1834. gCarla.gui.updateMiniCanvasLater()
  1835. elif action == patchcanvas.ACTION_PORT_INFO:
  1836. pass
  1837. elif action == patchcanvas.ACTION_PORT_RENAME:
  1838. pass
  1839. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1840. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1841. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1842. print("Connection failed:", host.get_last_error())
  1843. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1844. connectionId = value1
  1845. if not host.patchbay_disconnect(connectionId):
  1846. print("Disconnect failed:", host.get_last_error())
  1847. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1848. pluginId = value1
  1849. if not host.clone_plugin(pluginId):
  1850. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1851. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1852. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1853. pluginId = value1
  1854. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1855. if pwidget is not None:
  1856. pwidget.showEditDialog()
  1857. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1858. pluginId = value1
  1859. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1860. if pwidget is not None:
  1861. pwidget.showRenameDialog()
  1862. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  1863. pluginId = value1
  1864. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1865. if pwidget is not None:
  1866. pwidget.showReplaceDialog()
  1867. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1868. pluginId = value1
  1869. if not host.remove_plugin(pluginId):
  1870. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1871. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1872. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1873. pluginId = value1
  1874. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1875. if pwidget is not None:
  1876. pwidget.showCustomUI()
  1877. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  1878. gCarla.gui.showPluginActionsMenu()
  1879. # ------------------------------------------------------------------------------------------------------------
  1880. # Engine callback
  1881. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1882. # kdevelop likes this :)
  1883. if False: host = CarlaHostNull()
  1884. valueStr = charPtrToString(valueStr)
  1885. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1886. host.processMode = value1
  1887. host.transportMode = value2
  1888. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1889. host.processMode = value1
  1890. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1891. host.transportMode = value1
  1892. host.transportExtra = valueStr
  1893. if action == ENGINE_CALLBACK_DEBUG:
  1894. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1895. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1896. host.PluginAddedCallback.emit(pluginId, valueStr)
  1897. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1898. host.PluginRemovedCallback.emit(pluginId)
  1899. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1900. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1901. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1902. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1903. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1904. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1905. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1906. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1907. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1908. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1909. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1910. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1911. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1912. host.ProgramChangedCallback.emit(pluginId, value1)
  1913. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1914. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1915. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1916. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1917. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1918. host.UiStateChangedCallback.emit(pluginId, value1)
  1919. elif action == ENGINE_CALLBACK_NOTE_ON:
  1920. host.NoteOnCallback.emit(pluginId, value1, value2, round(value3))
  1921. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1922. host.NoteOffCallback.emit(pluginId, value1, value2)
  1923. elif action == ENGINE_CALLBACK_UPDATE:
  1924. host.UpdateCallback.emit(pluginId)
  1925. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1926. host.ReloadInfoCallback.emit(pluginId)
  1927. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1928. host.ReloadParametersCallback.emit(pluginId)
  1929. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1930. host.ReloadProgramsCallback.emit(pluginId)
  1931. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1932. host.ReloadAllCallback.emit(pluginId)
  1933. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1934. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1935. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1936. host.PatchbayClientRemovedCallback.emit(pluginId)
  1937. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1938. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1939. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1940. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1941. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1942. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1943. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1944. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1945. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1946. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1947. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1948. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1949. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1950. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1951. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1952. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1953. host.EngineStartedCallback.emit(value1, value2, value3, valueStr)
  1954. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1955. host.EngineStoppedCallback.emit()
  1956. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1957. host.ProcessModeChangedCallback.emit(value1)
  1958. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1959. host.TransportModeChangedCallback.emit(value1, valueStr)
  1960. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1961. host.BufferSizeChangedCallback.emit(value1)
  1962. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1963. host.SampleRateChangedCallback.emit(value3)
  1964. elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
  1965. host.ProjectLoadFinishedCallback.emit()
  1966. elif action == ENGINE_CALLBACK_NSM:
  1967. host.NSMCallback.emit(value1, value2, valueStr)
  1968. elif action == ENGINE_CALLBACK_IDLE:
  1969. QApplication.processEvents()
  1970. elif action == ENGINE_CALLBACK_INFO:
  1971. host.InfoCallback.emit(valueStr)
  1972. elif action == ENGINE_CALLBACK_ERROR:
  1973. host.ErrorCallback.emit(valueStr)
  1974. elif action == ENGINE_CALLBACK_QUIT:
  1975. host.QuitCallback.emit()
  1976. # ------------------------------------------------------------------------------------------------------------
  1977. # File callback
  1978. def fileCallback(ptr, action, isDir, title, filter):
  1979. ret = ("", "") if config_UseQt5 else ""
  1980. title = charPtrToString(title)
  1981. filter = charPtrToString(filter)
  1982. if action == FILE_CALLBACK_OPEN:
  1983. ret = QFileDialog.getOpenFileName(gCarla.gui, title, "", filter) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1984. elif action == FILE_CALLBACK_SAVE:
  1985. ret = QFileDialog.getSaveFileName(gCarla.gui, title, "", filter, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1986. if config_UseQt5:
  1987. ret = ret[0]
  1988. if not ret:
  1989. return None
  1990. # FIXME
  1991. global fileRet
  1992. fileRet = c_char_p(ret.encode("utf-8"))
  1993. retval = cast(byref(fileRet), POINTER(c_uintptr))
  1994. return retval.contents.value
  1995. # ------------------------------------------------------------------------------------------------------------
  1996. # Init host
  1997. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  1998. pathBinaries, pathResources = getPaths(libPrefix)
  1999. # --------------------------------------------------------------------------------------------------------
  2000. # Check if we should open main lib as local or global
  2001. settings = QSettings("falkTX", "Carla2")
  2002. try:
  2003. loadGlobal = settings.value(CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL, CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL, type=bool)
  2004. except:
  2005. loadGlobal = CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL
  2006. # --------------------------------------------------------------------------------------------------------
  2007. # Fail if binary dir is not found
  2008. if not os.path.exists(pathBinaries):
  2009. if failError:
  2010. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  2011. sys.exit(1)
  2012. return
  2013. # --------------------------------------------------------------------------------------------------------
  2014. # Set Carla library name
  2015. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  2016. libname = os.path.join(pathBinaries, libname)
  2017. utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION))
  2018. # --------------------------------------------------------------------------------------------------------
  2019. # Print info
  2020. print("Carla %s started, status:" % VERSION)
  2021. print(" Python version: %s" % sys.version.split(" ",1)[0])
  2022. print(" Qt version: %s" % qVersion())
  2023. print(" PyQt version: %s" % PYQT_VERSION_STR)
  2024. print(" Binary dir: %s" % pathBinaries)
  2025. print(" Resources dir: %s" % pathResources)
  2026. # --------------------------------------------------------------------------------------------------------
  2027. # Init host
  2028. if failError:
  2029. # no try
  2030. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2031. else:
  2032. try:
  2033. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2034. except:
  2035. host = CarlaHostQtNull()
  2036. host.isControl = isControl
  2037. host.isPlugin = isPlugin
  2038. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  2039. host.set_file_callback(fileCallback)
  2040. # If it's a plugin the paths are already set
  2041. if not isPlugin:
  2042. host.pathBinaries = pathBinaries
  2043. host.pathResources = pathResources
  2044. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  2045. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  2046. if not isControl:
  2047. host.nsmOK = host.nsm_init(os.getpid(), initName)
  2048. # --------------------------------------------------------------------------------------------------------
  2049. # Init utils
  2050. gCarla.utils = CarlaUtils(utilsname)
  2051. gCarla.utils.set_process_name(os.path.basename(initName))
  2052. try:
  2053. sys.stdout.flush()
  2054. except:
  2055. pass
  2056. sys.stdout = CarlaPrint(False)
  2057. sys.stderr = CarlaPrint(True)
  2058. if config_UseQt5:
  2059. sys.excepthook = sys_excepthook
  2060. # --------------------------------------------------------------------------------------------------------
  2061. # Done
  2062. return host
  2063. # ------------------------------------------------------------------------------------------------------------
  2064. # Load host settings
  2065. def loadHostSettings(host):
  2066. # kdevelop likes this :)
  2067. if False: host = CarlaHostNull()
  2068. settings = QSettings("falkTX", "Carla2")
  2069. try:
  2070. host.experimental = settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool)
  2071. except:
  2072. host.experimental = CARLA_DEFAULT_MAIN_EXPERIMENTAL
  2073. try:
  2074. host.exportLV2 = settings.value(CARLA_KEY_EXPERIMENTAL_EXPORT_LV2, CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT, type=bool)
  2075. except:
  2076. host.exportLV2 = CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT
  2077. try:
  2078. host.manageUIs = settings.value(CARLA_KEY_ENGINE_MANAGE_UIS, CARLA_DEFAULT_MANAGE_UIS, type=bool)
  2079. except:
  2080. host.manageUIs = CARLA_DEFAULT_MANAGE_UIS
  2081. try:
  2082. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  2083. except:
  2084. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  2085. try:
  2086. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  2087. except:
  2088. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  2089. try:
  2090. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  2091. except:
  2092. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  2093. try:
  2094. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  2095. except:
  2096. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  2097. try:
  2098. host.preventBadBehaviour = settings.value(CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, type=bool)
  2099. except:
  2100. host.preventBadBehaviour = CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR
  2101. try:
  2102. host.showLogs = settings.value(CARLA_KEY_MAIN_SHOW_LOGS, CARLA_DEFAULT_MAIN_SHOW_LOGS, type=bool)
  2103. except:
  2104. host.showLogs = CARLA_DEFAULT_MAIN_SHOW_LOGS
  2105. try:
  2106. host.showPluginBridges = settings.value(CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES, type=bool)
  2107. except:
  2108. host.showPluginBridges = CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES
  2109. try:
  2110. host.showWineBridges = settings.value(CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES, type=bool)
  2111. except:
  2112. host.showWineBridges = CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES
  2113. try:
  2114. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  2115. except:
  2116. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  2117. try:
  2118. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  2119. except:
  2120. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  2121. if host.isPlugin:
  2122. return
  2123. try:
  2124. host.transportExtra = settings.value(CARLA_KEY_ENGINE_TRANSPORT_EXTRA, "", type=str)
  2125. except:
  2126. host.transportExtra = ""
  2127. # enums
  2128. if host.audioDriverForced is None:
  2129. try:
  2130. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  2131. except:
  2132. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  2133. if not host.processModeForced:
  2134. try:
  2135. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  2136. except:
  2137. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  2138. host.nextProcessMode = host.processMode
  2139. # --------------------------------------------------------------------------------------------------------
  2140. # fix things if needed
  2141. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  2142. if LADISH_APP_NAME:
  2143. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  2144. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  2145. else:
  2146. host.transportMode = ENGINE_TRANSPORT_MODE_JACK
  2147. if gCarla.nogui:
  2148. host.showLogs = False
  2149. # --------------------------------------------------------------------------------------------------------
  2150. # run headless host now if nogui option enabled
  2151. if gCarla.nogui:
  2152. runHostWithoutUI(host)
  2153. # ------------------------------------------------------------------------------------------------------------
  2154. # Set host settings
  2155. def setHostSettings(host):
  2156. # kdevelop likes this :)
  2157. if False: host = CarlaHostNull()
  2158. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  2159. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  2160. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  2161. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  2162. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  2163. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  2164. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  2165. if host.isPlugin or host.isRemote or host.is_engine_running():
  2166. return
  2167. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  2168. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, host.transportExtra)
  2169. host.set_engine_option(ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT, host.showLogs, "")
  2170. # ------------------------------------------------------------------------------------------------------------
  2171. # Set Engine settings according to carla preferences. Returns selected audio driver.
  2172. def setEngineSettings(host):
  2173. # kdevelop likes this :)
  2174. if False: host = CarlaHostNull()
  2175. # --------------------------------------------------------------------------------------------------------
  2176. # do nothing if control
  2177. if host.isControl:
  2178. return "Control"
  2179. # --------------------------------------------------------------------------------------------------------
  2180. settings = QSettings("falkTX", "Carla2")
  2181. # --------------------------------------------------------------------------------------------------------
  2182. # main settings
  2183. setHostSettings(host)
  2184. # --------------------------------------------------------------------------------------------------------
  2185. # plugin paths
  2186. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  2187. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  2188. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  2189. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  2190. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  2191. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  2192. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  2193. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  2194. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  2195. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  2196. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  2197. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  2198. # --------------------------------------------------------------------------------------------------------
  2199. # don't continue if plugin
  2200. if host.isPlugin:
  2201. return "Plugin"
  2202. # --------------------------------------------------------------------------------------------------------
  2203. # wine settings
  2204. optWineExecutable = settings.value(CARLA_KEY_WINE_EXECUTABLE, CARLA_DEFAULT_WINE_EXECUTABLE, type=str)
  2205. optWineAutoPrefix = settings.value(CARLA_KEY_WINE_AUTO_PREFIX, CARLA_DEFAULT_WINE_AUTO_PREFIX, type=bool)
  2206. optWineFallbackPrefix = settings.value(CARLA_KEY_WINE_FALLBACK_PREFIX, CARLA_DEFAULT_WINE_FALLBACK_PREFIX, type=str)
  2207. optWineRtPrioEnabled = settings.value(CARLA_KEY_WINE_RT_PRIO_ENABLED, CARLA_DEFAULT_WINE_RT_PRIO_ENABLED, type=bool)
  2208. optWineBaseRtPrio = settings.value(CARLA_KEY_WINE_BASE_RT_PRIO, CARLA_DEFAULT_WINE_BASE_RT_PRIO, type=int)
  2209. optWineServerRtPrio = settings.value(CARLA_KEY_WINE_SERVER_RT_PRIO, CARLA_DEFAULT_WINE_SERVER_RT_PRIO, type=int)
  2210. host.set_engine_option(ENGINE_OPTION_WINE_EXECUTABLE, 0, optWineExecutable)
  2211. host.set_engine_option(ENGINE_OPTION_WINE_AUTO_PREFIX, 1 if optWineAutoPrefix else 0, "")
  2212. host.set_engine_option(ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, os.path.expanduser(optWineFallbackPrefix))
  2213. host.set_engine_option(ENGINE_OPTION_WINE_RT_PRIO_ENABLED, 1 if optWineRtPrioEnabled else 0, "")
  2214. host.set_engine_option(ENGINE_OPTION_WINE_BASE_RT_PRIO, optWineBaseRtPrio, "")
  2215. host.set_engine_option(ENGINE_OPTION_WINE_SERVER_RT_PRIO, optWineServerRtPrio, "")
  2216. # --------------------------------------------------------------------------------------------------------
  2217. # driver and device settings
  2218. # driver name
  2219. if host.audioDriverForced is not None:
  2220. audioDriver = host.audioDriverForced
  2221. else:
  2222. try:
  2223. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  2224. except:
  2225. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  2226. # driver options
  2227. try:
  2228. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  2229. except:
  2230. audioDevice = ""
  2231. try:
  2232. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  2233. except:
  2234. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  2235. try:
  2236. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  2237. except:
  2238. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  2239. try:
  2240. audioTripleBuffer = settings.value("%s%s/TripleBuffer" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER, type=int)
  2241. except:
  2242. audioTripleBuffer = CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER
  2243. # Only setup audio things if engine is not running
  2244. if not host.is_engine_running():
  2245. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  2246. if not audioDriver.startswith("JACK"):
  2247. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  2248. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  2249. host.set_engine_option(ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, audioTripleBuffer, "")
  2250. # --------------------------------------------------------------------------------------------------------
  2251. # fix things if needed
  2252. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  2253. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  2254. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, host.transportExtra)
  2255. # --------------------------------------------------------------------------------------------------------
  2256. # return selected driver name
  2257. return audioDriver
  2258. # ------------------------------------------------------------------------------------------------------------
  2259. # Run Carla without showing UI
  2260. def runHostWithoutUI(host):
  2261. # kdevelop likes this :)
  2262. if False: host = CarlaHostNull()
  2263. # --------------------------------------------------------------------------------------------------------
  2264. # Some initial checks
  2265. if not gCarla.nogui:
  2266. return
  2267. projectFile = getInitialProjectFile(QCoreApplication.instance(), True)
  2268. if not projectFile:
  2269. print("Carla no-gui mode can only be used together with a project file.")
  2270. sys.exit(1)
  2271. # --------------------------------------------------------------------------------------------------------
  2272. # Additional imports
  2273. from time import sleep
  2274. # --------------------------------------------------------------------------------------------------------
  2275. # Init engine
  2276. audioDriver = setEngineSettings(host)
  2277. if not host.engine_init(audioDriver, "Carla"):
  2278. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  2279. sys.exit(1)
  2280. if not host.load_project(projectFile):
  2281. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  2282. host.engine_close()
  2283. sys.exit(1)
  2284. # --------------------------------------------------------------------------------------------------------
  2285. # Idle
  2286. print("Carla ready!")
  2287. while host.is_engine_running() and not gCarla.term:
  2288. host.engine_idle()
  2289. sleep(0.0333) # 30 Hz
  2290. # --------------------------------------------------------------------------------------------------------
  2291. # Stop
  2292. host.engine_close()
  2293. sys.exit(0)
  2294. # ------------------------------------------------------------------------------------------------------------