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.

2292 lines
90KB

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