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.

2481 lines
95KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2016 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. if config_UseQt5:
  23. from PyQt5.QtCore import qCritical, QFileInfo, QModelIndex, QPointF, QTimer
  24. from PyQt5.QtGui import QImage, QPalette
  25. from PyQt5.QtWidgets import QAction, QApplication, QFileSystemModel, QListWidgetItem, QMainWindow
  26. else:
  27. from PyQt4.QtCore import qCritical, QFileInfo, QModelIndex, QPointF, QTimer
  28. from PyQt4.QtGui import QImage, QPalette
  29. from PyQt4.QtGui import QAction, QApplication, QFileSystemModel, QListWidgetItem, QMainWindow
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (Custom)
  32. import patchcanvas
  33. import ui_carla_host
  34. from carla_app import *
  35. from carla_database import *
  36. from carla_panels import *
  37. from carla_settings import *
  38. from carla_utils import *
  39. from carla_widgets import *
  40. from digitalpeakmeter import DigitalPeakMeter
  41. from 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. # Session Management support
  54. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  55. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  56. NSM_URL = os.getenv("NSM_URL")
  57. # ------------------------------------------------------------------------------------------------------------
  58. # Host Window
  59. class HostWindow(QMainWindow):
  60. #class HostWindow(QMainWindow, PluginEditParentMeta, metaclass=PyQtMetaClass):
  61. # signals
  62. SIGTERM = pyqtSignal()
  63. SIGUSR1 = pyqtSignal()
  64. # --------------------------------------------------------------------------------------------------------
  65. def __init__(self, host, withCanvas, parent=None):
  66. QMainWindow.__init__(self, parent)
  67. self.host = host
  68. self.ui = ui_carla_host.Ui_CarlaHostW()
  69. self.ui.setupUi(self)
  70. gCarla.gui = self
  71. if False:
  72. # kdevelop likes this :)
  73. host = CarlaHostNull()
  74. self.host = host
  75. self._true = c_char_p("true".encode("utf-8"))
  76. self.fParentOrSelf = parent or self
  77. # ----------------------------------------------------------------------------------------------------
  78. # Internal stuff
  79. self.fIdleTimerFast = 0
  80. self.fIdleTimerSlow = 0
  81. self.fLadspaRdfNeedsUpdate = True
  82. self.fLadspaRdfList = []
  83. self.fPluginCount = 0
  84. self.fPluginList = []
  85. self.fProjectFilename = ""
  86. self.fIsProjectLoading = False
  87. self.fCurrentlyRemovingAllPlugins = False
  88. # run a custom action after engine is properly closed
  89. # 1 for close carla, 2 for load project
  90. self.fCustomStopAction = 0
  91. # first attempt of auto-start engine doesn't show an error
  92. self.fFirstEngineInit = True
  93. # to be filled with key-value pairs of current settings
  94. self.fSavedSettings = {}
  95. if host.isControl:
  96. self.fClientName = "Carla-Control"
  97. self.fSessionManagerName = "Control"
  98. elif host.isPlugin:
  99. self.fClientName = "Carla-Plugin"
  100. self.fSessionManagerName = "Plugin"
  101. elif LADISH_APP_NAME:
  102. self.fClientName = LADISH_APP_NAME
  103. self.fSessionManagerName = "LADISH"
  104. elif NSM_URL and host.nsmOK:
  105. self.fClientName = "Carla.tmp"
  106. self.fSessionManagerName = "Non Session Manager TMP"
  107. else:
  108. self.fClientName = CARLA_CLIENT_NAME or "Carla"
  109. self.fSessionManagerName = ""
  110. # ----------------------------------------------------------------------------------------------------
  111. # Internal stuff (patchbay)
  112. self.fExportImage = QImage()
  113. self.fPeaksCleared = True
  114. self.fExternalPatchbay = False
  115. self.fSelectedPlugins = []
  116. self.fCanvasWidth = 0
  117. self.fCanvasHeight = 0
  118. self.fMiniCanvasUpdateTimeout = 0
  119. self.fWithCanvas = withCanvas
  120. # ----------------------------------------------------------------------------------------------------
  121. # Set up GUI (engine stopped)
  122. if self.host.isPlugin or self.host.isControl:
  123. self.ui.act_file_save.setVisible(False)
  124. self.ui.act_engine_start.setEnabled(False)
  125. self.ui.act_engine_start.setVisible(False)
  126. self.ui.act_engine_stop.setEnabled(False)
  127. self.ui.act_engine_stop.setVisible(False)
  128. self.ui.act_settings_show_time_panel.setEnabled(False)
  129. self.ui.act_settings_show_time_panel.setVisible(False)
  130. self.ui.menu_Engine.setEnabled(False)
  131. self.ui.menu_Engine.setVisible(False)
  132. self.ui.menu_Engine.menuAction().setVisible(False)
  133. if self.host.isControl:
  134. self.ui.act_file_new.setVisible(False)
  135. self.ui.act_file_open.setVisible(False)
  136. self.ui.act_file_save.setVisible(False)
  137. self.ui.act_file_save_as.setVisible(False)
  138. self.ui.act_plugin_add.setVisible(False)
  139. self.ui.act_plugin_add2.setVisible(False)
  140. self.ui.act_plugin_remove_all.setVisible(False)
  141. self.ui.menu_Plugin.setEnabled(False)
  142. self.ui.menu_Plugin.setVisible(False)
  143. self.ui.menu_Plugin.menuAction().setVisible(False)
  144. else:
  145. self.ui.act_file_save_as.setText(self.tr("Export as..."))
  146. else:
  147. self.ui.act_engine_start.setEnabled(True)
  148. if not self.host.isControl:
  149. self.ui.act_file_connect.setEnabled(False)
  150. self.ui.act_file_connect.setVisible(False)
  151. self.ui.act_file_refresh.setEnabled(False)
  152. self.ui.act_file_refresh.setVisible(False)
  153. if self.fSessionManagerName and not self.host.isPlugin:
  154. self.ui.act_file_new.setEnabled(False)
  155. self.ui.act_file_open.setEnabled(False)
  156. self.ui.act_file_save.setEnabled(False)
  157. self.ui.act_file_save_as.setEnabled(False)
  158. self.ui.act_engine_stop.setEnabled(False)
  159. self.ui.act_plugin_remove_all.setEnabled(False)
  160. self.ui.act_canvas_show_internal.setChecked(False)
  161. self.ui.act_canvas_show_internal.setVisible(False)
  162. self.ui.act_canvas_show_external.setChecked(False)
  163. self.ui.act_canvas_show_external.setVisible(False)
  164. self.ui.menu_PluginMacros.setEnabled(False)
  165. self.ui.menu_Canvas.setEnabled(False)
  166. self.ui.dockWidgetTitleBar = QWidget(self)
  167. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  168. if not withCanvas:
  169. self.ui.act_canvas_show_internal.setVisible(False)
  170. self.ui.act_canvas_show_external.setVisible(False)
  171. self.ui.act_canvas_arrange.setVisible(False)
  172. self.ui.act_canvas_refresh.setVisible(False)
  173. self.ui.act_canvas_save_image.setVisible(False)
  174. self.ui.act_canvas_zoom_100.setVisible(False)
  175. self.ui.act_canvas_zoom_fit.setVisible(False)
  176. self.ui.act_canvas_zoom_in.setVisible(False)
  177. self.ui.act_canvas_zoom_out.setVisible(False)
  178. self.ui.act_settings_show_meters.setVisible(False)
  179. self.ui.act_settings_show_keyboard.setVisible(False)
  180. self.ui.menu_Canvas_Zoom.setEnabled(False)
  181. self.ui.menu_Canvas_Zoom.setVisible(False)
  182. self.ui.menu_Canvas_Zoom.menuAction().setVisible(False)
  183. self.ui.menu_Canvas.setEnabled(False)
  184. self.ui.menu_Canvas.setVisible(False)
  185. self.ui.menu_Canvas.menuAction().setVisible(False)
  186. self.ui.miniCanvasPreview.hide()
  187. self.ui.tabWidget.removeTab(1)
  188. self.ui.tabWidget.tabBar().hide()
  189. if host.isControl:
  190. self.ui.dockWidget.hide()
  191. # ----------------------------------------------------------------------------------------------------
  192. # Set up GUI (disk)
  193. self.fDirModel = QFileSystemModel(self)
  194. self.fDirModel.setRootPath(HOME)
  195. self.fDirModel.setNameFilters(gCarla.utils.get_supported_file_extensions().split(";"))
  196. self.ui.fileTreeView.setModel(self.fDirModel)
  197. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  198. self.ui.fileTreeView.setColumnHidden(1, True)
  199. self.ui.fileTreeView.setColumnHidden(2, True)
  200. self.ui.fileTreeView.setColumnHidden(3, True)
  201. self.ui.fileTreeView.setHeaderHidden(True)
  202. # ----------------------------------------------------------------------------------------------------
  203. # Set up GUI (panels)
  204. self.ui.panelTime = CarlaPanelTime(host, self)
  205. self.ui.panelTime.setEnabled(False)
  206. self.ui.panelTime.adjustSize()
  207. # ----------------------------------------------------------------------------------------------------
  208. # Set up GUI (rack)
  209. self.ui.listWidget.setHost(self.host)
  210. sb = self.ui.listWidget.verticalScrollBar()
  211. self.ui.rackScrollBar.setMinimum(sb.minimum())
  212. self.ui.rackScrollBar.setMaximum(sb.maximum())
  213. self.ui.rackScrollBar.setValue(sb.value())
  214. sb.rangeChanged.connect(self.ui.rackScrollBar.setRange)
  215. sb.valueChanged.connect(self.ui.rackScrollBar.setValue)
  216. self.ui.rackScrollBar.rangeChanged.connect(sb.setRange)
  217. self.ui.rackScrollBar.valueChanged.connect(sb.setValue)
  218. self.ui.rack.setStyleSheet("""
  219. QLabel#pad_left {
  220. background-image: url(:/bitmaps/rack_padding_left.png);
  221. background-repeat: repeat-y;
  222. }
  223. QLabel#pad_right {
  224. background-image: url(:/bitmaps/rack_padding_right.png);
  225. background-repeat: repeat-y;
  226. }
  227. CarlaRackList#CarlaRackList {
  228. background-color: black;
  229. }
  230. """)
  231. # ----------------------------------------------------------------------------------------------------
  232. # Set up GUI (patchbay)
  233. self.ui.peak_in.setChannelCount(2)
  234. self.ui.peak_in.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  235. self.ui.peak_in.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  236. self.ui.peak_in.setFixedWidth(25)
  237. self.ui.peak_out.setChannelCount(2)
  238. self.ui.peak_out.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  239. self.ui.peak_out.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  240. self.ui.peak_out.setFixedWidth(25)
  241. self.ui.scrollArea = PixmapKeyboardHArea(self.ui.patchbay)
  242. self.ui.keyboard = self.ui.scrollArea.keyboard
  243. self.ui.patchbay.layout().addWidget(self.ui.scrollArea, 1, 0, 1, 0)
  244. self.ui.scrollArea.setEnabled(False)
  245. self.ui.miniCanvasPreview.setRealParent(self)
  246. # ----------------------------------------------------------------------------------------------------
  247. # Set up GUI (special stuff for Mac OS)
  248. if MACOS:
  249. self.ui.act_file_quit.setMenuRole(QAction.QuitRole)
  250. self.ui.act_settings_configure.setMenuRole(QAction.PreferencesRole)
  251. self.ui.act_help_about.setMenuRole(QAction.AboutRole)
  252. self.ui.act_help_about_juce.setMenuRole(QAction.ApplicationSpecificRole)
  253. self.ui.act_help_about_qt.setMenuRole(QAction.AboutQtRole)
  254. self.ui.menu_Settings.setTitle("Panels")
  255. self.ui.menu_Help.hide()
  256. # ----------------------------------------------------------------------------------------------------
  257. # Load Settings
  258. self.loadSettings(True)
  259. # ----------------------------------------------------------------------------------------------------
  260. # Set-up Canvas
  261. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  262. self.ui.graphicsView.setScene(self.scene)
  263. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, bool(self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  264. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  265. self.ui.glView = QGLWidget(self)
  266. self.ui.graphicsView.setViewport(self.ui.glView)
  267. self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  268. self.setupCanvas()
  269. # ----------------------------------------------------------------------------------------------------
  270. # Connect actions to functions
  271. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  272. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  273. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  274. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  275. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  276. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  277. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  278. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  279. self.ui.act_plugin_remove_all.triggered.connect(self.slot_pluginRemoveAll)
  280. self.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  281. self.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  282. self.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  283. self.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  284. self.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  285. self.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  286. self.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  287. self.ui.act_plugins_compact.triggered.connect(self.slot_pluginsCompact)
  288. self.ui.act_plugins_expand.triggered.connect(self.slot_pluginsExpand)
  289. self.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  290. self.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  291. self.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  292. self.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  293. self.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  294. self.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  295. self.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  296. self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  297. self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  298. self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  299. self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  300. self.ui.act_settings_show_time_panel.toggled.connect(self.slot_showTimePanel)
  301. self.ui.act_settings_show_toolbar.toggled.connect(self.slot_showToolbar)
  302. self.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  303. self.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  304. self.ui.act_settings_show_side_panel.toggled.connect(self.slot_showSidePanel)
  305. self.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  306. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  307. self.ui.act_help_about_juce.triggered.connect(self.slot_aboutJuce)
  308. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  309. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  310. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  311. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  312. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  313. self.ui.listWidget.customContextMenuRequested.connect(self.showPluginActionsMenu)
  314. self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  315. self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  316. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  317. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  318. self.ui.miniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  319. self.ui.panelTime.finished.connect(self.slot_timePanelClosed)
  320. self.ui.tabWidget.currentChanged.connect(self.slot_tabChanged)
  321. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  322. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  323. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  324. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  325. self.SIGTERM.connect(self.slot_handleSIGTERM)
  326. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  327. host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  328. host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  329. host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  330. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  331. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  332. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  333. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  334. host.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  335. host.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  336. host.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  337. host.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  338. host.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  339. host.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  340. host.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  341. host.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  342. host.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  343. host.NSMCallback.connect(self.slot_handleNSMCallback)
  344. host.DebugCallback.connect(self.slot_handleDebugCallback)
  345. host.InfoCallback.connect(self.slot_handleInfoCallback)
  346. host.ErrorCallback.connect(self.slot_handleErrorCallback)
  347. host.QuitCallback.connect(self.slot_handleQuitCallback)
  348. # ----------------------------------------------------------------------------------------------------
  349. # Final setup
  350. self.setProperWindowTitle()
  351. # Qt needs this so it properly creates & resizes the canvas
  352. self.ui.tabWidget.blockSignals(True)
  353. self.ui.tabWidget.setCurrentIndex(1)
  354. self.ui.tabWidget.setCurrentIndex(0)
  355. self.ui.tabWidget.blockSignals(False)
  356. # Plugin needs to have timers always running so it receives messages
  357. if self.host.isPlugin:
  358. self.startTimers()
  359. # Start in patchbay tab if using forced patchbay mode
  360. if host.processModeForced and host.processMode == ENGINE_PROCESS_MODE_PATCHBAY and not host.isControl:
  361. self.ui.tabWidget.setCurrentIndex(1)
  362. # Load initial project file if set
  363. if not (self.host.isControl or self.host.isPlugin):
  364. projectFile = getInitialProjectFile(QApplication.instance())
  365. if projectFile:
  366. self.loadProjectLater(projectFile)
  367. # For NSM we wait for the open message
  368. if NSM_URL and host.nsmOK:
  369. host.nsm_ready(-1)
  370. return
  371. QTimer.singleShot(0, self.slot_engineStart)
  372. # --------------------------------------------------------------------------------------------------------
  373. # Setup
  374. def compactPlugin(self, pluginId):
  375. if pluginId > self.fPluginCount:
  376. return
  377. pitem = self.fPluginList[pluginId]
  378. if pitem is None:
  379. return
  380. pitem.recreateWidget(True)
  381. def setLoadRDFsNeeded(self):
  382. self.fLadspaRdfNeedsUpdate = True
  383. def setProperWindowTitle(self):
  384. title = self.fClientName
  385. if self.fProjectFilename and not self.host.nsmOK:
  386. title += " - %s" % os.path.basename(self.fProjectFilename)
  387. if self.fSessionManagerName:
  388. title += " (%s)" % self.fSessionManagerName
  389. self.setWindowTitle(title)
  390. # --------------------------------------------------------------------------------------------------------
  391. # Files
  392. def loadProjectNow(self):
  393. if not self.fProjectFilename:
  394. return qCritical("ERROR: loading project without filename set")
  395. if self.host.nsmOK and not os.path.exists(self.fProjectFilename):
  396. return
  397. self.projectLoadingStarted()
  398. self.fIsProjectLoading = True
  399. self.host.load_project(self.fProjectFilename)
  400. self.fIsProjectLoading = False
  401. self.projectLoadingFinished()
  402. def loadProjectLater(self, filename):
  403. self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
  404. self.setProperWindowTitle()
  405. QTimer.singleShot(1, self.slot_loadProjectNow)
  406. def saveProjectNow(self):
  407. if not self.fProjectFilename:
  408. return qCritical("ERROR: saving project without filename set")
  409. self.host.save_project(self.fProjectFilename)
  410. def projectLoadingStarted(self):
  411. self.ui.rack.setEnabled(False)
  412. self.ui.graphicsView.setEnabled(False)
  413. def projectLoadingFinished(self):
  414. self.ui.rack.setEnabled(True)
  415. self.ui.graphicsView.setEnabled(True)
  416. QTimer.singleShot(1000, self.slot_canvasRefresh)
  417. # --------------------------------------------------------------------------------------------------------
  418. # Files (menu actions)
  419. @pyqtSlot()
  420. def slot_fileNew(self):
  421. self.slot_pluginRemoveAll()
  422. self.fProjectFilename = ""
  423. self.setProperWindowTitle()
  424. @pyqtSlot()
  425. def slot_fileOpen(self):
  426. fileFilter = self.tr("Carla Project File (*.carxp);;Carla Preset File (*.carxs)")
  427. filename = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  428. if config_UseQt5:
  429. filename = filename[0]
  430. if not filename:
  431. return
  432. newFile = True
  433. if self.fPluginCount > 0:
  434. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  435. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  436. newFile = (ask == QMessageBox.Yes)
  437. if newFile:
  438. self.slot_pluginRemoveAll()
  439. self.fProjectFilename = filename
  440. self.setProperWindowTitle()
  441. self.loadProjectNow()
  442. else:
  443. filenameOld = self.fProjectFilename
  444. self.fProjectFilename = filename
  445. self.loadProjectNow()
  446. self.fProjectFilename = filenameOld
  447. @pyqtSlot()
  448. def slot_fileSave(self, saveAs=False):
  449. if self.fProjectFilename and not saveAs:
  450. return self.saveProjectNow()
  451. fileFilter = self.tr("Carla Project File (*.carxp)")
  452. filename = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  453. if config_UseQt5:
  454. filename = filename[0]
  455. if not filename:
  456. return
  457. if not filename.lower().endswith(".carxp"):
  458. filename += ".carxp"
  459. if self.fProjectFilename != filename:
  460. self.fProjectFilename = filename
  461. self.setProperWindowTitle()
  462. self.saveProjectNow()
  463. @pyqtSlot()
  464. def slot_fileSaveAs(self):
  465. self.slot_fileSave(True)
  466. @pyqtSlot()
  467. def slot_loadProjectNow(self):
  468. self.loadProjectNow()
  469. # --------------------------------------------------------------------------------------------------------
  470. # Engine (menu actions)
  471. @pyqtSlot()
  472. def slot_engineStart(self):
  473. audioDriver = setEngineSettings(self.host)
  474. firstInit = self.fFirstEngineInit
  475. self.fFirstEngineInit = False
  476. if self.host.engine_init(audioDriver, self.fClientName) or firstInit:
  477. return
  478. audioError = self.host.get_last_error()
  479. if audioError:
  480. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  481. else:
  482. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  483. @pyqtSlot()
  484. def slot_engineStop(self, forced = False):
  485. if self.fPluginCount == 0:
  486. self.engineStopFinal()
  487. return True
  488. if not forced:
  489. 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"
  490. "Do you want to do this now?"),
  491. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  492. if ask != QMessageBox.Yes:
  493. return
  494. return self.slot_engineStopTryAgain()
  495. @pyqtSlot()
  496. def slot_engineStopTryAgain(self):
  497. if self.host.is_engine_running() and not self.host.set_engine_about_to_close():
  498. QTimer.singleShot(0, self.slot_engineStopTryAgain)
  499. return False
  500. self.engineStopFinal()
  501. return True
  502. def engineStopFinal(self):
  503. self.killTimers()
  504. self.removeAllPlugins()
  505. if self.host.is_engine_running():
  506. self.host.remove_all_plugins()
  507. if not self.host.engine_close():
  508. print(self.host.get_last_error())
  509. if self.fCustomStopAction == 1:
  510. self.close()
  511. elif self.fCustomStopAction == 2:
  512. self.slot_engineStart()
  513. self.loadProjectNow()
  514. self.host.nsm_ready(2) # open
  515. self.fCustomStopAction = 0
  516. # --------------------------------------------------------------------------------------------------------
  517. # Engine (host callbacks)
  518. @pyqtSlot(int, int, str)
  519. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  520. self.ui.menu_PluginMacros.setEnabled(True)
  521. self.ui.menu_Canvas.setEnabled(True)
  522. self.ui.act_canvas_show_internal.blockSignals(True)
  523. self.ui.act_canvas_show_external.blockSignals(True)
  524. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and not (self.host.isControl or self.host.isPlugin):
  525. self.ui.act_canvas_show_internal.setChecked(True)
  526. self.ui.act_canvas_show_internal.setVisible(True)
  527. self.ui.act_canvas_show_external.setChecked(False)
  528. self.ui.act_canvas_show_external.setVisible(True)
  529. else:
  530. self.ui.act_canvas_show_internal.setChecked(False)
  531. self.ui.act_canvas_show_internal.setVisible(False)
  532. self.ui.act_canvas_show_external.setChecked(False)
  533. self.ui.act_canvas_show_external.setVisible(False)
  534. self.ui.act_canvas_show_internal.blockSignals(False)
  535. self.ui.act_canvas_show_external.blockSignals(False)
  536. if not (self.host.isControl or self.host.isPlugin):
  537. canSave = (self.fProjectFilename and os.path.exists(self.fProjectFilename)) or not self.fSessionManagerName
  538. self.ui.act_file_save.setEnabled(canSave)
  539. self.ui.act_engine_start.setEnabled(False)
  540. self.ui.act_engine_stop.setEnabled(True)
  541. self.ui.panelTime.setEnabled(True)
  542. if self.host.isPlugin or not self.fSessionManagerName:
  543. self.ui.act_file_open.setEnabled(True)
  544. self.ui.act_file_save_as.setEnabled(True)
  545. self.startTimers()
  546. @pyqtSlot()
  547. def slot_handleEngineStoppedCallback(self):
  548. patchcanvas.clear()
  549. self.killTimers()
  550. # just in case
  551. self.removeAllPlugins()
  552. self.ui.menu_PluginMacros.setEnabled(False)
  553. self.ui.menu_Canvas.setEnabled(False)
  554. if not (self.host.isControl or self.host.isPlugin):
  555. self.ui.act_file_save.setEnabled(False)
  556. self.ui.act_engine_start.setEnabled(True)
  557. self.ui.act_engine_stop.setEnabled(False)
  558. self.ui.panelTime.setEnabled(False)
  559. if self.host.isPlugin or not self.fSessionManagerName:
  560. self.ui.act_file_open.setEnabled(False)
  561. self.ui.act_file_save_as.setEnabled(False)
  562. # --------------------------------------------------------------------------------------------------------
  563. # Plugins
  564. def removeAllPlugins(self):
  565. self.ui.act_plugin_remove_all.setEnabled(False)
  566. patchcanvas.handleAllPluginsRemoved()
  567. while self.ui.listWidget.takeItem(0):
  568. pass
  569. self.clearSideStuff()
  570. for pitem in self.fPluginList:
  571. if pitem is None:
  572. continue
  573. pitem.close()
  574. del pitem
  575. self.fPluginCount = 0
  576. self.fPluginList = []
  577. # --------------------------------------------------------------------------------------------------------
  578. # Plugins (menu actions)
  579. def showAddPluginDialog(self):
  580. dialog = PluginDatabaseW(self.fParentOrSelf, self.host)
  581. if not dialog.exec_():
  582. return
  583. if not self.host.is_engine_running():
  584. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  585. return
  586. btype = dialog.fRetPlugin['build']
  587. ptype = dialog.fRetPlugin['type']
  588. filename = dialog.fRetPlugin['filename']
  589. label = dialog.fRetPlugin['label']
  590. uniqueId = dialog.fRetPlugin['uniqueId']
  591. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  592. return (btype, ptype, filename, label, uniqueId, extraPtr)
  593. @pyqtSlot()
  594. def showPluginActionsMenu(self):
  595. menu = QMenu(self)
  596. if config_UseQt5:
  597. menu.addSection("Plugins")
  598. else:
  599. # fake section
  600. act = menu.addAction(" Plugins")
  601. font = act.font()
  602. font.setBold(True)
  603. act.setFont(font)
  604. act.setEnabled(False)
  605. menu.addSeparator()
  606. menu.addAction(self.ui.act_plugin_add)
  607. menu.addAction(self.ui.act_plugin_remove_all)
  608. if config_UseQt5:
  609. menu.addSection("All plugins (macros)")
  610. else:
  611. # fake space
  612. act = menu.addAction(" ")
  613. font = act.font()
  614. font.setBold(True)
  615. font.setPointSize(font.pointSize()/2)
  616. act.setEnabled(False)
  617. # fake section
  618. act = menu.addAction(" All plugins (macros)")
  619. font = act.font()
  620. font.setBold(True)
  621. act.setFont(font)
  622. act.setEnabled(False)
  623. menu.addSeparator()
  624. menu.addAction(self.ui.act_plugins_enable)
  625. menu.addAction(self.ui.act_plugins_disable)
  626. menu.addSeparator()
  627. menu.addAction(self.ui.act_plugins_volume100)
  628. menu.addAction(self.ui.act_plugins_mute)
  629. menu.addSeparator()
  630. menu.addAction(self.ui.act_plugins_wet100)
  631. menu.addAction(self.ui.act_plugins_bypass)
  632. menu.addSeparator()
  633. menu.addAction(self.ui.act_plugins_center)
  634. menu.addSeparator()
  635. menu.addAction(self.ui.act_plugins_compact)
  636. menu.addAction(self.ui.act_plugins_expand)
  637. menu.exec_(QCursor.pos())
  638. @pyqtSlot()
  639. def slot_pluginAdd(self):
  640. data = self.showAddPluginDialog()
  641. if data is None:
  642. return
  643. btype, ptype, filename, label, uniqueId, extraPtr = data
  644. if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0):
  645. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  646. @pyqtSlot()
  647. def slot_pluginRemoveAll(self):
  648. if self.fPluginCount == 0:
  649. return
  650. # FIXME - this is not working
  651. # removing a plugin causes flicker, the rack-list becomes empty for some time
  652. # this breaks the remove-all animation, so don't bother using it
  653. if False and not self.host.isPlugin:
  654. self.projectLoadingStarted()
  655. app = QApplication.instance()
  656. app.processEvents()
  657. for i in reversed(range(self.fPluginCount)):
  658. self.host.remove_plugin(i)
  659. app.processEvents()
  660. self.projectLoadingFinished()
  661. self.fCurrentlyRemovingAllPlugins = True
  662. ok = self.host.remove_all_plugins()
  663. self.fCurrentlyRemovingAllPlugins = False
  664. if ok:
  665. self.removeAllPlugins()
  666. else:
  667. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  668. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  669. self.fCurrentlyRemovingAllPlugins = False
  670. # --------------------------------------------------------------------------------------------------------
  671. # Plugins (macros)
  672. @pyqtSlot()
  673. def slot_pluginsEnable(self):
  674. if not self.host.is_engine_running():
  675. return
  676. for pitem in self.fPluginList:
  677. if pitem is None:
  678. break
  679. pitem.getWidget().setActive(True, True, True)
  680. @pyqtSlot()
  681. def slot_pluginsDisable(self):
  682. if not self.host.is_engine_running():
  683. return
  684. for pitem in self.fPluginList:
  685. if pitem is None:
  686. break
  687. pitem.getWidget().setActive(False, True, True)
  688. @pyqtSlot()
  689. def slot_pluginsVolume100(self):
  690. if not self.host.is_engine_running():
  691. return
  692. for pitem in self.fPluginList:
  693. if pitem is None:
  694. break
  695. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  696. @pyqtSlot()
  697. def slot_pluginsMute(self):
  698. if not self.host.is_engine_running():
  699. return
  700. for pitem in self.fPluginList:
  701. if pitem is None:
  702. break
  703. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  704. @pyqtSlot()
  705. def slot_pluginsWet100(self):
  706. if not self.host.is_engine_running():
  707. return
  708. for pitem in self.fPluginList:
  709. if pitem is None:
  710. break
  711. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  712. @pyqtSlot()
  713. def slot_pluginsBypass(self):
  714. if not self.host.is_engine_running():
  715. return
  716. for pitem in self.fPluginList:
  717. if pitem is None:
  718. break
  719. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  720. @pyqtSlot()
  721. def slot_pluginsCenter(self):
  722. if not self.host.is_engine_running():
  723. return
  724. for pitem in self.fPluginList:
  725. if pitem is None:
  726. break
  727. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  728. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  729. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  730. @pyqtSlot()
  731. def slot_pluginsCompact(self):
  732. for pitem in self.fPluginList:
  733. if pitem is None:
  734. break
  735. pitem.compact()
  736. @pyqtSlot()
  737. def slot_pluginsExpand(self):
  738. for pitem in self.fPluginList:
  739. if pitem is None:
  740. break
  741. pitem.expand()
  742. # --------------------------------------------------------------------------------------------------------
  743. # Plugins (host callbacks)
  744. @pyqtSlot(int, str)
  745. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  746. pitem = self.ui.listWidget.createItem(pluginId, self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  747. self.fPluginList.append(pitem)
  748. self.fPluginCount += 1
  749. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  750. @pyqtSlot(int)
  751. def slot_handlePluginRemovedCallback(self, pluginId):
  752. patchcanvas.handlePluginRemoved(pluginId)
  753. if pluginId in self.fSelectedPlugins:
  754. self.clearSideStuff()
  755. pitem = self.getPluginItem(pluginId)
  756. self.fPluginCount -= 1
  757. self.fPluginList.pop(pluginId)
  758. self.ui.listWidget.takeItem(pluginId)
  759. if pitem is not None:
  760. pitem.close()
  761. del pitem
  762. # push all plugins 1 slot back
  763. for i in range(pluginId, self.fPluginCount):
  764. pitem = self.fPluginList[i]
  765. pitem.setPluginId(i)
  766. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  767. # --------------------------------------------------------------------------------------------------------
  768. # Canvas
  769. def clearSideStuff(self):
  770. self.scene.clearSelection()
  771. self.fSelectedPlugins = []
  772. self.ui.keyboard.allNotesOff(False)
  773. self.ui.scrollArea.setEnabled(False)
  774. self.fPeaksCleared = True
  775. self.ui.peak_in.displayMeter(1, 0.0, True)
  776. self.ui.peak_in.displayMeter(2, 0.0, True)
  777. self.ui.peak_out.displayMeter(1, 0.0, True)
  778. self.ui.peak_out.displayMeter(2, 0.0, True)
  779. def setupCanvas(self):
  780. pOptions = patchcanvas.options_t()
  781. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  782. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  783. pOptions.auto_select_items = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS]
  784. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  785. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  786. pOptions.eyecandy = self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
  787. pFeatures = patchcanvas.features_t()
  788. pFeatures.group_info = False
  789. pFeatures.group_rename = False
  790. pFeatures.port_info = False
  791. pFeatures.port_rename = False
  792. pFeatures.handle_group_pos = True
  793. patchcanvas.setOptions(pOptions)
  794. patchcanvas.setFeatures(pFeatures)
  795. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  796. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  797. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  798. self.fCanvasWidth = int(tryCanvasSize[0])
  799. self.fCanvasHeight = int(tryCanvasSize[1])
  800. else:
  801. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  802. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  803. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  804. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  805. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  806. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  807. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  808. def updateCanvasInitialPos(self):
  809. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  810. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  811. patchcanvas.setInitialPos(x, y)
  812. def updateMiniCanvasLater(self):
  813. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  814. # --------------------------------------------------------------------------------------------------------
  815. # Canvas (menu actions)
  816. @pyqtSlot()
  817. def slot_canvasShowInternal(self):
  818. self.fExternalPatchbay = False
  819. self.ui.act_canvas_show_internal.blockSignals(True)
  820. self.ui.act_canvas_show_external.blockSignals(True)
  821. self.ui.act_canvas_show_internal.setChecked(True)
  822. self.ui.act_canvas_show_external.setChecked(False)
  823. self.ui.act_canvas_show_internal.blockSignals(False)
  824. self.ui.act_canvas_show_external.blockSignals(False)
  825. self.slot_canvasRefresh()
  826. @pyqtSlot()
  827. def slot_canvasShowExternal(self):
  828. self.fExternalPatchbay = True
  829. self.ui.act_canvas_show_internal.blockSignals(True)
  830. self.ui.act_canvas_show_external.blockSignals(True)
  831. self.ui.act_canvas_show_internal.setChecked(False)
  832. self.ui.act_canvas_show_external.setChecked(True)
  833. self.ui.act_canvas_show_internal.blockSignals(False)
  834. self.ui.act_canvas_show_external.blockSignals(False)
  835. self.slot_canvasRefresh()
  836. @pyqtSlot()
  837. def slot_canvasArrange(self):
  838. patchcanvas.arrange()
  839. @pyqtSlot()
  840. def slot_canvasRefresh(self):
  841. patchcanvas.clear()
  842. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and (self.host.isControl or self.host.isPlugin):
  843. return
  844. if self.host.is_engine_running():
  845. self.host.patchbay_refresh(self.fExternalPatchbay)
  846. self.updateMiniCanvasLater()
  847. @pyqtSlot()
  848. def slot_canvasZoomFit(self):
  849. self.scene.zoom_fit()
  850. @pyqtSlot()
  851. def slot_canvasZoomIn(self):
  852. self.scene.zoom_in()
  853. @pyqtSlot()
  854. def slot_canvasZoomOut(self):
  855. self.scene.zoom_out()
  856. @pyqtSlot()
  857. def slot_canvasZoomReset(self):
  858. self.scene.zoom_reset()
  859. @pyqtSlot()
  860. def slot_canvasSaveImage(self):
  861. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  862. if config_UseQt5:
  863. newPath = newPath[0]
  864. if not newPath:
  865. return
  866. self.scene.clearSelection()
  867. if newPath.lower().endswith((".jpg", ".jpeg")):
  868. imgFormat = "JPG"
  869. elif newPath.lower().endswith((".png",)):
  870. imgFormat = "PNG"
  871. else:
  872. # File-dialog may not auto-add the extension
  873. imgFormat = "PNG"
  874. newPath += ".png"
  875. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  876. painter = QPainter(self.fExportImage)
  877. painter.save()
  878. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  879. painter.setRenderHint(QPainter.TextAntialiasing)
  880. self.scene.render(painter)
  881. self.fExportImage.save(newPath, imgFormat, 100)
  882. painter.restore()
  883. # --------------------------------------------------------------------------------------------------------
  884. # Canvas (canvas callbacks)
  885. @pyqtSlot(int, int, QPointF)
  886. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  887. self.updateMiniCanvasLater()
  888. @pyqtSlot(float)
  889. def slot_canvasScaleChanged(self, scale):
  890. self.ui.miniCanvasPreview.setViewScale(scale)
  891. @pyqtSlot(list)
  892. def slot_canvasPluginSelected(self, pluginList):
  893. self.ui.keyboard.allNotesOff(False)
  894. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  895. self.fSelectedPlugins = pluginList
  896. # --------------------------------------------------------------------------------------------------------
  897. # Canvas (host callbacks)
  898. @pyqtSlot(int, int, int, str)
  899. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  900. pcSplit = patchcanvas.SPLIT_UNDEF
  901. pcIcon = patchcanvas.ICON_APPLICATION
  902. if clientIcon == PATCHBAY_ICON_PLUGIN:
  903. pcIcon = patchcanvas.ICON_PLUGIN
  904. if clientIcon == PATCHBAY_ICON_HARDWARE:
  905. pcIcon = patchcanvas.ICON_HARDWARE
  906. elif clientIcon == PATCHBAY_ICON_CARLA:
  907. pass
  908. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  909. pcIcon = patchcanvas.ICON_DISTRHO
  910. elif clientIcon == PATCHBAY_ICON_FILE:
  911. pcIcon = patchcanvas.ICON_FILE
  912. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  913. self.updateMiniCanvasLater()
  914. if pluginId < 0:
  915. return
  916. if pluginId >= self.fPluginCount:
  917. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  918. return
  919. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  920. @pyqtSlot(int)
  921. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  922. patchcanvas.removeGroup(clientId)
  923. self.updateMiniCanvasLater()
  924. @pyqtSlot(int, str)
  925. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  926. patchcanvas.renameGroup(clientId, newClientName)
  927. self.updateMiniCanvasLater()
  928. @pyqtSlot(int, int, int)
  929. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  930. pcIcon = patchcanvas.ICON_APPLICATION
  931. if clientIcon == PATCHBAY_ICON_PLUGIN:
  932. pcIcon = patchcanvas.ICON_PLUGIN
  933. if clientIcon == PATCHBAY_ICON_HARDWARE:
  934. pcIcon = patchcanvas.ICON_HARDWARE
  935. elif clientIcon == PATCHBAY_ICON_CARLA:
  936. pass
  937. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  938. pcIcon = patchcanvas.ICON_DISTRHO
  939. elif clientIcon == PATCHBAY_ICON_FILE:
  940. pcIcon = patchcanvas.ICON_FILE
  941. patchcanvas.setGroupIcon(clientId, pcIcon)
  942. self.updateMiniCanvasLater()
  943. if pluginId < 0:
  944. return
  945. if pluginId >= self.fPluginCount:
  946. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  947. return
  948. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  949. @pyqtSlot(int, int, int, str)
  950. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  951. if portFlags & PATCHBAY_PORT_IS_INPUT:
  952. portMode = patchcanvas.PORT_MODE_INPUT
  953. else:
  954. portMode = patchcanvas.PORT_MODE_OUTPUT
  955. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  956. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  957. isAlternate = False
  958. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  959. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  960. isAlternate = True
  961. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  962. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  963. isAlternate = False
  964. else:
  965. portType = patchcanvas.PORT_TYPE_NULL
  966. isAlternate = False
  967. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  968. self.updateMiniCanvasLater()
  969. @pyqtSlot(int, int)
  970. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  971. patchcanvas.removePort(groupId, portId)
  972. self.updateMiniCanvasLater()
  973. @pyqtSlot(int, int, str)
  974. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  975. patchcanvas.renamePort(groupId, portId, newPortName)
  976. self.updateMiniCanvasLater()
  977. @pyqtSlot(int, int, int, int, int)
  978. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  979. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  980. self.updateMiniCanvasLater()
  981. @pyqtSlot(int, int, int)
  982. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  983. patchcanvas.disconnectPorts(connectionId)
  984. self.updateMiniCanvasLater()
  985. # --------------------------------------------------------------------------------------------------------
  986. # Settings
  987. def saveSettings(self):
  988. settings = QSettings()
  989. settings.setValue("Geometry", self.saveGeometry())
  990. settings.setValue("TimePanelGeometry", self.ui.panelTime.saveGeometry())
  991. #settings.setValue("SplitterState", self.ui.splitter.saveState())
  992. if not (self.host.isControl or self.host.isPlugin):
  993. settings.setValue("ShowTimePanel", self.ui.panelTime.isVisible())
  994. settings.setValue("ShowToolbar", self.ui.toolBar.isEnabled())
  995. settings.setValue("ShowSidePanel", self.ui.dockWidget.isEnabled())
  996. diskFolders = []
  997. for i in range(self.ui.cb_disk.count()):
  998. diskFolders.append(self.ui.cb_disk.itemData(i))
  999. settings.setValue("DiskFolders", diskFolders)
  1000. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  1001. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  1002. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1003. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1004. def loadSettings(self, firstTime):
  1005. settings = QSettings()
  1006. if firstTime:
  1007. self.restoreGeometry(settings.value("Geometry", b""))
  1008. if not (self.host.isControl or self.host.isPlugin):
  1009. self.ui.panelTime.restoreGeometry(settings.value("TimePanelGeometry", b""))
  1010. showTimePanel = settings.value("ShowTimePanel", True, type=bool)
  1011. self.ui.act_settings_show_time_panel.setChecked(showTimePanel)
  1012. if showTimePanel:
  1013. QTimer.singleShot(0, self.ui.panelTime.show)
  1014. else:
  1015. self.ui.panelTime.hide()
  1016. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1017. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1018. self.ui.toolBar.setEnabled(showToolbar)
  1019. self.ui.toolBar.setVisible(showToolbar)
  1020. #if settings.contains("SplitterState"):
  1021. #self.ui.splitter.restoreState(settings.value("SplitterState", b""))
  1022. #else:
  1023. #self.ui.splitter.setSizes([210, 99999])
  1024. showSidePanel = settings.value("ShowSidePanel", True, type=bool)
  1025. self.ui.act_settings_show_side_panel.setChecked(showSidePanel)
  1026. self.ui.dockWidget.setEnabled(showSidePanel)
  1027. self.ui.dockWidget.setVisible(showSidePanel)
  1028. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  1029. self.ui.cb_disk.setItemData(0, HOME)
  1030. for i in range(len(diskFolders)):
  1031. if i == 0: continue
  1032. folder = diskFolders[i]
  1033. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1034. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  1035. # self.setUnifiedTitleAndToolBarOnMac(True)
  1036. showMeters = settings.value("ShowMeters", False, type=bool)
  1037. self.ui.act_settings_show_meters.setChecked(showMeters)
  1038. self.ui.peak_in.setVisible(showMeters)
  1039. self.ui.peak_out.setVisible(showMeters)
  1040. showKeyboard = settings.value("ShowKeyboard", not(MACOS or WINDOWS), type=bool)
  1041. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  1042. self.ui.scrollArea.setVisible(showKeyboard)
  1043. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  1044. # TODO - complete this
  1045. self.fSavedSettings = {
  1046. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  1047. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  1048. CARLA_KEY_MAIN_USE_CUSTOM_SKINS: settings.value(CARLA_KEY_MAIN_USE_CUSTOM_SKINS, CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS, type=bool),
  1049. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  1050. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  1051. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  1052. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS: settings.value(CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS, CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS, type=bool),
  1053. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  1054. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=int),
  1055. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  1056. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  1057. CARLA_KEY_CANVAS_HQ_ANTIALIASING : settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  1058. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  1059. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black")
  1060. }
  1061. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] == patchcanvas.EYECANDY_FULL else 0
  1062. setEngineSettings(self.host)
  1063. self.restartTimersIfNeeded()
  1064. # --------------------------------------------------------------------------------------------------------
  1065. # Settings (helpers)
  1066. @pyqtSlot()
  1067. def slot_restoreCanvasScrollbarValues(self):
  1068. settings = QSettings()
  1069. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  1070. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  1071. # --------------------------------------------------------------------------------------------------------
  1072. # Settings (menu actions)
  1073. @pyqtSlot(bool)
  1074. def slot_showTimePanel(self, yesNo):
  1075. self.ui.panelTime.setVisible(yesNo)
  1076. @pyqtSlot(bool)
  1077. def slot_showSidePanel(self, yesNo):
  1078. self.ui.dockWidget.setEnabled(yesNo)
  1079. self.ui.dockWidget.setVisible(yesNo)
  1080. @pyqtSlot(bool)
  1081. def slot_showToolbar(self, yesNo):
  1082. self.ui.toolBar.setEnabled(yesNo)
  1083. self.ui.toolBar.setVisible(yesNo)
  1084. @pyqtSlot(bool)
  1085. def slot_showCanvasMeters(self, yesNo):
  1086. self.ui.peak_in.setVisible(yesNo)
  1087. self.ui.peak_out.setVisible(yesNo)
  1088. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1089. @pyqtSlot(bool)
  1090. def slot_showCanvasKeyboard(self, yesNo):
  1091. self.ui.scrollArea.setVisible(yesNo)
  1092. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1093. @pyqtSlot()
  1094. def slot_configureCarla(self):
  1095. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1096. if not dialog.exec_():
  1097. return
  1098. self.loadSettings(False)
  1099. patchcanvas.clear()
  1100. self.setupCanvas()
  1101. self.slot_miniCanvasCheckAll()
  1102. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1103. pass
  1104. elif self.host.is_engine_running():
  1105. self.host.patchbay_refresh(self.fExternalPatchbay)
  1106. for pitem in self.fPluginList:
  1107. if pitem is None:
  1108. break
  1109. pitem.setUsingSkins(self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  1110. pitem.recreateWidget()
  1111. # --------------------------------------------------------------------------------------------------------
  1112. # About (menu actions)
  1113. @pyqtSlot()
  1114. def slot_aboutCarla(self):
  1115. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1116. @pyqtSlot()
  1117. def slot_aboutJuce(self):
  1118. JuceAboutW(self.fParentOrSelf).exec_()
  1119. @pyqtSlot()
  1120. def slot_aboutQt(self):
  1121. QApplication.instance().aboutQt()
  1122. # --------------------------------------------------------------------------------------------------------
  1123. # Disk (menu actions)
  1124. @pyqtSlot(int)
  1125. def slot_diskFolderChanged(self, index):
  1126. if index < 0:
  1127. return
  1128. elif index == 0:
  1129. filename = HOME
  1130. self.ui.b_disk_remove.setEnabled(False)
  1131. else:
  1132. filename = self.ui.cb_disk.itemData(index)
  1133. self.ui.b_disk_remove.setEnabled(True)
  1134. self.fDirModel.setRootPath(filename)
  1135. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1136. @pyqtSlot()
  1137. def slot_diskFolderAdd(self):
  1138. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1139. if newPath:
  1140. if newPath[-1] == os.sep:
  1141. newPath = newPath[:-1]
  1142. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1143. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1144. self.ui.b_disk_remove.setEnabled(True)
  1145. @pyqtSlot()
  1146. def slot_diskFolderRemove(self):
  1147. index = self.ui.cb_disk.currentIndex()
  1148. if index <= 0:
  1149. return
  1150. self.ui.cb_disk.removeItem(index)
  1151. if self.ui.cb_disk.currentIndex() == 0:
  1152. self.ui.b_disk_remove.setEnabled(False)
  1153. @pyqtSlot(QModelIndex)
  1154. def slot_fileTreeDoubleClicked(self, modelIndex):
  1155. filename = self.fDirModel.filePath(modelIndex)
  1156. if not self.host.load_file(filename):
  1157. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1158. self.tr("Failed to load file"),
  1159. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1160. # --------------------------------------------------------------------------------------------------------
  1161. # Canvas scrollbars
  1162. @pyqtSlot(int)
  1163. def slot_horizontalScrollBarChanged(self, value):
  1164. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1165. if maximum == 0:
  1166. xp = 0
  1167. else:
  1168. xp = float(value) / maximum
  1169. self.ui.miniCanvasPreview.setViewPosX(xp)
  1170. self.updateCanvasInitialPos()
  1171. @pyqtSlot(int)
  1172. def slot_verticalScrollBarChanged(self, value):
  1173. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1174. if maximum == 0:
  1175. yp = 0
  1176. else:
  1177. yp = float(value) / maximum
  1178. self.ui.miniCanvasPreview.setViewPosY(yp)
  1179. self.updateCanvasInitialPos()
  1180. # --------------------------------------------------------------------------------------------------------
  1181. # Canvas keyboard
  1182. @pyqtSlot(int)
  1183. def slot_noteOn(self, note):
  1184. for pluginId in self.fSelectedPlugins:
  1185. self.host.send_midi_note(pluginId, 0, note, 100)
  1186. pedit = self.getPluginEditDialog(pluginId)
  1187. pedit.noteOn(0, note, 100)
  1188. @pyqtSlot(int)
  1189. def slot_noteOff(self, note):
  1190. for pluginId in self.fSelectedPlugins:
  1191. self.host.send_midi_note(pluginId, 0, note, 0)
  1192. pedit = self.getPluginEditDialog(pluginId)
  1193. pedit.noteOff(0, note)
  1194. # --------------------------------------------------------------------------------------------------------
  1195. # Canvas keyboard (host callbacks)
  1196. @pyqtSlot(int, int, int, int)
  1197. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1198. if pluginId in self.fSelectedPlugins:
  1199. self.ui.keyboard.sendNoteOn(note, False)
  1200. @pyqtSlot(int, int, int)
  1201. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1202. if pluginId in self.fSelectedPlugins:
  1203. self.ui.keyboard.sendNoteOff(note, False)
  1204. # --------------------------------------------------------------------------------------------------------
  1205. @pyqtSlot(int)
  1206. def slot_handleUpdateCallback(self, pluginId):
  1207. pitem = self.getPluginItem(pluginId)
  1208. if pitem is None:
  1209. return
  1210. wasCompacted = pitem.isCompacted()
  1211. isCompacted = wasCompacted
  1212. for i in range(self.host.get_custom_data_count(pluginId)):
  1213. cdata = self.host.get_custom_data(pluginId, i)
  1214. if cdata['type'] == CUSTOM_DATA_TYPE_PROPERTY and cdata['key'] == "CarlaSkinIsCompacted":
  1215. isCompacted = bool(cdata['value'] == "true")
  1216. break
  1217. else:
  1218. return
  1219. if wasCompacted == isCompacted:
  1220. return
  1221. pitem.recreateWidget(True)
  1222. # --------------------------------------------------------------------------------------------------------
  1223. # MiniCanvas stuff
  1224. @pyqtSlot()
  1225. def slot_miniCanvasCheckAll(self):
  1226. self.slot_miniCanvasCheckSize()
  1227. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1228. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1229. @pyqtSlot()
  1230. def slot_miniCanvasCheckSize(self):
  1231. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1232. return
  1233. if self.ui.tabWidget.currentIndex() == 1:
  1234. width = self.ui.graphicsView.width()
  1235. height = self.ui.graphicsView.height()
  1236. else:
  1237. self.ui.tabWidget.blockSignals(True)
  1238. self.ui.tabWidget.setCurrentIndex(1)
  1239. width = self.ui.graphicsView.width()
  1240. height = self.ui.graphicsView.height()
  1241. self.ui.tabWidget.setCurrentIndex(0)
  1242. self.ui.tabWidget.blockSignals(False)
  1243. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1244. @pyqtSlot(float, float)
  1245. def slot_miniCanvasMoved(self, xp, yp):
  1246. hsb = self.ui.graphicsView.horizontalScrollBar()
  1247. vsb = self.ui.graphicsView.verticalScrollBar()
  1248. hsb.setValue(xp * hsb.maximum())
  1249. vsb.setValue(yp * vsb.maximum())
  1250. self.updateCanvasInitialPos()
  1251. # --------------------------------------------------------------------------------------------------------
  1252. # Timers
  1253. def startTimers(self):
  1254. if self.fIdleTimerFast == 0:
  1255. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1256. if self.fIdleTimerSlow == 0:
  1257. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1258. def restartTimersIfNeeded(self):
  1259. if self.fIdleTimerFast != 0:
  1260. self.killTimer(self.fIdleTimerFast)
  1261. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1262. if self.fIdleTimerSlow != 0:
  1263. self.killTimer(self.fIdleTimerSlow)
  1264. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1265. def killTimers(self):
  1266. if self.fIdleTimerFast != 0:
  1267. self.killTimer(self.fIdleTimerFast)
  1268. self.fIdleTimerFast = 0
  1269. if self.fIdleTimerSlow != 0:
  1270. self.killTimer(self.fIdleTimerSlow)
  1271. self.fIdleTimerSlow = 0
  1272. # --------------------------------------------------------------------------------------------------------
  1273. # Misc
  1274. @pyqtSlot()
  1275. def slot_timePanelClosed(self):
  1276. self.ui.act_settings_show_time_panel.setChecked(False)
  1277. @pyqtSlot(int)
  1278. def slot_tabChanged(self, index):
  1279. if index != 1:
  1280. return
  1281. self.ui.graphicsView.setFocus()
  1282. @pyqtSlot(int)
  1283. def slot_handleReloadAllCallback(self, pluginId):
  1284. if pluginId >= self.fPluginCount:
  1285. return
  1286. pitem = self.fPluginList[pluginId]
  1287. if pitem is None:
  1288. return
  1289. pitem.recreateWidget()
  1290. # --------------------------------------------------------------------------------------------------------
  1291. @pyqtSlot(int, int, str)
  1292. def slot_handleNSMCallback(self, value1, value2, valueStr):
  1293. # Error
  1294. if value1 == 0:
  1295. pass
  1296. # Reply
  1297. elif value1 == 1:
  1298. self.fFirstEngineInit = False
  1299. self.fSessionManagerName = valueStr
  1300. self.setProperWindowTitle()
  1301. # Open
  1302. elif value1 == 2:
  1303. self.fClientName = os.path.basename(valueStr)
  1304. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1305. self.setProperWindowTitle()
  1306. self.fCustomStopAction = 2
  1307. self.slot_engineStop(True)
  1308. return
  1309. # Save
  1310. elif value1 == 3:
  1311. self.saveProjectNow()
  1312. # Session is Loaded
  1313. elif value1 == 4:
  1314. pass
  1315. # Show Optional Gui
  1316. elif value1 == 5:
  1317. self.show()
  1318. # Hide Optional Gui
  1319. elif value1 == 6:
  1320. self.hide()
  1321. self.host.nsm_ready(value1)
  1322. # --------------------------------------------------------------------------------------------------------
  1323. @pyqtSlot(int, int, int, float, str)
  1324. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1325. print("DEBUG:", pluginId, value1, value2, value3, valueStr)
  1326. @pyqtSlot(str)
  1327. def slot_handleInfoCallback(self, info):
  1328. QMessageBox.information(self, "Information", info)
  1329. @pyqtSlot(str)
  1330. def slot_handleErrorCallback(self, error):
  1331. QMessageBox.critical(self, "Error", error)
  1332. @pyqtSlot()
  1333. def slot_handleQuitCallback(self):
  1334. pass # TODO
  1335. # --------------------------------------------------------------------------------------------------------
  1336. @pyqtSlot()
  1337. def slot_handleSIGUSR1(self):
  1338. print("Got SIGUSR1 -> Saving project now")
  1339. self.slot_fileSave()
  1340. @pyqtSlot()
  1341. def slot_handleSIGTERM(self):
  1342. print("Got SIGTERM -> Closing now")
  1343. self.fCustomStopAction = 1
  1344. self.slot_engineStop(True)
  1345. # --------------------------------------------------------------------------------------------------------
  1346. # Internal stuff
  1347. def getExtraPtr(self, plugin):
  1348. ptype = plugin['type']
  1349. if ptype == PLUGIN_LADSPA:
  1350. uniqueId = plugin['uniqueId']
  1351. self.maybeLoadRDFs()
  1352. for rdfItem in self.fLadspaRdfList:
  1353. if rdfItem.UniqueID == uniqueId:
  1354. return pointer(rdfItem)
  1355. elif ptype in (PLUGIN_GIG, PLUGIN_SF2):
  1356. if plugin['name'].lower().endswith(" (16 outputs)"):
  1357. return self._true
  1358. return None
  1359. def maybeLoadRDFs(self):
  1360. if not self.fLadspaRdfNeedsUpdate:
  1361. return
  1362. self.fLadspaRdfNeedsUpdate = False
  1363. self.fLadspaRdfList = []
  1364. if not haveLRDF:
  1365. return
  1366. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1367. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1368. if os.path.exists(frLadspaFile):
  1369. frLadspa = open(frLadspaFile, 'r')
  1370. try:
  1371. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1372. except:
  1373. pass
  1374. frLadspa.close()
  1375. # --------------------------------------------------------------------------------------------------------
  1376. def getPluginItem(self, pluginId):
  1377. if pluginId >= self.fPluginCount:
  1378. return None
  1379. pitem = self.fPluginList[pluginId]
  1380. if pitem is None:
  1381. return None
  1382. #if False:
  1383. #return CarlaRackItem(self, 0, False)
  1384. return pitem
  1385. def getPluginEditDialog(self, pluginId):
  1386. if pluginId >= self.fPluginCount:
  1387. return None
  1388. pitem = self.fPluginList[pluginId]
  1389. if pitem is None:
  1390. return None
  1391. if False:
  1392. return PluginEdit(self, self.host, 0)
  1393. return pitem.getEditDialog()
  1394. def getPluginSlotWidget(self, pluginId):
  1395. if pluginId >= self.fPluginCount:
  1396. return None
  1397. pitem = self.fPluginList[pluginId]
  1398. if pitem is None:
  1399. return None
  1400. #if False:
  1401. #return AbstractPluginSlot()
  1402. return pitem.getWidget()
  1403. # --------------------------------------------------------------------------------------------------------
  1404. def waitForPendingEvents(self):
  1405. pass
  1406. # --------------------------------------------------------------------------------------------------------
  1407. # show/hide event
  1408. def showEvent(self, event):
  1409. QMainWindow.showEvent(self, event)
  1410. # set our gui as parent for all plugins UIs
  1411. if self.host.manageUIs and not (self.host.isControl or self.host.isPlugin):
  1412. winIdStr = "%x" % int(self.winId())
  1413. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1414. def hideEvent(self, event):
  1415. # disable parent
  1416. if not (self.host.isControl or self.host.isPlugin):
  1417. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1418. QMainWindow.hideEvent(self, event)
  1419. # --------------------------------------------------------------------------------------------------------
  1420. # resize event
  1421. def fixCanvasPreviewSize(self):
  1422. self.ui.patchbay.resize(self.ui.rack.size())
  1423. self.slot_miniCanvasCheckSize()
  1424. def resizeEvent(self, event):
  1425. QMainWindow.resizeEvent(self, event)
  1426. if self.ui.tabWidget.currentIndex() != 1:
  1427. size = self.ui.rack.size()
  1428. self.ui.patchbay.resize(size)
  1429. self.slot_miniCanvasCheckSize()
  1430. # --------------------------------------------------------------------------------------------------------
  1431. # timer event
  1432. def idleFast(self):
  1433. self.host.engine_idle()
  1434. self.ui.panelTime.refreshTransport()
  1435. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1436. return
  1437. for pitem in self.fPluginList:
  1438. if pitem is None:
  1439. break
  1440. pitem.getWidget().idleFast()
  1441. for pluginId in self.fSelectedPlugins:
  1442. self.fPeaksCleared = False
  1443. if self.ui.peak_in.isVisible():
  1444. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1445. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1446. if self.ui.peak_out.isVisible():
  1447. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1448. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1449. return
  1450. if self.fPeaksCleared:
  1451. return
  1452. self.fPeaksCleared = True
  1453. self.ui.peak_in.displayMeter(1, 0.0, True)
  1454. self.ui.peak_in.displayMeter(2, 0.0, True)
  1455. self.ui.peak_out.displayMeter(1, 0.0, True)
  1456. self.ui.peak_out.displayMeter(2, 0.0, True)
  1457. def idleSlow(self):
  1458. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1459. return
  1460. for pitem in self.fPluginList:
  1461. if pitem is None:
  1462. break
  1463. pitem.getWidget().idleSlow()
  1464. def timerEvent(self, event):
  1465. if event.timerId() == self.fIdleTimerFast:
  1466. self.idleFast()
  1467. elif event.timerId() == self.fIdleTimerSlow:
  1468. self.idleSlow()
  1469. QMainWindow.timerEvent(self, event)
  1470. # --------------------------------------------------------------------------------------------------------
  1471. # paint event
  1472. #def paintEvent(self, event):
  1473. #QMainWindow.paintEvent(self, event)
  1474. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1475. #return
  1476. #painter = QPainter(self)
  1477. #painter.setBrush(QColor(36, 36, 36))
  1478. #painter.setPen(QColor(62, 62, 62))
  1479. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1480. # --------------------------------------------------------------------------------------------------------
  1481. # close event
  1482. def closeEvent(self, event):
  1483. self.killTimers()
  1484. self.saveSettings()
  1485. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  1486. if not self.slot_engineStop(True):
  1487. self.fCustomStopAction = 1
  1488. event.ignore()
  1489. return
  1490. QMainWindow.closeEvent(self, event)
  1491. # ------------------------------------------------------------------------------------------------
  1492. # Canvas callback
  1493. def canvasCallback(action, value1, value2, valueStr):
  1494. host = gCarla.gui.host
  1495. if action == patchcanvas.ACTION_GROUP_INFO:
  1496. pass
  1497. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1498. pass
  1499. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1500. groupId = value1
  1501. patchcanvas.splitGroup(groupId)
  1502. gCarla.gui.updateMiniCanvasLater()
  1503. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1504. groupId = value1
  1505. patchcanvas.joinGroup(groupId)
  1506. gCarla.gui.updateMiniCanvasLater()
  1507. elif action == patchcanvas.ACTION_PORT_INFO:
  1508. pass
  1509. elif action == patchcanvas.ACTION_PORT_RENAME:
  1510. pass
  1511. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1512. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1513. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1514. print("Connection failed:", host.get_last_error())
  1515. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1516. connectionId = value1
  1517. if not host.patchbay_disconnect(connectionId):
  1518. print("Disconnect failed:", host.get_last_error())
  1519. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1520. pluginId = value1
  1521. if not host.clone_plugin(pluginId):
  1522. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1523. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1524. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1525. pluginId = value1
  1526. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1527. if pwidget is not None:
  1528. pwidget.showEditDialog()
  1529. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1530. pluginId = value1
  1531. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1532. if pwidget is not None:
  1533. pwidget.showRenameDialog()
  1534. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  1535. pluginId = value1
  1536. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1537. if pwidget is not None:
  1538. pwidget.showReplaceDialog()
  1539. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1540. pluginId = value1
  1541. if not host.remove_plugin(pluginId):
  1542. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1543. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1544. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1545. pluginId = value1
  1546. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1547. if pwidget is not None:
  1548. pwidget.showCustomUI()
  1549. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  1550. gCarla.gui.showPluginActionsMenu()
  1551. # ------------------------------------------------------------------------------------------------------------
  1552. # Engine callback
  1553. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1554. # kdevelop likes this :)
  1555. if False: host = CarlaHostNull()
  1556. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1557. host.processMode = value1
  1558. host.transportMode = value2
  1559. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1560. host.processMode = value1
  1561. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1562. host.transportMode = value1
  1563. valueStr = charPtrToString(valueStr)
  1564. if action == ENGINE_CALLBACK_DEBUG:
  1565. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1566. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1567. host.PluginAddedCallback.emit(pluginId, valueStr)
  1568. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1569. host.PluginRemovedCallback.emit(pluginId)
  1570. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1571. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1572. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1573. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1574. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1575. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1576. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1577. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1578. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1579. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1580. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1581. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1582. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1583. host.ProgramChangedCallback.emit(pluginId, value1)
  1584. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1585. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1586. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1587. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1588. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1589. host.UiStateChangedCallback.emit(pluginId, value1)
  1590. elif action == ENGINE_CALLBACK_NOTE_ON:
  1591. host.NoteOnCallback.emit(pluginId, value1, value2, round(value3))
  1592. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1593. host.NoteOffCallback.emit(pluginId, value1, value2)
  1594. elif action == ENGINE_CALLBACK_UPDATE:
  1595. host.UpdateCallback.emit(pluginId)
  1596. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1597. host.ReloadInfoCallback.emit(pluginId)
  1598. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1599. host.ReloadParametersCallback.emit(pluginId)
  1600. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1601. host.ReloadProgramsCallback.emit(pluginId)
  1602. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1603. host.ReloadAllCallback.emit(pluginId)
  1604. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1605. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1606. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1607. host.PatchbayClientRemovedCallback.emit(pluginId)
  1608. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1609. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1610. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1611. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1612. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1613. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1614. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1615. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1616. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1617. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1618. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1619. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1620. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1621. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1622. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1623. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1624. host.EngineStartedCallback.emit(value1, value2, valueStr)
  1625. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1626. host.EngineStoppedCallback.emit()
  1627. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1628. host.ProcessModeChangedCallback.emit(value1)
  1629. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1630. host.TransportModeChangedCallback.emit(value1)
  1631. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1632. host.BufferSizeChangedCallback.emit(value1)
  1633. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1634. host.SampleRateChangedCallback.emit(value3)
  1635. elif action == ENGINE_CALLBACK_NSM:
  1636. host.NSMCallback.emit(value1, value2, valueStr)
  1637. elif action == ENGINE_CALLBACK_IDLE:
  1638. QApplication.instance().processEvents()
  1639. elif action == ENGINE_CALLBACK_INFO:
  1640. host.InfoCallback.emit(valueStr)
  1641. elif action == ENGINE_CALLBACK_ERROR:
  1642. host.ErrorCallback.emit(valueStr)
  1643. elif action == ENGINE_CALLBACK_QUIT:
  1644. host.QuitCallback.emit()
  1645. # ------------------------------------------------------------------------------------------------------------
  1646. # File callback
  1647. def fileCallback(ptr, action, isDir, title, filter):
  1648. ret = ("", "") if config_UseQt5 else ""
  1649. if action == FILE_CALLBACK_DEBUG:
  1650. pass
  1651. elif action == FILE_CALLBACK_OPEN:
  1652. ret = QFileDialog.getOpenFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter) ) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1653. elif action == FILE_CALLBACK_SAVE:
  1654. ret = QFileDialog.getSaveFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter), QFileDialog.ShowDirsOnly if isDir else 0x0)
  1655. if config_UseQt5:
  1656. ret = ret[0]
  1657. if not ret:
  1658. return None
  1659. # FIXME
  1660. global fileRet
  1661. fileRet = c_char_p(ret.encode("utf-8"))
  1662. retval = cast(byref(fileRet), POINTER(c_uintptr))
  1663. return retval.contents.value
  1664. # ------------------------------------------------------------------------------------------------------------
  1665. # Init host
  1666. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  1667. pathBinaries, pathResources = getPaths(libPrefix)
  1668. # --------------------------------------------------------------------------------------------------------
  1669. # Fail if binary dir is not found
  1670. if not os.path.exists(pathBinaries):
  1671. if failError:
  1672. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  1673. sys.exit(1)
  1674. return
  1675. # --------------------------------------------------------------------------------------------------------
  1676. # Set Carla library name
  1677. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  1678. utilsname = "libcarla_utils.%s" % (DLL_EXTENSION)
  1679. # --------------------------------------------------------------------------------------------------------
  1680. # Print info
  1681. print("Carla %s started, status:" % VERSION)
  1682. print(" Python version: %s" % sys.version.split(" ",1)[0])
  1683. print(" Qt version: %s" % qVersion())
  1684. print(" PyQt version: %s" % PYQT_VERSION_STR)
  1685. print(" Binary dir: %s" % pathBinaries)
  1686. print(" Resources dir: %s" % pathResources)
  1687. # --------------------------------------------------------------------------------------------------------
  1688. # Init host
  1689. if failError:
  1690. # no try
  1691. host = HostClass() if HostClass is not None else CarlaHostQtDLL(os.path.join(pathBinaries, libname))
  1692. else:
  1693. try:
  1694. host = HostClass() if HostClass is not None else CarlaHostQtDLL(os.path.join(pathBinaries, libname))
  1695. except:
  1696. host = CarlaHostQtNull()
  1697. host.isControl = isControl
  1698. host.isPlugin = isPlugin
  1699. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  1700. host.set_file_callback(fileCallback)
  1701. # If it's a plugin the paths are already set
  1702. if not isPlugin:
  1703. host.pathBinaries = pathBinaries
  1704. host.pathResources = pathResources
  1705. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  1706. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  1707. if not isControl:
  1708. host.nsmOK = host.nsm_init(os.getpid(), initName)
  1709. # --------------------------------------------------------------------------------------------------------
  1710. # Init utils
  1711. gCarla.utils = CarlaUtils(os.path.join(pathBinaries, utilsname))
  1712. gCarla.utils.set_process_name(os.path.basename(initName))
  1713. #gCarla.utils.set_locale_C()
  1714. # --------------------------------------------------------------------------------------------------------
  1715. # Done
  1716. return host
  1717. # ------------------------------------------------------------------------------------------------------------
  1718. # Load host settings
  1719. def loadHostSettings(host):
  1720. # kdevelop likes this :)
  1721. if False: host = CarlaHostNull()
  1722. settings = QSettings("falkTX", "Carla2")
  1723. # bool values
  1724. try:
  1725. host.manageUIs = settings.value(CARLA_KEY_MAIN_MANAGE_UIS, CARLA_DEFAULT_MAIN_MANAGE_UIS, type=bool)
  1726. except:
  1727. host.manageUIs = CARLA_DEFAULT_MAIN_MANAGE_UIS
  1728. try:
  1729. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  1730. except:
  1731. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  1732. try:
  1733. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  1734. except:
  1735. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  1736. try:
  1737. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  1738. except:
  1739. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  1740. try:
  1741. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  1742. except:
  1743. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  1744. # int values
  1745. try:
  1746. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  1747. except:
  1748. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  1749. try:
  1750. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  1751. except:
  1752. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  1753. if host.isPlugin:
  1754. return
  1755. # enums
  1756. try:
  1757. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  1758. except:
  1759. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  1760. if not host.processModeForced:
  1761. try:
  1762. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  1763. except:
  1764. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  1765. host.nextProcessMode = host.processMode
  1766. # --------------------------------------------------------------------------------------------------------
  1767. # fix things if needed
  1768. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  1769. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  1770. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  1771. # --------------------------------------------------------------------------------------------------------
  1772. # run headless host now if nogui option enabled
  1773. if gCarla.nogui:
  1774. runHostWithoutUI(host)
  1775. # ------------------------------------------------------------------------------------------------------------
  1776. # Set host settings
  1777. def setHostSettings(host):
  1778. # kdevelop likes this :)
  1779. if False: host = CarlaHostNull()
  1780. # TEST
  1781. #host.preventBadBehaviour = True
  1782. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  1783. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  1784. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  1785. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  1786. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  1787. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  1788. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  1789. if host.isPlugin:
  1790. return
  1791. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  1792. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, "")
  1793. # ------------------------------------------------------------------------------------------------------------
  1794. # Set Engine settings according to carla preferences. Returns selected audio driver.
  1795. def setEngineSettings(host):
  1796. # kdevelop likes this :)
  1797. if False: host = CarlaHostNull()
  1798. # --------------------------------------------------------------------------------------------------------
  1799. # do nothing if control
  1800. if host.isControl:
  1801. return "Control"
  1802. # --------------------------------------------------------------------------------------------------------
  1803. settings = QSettings("falkTX", "Carla2")
  1804. # --------------------------------------------------------------------------------------------------------
  1805. # main settings
  1806. setHostSettings(host)
  1807. # --------------------------------------------------------------------------------------------------------
  1808. # plugin paths
  1809. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  1810. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  1811. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  1812. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  1813. VST3_PATH = toList(settings.value(CARLA_KEY_PATHS_VST3, CARLA_DEFAULT_VST3_PATH))
  1814. GIG_PATH = toList(settings.value(CARLA_KEY_PATHS_GIG, CARLA_DEFAULT_GIG_PATH))
  1815. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  1816. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  1817. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  1818. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  1819. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  1820. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  1821. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST3, splitter.join(VST3_PATH))
  1822. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_GIG, splitter.join(GIG_PATH))
  1823. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  1824. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  1825. # --------------------------------------------------------------------------------------------------------
  1826. # don't continue if plugin
  1827. if host.isPlugin:
  1828. return "Plugin"
  1829. # --------------------------------------------------------------------------------------------------------
  1830. # driver and device settings
  1831. # driver name
  1832. try:
  1833. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  1834. except:
  1835. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  1836. # driver options
  1837. try:
  1838. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  1839. except:
  1840. audioDevice = ""
  1841. try:
  1842. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  1843. except:
  1844. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  1845. try:
  1846. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  1847. except:
  1848. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  1849. try:
  1850. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  1851. except:
  1852. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  1853. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  1854. host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  1855. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  1856. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  1857. # --------------------------------------------------------------------------------------------------------
  1858. # fix things if needed
  1859. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  1860. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  1861. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")
  1862. # --------------------------------------------------------------------------------------------------------
  1863. # return selected driver name
  1864. return audioDriver
  1865. # ------------------------------------------------------------------------------------------------------------
  1866. # Run Carla without showing UI
  1867. def runHostWithoutUI(host):
  1868. # kdevelop likes this :)
  1869. if False: host = CarlaHostNull()
  1870. # --------------------------------------------------------------------------------------------------------
  1871. # Some initial checks
  1872. if not gCarla.nogui:
  1873. return
  1874. projectFile = getInitialProjectFile(QCoreApplication.instance(), True)
  1875. if not projectFile:
  1876. print("Carla no-gui mode can only be used together with a project file.")
  1877. sys.exit(1)
  1878. # --------------------------------------------------------------------------------------------------------
  1879. # Additional imports
  1880. from time import sleep
  1881. # --------------------------------------------------------------------------------------------------------
  1882. # Init engine
  1883. audioDriver = setEngineSettings(host)
  1884. if not host.engine_init(audioDriver, "Carla-nogui"):
  1885. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  1886. sys.exit(1)
  1887. if not host.load_project(projectFile):
  1888. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  1889. host.engine_close()
  1890. sys.exit(1)
  1891. # --------------------------------------------------------------------------------------------------------
  1892. # Idle
  1893. while host.is_engine_running() and not gCarla.term:
  1894. host.engine_idle()
  1895. sleep(0.5)
  1896. # --------------------------------------------------------------------------------------------------------
  1897. # Stop
  1898. host.engine_close()
  1899. sys.exit(0)
  1900. # ------------------------------------------------------------------------------------------------------------