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.

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