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.

3007 lines
116KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2019 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 (Global)
  19. import json
  20. from PyQt5.Qt import PYQT_VERSION
  21. from PyQt5.QtCore import qCritical, QEventLoop, QFileInfo, QModelIndex, QPointF, QTimer, QEvent
  22. from PyQt5.QtGui import QImage, QPalette, QBrush
  23. from PyQt5.QtWidgets import QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QMainWindow
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Imports (Custom)
  26. import ui_carla_host
  27. from carla_app import *
  28. from carla_database import *
  29. from carla_settings import *
  30. from carla_utils import *
  31. from carla_widgets import *
  32. from patchcanvas import patchcanvas
  33. from widgets.digitalpeakmeter import DigitalPeakMeter
  34. from widgets.pixmapkeyboard import PixmapKeyboardHArea
  35. # ------------------------------------------------------------------------------------------------------------
  36. # Try Import OpenGL
  37. try:
  38. from PyQt5.QtOpenGL import QGLWidget
  39. hasGL = True
  40. except:
  41. hasGL = False
  42. # ------------------------------------------------------------------------------------------------------------
  43. # Safe exception hook, needed for PyQt5
  44. def sys_excepthook(typ, value, tback):
  45. return sys.__excepthook__(typ, value, tback)
  46. # ------------------------------------------------------------------------------------------------------------
  47. # Session Management support
  48. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  49. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  50. NSM_URL = os.getenv("NSM_URL")
  51. # ------------------------------------------------------------------------------------------------------------
  52. # Small print helper
  53. def processMode2Str(processMode):
  54. if processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  55. return "Single client"
  56. if processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  57. return "Multi client"
  58. if processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  59. return "Continuous Rack"
  60. if processMode == ENGINE_PROCESS_MODE_PATCHBAY:
  61. return "Patchbay"
  62. if processMode == ENGINE_PROCESS_MODE_BRIDGE:
  63. return "Bridge"
  64. return "Unknown"
  65. # ------------------------------------------------------------------------------------------------------------
  66. # Carla Print class
  67. class CarlaPrint:
  68. def __init__(self, err):
  69. self.err = err
  70. def flush(self):
  71. gCarla.utils.fflush(self.err)
  72. def write(self, string):
  73. gCarla.utils.fputs(self.err, string)
  74. # ------------------------------------------------------------------------------------------------------------
  75. # Host Window
  76. class HostWindow(QMainWindow):
  77. #class HostWindow(QMainWindow, PluginEditParentMeta, metaclass=PyQtMetaClass):
  78. # signals
  79. SIGTERM = pyqtSignal()
  80. SIGUSR1 = pyqtSignal()
  81. # CustomActions
  82. CUSTOM_ACTION_NONE = 0
  83. CUSTOM_ACTION_APP_CLOSE = 1
  84. CUSTOM_ACTION_PROJECT_LOAD = 2
  85. # --------------------------------------------------------------------------------------------------------
  86. def __init__(self, host, withCanvas, parent=None):
  87. QMainWindow.__init__(self, parent)
  88. self.host = host
  89. self.ui = ui_carla_host.Ui_CarlaHostW()
  90. self.ui.setupUi(self)
  91. gCarla.gui = self
  92. if False:
  93. # kdevelop likes this :)
  94. host = CarlaHostNull()
  95. self.host = host
  96. self._true = c_char_p("true".encode("utf-8"))
  97. self.fParentOrSelf = parent or self
  98. # ----------------------------------------------------------------------------------------------------
  99. # Internal stuff
  100. self.fIdleTimerFast = 0
  101. self.fIdleTimerSlow = 0
  102. self.fLadspaRdfNeedsUpdate = True
  103. self.fLadspaRdfList = []
  104. self.fPluginCount = 0
  105. self.fPluginList = []
  106. self.fProjectFilename = ""
  107. self.fIsProjectLoading = False
  108. self.fCurrentlyRemovingAllPlugins = False
  109. self.fLastTransportBPM = 0.0
  110. self.fLastTransportFrame = 0
  111. self.fLastTransportState = False
  112. self.fSampleRate = 0.0
  113. if MACOS:
  114. self.fMacClosingHelper = True
  115. # run a custom action after engine is properly closed
  116. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  117. # first attempt of auto-start engine doesn't show an error
  118. self.fFirstEngineInit = True
  119. # to be filled with key-value pairs of current settings
  120. self.fSavedSettings = {}
  121. if host.isControl:
  122. self.fClientName = "Carla-Control"
  123. self.fSessionManagerName = "Control"
  124. elif host.isPlugin:
  125. self.fClientName = "Carla-Plugin"
  126. self.fSessionManagerName = "Plugin"
  127. elif LADISH_APP_NAME:
  128. self.fClientName = LADISH_APP_NAME
  129. self.fSessionManagerName = "LADISH"
  130. elif NSM_URL and host.nsmOK:
  131. self.fClientName = "Carla.tmp"
  132. self.fSessionManagerName = "Non Session Manager TMP"
  133. else:
  134. self.fClientName = CARLA_CLIENT_NAME or "Carla"
  135. self.fSessionManagerName = ""
  136. # ----------------------------------------------------------------------------------------------------
  137. # Internal stuff (patchbay)
  138. self.fExportImage = QImage()
  139. self.fPeaksCleared = True
  140. self.fExternalPatchbay = False
  141. self.fSelectedPlugins = []
  142. self.fCanvasWidth = 0
  143. self.fCanvasHeight = 0
  144. self.fMiniCanvasUpdateTimeout = 0
  145. self.fWithCanvas = withCanvas
  146. # ----------------------------------------------------------------------------------------------------
  147. # Set up GUI (engine stopped)
  148. if self.host.isPlugin or self.host.isControl:
  149. self.ui.act_file_save.setVisible(False)
  150. self.ui.act_engine_start.setEnabled(False)
  151. self.ui.act_engine_start.setVisible(False)
  152. self.ui.act_engine_stop.setEnabled(False)
  153. self.ui.act_engine_stop.setVisible(False)
  154. self.ui.menu_Engine.setEnabled(False)
  155. self.ui.menu_Engine.setVisible(False)
  156. self.ui.menu_Engine.menuAction().setVisible(False)
  157. self.ui.tabWidget.removeTab(2)
  158. if self.host.isControl:
  159. self.ui.act_file_new.setVisible(False)
  160. self.ui.act_file_open.setVisible(False)
  161. self.ui.act_file_save.setVisible(False)
  162. self.ui.act_file_save_as.setVisible(False)
  163. self.ui.act_plugin_add.setVisible(False)
  164. self.ui.act_plugin_add2.setVisible(False)
  165. self.ui.act_plugin_remove_all.setVisible(False)
  166. self.ui.act_add_jack.setVisible(False)
  167. self.ui.menu_Plugin.setEnabled(False)
  168. self.ui.menu_Plugin.setVisible(False)
  169. self.ui.menu_Plugin.menuAction().setVisible(False)
  170. else:
  171. self.ui.act_file_save_as.setText(self.tr("Export as..."))
  172. else:
  173. self.ui.act_engine_start.setEnabled(True)
  174. if WINDOWS:
  175. self.ui.tabWidget.removeTab(2)
  176. if not self.host.isControl:
  177. self.ui.act_file_connect.setEnabled(False)
  178. self.ui.act_file_connect.setVisible(False)
  179. self.ui.act_file_refresh.setEnabled(False)
  180. self.ui.act_file_refresh.setVisible(False)
  181. if self.fSessionManagerName and not self.host.isPlugin:
  182. self.ui.act_file_new.setEnabled(False)
  183. self.ui.act_file_open.setEnabled(False)
  184. self.ui.act_file_save.setEnabled(False)
  185. self.ui.act_file_save_as.setEnabled(False)
  186. self.ui.act_engine_stop.setEnabled(False)
  187. self.ui.act_plugin_remove_all.setEnabled(False)
  188. self.ui.act_canvas_show_internal.setChecked(False)
  189. self.ui.act_canvas_show_internal.setVisible(False)
  190. self.ui.act_canvas_show_external.setChecked(False)
  191. self.ui.act_canvas_show_external.setVisible(False)
  192. self.ui.menu_PluginMacros.setEnabled(False)
  193. self.ui.menu_Canvas.setEnabled(False)
  194. self.ui.dockWidgetTitleBar = QWidget(self)
  195. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  196. if not withCanvas:
  197. self.ui.act_canvas_show_internal.setVisible(False)
  198. self.ui.act_canvas_show_external.setVisible(False)
  199. self.ui.act_canvas_arrange.setVisible(False)
  200. self.ui.act_canvas_refresh.setVisible(False)
  201. self.ui.act_canvas_save_image.setVisible(False)
  202. self.ui.act_canvas_zoom_100.setVisible(False)
  203. self.ui.act_canvas_zoom_fit.setVisible(False)
  204. self.ui.act_canvas_zoom_in.setVisible(False)
  205. self.ui.act_canvas_zoom_out.setVisible(False)
  206. self.ui.act_settings_show_meters.setVisible(False)
  207. self.ui.act_settings_show_keyboard.setVisible(False)
  208. self.ui.menu_Canvas_Zoom.setEnabled(False)
  209. self.ui.menu_Canvas_Zoom.setVisible(False)
  210. self.ui.menu_Canvas_Zoom.menuAction().setVisible(False)
  211. self.ui.menu_Canvas.setEnabled(False)
  212. self.ui.menu_Canvas.setVisible(False)
  213. self.ui.menu_Canvas.menuAction().setVisible(False)
  214. self.ui.miniCanvasPreview.hide()
  215. self.ui.tabWidget.removeTab(1)
  216. if WINDOWS:
  217. self.ui.tabWidget.tabBar().hide()
  218. if host.isControl:
  219. self.ui.dockWidget.hide()
  220. # ----------------------------------------------------------------------------------------------------
  221. # Set up GUI (disk)
  222. exts = gCarla.utils.get_supported_file_extensions()
  223. self.fDirModel = QFileSystemModel(self)
  224. self.fDirModel.setRootPath(HOME)
  225. self.fDirModel.setNameFilters(tuple(("*." + i) for i in exts))
  226. self.ui.fileTreeView.setModel(self.fDirModel)
  227. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  228. self.ui.fileTreeView.setColumnHidden(1, True)
  229. self.ui.fileTreeView.setColumnHidden(2, True)
  230. self.ui.fileTreeView.setColumnHidden(3, True)
  231. self.ui.fileTreeView.setHeaderHidden(True)
  232. # ----------------------------------------------------------------------------------------------------
  233. # Set up GUI (transport)
  234. fontMetrics = QFontMetrics(self.ui.l_transport_bbt.font())
  235. minValueWidth = fontMetrics.width("000|00|0000")
  236. minLabelWidth = fontMetrics.width(self.ui.label_transport_frame.text())
  237. labelTimeWidth = fontMetrics.width(self.ui.label_transport_time.text())
  238. labelBBTWidth = fontMetrics.width(self.ui.label_transport_bbt.text())
  239. if minLabelWidth < labelTimeWidth:
  240. minLabelWidth = labelTimeWidth
  241. if minLabelWidth < labelBBTWidth:
  242. minLabelWidth = labelBBTWidth
  243. self.ui.label_transport_frame.setMinimumWidth(minLabelWidth + 3)
  244. self.ui.label_transport_time.setMinimumWidth(minLabelWidth + 3)
  245. self.ui.label_transport_bbt.setMinimumWidth(minLabelWidth + 3)
  246. self.ui.l_transport_bbt.setMinimumWidth(minValueWidth + 3)
  247. self.ui.l_transport_frame.setMinimumWidth(minValueWidth + 3)
  248. self.ui.l_transport_time.setMinimumWidth(minValueWidth + 3)
  249. if host.isControl or host.isPlugin:
  250. self.ui.b_transport_play.setEnabled(False)
  251. self.ui.b_transport_stop.setEnabled(False)
  252. self.ui.b_transport_backwards.setEnabled(False)
  253. self.ui.b_transport_forwards.setEnabled(False)
  254. self.ui.group_transport_controls.setEnabled(False)
  255. self.ui.group_transport_controls.setVisible(False)
  256. self.ui.cb_transport_link.setEnabled(False)
  257. self.ui.cb_transport_link.setVisible(False)
  258. self.ui.cb_transport_jack.setEnabled(False)
  259. self.ui.cb_transport_jack.setVisible(False)
  260. self.ui.dsb_transport_bpm.setEnabled(False)
  261. self.ui.dsb_transport_bpm.setReadOnly(True)
  262. self.ui.w_transport.setEnabled(False)
  263. # ----------------------------------------------------------------------------------------------------
  264. # Set up GUI (rack)
  265. self.ui.listWidget.setHostAndParent(self.host, self)
  266. sb = self.ui.listWidget.verticalScrollBar()
  267. self.ui.rackScrollBar.setMinimum(sb.minimum())
  268. self.ui.rackScrollBar.setMaximum(sb.maximum())
  269. self.ui.rackScrollBar.setValue(sb.value())
  270. sb.rangeChanged.connect(self.ui.rackScrollBar.setRange)
  271. sb.valueChanged.connect(self.ui.rackScrollBar.setValue)
  272. self.ui.rackScrollBar.rangeChanged.connect(sb.setRange)
  273. self.ui.rackScrollBar.valueChanged.connect(sb.setValue)
  274. self.updateStyle()
  275. self.ui.rack.setStyleSheet("""
  276. CarlaRackList#CarlaRackList {
  277. background-color: black;
  278. }
  279. """)
  280. # ----------------------------------------------------------------------------------------------------
  281. # Set up GUI (patchbay)
  282. self.ui.peak_in.setChannelCount(2)
  283. self.ui.peak_in.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  284. self.ui.peak_in.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  285. self.ui.peak_in.setFixedWidth(25)
  286. self.ui.peak_out.setChannelCount(2)
  287. self.ui.peak_out.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  288. self.ui.peak_out.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  289. self.ui.peak_out.setFixedWidth(25)
  290. self.ui.scrollArea = PixmapKeyboardHArea(self.ui.patchbay)
  291. self.ui.keyboard = self.ui.scrollArea.keyboard
  292. self.ui.patchbay.layout().addWidget(self.ui.scrollArea, 1, 0, 1, 0)
  293. self.ui.scrollArea.setEnabled(False)
  294. self.ui.miniCanvasPreview.setRealParent(self)
  295. self.ui.verticalLayout_7.setContentsMargins(0, 0, 0, 1)
  296. # ----------------------------------------------------------------------------------------------------
  297. # Set up GUI (special stuff for Mac OS)
  298. if MACOS:
  299. self.ui.act_file_quit.setMenuRole(QAction.QuitRole)
  300. self.ui.act_settings_configure.setMenuRole(QAction.PreferencesRole)
  301. self.ui.act_help_about.setMenuRole(QAction.AboutRole)
  302. self.ui.act_help_about_qt.setMenuRole(QAction.AboutQtRole)
  303. self.ui.menu_Settings.setTitle("Panels")
  304. self.ui.menu_Help.menuAction().setVisible(False)
  305. # ----------------------------------------------------------------------------------------------------
  306. # Load Settings
  307. self.loadSettings(True)
  308. # ----------------------------------------------------------------------------------------------------
  309. # Set-up Canvas
  310. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  311. self.ui.graphicsView.setScene(self.scene)
  312. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, bool(self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  313. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  314. self.ui.glView = QGLWidget(self)
  315. self.ui.graphicsView.setViewport(self.ui.glView)
  316. self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  317. self.setupCanvas()
  318. # ----------------------------------------------------------------------------------------------------
  319. # Connect actions to functions
  320. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  321. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  322. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  323. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  324. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  325. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  326. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  327. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  328. self.ui.act_plugin_remove_all.triggered.connect(self.slot_confirmRemoveAll)
  329. self.ui.act_add_jack.triggered.connect(self.slot_jackAppAdd)
  330. self.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  331. self.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  332. self.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  333. self.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  334. self.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  335. self.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  336. self.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  337. self.ui.act_plugins_compact.triggered.connect(self.slot_pluginsCompact)
  338. self.ui.act_plugins_expand.triggered.connect(self.slot_pluginsExpand)
  339. self.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  340. self.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  341. self.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  342. self.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  343. self.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  344. self.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  345. self.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  346. self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  347. self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  348. self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  349. self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  350. self.ui.act_settings_show_toolbar.toggled.connect(self.slot_showToolbar)
  351. self.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  352. self.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  353. self.ui.act_settings_show_side_panel.toggled.connect(self.slot_showSidePanel)
  354. self.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  355. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  356. self.ui.act_help_about_juce.triggered.connect(self.slot_aboutJuce)
  357. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  358. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  359. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  360. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  361. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  362. self.ui.b_transport_play.clicked.connect(self.slot_transportPlayPause)
  363. self.ui.b_transport_stop.clicked.connect(self.slot_transportStop)
  364. self.ui.b_transport_backwards.clicked.connect(self.slot_transportBackwards)
  365. self.ui.b_transport_forwards.clicked.connect(self.slot_transportForwards)
  366. self.ui.dsb_transport_bpm.valueChanged.connect(self.slot_transportBpmChanged)
  367. self.ui.cb_transport_jack.clicked.connect(self.slot_transportJackEnabled)
  368. self.ui.cb_transport_link.clicked.connect(self.slot_transportLinkEnabled)
  369. self.ui.listWidget.customContextMenuRequested.connect(self.showPluginActionsMenu)
  370. self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  371. self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  372. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  373. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  374. self.ui.miniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  375. self.ui.tabWidget.currentChanged.connect(self.slot_tabChanged)
  376. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  377. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  378. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  379. self.scene.selectionChanged.connect(self.slot_canvasSelectionChanged)
  380. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  381. self.SIGTERM.connect(self.slot_handleSIGTERM)
  382. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  383. host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  384. host.TransportModeChangedCallback.connect(self.slot_handleTransportModeChangedCallback)
  385. host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  386. host.ProjectLoadFinishedCallback.connect(self.slot_handleProjectLoadFinishedCallback)
  387. host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  388. host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  389. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  390. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  391. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  392. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  393. host.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  394. host.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  395. host.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  396. host.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  397. host.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  398. host.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  399. host.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  400. host.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  401. host.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  402. host.NSMCallback.connect(self.slot_handleNSMCallback)
  403. host.DebugCallback.connect(self.slot_handleDebugCallback)
  404. host.InfoCallback.connect(self.slot_handleInfoCallback)
  405. host.ErrorCallback.connect(self.slot_handleErrorCallback)
  406. host.QuitCallback.connect(self.slot_handleQuitCallback)
  407. # ----------------------------------------------------------------------------------------------------
  408. # Final setup
  409. self.ui.text_logs.clear()
  410. self.setProperWindowTitle()
  411. # Disable non-supported features
  412. features = gCarla.utils.get_supported_features()
  413. if "link" not in features:
  414. self.ui.cb_transport_link.setEnabled(False)
  415. self.ui.cb_transport_link.setVisible(False)
  416. if "juce" not in features:
  417. self.ui.act_help_about_juce.setEnabled(False)
  418. self.ui.act_help_about_juce.setVisible(False)
  419. # Plugin needs to have timers always running so it receives messages
  420. if self.host.isPlugin or self.host.isRemote:
  421. self.startTimers()
  422. # Qt needs this so it properly creates & resizes the canvas
  423. self.ui.tabWidget.blockSignals(True)
  424. self.ui.tabWidget.setCurrentIndex(1)
  425. self.ui.tabWidget.setCurrentIndex(0)
  426. self.ui.tabWidget.blockSignals(False)
  427. # Start in patchbay tab if using forced patchbay mode
  428. if host.processModeForced and host.processMode == ENGINE_PROCESS_MODE_PATCHBAY and not host.isControl:
  429. self.ui.tabWidget.setCurrentIndex(1)
  430. # Load initial project file if set
  431. if not (self.host.isControl or self.host.isPlugin):
  432. projectFile = getInitialProjectFile(QApplication.instance())
  433. if projectFile:
  434. self.loadProjectLater(projectFile)
  435. # For NSM we wait for the open message
  436. if NSM_URL and host.nsmOK:
  437. host.nsm_ready(-1)
  438. return
  439. QTimer.singleShot(0, self.slot_engineStart)
  440. # --------------------------------------------------------------------------------------------------------
  441. # Setup
  442. def compactPlugin(self, pluginId):
  443. if pluginId > self.fPluginCount:
  444. return
  445. pitem = self.fPluginList[pluginId]
  446. if pitem is None:
  447. return
  448. pitem.recreateWidget(True)
  449. def changePluginColor(self, pluginId, color, colorStr):
  450. if pluginId > self.fPluginCount:
  451. return
  452. pitem = self.fPluginList[pluginId]
  453. if pitem is None:
  454. return
  455. self.host.set_custom_data(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaColor", colorStr)
  456. pitem.recreateWidget(newColor = color)
  457. def changePluginSkin(self, pluginId, skin):
  458. if pluginId > self.fPluginCount:
  459. return
  460. pitem = self.fPluginList[pluginId]
  461. if pitem is None:
  462. return
  463. self.host.set_custom_data(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkin", skin)
  464. if skin not in ("default","rncbc","presets","mpresets"):
  465. pitem.recreateWidget(newSkin = skin, newColor = (255,255,255))
  466. else:
  467. pitem.recreateWidget(newSkin = skin)
  468. def switchPlugins(self, pluginIdA, pluginIdB):
  469. if pluginIdA == pluginIdB:
  470. return
  471. if pluginIdA < 0 or pluginIdB < 0:
  472. return
  473. if pluginIdA >= self.fPluginCount or pluginIdB >= self.fPluginCount:
  474. return
  475. self.host.switch_plugins(pluginIdA, pluginIdB)
  476. itemA = self.fPluginList[pluginIdA]
  477. compactA = itemA.isCompacted()
  478. guiShownA = itemA.isGuiShown()
  479. itemB = self.fPluginList[pluginIdB]
  480. compactB = itemB.isCompacted()
  481. guiShownB = itemB.isGuiShown()
  482. itemA.setPluginId(pluginIdA)
  483. itemA.recreateWidget2(compactB, guiShownB)
  484. itemB.setPluginId(pluginIdB)
  485. itemB.recreateWidget2(compactA, guiShownA)
  486. self.slot_canvasRefresh()
  487. def setLoadRDFsNeeded(self):
  488. self.fLadspaRdfNeedsUpdate = True
  489. def setProperWindowTitle(self):
  490. title = self.fClientName
  491. if self.fProjectFilename and not self.host.nsmOK:
  492. title += " - %s" % os.path.basename(self.fProjectFilename)
  493. if self.fSessionManagerName:
  494. title += " (%s)" % self.fSessionManagerName
  495. self.setWindowTitle(title)
  496. # --------------------------------------------------------------------------------------------------------
  497. # Files
  498. def makeExtraFilename(self):
  499. return self.fProjectFilename.rsplit(".",1)[0]+".json"
  500. def loadProjectNow(self):
  501. if not self.fProjectFilename:
  502. return qCritical("ERROR: loading project without filename set")
  503. if self.host.nsmOK and not os.path.exists(self.fProjectFilename):
  504. return
  505. self.projectLoadingStarted()
  506. self.fIsProjectLoading = True
  507. self.host.load_project(self.fProjectFilename)
  508. # Project finished loading is sent by engine
  509. def loadProjectLater(self, filename):
  510. self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
  511. self.setProperWindowTitle()
  512. QTimer.singleShot(1, self.slot_loadProjectNow)
  513. def saveProjectNow(self):
  514. if not self.fProjectFilename:
  515. return qCritical("ERROR: saving project without filename set")
  516. self.host.save_project(self.fProjectFilename)
  517. with open(self.makeExtraFilename(), 'w') as fh:
  518. json.dump({
  519. 'canvas': patchcanvas.saveGroupPositions(),
  520. }, fh)
  521. def projectLoadingStarted(self):
  522. self.ui.rack.setEnabled(False)
  523. self.ui.graphicsView.setEnabled(False)
  524. def projectLoadingFinished(self):
  525. self.ui.rack.setEnabled(True)
  526. self.ui.graphicsView.setEnabled(True)
  527. QTimer.singleShot(1000, self.slot_canvasRefresh)
  528. extrafile = self.makeExtraFilename()
  529. if not os.path.exists(extrafile):
  530. return
  531. try:
  532. with open(extrafile, "r") as fh:
  533. canvasdata = json.load(fh)['canvas']
  534. except:
  535. return
  536. patchcanvas.restoreGroupPositions(canvasdata)
  537. # --------------------------------------------------------------------------------------------------------
  538. # Files (menu actions)
  539. @pyqtSlot()
  540. def slot_fileNew(self):
  541. if self.fPluginCount > 0 and QMessageBox.question(self, self.tr("New File"),
  542. self.tr("Plugins that are currently loaded will be removed. Are you sure?"),
  543. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  544. return
  545. self.pluginRemoveAll()
  546. self.fProjectFilename = ""
  547. self.setProperWindowTitle()
  548. @pyqtSlot()
  549. def slot_fileOpen(self):
  550. fileFilter = self.tr("Carla Project File (*.carxp);;Carla Preset File (*.carxs)")
  551. filename, ok = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  552. # FIXME use ok value, test if it works as expected
  553. if not filename:
  554. return
  555. newFile = True
  556. if self.fPluginCount > 0:
  557. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  558. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  559. newFile = (ask == QMessageBox.Yes)
  560. if newFile:
  561. self.pluginRemoveAll()
  562. self.fProjectFilename = filename
  563. self.setProperWindowTitle()
  564. self.loadProjectNow()
  565. else:
  566. filenameOld = self.fProjectFilename
  567. self.fProjectFilename = filename
  568. self.loadProjectNow()
  569. self.fProjectFilename = filenameOld
  570. @pyqtSlot()
  571. def slot_fileSave(self, saveAs=False):
  572. if self.fProjectFilename and not saveAs:
  573. return self.saveProjectNow()
  574. fileFilter = self.tr("Carla Project File (*.carxp)")
  575. filename, ok = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  576. # FIXME use ok value, test if it works as expected
  577. if not filename:
  578. return
  579. if not filename.lower().endswith(".carxp"):
  580. filename += ".carxp"
  581. if self.fProjectFilename != filename:
  582. self.fProjectFilename = filename
  583. self.setProperWindowTitle()
  584. self.saveProjectNow()
  585. @pyqtSlot()
  586. def slot_fileSaveAs(self):
  587. self.slot_fileSave(True)
  588. @pyqtSlot()
  589. def slot_loadProjectNow(self):
  590. self.loadProjectNow()
  591. # --------------------------------------------------------------------------------------------------------
  592. # Engine (menu actions)
  593. @pyqtSlot()
  594. def slot_engineStart(self):
  595. audioDriver = setEngineSettings(self.host)
  596. firstInit = self.fFirstEngineInit
  597. self.fFirstEngineInit = False
  598. self.ui.text_logs.appendPlainText("======= Starting engine =======")
  599. if self.host.engine_init(audioDriver, self.fClientName):
  600. if firstInit and not (self.host.isControl or self.host.isPlugin):
  601. settings = QSettings()
  602. lastBpm = settings.value("LastBPM", 120.0, type=float)
  603. del settings
  604. self.host.transport_bpm(lastBpm)
  605. return
  606. elif firstInit:
  607. self.ui.text_logs.appendPlainText("Failed to start engine on first try, ignored")
  608. return
  609. audioError = self.host.get_last_error()
  610. if audioError:
  611. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  612. else:
  613. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  614. @pyqtSlot()
  615. def slot_engineStop(self, forced = False):
  616. self.ui.text_logs.appendPlainText("======= Stopping engine =======")
  617. if self.fPluginCount == 0:
  618. self.engineStopFinal()
  619. return True
  620. if not forced:
  621. 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"
  622. "Do you want to do this now?"),
  623. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  624. if ask != QMessageBox.Yes:
  625. return False
  626. return self.slot_engineStopTryAgain()
  627. @pyqtSlot()
  628. def slot_engineStopTryAgain(self):
  629. if self.host.is_engine_running() and not self.host.set_engine_about_to_close():
  630. QTimer.singleShot(0, self.slot_engineStopTryAgain)
  631. return False
  632. self.engineStopFinal()
  633. return True
  634. def engineStopFinal(self):
  635. self.killTimers()
  636. self.removeAllPlugins()
  637. if self.host.is_engine_running():
  638. self.host.remove_all_plugins()
  639. if not self.host.engine_close():
  640. self.ui.text_logs.appendPlainText("Failed to stop engine, error was:")
  641. self.ui.text_logs.appendPlainText(self.host.get_last_error())
  642. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  643. self.close()
  644. elif self.fCustomStopAction == self.CUSTOM_ACTION_PROJECT_LOAD:
  645. self.slot_engineStart()
  646. self.loadProjectNow()
  647. self.host.nsm_ready(2) # open
  648. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  649. # --------------------------------------------------------------------------------------------------------
  650. # Engine (host callbacks)
  651. @pyqtSlot(int, int, float, str)
  652. def slot_handleEngineStartedCallback(self, processMode, transportMode, sampleRate, driverName):
  653. self.fSampleRate = sampleRate
  654. self.ui.menu_PluginMacros.setEnabled(True)
  655. self.ui.menu_Canvas.setEnabled(True)
  656. self.ui.w_transport.setEnabled(True)
  657. self.ui.act_canvas_show_internal.blockSignals(True)
  658. self.ui.act_canvas_show_external.blockSignals(True)
  659. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and not (self.host.isControl or self.host.isPlugin):
  660. self.ui.act_canvas_show_internal.setChecked(True)
  661. self.ui.act_canvas_show_internal.setVisible(True)
  662. self.ui.act_canvas_show_external.setChecked(False)
  663. self.ui.act_canvas_show_external.setVisible(True)
  664. else:
  665. self.ui.act_canvas_show_internal.setChecked(False)
  666. self.ui.act_canvas_show_internal.setVisible(False)
  667. self.ui.act_canvas_show_external.setChecked(False)
  668. self.ui.act_canvas_show_external.setVisible(False)
  669. self.ui.act_canvas_show_internal.blockSignals(False)
  670. self.ui.act_canvas_show_external.blockSignals(False)
  671. if not (self.host.isControl or self.host.isPlugin):
  672. canSave = (self.fProjectFilename and os.path.exists(self.fProjectFilename)) or not self.fSessionManagerName
  673. self.ui.act_file_save.setEnabled(canSave)
  674. self.ui.act_engine_start.setEnabled(False)
  675. self.ui.act_engine_stop.setEnabled(True)
  676. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  677. if self.host.isPlugin or not self.fSessionManagerName:
  678. self.ui.act_file_open.setEnabled(True)
  679. self.ui.act_file_save_as.setEnabled(True)
  680. self.refreshTransport(True)
  681. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  682. self.ui.cb_transport_jack.setEnabled(driverName == "JACK" and processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  683. if self.ui.cb_transport_link.isEnabled():
  684. self.ui.cb_transport_link.setChecked(":link:" in self.host.transportExtra)
  685. self.startTimers()
  686. self.ui.text_logs.appendPlainText("======= Engine started ========")
  687. self.ui.text_logs.appendPlainText("Carla engine started, details:")
  688. self.ui.text_logs.appendPlainText(" Driver name: %s" % driverName)
  689. self.ui.text_logs.appendPlainText(" Sample rate: %.1f" % sampleRate)
  690. self.ui.text_logs.appendPlainText(" Process mode: %s" % processMode2Str(processMode))
  691. @pyqtSlot()
  692. def slot_handleEngineStoppedCallback(self):
  693. self.ui.text_logs.appendPlainText("======= Engine stopped ========")
  694. patchcanvas.clear()
  695. self.killTimers()
  696. # just in case
  697. self.removeAllPlugins()
  698. self.ui.menu_PluginMacros.setEnabled(False)
  699. self.ui.menu_Canvas.setEnabled(False)
  700. self.ui.w_transport.setEnabled(False)
  701. if not (self.host.isControl or self.host.isPlugin):
  702. self.ui.act_file_save.setEnabled(False)
  703. self.ui.act_engine_start.setEnabled(True)
  704. self.ui.act_engine_stop.setEnabled(False)
  705. if self.host.isPlugin or not self.fSessionManagerName:
  706. self.ui.act_file_open.setEnabled(False)
  707. self.ui.act_file_save_as.setEnabled(False)
  708. @pyqtSlot(int, str)
  709. def slot_handleTransportModeChangedCallback(self, transportMode, transportExtra):
  710. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  711. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  712. self.ui.cb_transport_link.setChecked(":link:" in transportExtra)
  713. @pyqtSlot(float)
  714. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  715. self.fSampleRate = newSampleRate
  716. self.refreshTransport(True)
  717. @pyqtSlot()
  718. def slot_handleProjectLoadFinishedCallback(self):
  719. self.fIsProjectLoading = False
  720. self.projectLoadingFinished()
  721. # --------------------------------------------------------------------------------------------------------
  722. # Plugins
  723. def removeAllPlugins(self):
  724. self.ui.act_plugin_remove_all.setEnabled(False)
  725. patchcanvas.handleAllPluginsRemoved()
  726. while self.ui.listWidget.takeItem(0):
  727. pass
  728. self.clearSideStuff()
  729. for pitem in self.fPluginList:
  730. if pitem is None:
  731. continue
  732. pitem.close()
  733. del pitem
  734. self.fPluginCount = 0
  735. self.fPluginList = []
  736. # --------------------------------------------------------------------------------------------------------
  737. # Plugins (menu actions)
  738. def showAddPluginDialog(self):
  739. dialog = PluginDatabaseW(self.fParentOrSelf, self.host)
  740. if not dialog.exec_():
  741. return
  742. if not self.host.is_engine_running():
  743. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  744. return
  745. btype = dialog.fRetPlugin['build']
  746. ptype = dialog.fRetPlugin['type']
  747. filename = dialog.fRetPlugin['filename']
  748. label = dialog.fRetPlugin['label']
  749. uniqueId = dialog.fRetPlugin['uniqueId']
  750. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  751. return (btype, ptype, filename, label, uniqueId, extraPtr)
  752. def showAddJackAppDialog(self):
  753. dialog = JackApplicationW(self.fParentOrSelf, self.host)
  754. if not dialog.exec_():
  755. return
  756. if not self.host.is_engine_running():
  757. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  758. return
  759. return dialog.getCommandAndFlags()
  760. @pyqtSlot()
  761. def showPluginActionsMenu(self):
  762. menu = QMenu(self)
  763. menu.addSection("Plugins")
  764. menu.addAction(self.ui.act_plugin_add)
  765. menu.addAction(self.ui.act_plugin_remove_all)
  766. menu.addSection("All plugins (macros)")
  767. menu.addAction(self.ui.act_plugins_enable)
  768. menu.addAction(self.ui.act_plugins_disable)
  769. menu.addSeparator()
  770. menu.addAction(self.ui.act_plugins_volume100)
  771. menu.addAction(self.ui.act_plugins_mute)
  772. menu.addSeparator()
  773. menu.addAction(self.ui.act_plugins_wet100)
  774. menu.addAction(self.ui.act_plugins_bypass)
  775. menu.addSeparator()
  776. menu.addAction(self.ui.act_plugins_center)
  777. menu.addSeparator()
  778. menu.addAction(self.ui.act_plugins_compact)
  779. menu.addAction(self.ui.act_plugins_expand)
  780. menu.exec_(QCursor.pos())
  781. @pyqtSlot()
  782. def slot_pluginAdd(self):
  783. data = self.showAddPluginDialog()
  784. if data is None:
  785. return
  786. btype, ptype, filename, label, uniqueId, extraPtr = data
  787. if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0):
  788. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  789. @pyqtSlot()
  790. def slot_confirmRemoveAll(self):
  791. if self.fPluginCount == 0:
  792. return
  793. if QMessageBox.question(self, self.tr("Remove All"),
  794. self.tr("Are you sure you want to remove all plugins?"),
  795. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  796. return
  797. self.pluginRemoveAll()
  798. def pluginRemoveAll(self):
  799. if self.fPluginCount == 0:
  800. return
  801. # FIXME - this is not working
  802. # removing a plugin causes flicker, the rack-list becomes empty for some time
  803. # this breaks the remove-all animation, so don't bother using it
  804. if False and not self.host.isPlugin:
  805. self.projectLoadingStarted()
  806. app = QApplication.instance()
  807. app.processEvents()
  808. for i in reversed(range(self.fPluginCount)):
  809. self.host.remove_plugin(i)
  810. app.processEvents()
  811. self.projectLoadingFinished()
  812. self.fCurrentlyRemovingAllPlugins = True
  813. ok = self.host.remove_all_plugins()
  814. self.fCurrentlyRemovingAllPlugins = False
  815. if ok:
  816. self.removeAllPlugins()
  817. else:
  818. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  819. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  820. self.fCurrentlyRemovingAllPlugins = False
  821. @pyqtSlot()
  822. def slot_jackAppAdd(self):
  823. data = self.showAddJackAppDialog()
  824. if data is None:
  825. return
  826. filename, name, label = data
  827. if not filename:
  828. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Cannot add jack application"),
  829. self.tr("command is empty"), QMessageBox.Ok, QMessageBox.Ok)
  830. return
  831. if not self.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, filename, name, label, 0, None, 0x0):
  832. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"),
  833. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  834. # --------------------------------------------------------------------------------------------------------
  835. # Plugins (macros)
  836. @pyqtSlot()
  837. def slot_pluginsEnable(self):
  838. if not self.host.is_engine_running():
  839. return
  840. for pitem in self.fPluginList:
  841. if pitem is None:
  842. break
  843. pitem.getWidget().setActive(True, True, True)
  844. @pyqtSlot()
  845. def slot_pluginsDisable(self):
  846. if not self.host.is_engine_running():
  847. return
  848. for pitem in self.fPluginList:
  849. if pitem is None:
  850. break
  851. pitem.getWidget().setActive(False, True, True)
  852. @pyqtSlot()
  853. def slot_pluginsVolume100(self):
  854. if not self.host.is_engine_running():
  855. return
  856. for pitem in self.fPluginList:
  857. if pitem is None:
  858. break
  859. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  860. @pyqtSlot()
  861. def slot_pluginsMute(self):
  862. if not self.host.is_engine_running():
  863. return
  864. for pitem in self.fPluginList:
  865. if pitem is None:
  866. break
  867. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  868. @pyqtSlot()
  869. def slot_pluginsWet100(self):
  870. if not self.host.is_engine_running():
  871. return
  872. for pitem in self.fPluginList:
  873. if pitem is None:
  874. break
  875. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  876. @pyqtSlot()
  877. def slot_pluginsBypass(self):
  878. if not self.host.is_engine_running():
  879. return
  880. for pitem in self.fPluginList:
  881. if pitem is None:
  882. break
  883. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  884. @pyqtSlot()
  885. def slot_pluginsCenter(self):
  886. if not self.host.is_engine_running():
  887. return
  888. for pitem in self.fPluginList:
  889. if pitem is None:
  890. break
  891. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  892. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  893. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  894. @pyqtSlot()
  895. def slot_pluginsCompact(self):
  896. for pitem in self.fPluginList:
  897. if pitem is None:
  898. break
  899. pitem.compact()
  900. @pyqtSlot()
  901. def slot_pluginsExpand(self):
  902. for pitem in self.fPluginList:
  903. if pitem is None:
  904. break
  905. pitem.expand()
  906. # --------------------------------------------------------------------------------------------------------
  907. # Plugins (host callbacks)
  908. @pyqtSlot(int, str)
  909. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  910. pitem = self.ui.listWidget.createItem(pluginId)
  911. self.fPluginList.append(pitem)
  912. self.fPluginCount += 1
  913. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  914. @pyqtSlot(int)
  915. def slot_handlePluginRemovedCallback(self, pluginId):
  916. patchcanvas.handlePluginRemoved(pluginId)
  917. if pluginId in self.fSelectedPlugins:
  918. self.clearSideStuff()
  919. pitem = self.getPluginItem(pluginId)
  920. self.fPluginCount -= 1
  921. self.fPluginList.pop(pluginId)
  922. self.ui.listWidget.takeItem(pluginId)
  923. if pitem is not None:
  924. pitem.close()
  925. del pitem
  926. # push all plugins 1 slot back
  927. for i in range(pluginId, self.fPluginCount):
  928. pitem = self.fPluginList[i]
  929. pitem.setPluginId(i)
  930. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  931. # --------------------------------------------------------------------------------------------------------
  932. # Canvas
  933. def clearSideStuff(self):
  934. self.scene.clearSelection()
  935. self.fSelectedPlugins = []
  936. self.ui.keyboard.allNotesOff(False)
  937. self.ui.scrollArea.setEnabled(False)
  938. self.fPeaksCleared = True
  939. self.ui.peak_in.displayMeter(1, 0.0, True)
  940. self.ui.peak_in.displayMeter(2, 0.0, True)
  941. self.ui.peak_out.displayMeter(1, 0.0, True)
  942. self.ui.peak_out.displayMeter(2, 0.0, True)
  943. def setupCanvas(self):
  944. pOptions = patchcanvas.options_t()
  945. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  946. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  947. pOptions.auto_select_items = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS]
  948. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  949. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  950. if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY]:
  951. pOptions.eyecandy = patchcanvas.EYECANDY_FULL
  952. elif self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]:
  953. pOptions.eyecandy = patchcanvas.EYECANDY_SMALL
  954. else:
  955. pOptions.eyecandy = patchcanvas.EYECANDY_NONE
  956. pFeatures = patchcanvas.features_t()
  957. pFeatures.group_info = False
  958. pFeatures.group_rename = False
  959. pFeatures.port_info = False
  960. pFeatures.port_rename = False
  961. pFeatures.handle_group_pos = True
  962. patchcanvas.setOptions(pOptions)
  963. patchcanvas.setFeatures(pFeatures)
  964. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  965. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  966. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  967. self.fCanvasWidth = int(tryCanvasSize[0])
  968. self.fCanvasHeight = int(tryCanvasSize[1])
  969. else:
  970. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  971. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  972. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  973. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  974. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  975. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  976. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  977. def updateCanvasInitialPos(self):
  978. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  979. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  980. patchcanvas.setInitialPos(x, y)
  981. def updateMiniCanvasLater(self):
  982. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  983. # --------------------------------------------------------------------------------------------------------
  984. # Canvas (menu actions)
  985. @pyqtSlot()
  986. def slot_canvasShowInternal(self):
  987. self.fExternalPatchbay = False
  988. self.ui.act_canvas_show_internal.blockSignals(True)
  989. self.ui.act_canvas_show_external.blockSignals(True)
  990. self.ui.act_canvas_show_internal.setChecked(True)
  991. self.ui.act_canvas_show_external.setChecked(False)
  992. self.ui.act_canvas_show_internal.blockSignals(False)
  993. self.ui.act_canvas_show_external.blockSignals(False)
  994. self.slot_canvasRefresh()
  995. @pyqtSlot()
  996. def slot_canvasShowExternal(self):
  997. self.fExternalPatchbay = True
  998. self.ui.act_canvas_show_internal.blockSignals(True)
  999. self.ui.act_canvas_show_external.blockSignals(True)
  1000. self.ui.act_canvas_show_internal.setChecked(False)
  1001. self.ui.act_canvas_show_external.setChecked(True)
  1002. self.ui.act_canvas_show_internal.blockSignals(False)
  1003. self.ui.act_canvas_show_external.blockSignals(False)
  1004. self.slot_canvasRefresh()
  1005. @pyqtSlot()
  1006. def slot_canvasArrange(self):
  1007. patchcanvas.arrange()
  1008. @pyqtSlot()
  1009. def slot_canvasRefresh(self):
  1010. patchcanvas.clear()
  1011. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and (self.host.isControl or self.host.isPlugin):
  1012. return
  1013. if self.host.is_engine_running():
  1014. self.host.patchbay_refresh(self.fExternalPatchbay)
  1015. self.updateMiniCanvasLater()
  1016. @pyqtSlot()
  1017. def slot_canvasZoomFit(self):
  1018. self.scene.zoom_fit()
  1019. @pyqtSlot()
  1020. def slot_canvasZoomIn(self):
  1021. self.scene.zoom_in()
  1022. @pyqtSlot()
  1023. def slot_canvasZoomOut(self):
  1024. self.scene.zoom_out()
  1025. @pyqtSlot()
  1026. def slot_canvasZoomReset(self):
  1027. self.scene.zoom_reset()
  1028. @pyqtSlot()
  1029. def slot_canvasSaveImage(self):
  1030. newPath, ok = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  1031. # FIXME use ok value, test if it works as expected
  1032. if not newPath:
  1033. return
  1034. self.scene.clearSelection()
  1035. if newPath.lower().endswith((".jpg", ".jpeg")):
  1036. imgFormat = "JPG"
  1037. elif newPath.lower().endswith((".png",)):
  1038. imgFormat = "PNG"
  1039. else:
  1040. # File-dialog may not auto-add the extension
  1041. imgFormat = "PNG"
  1042. newPath += ".png"
  1043. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  1044. painter = QPainter(self.fExportImage)
  1045. painter.save()
  1046. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  1047. painter.setRenderHint(QPainter.TextAntialiasing)
  1048. self.scene.render(painter)
  1049. self.fExportImage.save(newPath, imgFormat, 100)
  1050. painter.restore()
  1051. # --------------------------------------------------------------------------------------------------------
  1052. # Canvas (canvas callbacks)
  1053. @pyqtSlot(int, int, QPointF)
  1054. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  1055. self.updateMiniCanvasLater()
  1056. @pyqtSlot()
  1057. def slot_canvasSelectionChanged(self):
  1058. self.updateMiniCanvasLater()
  1059. @pyqtSlot(float)
  1060. def slot_canvasScaleChanged(self, scale):
  1061. self.ui.miniCanvasPreview.setViewScale(scale)
  1062. @pyqtSlot(list)
  1063. def slot_canvasPluginSelected(self, pluginList):
  1064. self.ui.keyboard.allNotesOff(False)
  1065. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  1066. self.fSelectedPlugins = pluginList
  1067. # --------------------------------------------------------------------------------------------------------
  1068. # Canvas (host callbacks)
  1069. @pyqtSlot(int, int, int, str)
  1070. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  1071. pcSplit = patchcanvas.SPLIT_UNDEF
  1072. pcIcon = patchcanvas.ICON_APPLICATION
  1073. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1074. pcIcon = patchcanvas.ICON_PLUGIN
  1075. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1076. pcIcon = patchcanvas.ICON_HARDWARE
  1077. elif clientIcon == PATCHBAY_ICON_CARLA:
  1078. pass
  1079. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1080. pcIcon = patchcanvas.ICON_DISTRHO
  1081. elif clientIcon == PATCHBAY_ICON_FILE:
  1082. pcIcon = patchcanvas.ICON_FILE
  1083. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  1084. self.updateMiniCanvasLater()
  1085. if pluginId < 0:
  1086. return
  1087. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1088. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1089. return
  1090. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1091. hasCustomUI = False
  1092. else:
  1093. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1094. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1095. @pyqtSlot(int)
  1096. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  1097. patchcanvas.removeGroup(clientId)
  1098. self.updateMiniCanvasLater()
  1099. @pyqtSlot(int, str)
  1100. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  1101. patchcanvas.renameGroup(clientId, newClientName)
  1102. self.updateMiniCanvasLater()
  1103. @pyqtSlot(int, int, int)
  1104. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  1105. pcIcon = patchcanvas.ICON_APPLICATION
  1106. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1107. pcIcon = patchcanvas.ICON_PLUGIN
  1108. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1109. pcIcon = patchcanvas.ICON_HARDWARE
  1110. elif clientIcon == PATCHBAY_ICON_CARLA:
  1111. pass
  1112. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1113. pcIcon = patchcanvas.ICON_DISTRHO
  1114. elif clientIcon == PATCHBAY_ICON_FILE:
  1115. pcIcon = patchcanvas.ICON_FILE
  1116. patchcanvas.setGroupIcon(clientId, pcIcon)
  1117. self.updateMiniCanvasLater()
  1118. if pluginId < 0:
  1119. return
  1120. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1121. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1122. return
  1123. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1124. hasCustomUI = False
  1125. else:
  1126. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1127. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1128. @pyqtSlot(int, int, int, str)
  1129. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  1130. if portFlags & PATCHBAY_PORT_IS_INPUT:
  1131. portMode = patchcanvas.PORT_MODE_INPUT
  1132. else:
  1133. portMode = patchcanvas.PORT_MODE_OUTPUT
  1134. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  1135. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1136. isAlternate = False
  1137. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  1138. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1139. isAlternate = True
  1140. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  1141. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  1142. isAlternate = False
  1143. else:
  1144. portType = patchcanvas.PORT_TYPE_NULL
  1145. isAlternate = False
  1146. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  1147. self.updateMiniCanvasLater()
  1148. @pyqtSlot(int, int)
  1149. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  1150. patchcanvas.removePort(groupId, portId)
  1151. self.updateMiniCanvasLater()
  1152. @pyqtSlot(int, int, str)
  1153. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  1154. patchcanvas.renamePort(groupId, portId, newPortName)
  1155. self.updateMiniCanvasLater()
  1156. @pyqtSlot(int, int, int, int, int)
  1157. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  1158. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  1159. self.updateMiniCanvasLater()
  1160. @pyqtSlot(int, int, int)
  1161. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  1162. patchcanvas.disconnectPorts(connectionId)
  1163. self.updateMiniCanvasLater()
  1164. # --------------------------------------------------------------------------------------------------------
  1165. # Settings
  1166. def saveSettings(self):
  1167. settings = QSettings()
  1168. settings.setValue("Geometry", self.saveGeometry())
  1169. settings.setValue("ShowToolbar", self.ui.toolBar.isEnabled())
  1170. settings.setValue("ShowSidePanel", self.ui.dockWidget.isEnabled())
  1171. diskFolders = []
  1172. for i in range(self.ui.cb_disk.count()):
  1173. diskFolders.append(self.ui.cb_disk.itemData(i))
  1174. settings.setValue("DiskFolders", diskFolders)
  1175. settings.setValue("LastBPM", self.fLastTransportBPM)
  1176. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  1177. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  1178. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1179. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1180. settings.setValue(CARLA_KEY_ENGINE_TRANSPORT_MODE, self.host.transportMode)
  1181. settings.setValue(CARLA_KEY_ENGINE_TRANSPORT_EXTRA, self.host.transportExtra)
  1182. def loadSettings(self, firstTime):
  1183. settings = QSettings()
  1184. if firstTime:
  1185. self.restoreGeometry(settings.value("Geometry", b""))
  1186. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1187. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1188. self.ui.toolBar.setEnabled(showToolbar)
  1189. self.ui.toolBar.setVisible(showToolbar)
  1190. #if settings.contains("SplitterState"):
  1191. #self.ui.splitter.restoreState(settings.value("SplitterState", b""))
  1192. #else:
  1193. #self.ui.splitter.setSizes([210, 99999])
  1194. showSidePanel = settings.value("ShowSidePanel", True, type=bool)
  1195. self.ui.act_settings_show_side_panel.setChecked(showSidePanel)
  1196. self.slot_showSidePanel(showSidePanel)
  1197. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  1198. self.ui.cb_disk.setItemData(0, HOME)
  1199. for i in range(len(diskFolders)):
  1200. if i == 0: continue
  1201. folder = diskFolders[i]
  1202. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1203. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  1204. # self.setUnifiedTitleAndToolBarOnMac(True)
  1205. showMeters = settings.value("ShowMeters", True, type=bool)
  1206. self.ui.act_settings_show_meters.setChecked(showMeters)
  1207. self.ui.peak_in.setVisible(showMeters)
  1208. self.ui.peak_out.setVisible(showMeters)
  1209. showKeyboard = settings.value("ShowKeyboard", True, type=bool)
  1210. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  1211. self.ui.scrollArea.setVisible(showKeyboard)
  1212. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  1213. # TODO - complete this
  1214. self.fSavedSettings = {
  1215. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  1216. CARLA_KEY_MAIN_CONFIRM_EXIT: settings.value(CARLA_KEY_MAIN_CONFIRM_EXIT, CARLA_DEFAULT_MAIN_CONFIRM_EXIT, type=bool),
  1217. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  1218. CARLA_KEY_MAIN_EXPERIMENTAL: settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool),
  1219. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  1220. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  1221. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  1222. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS: settings.value(CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS, CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS, type=bool),
  1223. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  1224. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=bool),
  1225. CARLA_KEY_CANVAS_FANCY_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_FANCY_EYE_CANDY, CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY, type=bool),
  1226. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  1227. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  1228. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  1229. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  1230. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black"),
  1231. }
  1232. settings = QSettings("falkTX", "Carla2")
  1233. if self.host.experimental and not self.host.isControl:
  1234. self.ui.act_add_jack.setVisible(settings.value(CARLA_KEY_EXPERIMENTAL_JACK_APPS,
  1235. CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS, type=bool))
  1236. else:
  1237. self.ui.act_add_jack.setVisible(False)
  1238. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY] else 0
  1239. setEngineSettings(self.host)
  1240. self.restartTimersIfNeeded()
  1241. # --------------------------------------------------------------------------------------------------------
  1242. # Settings (helpers)
  1243. def enableTransport(self, enabled):
  1244. self.ui.group_transport_controls.setEnabled(enabled)
  1245. self.ui.group_transport_settings.setEnabled(enabled)
  1246. @pyqtSlot()
  1247. def slot_restoreCanvasScrollbarValues(self):
  1248. settings = QSettings()
  1249. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  1250. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  1251. # --------------------------------------------------------------------------------------------------------
  1252. # Settings (menu actions)
  1253. @pyqtSlot(bool)
  1254. def slot_showSidePanel(self, yesNo):
  1255. self.ui.dockWidget.setEnabled(yesNo)
  1256. self.ui.dockWidget.setVisible(yesNo)
  1257. @pyqtSlot(bool)
  1258. def slot_showToolbar(self, yesNo):
  1259. self.ui.toolBar.setEnabled(yesNo)
  1260. self.ui.toolBar.setVisible(yesNo)
  1261. @pyqtSlot(bool)
  1262. def slot_showCanvasMeters(self, yesNo):
  1263. self.ui.peak_in.setVisible(yesNo)
  1264. self.ui.peak_out.setVisible(yesNo)
  1265. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1266. @pyqtSlot(bool)
  1267. def slot_showCanvasKeyboard(self, yesNo):
  1268. self.ui.scrollArea.setVisible(yesNo)
  1269. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1270. @pyqtSlot()
  1271. def slot_configureCarla(self):
  1272. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1273. if not dialog.exec_():
  1274. return
  1275. self.loadSettings(False)
  1276. patchcanvas.clear()
  1277. self.setupCanvas()
  1278. self.slot_miniCanvasCheckAll()
  1279. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1280. pass
  1281. elif self.host.is_engine_running():
  1282. self.host.patchbay_refresh(self.fExternalPatchbay)
  1283. # --------------------------------------------------------------------------------------------------------
  1284. # About (menu actions)
  1285. @pyqtSlot()
  1286. def slot_aboutCarla(self):
  1287. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1288. @pyqtSlot()
  1289. def slot_aboutJuce(self):
  1290. JuceAboutW(self.fParentOrSelf).exec_()
  1291. @pyqtSlot()
  1292. def slot_aboutQt(self):
  1293. QApplication.instance().aboutQt()
  1294. # --------------------------------------------------------------------------------------------------------
  1295. # Disk (menu actions)
  1296. @pyqtSlot(int)
  1297. def slot_diskFolderChanged(self, index):
  1298. if index < 0:
  1299. return
  1300. elif index == 0:
  1301. filename = HOME
  1302. self.ui.b_disk_remove.setEnabled(False)
  1303. else:
  1304. filename = self.ui.cb_disk.itemData(index)
  1305. self.ui.b_disk_remove.setEnabled(True)
  1306. self.fDirModel.setRootPath(filename)
  1307. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1308. @pyqtSlot()
  1309. def slot_diskFolderAdd(self):
  1310. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1311. if newPath:
  1312. if newPath[-1] == os.sep:
  1313. newPath = newPath[:-1]
  1314. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1315. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1316. self.ui.b_disk_remove.setEnabled(True)
  1317. @pyqtSlot()
  1318. def slot_diskFolderRemove(self):
  1319. index = self.ui.cb_disk.currentIndex()
  1320. if index <= 0:
  1321. return
  1322. self.ui.cb_disk.removeItem(index)
  1323. if self.ui.cb_disk.currentIndex() == 0:
  1324. self.ui.b_disk_remove.setEnabled(False)
  1325. @pyqtSlot(QModelIndex)
  1326. def slot_fileTreeDoubleClicked(self, modelIndex):
  1327. filename = self.fDirModel.filePath(modelIndex)
  1328. if not self.ui.listWidget.isDragUrlValid(filename):
  1329. return
  1330. if not self.host.load_file(filename):
  1331. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1332. self.tr("Failed to load file"),
  1333. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1334. # --------------------------------------------------------------------------------------------------------
  1335. # Transport
  1336. def refreshTransport(self, forced = False):
  1337. if not self.isVisible():
  1338. return
  1339. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  1340. return
  1341. timeInfo = self.host.get_transport_info()
  1342. playing = timeInfo['playing']
  1343. frame = timeInfo['frame']
  1344. bpm = timeInfo['bpm']
  1345. if playing != self.fLastTransportState or forced:
  1346. if playing:
  1347. icon = getIcon("media-playback-pause")
  1348. self.ui.b_transport_play.setChecked(True)
  1349. self.ui.b_transport_play.setIcon(icon)
  1350. #self.ui.b_transport_play.setText(self.tr("&Pause"))
  1351. else:
  1352. icon = getIcon("media-playback-start")
  1353. self.ui.b_transport_play.setChecked(False)
  1354. self.ui.b_transport_play.setIcon(icon)
  1355. #self.ui.b_play.setText(self.tr("&Play"))
  1356. self.fLastTransportState = playing
  1357. if frame != self.fLastTransportFrame or forced:
  1358. self.fLastTransportFrame = frame
  1359. time = frame / self.fSampleRate
  1360. secs = time % 60
  1361. mins = (time / 60) % 60
  1362. hrs = (time / 3600) % 60
  1363. self.ui.l_transport_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  1364. frame1 = frame % 1000
  1365. frame2 = (frame / 1000) % 1000
  1366. frame3 = (frame / 1000000) % 1000
  1367. self.ui.l_transport_frame.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  1368. bar = timeInfo['bar']
  1369. beat = timeInfo['beat']
  1370. tick = timeInfo['tick']
  1371. self.ui.l_transport_bbt.setText("%03i|%02i|%04i" % (bar, beat, tick))
  1372. if bpm != self.fLastTransportBPM or forced:
  1373. self.fLastTransportBPM = bpm
  1374. if bpm > 0.0:
  1375. self.ui.dsb_transport_bpm.blockSignals(True)
  1376. self.ui.dsb_transport_bpm.setValue(bpm)
  1377. self.ui.dsb_transport_bpm.blockSignals(False)
  1378. self.ui.dsb_transport_bpm.setStyleSheet("")
  1379. else:
  1380. self.ui.dsb_transport_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  1381. # --------------------------------------------------------------------------------------------------------
  1382. # Transport (menu actions)
  1383. @pyqtSlot(bool)
  1384. def slot_transportPlayPause(self, toggled):
  1385. if self.host.isPlugin or not self.host.is_engine_running():
  1386. return
  1387. if toggled:
  1388. self.host.transport_play()
  1389. else:
  1390. self.host.transport_pause()
  1391. self.refreshTransport()
  1392. @pyqtSlot()
  1393. def slot_transportStop(self):
  1394. if self.host.isPlugin or not self.host.is_engine_running():
  1395. return
  1396. self.host.transport_pause()
  1397. self.host.transport_relocate(0)
  1398. self.refreshTransport()
  1399. @pyqtSlot()
  1400. def slot_transportBackwards(self):
  1401. if self.host.isPlugin or not self.host.is_engine_running():
  1402. return
  1403. newFrame = self.host.get_current_transport_frame() - 100000
  1404. if newFrame < 0:
  1405. newFrame = 0
  1406. self.host.transport_relocate(newFrame)
  1407. @pyqtSlot(float)
  1408. def slot_transportBpmChanged(self, newValue):
  1409. self.host.transport_bpm(newValue)
  1410. @pyqtSlot()
  1411. def slot_transportForwards(self):
  1412. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  1413. return
  1414. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  1415. self.host.transport_relocate(newFrame)
  1416. @pyqtSlot(bool)
  1417. def slot_transportJackEnabled(self, clicked):
  1418. if not self.host.is_engine_running():
  1419. return
  1420. self.host.transportMode = ENGINE_TRANSPORT_MODE_JACK if clicked else ENGINE_TRANSPORT_MODE_INTERNAL
  1421. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE,
  1422. self.host.transportMode,
  1423. self.host.transportExtra)
  1424. @pyqtSlot(bool)
  1425. def slot_transportLinkEnabled(self, clicked):
  1426. if not self.host.is_engine_running():
  1427. return
  1428. extra = ":link:" if clicked else ""
  1429. self.host.transportExtra = extra
  1430. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE,
  1431. self.host.transportMode,
  1432. self.host.transportExtra)
  1433. # --------------------------------------------------------------------------------------------------------
  1434. # Canvas scrollbars
  1435. @pyqtSlot(int)
  1436. def slot_horizontalScrollBarChanged(self, value):
  1437. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1438. if maximum == 0:
  1439. xp = 0
  1440. else:
  1441. xp = float(value) / maximum
  1442. self.ui.miniCanvasPreview.setViewPosX(xp)
  1443. self.updateCanvasInitialPos()
  1444. @pyqtSlot(int)
  1445. def slot_verticalScrollBarChanged(self, value):
  1446. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1447. if maximum == 0:
  1448. yp = 0
  1449. else:
  1450. yp = float(value) / maximum
  1451. self.ui.miniCanvasPreview.setViewPosY(yp)
  1452. self.updateCanvasInitialPos()
  1453. # --------------------------------------------------------------------------------------------------------
  1454. # Canvas keyboard
  1455. @pyqtSlot(int)
  1456. def slot_noteOn(self, note):
  1457. for pluginId in self.fSelectedPlugins:
  1458. self.host.send_midi_note(pluginId, 0, note, 100)
  1459. pedit = self.getPluginEditDialog(pluginId)
  1460. pedit.noteOn(0, note, 100)
  1461. @pyqtSlot(int)
  1462. def slot_noteOff(self, note):
  1463. for pluginId in self.fSelectedPlugins:
  1464. self.host.send_midi_note(pluginId, 0, note, 0)
  1465. pedit = self.getPluginEditDialog(pluginId)
  1466. pedit.noteOff(0, note)
  1467. # --------------------------------------------------------------------------------------------------------
  1468. # Canvas keyboard (host callbacks)
  1469. @pyqtSlot(int, int, int, int)
  1470. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1471. if pluginId in self.fSelectedPlugins:
  1472. self.ui.keyboard.sendNoteOn(note, False)
  1473. @pyqtSlot(int, int, int)
  1474. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1475. if pluginId in self.fSelectedPlugins:
  1476. self.ui.keyboard.sendNoteOff(note, False)
  1477. # --------------------------------------------------------------------------------------------------------
  1478. @pyqtSlot(int)
  1479. def slot_handleUpdateCallback(self, pluginId):
  1480. pitem = self.getPluginItem(pluginId)
  1481. if pitem is None:
  1482. return
  1483. wasCompacted = pitem.isCompacted()
  1484. isCompacted = wasCompacted
  1485. check = self.host.get_custom_data_value(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkinIsCompacted")
  1486. if not check:
  1487. return
  1488. isCompacted = bool(check == "true")
  1489. if wasCompacted == isCompacted:
  1490. return
  1491. pitem.recreateWidget(True)
  1492. # --------------------------------------------------------------------------------------------------------
  1493. # MiniCanvas stuff
  1494. @pyqtSlot()
  1495. def slot_miniCanvasCheckAll(self):
  1496. self.slot_miniCanvasCheckSize()
  1497. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1498. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1499. @pyqtSlot()
  1500. def slot_miniCanvasCheckSize(self):
  1501. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1502. return
  1503. currentIndex = self.ui.tabWidget.currentIndex()
  1504. if currentIndex == 1:
  1505. width = self.ui.graphicsView.width()
  1506. height = self.ui.graphicsView.height()
  1507. else:
  1508. self.ui.tabWidget.blockSignals(True)
  1509. self.ui.tabWidget.setCurrentIndex(1)
  1510. width = self.ui.graphicsView.width()
  1511. height = self.ui.graphicsView.height()
  1512. self.ui.tabWidget.setCurrentIndex(currentIndex)
  1513. self.ui.tabWidget.blockSignals(False)
  1514. self.scene.updateLimits()
  1515. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1516. @pyqtSlot(float, float)
  1517. def slot_miniCanvasMoved(self, xp, yp):
  1518. hsb = self.ui.graphicsView.horizontalScrollBar()
  1519. vsb = self.ui.graphicsView.verticalScrollBar()
  1520. hsb.setValue(xp * hsb.maximum())
  1521. vsb.setValue(yp * vsb.maximum())
  1522. self.updateCanvasInitialPos()
  1523. # --------------------------------------------------------------------------------------------------------
  1524. # Timers
  1525. def startTimers(self):
  1526. if self.fIdleTimerFast == 0:
  1527. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1528. if self.fIdleTimerSlow == 0:
  1529. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1530. def restartTimersIfNeeded(self):
  1531. if self.fIdleTimerFast != 0:
  1532. self.killTimer(self.fIdleTimerFast)
  1533. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1534. if self.fIdleTimerSlow != 0:
  1535. self.killTimer(self.fIdleTimerSlow)
  1536. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1537. def killTimers(self):
  1538. if self.fIdleTimerFast != 0:
  1539. self.killTimer(self.fIdleTimerFast)
  1540. self.fIdleTimerFast = 0
  1541. if self.fIdleTimerSlow != 0:
  1542. self.killTimer(self.fIdleTimerSlow)
  1543. self.fIdleTimerSlow = 0
  1544. # --------------------------------------------------------------------------------------------------------
  1545. # Misc
  1546. @pyqtSlot(int)
  1547. def slot_tabChanged(self, index):
  1548. if index != 1:
  1549. return
  1550. self.ui.graphicsView.setFocus()
  1551. @pyqtSlot(int)
  1552. def slot_handleReloadAllCallback(self, pluginId):
  1553. if pluginId >= self.fPluginCount:
  1554. return
  1555. pitem = self.fPluginList[pluginId]
  1556. if pitem is None:
  1557. return
  1558. pitem.recreateWidget()
  1559. # --------------------------------------------------------------------------------------------------------
  1560. @pyqtSlot(int, int, str)
  1561. def slot_handleNSMCallback(self, value1, value2, valueStr):
  1562. # Error
  1563. if value1 == 0:
  1564. pass
  1565. # Reply
  1566. elif value1 == 1:
  1567. self.fFirstEngineInit = False
  1568. self.fSessionManagerName = valueStr
  1569. self.setProperWindowTitle()
  1570. # Open
  1571. elif value1 == 2:
  1572. self.fClientName = os.path.basename(valueStr)
  1573. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1574. self.setProperWindowTitle()
  1575. self.fCustomStopAction = self.CUSTOM_ACTION_PROJECT_LOAD
  1576. self.slot_engineStop(True)
  1577. return
  1578. # Save
  1579. elif value1 == 3:
  1580. self.saveProjectNow()
  1581. # Session is Loaded
  1582. elif value1 == 4:
  1583. pass
  1584. # Show Optional Gui
  1585. elif value1 == 5:
  1586. self.show()
  1587. # Hide Optional Gui
  1588. elif value1 == 6:
  1589. self.hide()
  1590. self.host.nsm_ready(value1)
  1591. # --------------------------------------------------------------------------------------------------------
  1592. def fixLogText(self, text):
  1593. return text.replace("\x1b[30;1m", "").replace("\x1b[31m", "").replace("\x1b[0m", "")
  1594. @pyqtSlot(int, int, int, float, str)
  1595. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1596. self.ui.text_logs.appendPlainText(self.fixLogText(valueStr))
  1597. @pyqtSlot(str)
  1598. def slot_handleInfoCallback(self, info):
  1599. QMessageBox.information(self, "Information", info)
  1600. @pyqtSlot(str)
  1601. def slot_handleErrorCallback(self, error):
  1602. QMessageBox.critical(self, "Error", error)
  1603. @pyqtSlot()
  1604. def slot_handleQuitCallback(self):
  1605. pass # TODO
  1606. # --------------------------------------------------------------------------------------------------------
  1607. @pyqtSlot()
  1608. def slot_handleSIGUSR1(self):
  1609. print("Got SIGUSR1 -> Saving project now")
  1610. self.slot_fileSave()
  1611. @pyqtSlot()
  1612. def slot_handleSIGTERM(self):
  1613. print("Got SIGTERM -> Closing now")
  1614. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1615. self.slot_engineStop(True)
  1616. # --------------------------------------------------------------------------------------------------------
  1617. # Internal stuff
  1618. def getExtraPtr(self, plugin):
  1619. ptype = plugin['type']
  1620. if ptype == PLUGIN_LADSPA:
  1621. uniqueId = plugin['uniqueId']
  1622. self.maybeLoadRDFs()
  1623. for rdfItem in self.fLadspaRdfList:
  1624. if rdfItem.UniqueID == uniqueId:
  1625. return pointer(rdfItem)
  1626. elif ptype == PLUGIN_SF2:
  1627. if plugin['name'].lower().endswith(" (16 outputs)"):
  1628. return self._true
  1629. return None
  1630. def maybeLoadRDFs(self):
  1631. if not self.fLadspaRdfNeedsUpdate:
  1632. return
  1633. self.fLadspaRdfNeedsUpdate = False
  1634. self.fLadspaRdfList = []
  1635. if not haveLRDF:
  1636. return
  1637. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1638. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1639. if os.path.exists(frLadspaFile):
  1640. frLadspa = open(frLadspaFile, 'r')
  1641. try:
  1642. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1643. except:
  1644. pass
  1645. frLadspa.close()
  1646. # --------------------------------------------------------------------------------------------------------
  1647. def getPluginCount(self):
  1648. return self.fPluginCount
  1649. def getPluginItem(self, pluginId):
  1650. if pluginId >= self.fPluginCount:
  1651. return None
  1652. pitem = self.fPluginList[pluginId]
  1653. if pitem is None:
  1654. return None
  1655. #if False:
  1656. #return CarlaRackItem(self, 0, False)
  1657. return pitem
  1658. def getPluginEditDialog(self, pluginId):
  1659. if pluginId >= self.fPluginCount:
  1660. return None
  1661. pitem = self.fPluginList[pluginId]
  1662. if pitem is None:
  1663. return None
  1664. if False:
  1665. return PluginEdit(self, self.host, 0)
  1666. return pitem.getEditDialog()
  1667. def getPluginSlotWidget(self, pluginId):
  1668. if pluginId >= self.fPluginCount:
  1669. return None
  1670. pitem = self.fPluginList[pluginId]
  1671. if pitem is None:
  1672. return None
  1673. #if False:
  1674. #return AbstractPluginSlot()
  1675. return pitem.getWidget()
  1676. # --------------------------------------------------------------------------------------------------------
  1677. def waitForPendingEvents(self):
  1678. pass
  1679. # --------------------------------------------------------------------------------------------------------
  1680. # show/hide event
  1681. def showEvent(self, event):
  1682. self.refreshTransport(True)
  1683. QMainWindow.showEvent(self, event)
  1684. # set our gui as parent for all plugins UIs
  1685. if self.host.manageUIs and not (self.host.isControl or self.host.isPlugin):
  1686. if MACOS:
  1687. nsViewPtr = int(self.winId())
  1688. winIdStr = "%x" % gCarla.utils.cocoa_get_window(nsViewPtr)
  1689. else:
  1690. winIdStr = "%x" % int(self.winId())
  1691. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1692. def hideEvent(self, event):
  1693. # disable parent
  1694. if not (self.host.isControl or self.host.isPlugin):
  1695. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1696. QMainWindow.hideEvent(self, event)
  1697. # --------------------------------------------------------------------------------------------------------
  1698. # resize event
  1699. def resizeEvent(self, event):
  1700. QMainWindow.resizeEvent(self, event)
  1701. self.slot_miniCanvasCheckSize()
  1702. # --------------------------------------------------------------------------------------------------------
  1703. # timer event
  1704. def idleFast(self):
  1705. self.host.engine_idle()
  1706. self.refreshTransport()
  1707. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1708. return
  1709. for pitem in self.fPluginList:
  1710. if pitem is None:
  1711. break
  1712. pitem.getWidget().idleFast()
  1713. for pluginId in self.fSelectedPlugins:
  1714. self.fPeaksCleared = False
  1715. if self.ui.peak_in.isVisible():
  1716. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1717. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1718. if self.ui.peak_out.isVisible():
  1719. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1720. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1721. return
  1722. if self.fPeaksCleared:
  1723. return
  1724. self.fPeaksCleared = True
  1725. self.ui.peak_in.displayMeter(1, 0.0, True)
  1726. self.ui.peak_in.displayMeter(2, 0.0, True)
  1727. self.ui.peak_out.displayMeter(1, 0.0, True)
  1728. self.ui.peak_out.displayMeter(2, 0.0, True)
  1729. def idleSlow(self):
  1730. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1731. return
  1732. for pitem in self.fPluginList:
  1733. if pitem is None:
  1734. break
  1735. pitem.getWidget().idleSlow()
  1736. def timerEvent(self, event):
  1737. if event.timerId() == self.fIdleTimerFast:
  1738. self.idleFast()
  1739. elif event.timerId() == self.fIdleTimerSlow:
  1740. self.idleSlow()
  1741. QMainWindow.timerEvent(self, event)
  1742. # --------------------------------------------------------------------------------------------------------
  1743. # color/style change event
  1744. def changeEvent(self, event):
  1745. if event.type() in (QEvent.PaletteChange, QEvent.StyleChange):
  1746. self.updateStyle()
  1747. QWidget.changeEvent(self, event)
  1748. def updateStyle(self):
  1749. # Rack padding images setup
  1750. rack_imgL = QImage(":/bitmaps/rack_padding_left.png")
  1751. rack_imgR = QImage(":/bitmaps/rack_padding_right.png")
  1752. min_value = 0.07
  1753. if PYQT_VERSION >= 0x50600:
  1754. value_fix = 1.0/(1.0-rack_imgL.scaled(1, 1, Qt.IgnoreAspectRatio, Qt.SmoothTransformation).pixelColor(0,0).blackF())
  1755. else:
  1756. value_fix = 1.5
  1757. bg_color = self.ui.rack.palette().window().color()
  1758. bg_value = 1.0 - bg_color.blackF()
  1759. if bg_value != 0.0 and bg_value < min_value:
  1760. pad_color = bg_color.lighter(100*min_value/bg_value*value_fix)
  1761. else:
  1762. pad_color = QColor.fromHsvF(0.0, 0.0, min_value*value_fix)
  1763. painter = QPainter()
  1764. fillRect = rack_imgL.rect().adjusted(-1,-1,1,1)
  1765. painter.begin(rack_imgL)
  1766. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  1767. painter.setBrush(pad_color)
  1768. painter.drawRect(fillRect)
  1769. painter.end()
  1770. rack_pixmapL = QPixmap(rack_imgL)
  1771. self.imgL_palette = QPalette()
  1772. self.imgL_palette.setBrush(QPalette.Window, QBrush(rack_pixmapL))
  1773. self.ui.pad_left.setPalette(self.imgL_palette)
  1774. self.ui.pad_left.setAutoFillBackground(True)
  1775. painter.begin(rack_imgR)
  1776. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  1777. painter.setBrush(pad_color)
  1778. painter.drawRect(fillRect)
  1779. painter.end()
  1780. rack_pixmapR = QPixmap(rack_imgR)
  1781. self.imgR_palette = QPalette()
  1782. self.imgR_palette.setBrush(QPalette.Window, QBrush(rack_pixmapR))
  1783. self.ui.pad_right.setPalette(self.imgR_palette)
  1784. self.ui.pad_right.setAutoFillBackground(True)
  1785. # --------------------------------------------------------------------------------------------------------
  1786. # paint event
  1787. #def paintEvent(self, event):
  1788. #QMainWindow.paintEvent(self, event)
  1789. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1790. #return
  1791. #painter = QPainter(self)
  1792. #painter.setBrush(QColor(36, 36, 36))
  1793. #painter.setPen(QColor(62, 62, 62))
  1794. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1795. # --------------------------------------------------------------------------------------------------------
  1796. # close event
  1797. def shouldIgnoreClose(self):
  1798. if self.host.isControl or self.host.isPlugin:
  1799. return False
  1800. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  1801. return False
  1802. if self.fSavedSettings[CARLA_KEY_MAIN_CONFIRM_EXIT]:
  1803. return QMessageBox.question(self, self.tr("Quit"),
  1804. self.tr("Are you sure you want to quit Carla?"),
  1805. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No
  1806. return False
  1807. def closeEvent(self, event):
  1808. if self.shouldIgnoreClose():
  1809. event.ignore()
  1810. return
  1811. if MACOS and self.fMacClosingHelper and not (self.host.isControl or self.host.isPlugin):
  1812. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1813. self.fMacClosingHelper = False
  1814. event.ignore()
  1815. for i in reversed(range(self.fPluginCount)):
  1816. self.host.show_custom_ui(i, False)
  1817. QTimer.singleShot(100, self.close)
  1818. return
  1819. self.killTimers()
  1820. self.saveSettings()
  1821. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  1822. if not self.slot_engineStop(True):
  1823. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1824. event.ignore()
  1825. return
  1826. QMainWindow.closeEvent(self, event)
  1827. # ------------------------------------------------------------------------------------------------
  1828. # Canvas callback
  1829. def canvasCallback(action, value1, value2, valueStr):
  1830. host = gCarla.gui.host
  1831. if action == patchcanvas.ACTION_GROUP_INFO:
  1832. pass
  1833. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1834. pass
  1835. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1836. groupId = value1
  1837. patchcanvas.splitGroup(groupId)
  1838. gCarla.gui.updateMiniCanvasLater()
  1839. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1840. groupId = value1
  1841. patchcanvas.joinGroup(groupId)
  1842. gCarla.gui.updateMiniCanvasLater()
  1843. elif action == patchcanvas.ACTION_PORT_INFO:
  1844. pass
  1845. elif action == patchcanvas.ACTION_PORT_RENAME:
  1846. pass
  1847. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1848. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1849. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1850. print("Connection failed:", host.get_last_error())
  1851. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1852. connectionId = value1
  1853. if not host.patchbay_disconnect(connectionId):
  1854. print("Disconnect failed:", host.get_last_error())
  1855. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1856. pluginId = value1
  1857. if not host.clone_plugin(pluginId):
  1858. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1859. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1860. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1861. pluginId = value1
  1862. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1863. if pwidget is not None:
  1864. pwidget.showEditDialog()
  1865. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1866. pluginId = value1
  1867. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1868. if pwidget is not None:
  1869. pwidget.showRenameDialog()
  1870. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  1871. pluginId = value1
  1872. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1873. if pwidget is not None:
  1874. pwidget.showReplaceDialog()
  1875. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1876. pluginId = value1
  1877. if not host.remove_plugin(pluginId):
  1878. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1879. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1880. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1881. pluginId = value1
  1882. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1883. if pwidget is not None:
  1884. pwidget.showCustomUI()
  1885. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  1886. gCarla.gui.showPluginActionsMenu()
  1887. # ------------------------------------------------------------------------------------------------------------
  1888. # Engine callback
  1889. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1890. # kdevelop likes this :)
  1891. if False: host = CarlaHostNull()
  1892. valueStr = charPtrToString(valueStr)
  1893. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1894. host.processMode = value1
  1895. host.transportMode = value2
  1896. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1897. host.processMode = value1
  1898. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1899. host.transportMode = value1
  1900. host.transportExtra = valueStr
  1901. if action == ENGINE_CALLBACK_DEBUG:
  1902. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1903. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1904. host.PluginAddedCallback.emit(pluginId, valueStr)
  1905. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1906. host.PluginRemovedCallback.emit(pluginId)
  1907. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1908. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1909. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1910. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1911. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1912. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1913. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1914. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1915. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1916. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1917. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1918. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1919. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1920. host.ProgramChangedCallback.emit(pluginId, value1)
  1921. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1922. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1923. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1924. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1925. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1926. host.UiStateChangedCallback.emit(pluginId, value1)
  1927. elif action == ENGINE_CALLBACK_NOTE_ON:
  1928. host.NoteOnCallback.emit(pluginId, value1, value2, round(value3))
  1929. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1930. host.NoteOffCallback.emit(pluginId, value1, value2)
  1931. elif action == ENGINE_CALLBACK_UPDATE:
  1932. host.UpdateCallback.emit(pluginId)
  1933. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1934. host.ReloadInfoCallback.emit(pluginId)
  1935. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1936. host.ReloadParametersCallback.emit(pluginId)
  1937. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1938. host.ReloadProgramsCallback.emit(pluginId)
  1939. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1940. host.ReloadAllCallback.emit(pluginId)
  1941. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1942. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1943. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1944. host.PatchbayClientRemovedCallback.emit(pluginId)
  1945. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1946. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1947. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1948. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1949. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1950. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1951. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1952. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1953. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1954. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1955. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1956. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1957. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1958. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1959. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1960. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1961. host.EngineStartedCallback.emit(value1, value2, value3, valueStr)
  1962. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1963. host.EngineStoppedCallback.emit()
  1964. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1965. host.ProcessModeChangedCallback.emit(value1)
  1966. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1967. host.TransportModeChangedCallback.emit(value1, valueStr)
  1968. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1969. host.BufferSizeChangedCallback.emit(value1)
  1970. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1971. host.SampleRateChangedCallback.emit(value3)
  1972. elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
  1973. host.ProjectLoadFinishedCallback.emit()
  1974. elif action == ENGINE_CALLBACK_NSM:
  1975. host.NSMCallback.emit(value1, value2, valueStr)
  1976. elif action == ENGINE_CALLBACK_IDLE:
  1977. QApplication.processEvents()
  1978. elif action == ENGINE_CALLBACK_INFO:
  1979. host.InfoCallback.emit(valueStr)
  1980. elif action == ENGINE_CALLBACK_ERROR:
  1981. host.ErrorCallback.emit(valueStr)
  1982. elif action == ENGINE_CALLBACK_QUIT:
  1983. host.QuitCallback.emit()
  1984. # ------------------------------------------------------------------------------------------------------------
  1985. # File callback
  1986. def fileCallback(ptr, action, isDir, title, filter):
  1987. title = charPtrToString(title)
  1988. filter = charPtrToString(filter)
  1989. if action == FILE_CALLBACK_OPEN:
  1990. ret, ok = QFileDialog.getOpenFileName(gCarla.gui, title, "", filter) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1991. elif action == FILE_CALLBACK_SAVE:
  1992. ret, ok = QFileDialog.getSaveFileName(gCarla.gui, title, "", filter, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1993. else:
  1994. ret, ok = ("", "")
  1995. # FIXME use ok value, test if it works as expected
  1996. if not ret:
  1997. return None
  1998. # FIXME
  1999. global fileRet
  2000. fileRet = c_char_p(ret.encode("utf-8"))
  2001. retval = cast(byref(fileRet), POINTER(c_uintptr))
  2002. return retval.contents.value
  2003. # ------------------------------------------------------------------------------------------------------------
  2004. # Init host
  2005. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  2006. pathBinaries, pathResources = getPaths(libPrefix)
  2007. # --------------------------------------------------------------------------------------------------------
  2008. # Check if we should open main lib as local or global
  2009. settings = QSettings("falkTX", "Carla2")
  2010. try:
  2011. loadGlobal = settings.value(CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL, CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL, type=bool)
  2012. except:
  2013. loadGlobal = CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL
  2014. # --------------------------------------------------------------------------------------------------------
  2015. # Fail if binary dir is not found
  2016. if not os.path.exists(pathBinaries):
  2017. if failError:
  2018. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  2019. sys.exit(1)
  2020. return
  2021. # --------------------------------------------------------------------------------------------------------
  2022. # Set Carla library name
  2023. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  2024. libname = os.path.join(pathBinaries, libname)
  2025. utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION))
  2026. # --------------------------------------------------------------------------------------------------------
  2027. # Print info
  2028. print("Carla %s started, status:" % VERSION)
  2029. print(" Python version: %s" % sys.version.split(" ",1)[0])
  2030. print(" Qt version: %s" % qVersion())
  2031. print(" PyQt version: %s" % PYQT_VERSION_STR)
  2032. print(" Binary dir: %s" % pathBinaries)
  2033. print(" Resources dir: %s" % pathResources)
  2034. # --------------------------------------------------------------------------------------------------------
  2035. # Init host
  2036. if failError:
  2037. # no try
  2038. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2039. else:
  2040. try:
  2041. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2042. except:
  2043. host = CarlaHostQtNull()
  2044. host.isControl = isControl
  2045. host.isPlugin = isPlugin
  2046. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  2047. host.set_file_callback(fileCallback)
  2048. # If it's a plugin the paths are already set
  2049. if not isPlugin:
  2050. host.pathBinaries = pathBinaries
  2051. host.pathResources = pathResources
  2052. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  2053. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  2054. if not isControl:
  2055. host.nsmOK = host.nsm_init(os.getpid(), initName)
  2056. # --------------------------------------------------------------------------------------------------------
  2057. # Init utils
  2058. gCarla.utils = CarlaUtils(utilsname)
  2059. gCarla.utils.set_process_name(os.path.basename(initName))
  2060. try:
  2061. sys.stdout.flush()
  2062. except:
  2063. pass
  2064. sys.stdout = CarlaPrint(False)
  2065. sys.stderr = CarlaPrint(True)
  2066. sys.excepthook = sys_excepthook
  2067. # --------------------------------------------------------------------------------------------------------
  2068. # Done
  2069. return host
  2070. # ------------------------------------------------------------------------------------------------------------
  2071. # Load host settings
  2072. def loadHostSettings(host):
  2073. # kdevelop likes this :)
  2074. if False: host = CarlaHostNull()
  2075. settings = QSettings("falkTX", "Carla2")
  2076. try:
  2077. host.experimental = settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool)
  2078. except:
  2079. host.experimental = CARLA_DEFAULT_MAIN_EXPERIMENTAL
  2080. try:
  2081. host.exportLV2 = settings.value(CARLA_KEY_EXPERIMENTAL_EXPORT_LV2, CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT, type=bool)
  2082. except:
  2083. host.exportLV2 = CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT
  2084. try:
  2085. host.manageUIs = settings.value(CARLA_KEY_ENGINE_MANAGE_UIS, CARLA_DEFAULT_MANAGE_UIS, type=bool)
  2086. except:
  2087. host.manageUIs = CARLA_DEFAULT_MANAGE_UIS
  2088. try:
  2089. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  2090. except:
  2091. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  2092. try:
  2093. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  2094. except:
  2095. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  2096. try:
  2097. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  2098. except:
  2099. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  2100. try:
  2101. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  2102. except:
  2103. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  2104. try:
  2105. host.preventBadBehaviour = settings.value(CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, type=bool)
  2106. except:
  2107. host.preventBadBehaviour = CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR
  2108. try:
  2109. host.showLogs = settings.value(CARLA_KEY_MAIN_SHOW_LOGS, CARLA_DEFAULT_MAIN_SHOW_LOGS, type=bool)
  2110. except:
  2111. host.showLogs = CARLA_DEFAULT_MAIN_SHOW_LOGS
  2112. try:
  2113. host.showPluginBridges = settings.value(CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES, type=bool)
  2114. except:
  2115. host.showPluginBridges = CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES
  2116. try:
  2117. host.showWineBridges = settings.value(CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES, type=bool)
  2118. except:
  2119. host.showWineBridges = CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES
  2120. try:
  2121. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  2122. except:
  2123. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  2124. try:
  2125. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  2126. except:
  2127. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  2128. if host.isPlugin:
  2129. return
  2130. try:
  2131. host.transportExtra = settings.value(CARLA_KEY_ENGINE_TRANSPORT_EXTRA, "", type=str)
  2132. except:
  2133. host.transportExtra = ""
  2134. # enums
  2135. if host.audioDriverForced is None:
  2136. try:
  2137. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  2138. except:
  2139. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  2140. if not host.processModeForced:
  2141. try:
  2142. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  2143. except:
  2144. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  2145. host.nextProcessMode = host.processMode
  2146. # --------------------------------------------------------------------------------------------------------
  2147. # fix things if needed
  2148. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  2149. if LADISH_APP_NAME:
  2150. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  2151. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  2152. else:
  2153. host.transportMode = ENGINE_TRANSPORT_MODE_JACK
  2154. if gCarla.nogui:
  2155. host.showLogs = False
  2156. # --------------------------------------------------------------------------------------------------------
  2157. # run headless host now if nogui option enabled
  2158. if gCarla.nogui:
  2159. runHostWithoutUI(host)
  2160. # ------------------------------------------------------------------------------------------------------------
  2161. # Set host settings
  2162. def setHostSettings(host):
  2163. # kdevelop likes this :)
  2164. if False: host = CarlaHostNull()
  2165. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  2166. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  2167. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  2168. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  2169. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  2170. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  2171. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  2172. if host.isPlugin or host.isRemote or host.is_engine_running():
  2173. return
  2174. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  2175. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, host.transportExtra)
  2176. host.set_engine_option(ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT, host.showLogs, "")
  2177. # ------------------------------------------------------------------------------------------------------------
  2178. # Set Engine settings according to carla preferences. Returns selected audio driver.
  2179. def setEngineSettings(host):
  2180. # kdevelop likes this :)
  2181. if False: host = CarlaHostNull()
  2182. # --------------------------------------------------------------------------------------------------------
  2183. # do nothing if control
  2184. if host.isControl:
  2185. return "Control"
  2186. # --------------------------------------------------------------------------------------------------------
  2187. settings = QSettings("falkTX", "Carla2")
  2188. # --------------------------------------------------------------------------------------------------------
  2189. # main settings
  2190. setHostSettings(host)
  2191. # --------------------------------------------------------------------------------------------------------
  2192. # plugin paths
  2193. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  2194. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  2195. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  2196. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  2197. VST3_PATH = toList(settings.value(CARLA_KEY_PATHS_VST3, CARLA_DEFAULT_VST3_PATH))
  2198. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  2199. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  2200. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  2201. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  2202. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  2203. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  2204. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST3, splitter.join(VST3_PATH))
  2205. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  2206. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  2207. # --------------------------------------------------------------------------------------------------------
  2208. # don't continue if plugin
  2209. if host.isPlugin:
  2210. return "Plugin"
  2211. # --------------------------------------------------------------------------------------------------------
  2212. # wine settings
  2213. optWineExecutable = settings.value(CARLA_KEY_WINE_EXECUTABLE, CARLA_DEFAULT_WINE_EXECUTABLE, type=str)
  2214. optWineAutoPrefix = settings.value(CARLA_KEY_WINE_AUTO_PREFIX, CARLA_DEFAULT_WINE_AUTO_PREFIX, type=bool)
  2215. optWineFallbackPrefix = settings.value(CARLA_KEY_WINE_FALLBACK_PREFIX, CARLA_DEFAULT_WINE_FALLBACK_PREFIX, type=str)
  2216. optWineRtPrioEnabled = settings.value(CARLA_KEY_WINE_RT_PRIO_ENABLED, CARLA_DEFAULT_WINE_RT_PRIO_ENABLED, type=bool)
  2217. optWineBaseRtPrio = settings.value(CARLA_KEY_WINE_BASE_RT_PRIO, CARLA_DEFAULT_WINE_BASE_RT_PRIO, type=int)
  2218. optWineServerRtPrio = settings.value(CARLA_KEY_WINE_SERVER_RT_PRIO, CARLA_DEFAULT_WINE_SERVER_RT_PRIO, type=int)
  2219. host.set_engine_option(ENGINE_OPTION_WINE_EXECUTABLE, 0, optWineExecutable)
  2220. host.set_engine_option(ENGINE_OPTION_WINE_AUTO_PREFIX, 1 if optWineAutoPrefix else 0, "")
  2221. host.set_engine_option(ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, os.path.expanduser(optWineFallbackPrefix))
  2222. host.set_engine_option(ENGINE_OPTION_WINE_RT_PRIO_ENABLED, 1 if optWineRtPrioEnabled else 0, "")
  2223. host.set_engine_option(ENGINE_OPTION_WINE_BASE_RT_PRIO, optWineBaseRtPrio, "")
  2224. host.set_engine_option(ENGINE_OPTION_WINE_SERVER_RT_PRIO, optWineServerRtPrio, "")
  2225. # --------------------------------------------------------------------------------------------------------
  2226. # driver and device settings
  2227. # driver name
  2228. if host.audioDriverForced is not None:
  2229. audioDriver = host.audioDriverForced
  2230. else:
  2231. try:
  2232. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  2233. except:
  2234. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  2235. # driver options
  2236. try:
  2237. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  2238. except:
  2239. audioDevice = ""
  2240. try:
  2241. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  2242. except:
  2243. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  2244. try:
  2245. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  2246. except:
  2247. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  2248. try:
  2249. audioTripleBuffer = settings.value("%s%s/TripleBuffer" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER, type=int)
  2250. except:
  2251. audioTripleBuffer = CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER
  2252. # Only setup audio things if engine is not running
  2253. if not host.is_engine_running():
  2254. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  2255. if not audioDriver.startswith("JACK"):
  2256. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  2257. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  2258. host.set_engine_option(ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, audioTripleBuffer, "")
  2259. # --------------------------------------------------------------------------------------------------------
  2260. # fix things if needed
  2261. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  2262. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  2263. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, host.transportExtra)
  2264. # --------------------------------------------------------------------------------------------------------
  2265. # return selected driver name
  2266. return audioDriver
  2267. # ------------------------------------------------------------------------------------------------------------
  2268. # Run Carla without showing UI
  2269. def runHostWithoutUI(host):
  2270. # kdevelop likes this :)
  2271. if False: host = CarlaHostNull()
  2272. # --------------------------------------------------------------------------------------------------------
  2273. # Some initial checks
  2274. if not gCarla.nogui:
  2275. return
  2276. projectFile = getInitialProjectFile(QCoreApplication.instance(), True)
  2277. if not projectFile:
  2278. print("Carla no-gui mode can only be used together with a project file.")
  2279. sys.exit(1)
  2280. # --------------------------------------------------------------------------------------------------------
  2281. # Additional imports
  2282. from time import sleep
  2283. # --------------------------------------------------------------------------------------------------------
  2284. # Init engine
  2285. audioDriver = setEngineSettings(host)
  2286. if not host.engine_init(audioDriver, "Carla"):
  2287. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  2288. sys.exit(1)
  2289. if not host.load_project(projectFile):
  2290. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  2291. host.engine_close()
  2292. sys.exit(1)
  2293. # --------------------------------------------------------------------------------------------------------
  2294. # Idle
  2295. print("Carla ready!")
  2296. while host.is_engine_running() and not gCarla.term:
  2297. host.engine_idle()
  2298. sleep(0.0333) # 30 Hz
  2299. # --------------------------------------------------------------------------------------------------------
  2300. # Stop
  2301. host.engine_close()
  2302. sys.exit(0)
  2303. # ------------------------------------------------------------------------------------------------------------