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.

2268 lines
88KB

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