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.

2136 lines
82KB

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