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.

2950 lines
114KB

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