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.

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