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.

3368 lines
133KB

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