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.

2164 lines
84KB

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