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.

3687 lines
151KB

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