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.

3307 lines
131KB

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