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.

2496 lines
95KB

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