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.

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