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.

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