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.

2396 lines
93KB

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