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.

2169 lines
85KB

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