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.

2383 lines
92KB

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