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.

3235 lines
128KB

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