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.

2130 lines
83KB

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