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.

2954 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. if firstInit and not (self.host.isControl or self.host.isPlugin):
  595. settings = QSettings()
  596. lastBpm = settings.value("LastBPM", 120.0, type=float)
  597. del settings
  598. self.host.transport_bpm(lastBpm)
  599. return
  600. elif firstInit:
  601. self.ui.text_logs.appendPlainText("Failed to start engine on first try, ignored")
  602. return
  603. audioError = self.host.get_last_error()
  604. if audioError:
  605. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  606. else:
  607. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  608. @pyqtSlot()
  609. def slot_engineStop(self, forced = False):
  610. self.ui.text_logs.appendPlainText("======= Stopping engine =======")
  611. if self.fPluginCount == 0:
  612. self.engineStopFinal()
  613. return True
  614. if not forced:
  615. 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"
  616. "Do you want to do this now?"),
  617. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  618. if ask != QMessageBox.Yes:
  619. return False
  620. return self.slot_engineStopTryAgain()
  621. @pyqtSlot()
  622. def slot_engineStopTryAgain(self):
  623. if self.host.is_engine_running() and not self.host.set_engine_about_to_close():
  624. QTimer.singleShot(0, self.slot_engineStopTryAgain)
  625. return False
  626. self.engineStopFinal()
  627. return True
  628. def engineStopFinal(self):
  629. self.killTimers()
  630. self.removeAllPlugins()
  631. if self.host.is_engine_running():
  632. self.host.remove_all_plugins()
  633. if not self.host.engine_close():
  634. self.ui.text_logs.appendPlainText("Failed to stop engine, error was:")
  635. self.ui.text_logs.appendPlainText(self.host.get_last_error())
  636. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  637. self.close()
  638. elif self.fCustomStopAction == self.CUSTOM_ACTION_PROJECT_LOAD:
  639. self.slot_engineStart()
  640. self.loadProjectNow()
  641. self.host.nsm_ready(2) # open
  642. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  643. # --------------------------------------------------------------------------------------------------------
  644. # Engine (host callbacks)
  645. @pyqtSlot(int, int, float, str)
  646. def slot_handleEngineStartedCallback(self, processMode, transportMode, sampleRate, driverName):
  647. self.fSampleRate = sampleRate
  648. self.ui.menu_PluginMacros.setEnabled(True)
  649. self.ui.menu_Canvas.setEnabled(True)
  650. self.ui.w_transport.setEnabled(True)
  651. self.ui.act_canvas_show_internal.blockSignals(True)
  652. self.ui.act_canvas_show_external.blockSignals(True)
  653. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and not (self.host.isControl or self.host.isPlugin):
  654. self.ui.act_canvas_show_internal.setChecked(True)
  655. self.ui.act_canvas_show_internal.setVisible(True)
  656. self.ui.act_canvas_show_external.setChecked(False)
  657. self.ui.act_canvas_show_external.setVisible(True)
  658. else:
  659. self.ui.act_canvas_show_internal.setChecked(False)
  660. self.ui.act_canvas_show_internal.setVisible(False)
  661. self.ui.act_canvas_show_external.setChecked(False)
  662. self.ui.act_canvas_show_external.setVisible(False)
  663. self.ui.act_canvas_show_internal.blockSignals(False)
  664. self.ui.act_canvas_show_external.blockSignals(False)
  665. if not (self.host.isControl or self.host.isPlugin):
  666. canSave = (self.fProjectFilename and os.path.exists(self.fProjectFilename)) or not self.fSessionManagerName
  667. self.ui.act_file_save.setEnabled(canSave)
  668. self.ui.act_engine_start.setEnabled(False)
  669. self.ui.act_engine_stop.setEnabled(True)
  670. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  671. if self.host.isPlugin or not self.fSessionManagerName:
  672. self.ui.act_file_open.setEnabled(True)
  673. self.ui.act_file_save_as.setEnabled(True)
  674. self.refreshTransport(True)
  675. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  676. self.ui.cb_transport_jack.setEnabled(driverName == "JACK")
  677. self.startTimers()
  678. self.ui.text_logs.appendPlainText("======= Engine started ========")
  679. self.ui.text_logs.appendPlainText("Carla engine started, details:")
  680. self.ui.text_logs.appendPlainText(" Driver name: %s" % driverName)
  681. self.ui.text_logs.appendPlainText(" Sample rate: %.1f" % sampleRate)
  682. self.ui.text_logs.appendPlainText(" Process mode: %s" % processMode2Str(processMode))
  683. @pyqtSlot()
  684. def slot_handleEngineStoppedCallback(self):
  685. self.ui.text_logs.appendPlainText("======= Engine stopped ========")
  686. patchcanvas.clear()
  687. self.killTimers()
  688. # just in case
  689. self.removeAllPlugins()
  690. self.ui.menu_PluginMacros.setEnabled(False)
  691. self.ui.menu_Canvas.setEnabled(False)
  692. self.ui.w_transport.setEnabled(False)
  693. if not (self.host.isControl or self.host.isPlugin):
  694. self.ui.act_file_save.setEnabled(False)
  695. self.ui.act_engine_start.setEnabled(True)
  696. self.ui.act_engine_stop.setEnabled(False)
  697. if self.host.isPlugin or not self.fSessionManagerName:
  698. self.ui.act_file_open.setEnabled(False)
  699. self.ui.act_file_save_as.setEnabled(False)
  700. @pyqtSlot(float)
  701. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  702. self.fSampleRate = newSampleRate
  703. self.refreshTransport(True)
  704. @pyqtSlot()
  705. def slot_handleProjectLoadFinishedCallback(self):
  706. self.fIsProjectLoading = False
  707. self.projectLoadingFinished()
  708. # --------------------------------------------------------------------------------------------------------
  709. # Plugins
  710. def removeAllPlugins(self):
  711. self.ui.act_plugin_remove_all.setEnabled(False)
  712. patchcanvas.handleAllPluginsRemoved()
  713. while self.ui.listWidget.takeItem(0):
  714. pass
  715. self.clearSideStuff()
  716. for pitem in self.fPluginList:
  717. if pitem is None:
  718. continue
  719. pitem.close()
  720. del pitem
  721. self.fPluginCount = 0
  722. self.fPluginList = []
  723. # --------------------------------------------------------------------------------------------------------
  724. # Plugins (menu actions)
  725. def showAddPluginDialog(self):
  726. dialog = PluginDatabaseW(self.fParentOrSelf, self.host)
  727. if not dialog.exec_():
  728. return
  729. if not self.host.is_engine_running():
  730. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  731. return
  732. btype = dialog.fRetPlugin['build']
  733. ptype = dialog.fRetPlugin['type']
  734. filename = dialog.fRetPlugin['filename']
  735. label = dialog.fRetPlugin['label']
  736. uniqueId = dialog.fRetPlugin['uniqueId']
  737. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  738. return (btype, ptype, filename, label, uniqueId, extraPtr)
  739. def showAddJackAppDialog(self):
  740. dialog = JackApplicationW(self.fParentOrSelf, self.host)
  741. if not dialog.exec_():
  742. return
  743. if not self.host.is_engine_running():
  744. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  745. return
  746. return dialog.getCommandAndFlags()
  747. @pyqtSlot()
  748. def showPluginActionsMenu(self):
  749. menu = QMenu(self)
  750. if config_UseQt5:
  751. menu.addSection("Plugins")
  752. else:
  753. # fake section
  754. act = menu.addAction(" Plugins")
  755. font = act.font()
  756. font.setBold(True)
  757. act.setFont(font)
  758. act.setEnabled(False)
  759. menu.addSeparator()
  760. menu.addAction(self.ui.act_plugin_add)
  761. menu.addAction(self.ui.act_plugin_remove_all)
  762. if config_UseQt5:
  763. menu.addSection("All plugins (macros)")
  764. else:
  765. # fake space
  766. act = menu.addAction(" ")
  767. font = act.font()
  768. font.setBold(True)
  769. font.setPointSize(font.pointSize()/2)
  770. act.setEnabled(False)
  771. # fake section
  772. act = menu.addAction(" All plugins (macros)")
  773. font = act.font()
  774. font.setBold(True)
  775. act.setFont(font)
  776. act.setEnabled(False)
  777. menu.addSeparator()
  778. menu.addAction(self.ui.act_plugins_enable)
  779. menu.addAction(self.ui.act_plugins_disable)
  780. menu.addSeparator()
  781. menu.addAction(self.ui.act_plugins_volume100)
  782. menu.addAction(self.ui.act_plugins_mute)
  783. menu.addSeparator()
  784. menu.addAction(self.ui.act_plugins_wet100)
  785. menu.addAction(self.ui.act_plugins_bypass)
  786. menu.addSeparator()
  787. menu.addAction(self.ui.act_plugins_center)
  788. menu.addSeparator()
  789. menu.addAction(self.ui.act_plugins_compact)
  790. menu.addAction(self.ui.act_plugins_expand)
  791. menu.exec_(QCursor.pos())
  792. @pyqtSlot()
  793. def slot_pluginAdd(self):
  794. data = self.showAddPluginDialog()
  795. if data is None:
  796. return
  797. btype, ptype, filename, label, uniqueId, extraPtr = data
  798. if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0):
  799. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  800. @pyqtSlot()
  801. def slot_confirmRemoveAll(self):
  802. if self.fPluginCount == 0:
  803. return
  804. if QMessageBox.question(self, self.tr("Remove All"),
  805. self.tr("Are you sure you want to remove all plugins?"),
  806. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  807. return
  808. self.pluginRemoveAll()
  809. def pluginRemoveAll(self):
  810. if self.fPluginCount == 0:
  811. return
  812. # FIXME - this is not working
  813. # removing a plugin causes flicker, the rack-list becomes empty for some time
  814. # this breaks the remove-all animation, so don't bother using it
  815. if False and not self.host.isPlugin:
  816. self.projectLoadingStarted()
  817. app = QApplication.instance()
  818. app.processEvents()
  819. for i in reversed(range(self.fPluginCount)):
  820. self.host.remove_plugin(i)
  821. app.processEvents()
  822. self.projectLoadingFinished()
  823. self.fCurrentlyRemovingAllPlugins = True
  824. ok = self.host.remove_all_plugins()
  825. self.fCurrentlyRemovingAllPlugins = False
  826. if ok:
  827. self.removeAllPlugins()
  828. else:
  829. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  830. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  831. self.fCurrentlyRemovingAllPlugins = False
  832. @pyqtSlot()
  833. def slot_jackAppAdd(self):
  834. data = self.showAddJackAppDialog()
  835. if data is None:
  836. return
  837. filename, name, label = data
  838. if not filename:
  839. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Cannot add jack application"),
  840. self.tr("command is empty"), QMessageBox.Ok, QMessageBox.Ok)
  841. return
  842. if not self.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, filename, name, label, 0, None, 0x0):
  843. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"),
  844. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  845. # --------------------------------------------------------------------------------------------------------
  846. # Plugins (macros)
  847. @pyqtSlot()
  848. def slot_pluginsEnable(self):
  849. if not self.host.is_engine_running():
  850. return
  851. for pitem in self.fPluginList:
  852. if pitem is None:
  853. break
  854. pitem.getWidget().setActive(True, True, True)
  855. @pyqtSlot()
  856. def slot_pluginsDisable(self):
  857. if not self.host.is_engine_running():
  858. return
  859. for pitem in self.fPluginList:
  860. if pitem is None:
  861. break
  862. pitem.getWidget().setActive(False, True, True)
  863. @pyqtSlot()
  864. def slot_pluginsVolume100(self):
  865. if not self.host.is_engine_running():
  866. return
  867. for pitem in self.fPluginList:
  868. if pitem is None:
  869. break
  870. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  871. @pyqtSlot()
  872. def slot_pluginsMute(self):
  873. if not self.host.is_engine_running():
  874. return
  875. for pitem in self.fPluginList:
  876. if pitem is None:
  877. break
  878. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  879. @pyqtSlot()
  880. def slot_pluginsWet100(self):
  881. if not self.host.is_engine_running():
  882. return
  883. for pitem in self.fPluginList:
  884. if pitem is None:
  885. break
  886. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  887. @pyqtSlot()
  888. def slot_pluginsBypass(self):
  889. if not self.host.is_engine_running():
  890. return
  891. for pitem in self.fPluginList:
  892. if pitem is None:
  893. break
  894. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  895. @pyqtSlot()
  896. def slot_pluginsCenter(self):
  897. if not self.host.is_engine_running():
  898. return
  899. for pitem in self.fPluginList:
  900. if pitem is None:
  901. break
  902. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  903. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  904. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  905. @pyqtSlot()
  906. def slot_pluginsCompact(self):
  907. for pitem in self.fPluginList:
  908. if pitem is None:
  909. break
  910. pitem.compact()
  911. @pyqtSlot()
  912. def slot_pluginsExpand(self):
  913. for pitem in self.fPluginList:
  914. if pitem is None:
  915. break
  916. pitem.expand()
  917. # --------------------------------------------------------------------------------------------------------
  918. # Plugins (host callbacks)
  919. @pyqtSlot(int, str)
  920. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  921. pitem = self.ui.listWidget.createItem(pluginId, self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  922. self.fPluginList.append(pitem)
  923. self.fPluginCount += 1
  924. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  925. @pyqtSlot(int)
  926. def slot_handlePluginRemovedCallback(self, pluginId):
  927. patchcanvas.handlePluginRemoved(pluginId)
  928. if pluginId in self.fSelectedPlugins:
  929. self.clearSideStuff()
  930. pitem = self.getPluginItem(pluginId)
  931. self.fPluginCount -= 1
  932. self.fPluginList.pop(pluginId)
  933. self.ui.listWidget.takeItem(pluginId)
  934. if pitem is not None:
  935. pitem.close()
  936. del pitem
  937. # push all plugins 1 slot back
  938. for i in range(pluginId, self.fPluginCount):
  939. pitem = self.fPluginList[i]
  940. pitem.setPluginId(i)
  941. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  942. # --------------------------------------------------------------------------------------------------------
  943. # Canvas
  944. def clearSideStuff(self):
  945. self.scene.clearSelection()
  946. self.fSelectedPlugins = []
  947. self.ui.keyboard.allNotesOff(False)
  948. self.ui.scrollArea.setEnabled(False)
  949. self.fPeaksCleared = True
  950. self.ui.peak_in.displayMeter(1, 0.0, True)
  951. self.ui.peak_in.displayMeter(2, 0.0, True)
  952. self.ui.peak_out.displayMeter(1, 0.0, True)
  953. self.ui.peak_out.displayMeter(2, 0.0, True)
  954. def setupCanvas(self):
  955. pOptions = patchcanvas.options_t()
  956. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  957. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  958. pOptions.auto_select_items = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS]
  959. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  960. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  961. if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY]:
  962. pOptions.eyecandy = patchcanvas.EYECANDY_FULL
  963. elif self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]:
  964. pOptions.eyecandy = patchcanvas.EYECANDY_SMALL
  965. else:
  966. pOptions.eyecandy = patchcanvas.EYECANDY_NONE
  967. pFeatures = patchcanvas.features_t()
  968. pFeatures.group_info = False
  969. pFeatures.group_rename = False
  970. pFeatures.port_info = False
  971. pFeatures.port_rename = False
  972. pFeatures.handle_group_pos = True
  973. patchcanvas.setOptions(pOptions)
  974. patchcanvas.setFeatures(pFeatures)
  975. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  976. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  977. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  978. self.fCanvasWidth = int(tryCanvasSize[0])
  979. self.fCanvasHeight = int(tryCanvasSize[1])
  980. else:
  981. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  982. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  983. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  984. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  985. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  986. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  987. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  988. def updateCanvasInitialPos(self):
  989. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  990. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  991. patchcanvas.setInitialPos(x, y)
  992. def updateMiniCanvasLater(self):
  993. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  994. # --------------------------------------------------------------------------------------------------------
  995. # Canvas (menu actions)
  996. @pyqtSlot()
  997. def slot_canvasShowInternal(self):
  998. self.fExternalPatchbay = False
  999. self.ui.act_canvas_show_internal.blockSignals(True)
  1000. self.ui.act_canvas_show_external.blockSignals(True)
  1001. self.ui.act_canvas_show_internal.setChecked(True)
  1002. self.ui.act_canvas_show_external.setChecked(False)
  1003. self.ui.act_canvas_show_internal.blockSignals(False)
  1004. self.ui.act_canvas_show_external.blockSignals(False)
  1005. self.slot_canvasRefresh()
  1006. @pyqtSlot()
  1007. def slot_canvasShowExternal(self):
  1008. self.fExternalPatchbay = True
  1009. self.ui.act_canvas_show_internal.blockSignals(True)
  1010. self.ui.act_canvas_show_external.blockSignals(True)
  1011. self.ui.act_canvas_show_internal.setChecked(False)
  1012. self.ui.act_canvas_show_external.setChecked(True)
  1013. self.ui.act_canvas_show_internal.blockSignals(False)
  1014. self.ui.act_canvas_show_external.blockSignals(False)
  1015. self.slot_canvasRefresh()
  1016. @pyqtSlot()
  1017. def slot_canvasArrange(self):
  1018. patchcanvas.arrange()
  1019. @pyqtSlot()
  1020. def slot_canvasRefresh(self):
  1021. patchcanvas.clear()
  1022. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and (self.host.isControl or self.host.isPlugin):
  1023. return
  1024. if self.host.is_engine_running():
  1025. self.host.patchbay_refresh(self.fExternalPatchbay)
  1026. self.updateMiniCanvasLater()
  1027. @pyqtSlot()
  1028. def slot_canvasZoomFit(self):
  1029. self.scene.zoom_fit()
  1030. @pyqtSlot()
  1031. def slot_canvasZoomIn(self):
  1032. self.scene.zoom_in()
  1033. @pyqtSlot()
  1034. def slot_canvasZoomOut(self):
  1035. self.scene.zoom_out()
  1036. @pyqtSlot()
  1037. def slot_canvasZoomReset(self):
  1038. self.scene.zoom_reset()
  1039. @pyqtSlot()
  1040. def slot_canvasSaveImage(self):
  1041. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  1042. if config_UseQt5:
  1043. newPath = newPath[0]
  1044. if not newPath:
  1045. return
  1046. self.scene.clearSelection()
  1047. if newPath.lower().endswith((".jpg", ".jpeg")):
  1048. imgFormat = "JPG"
  1049. elif newPath.lower().endswith((".png",)):
  1050. imgFormat = "PNG"
  1051. else:
  1052. # File-dialog may not auto-add the extension
  1053. imgFormat = "PNG"
  1054. newPath += ".png"
  1055. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  1056. painter = QPainter(self.fExportImage)
  1057. painter.save()
  1058. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  1059. painter.setRenderHint(QPainter.TextAntialiasing)
  1060. self.scene.render(painter)
  1061. self.fExportImage.save(newPath, imgFormat, 100)
  1062. painter.restore()
  1063. # --------------------------------------------------------------------------------------------------------
  1064. # Canvas (canvas callbacks)
  1065. @pyqtSlot(int, int, QPointF)
  1066. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  1067. self.updateMiniCanvasLater()
  1068. @pyqtSlot(float)
  1069. def slot_canvasScaleChanged(self, scale):
  1070. self.ui.miniCanvasPreview.setViewScale(scale)
  1071. @pyqtSlot(list)
  1072. def slot_canvasPluginSelected(self, pluginList):
  1073. self.ui.keyboard.allNotesOff(False)
  1074. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  1075. self.fSelectedPlugins = pluginList
  1076. # --------------------------------------------------------------------------------------------------------
  1077. # Canvas (host callbacks)
  1078. @pyqtSlot(int, int, int, str)
  1079. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  1080. pcSplit = patchcanvas.SPLIT_UNDEF
  1081. pcIcon = patchcanvas.ICON_APPLICATION
  1082. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1083. pcIcon = patchcanvas.ICON_PLUGIN
  1084. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1085. pcIcon = patchcanvas.ICON_HARDWARE
  1086. elif clientIcon == PATCHBAY_ICON_CARLA:
  1087. pass
  1088. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1089. pcIcon = patchcanvas.ICON_DISTRHO
  1090. elif clientIcon == PATCHBAY_ICON_FILE:
  1091. pcIcon = patchcanvas.ICON_FILE
  1092. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  1093. self.updateMiniCanvasLater()
  1094. if pluginId < 0:
  1095. return
  1096. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1097. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1098. return
  1099. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1100. hasCustomUI = False
  1101. else:
  1102. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1103. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1104. @pyqtSlot(int)
  1105. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  1106. patchcanvas.removeGroup(clientId)
  1107. self.updateMiniCanvasLater()
  1108. @pyqtSlot(int, str)
  1109. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  1110. patchcanvas.renameGroup(clientId, newClientName)
  1111. self.updateMiniCanvasLater()
  1112. @pyqtSlot(int, int, int)
  1113. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  1114. pcIcon = patchcanvas.ICON_APPLICATION
  1115. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1116. pcIcon = patchcanvas.ICON_PLUGIN
  1117. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1118. pcIcon = patchcanvas.ICON_HARDWARE
  1119. elif clientIcon == PATCHBAY_ICON_CARLA:
  1120. pass
  1121. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1122. pcIcon = patchcanvas.ICON_DISTRHO
  1123. elif clientIcon == PATCHBAY_ICON_FILE:
  1124. pcIcon = patchcanvas.ICON_FILE
  1125. patchcanvas.setGroupIcon(clientId, pcIcon)
  1126. self.updateMiniCanvasLater()
  1127. if pluginId < 0:
  1128. return
  1129. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1130. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1131. return
  1132. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1133. hasCustomUI = False
  1134. else:
  1135. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1136. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1137. @pyqtSlot(int, int, int, str)
  1138. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  1139. if portFlags & PATCHBAY_PORT_IS_INPUT:
  1140. portMode = patchcanvas.PORT_MODE_INPUT
  1141. else:
  1142. portMode = patchcanvas.PORT_MODE_OUTPUT
  1143. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  1144. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1145. isAlternate = False
  1146. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  1147. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1148. isAlternate = True
  1149. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  1150. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  1151. isAlternate = False
  1152. else:
  1153. portType = patchcanvas.PORT_TYPE_NULL
  1154. isAlternate = False
  1155. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  1156. self.updateMiniCanvasLater()
  1157. @pyqtSlot(int, int)
  1158. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  1159. patchcanvas.removePort(groupId, portId)
  1160. self.updateMiniCanvasLater()
  1161. @pyqtSlot(int, int, str)
  1162. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  1163. patchcanvas.renamePort(groupId, portId, newPortName)
  1164. self.updateMiniCanvasLater()
  1165. @pyqtSlot(int, int, int, int, int)
  1166. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  1167. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  1168. self.updateMiniCanvasLater()
  1169. @pyqtSlot(int, int, int)
  1170. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  1171. patchcanvas.disconnectPorts(connectionId)
  1172. self.updateMiniCanvasLater()
  1173. # --------------------------------------------------------------------------------------------------------
  1174. # Settings
  1175. def saveSettings(self):
  1176. settings = QSettings()
  1177. settings.setValue("Geometry", self.saveGeometry())
  1178. settings.setValue("ShowToolbar", self.ui.toolBar.isEnabled())
  1179. settings.setValue("ShowSidePanel", self.ui.dockWidget.isEnabled())
  1180. diskFolders = []
  1181. for i in range(self.ui.cb_disk.count()):
  1182. diskFolders.append(self.ui.cb_disk.itemData(i))
  1183. settings.setValue("DiskFolders", diskFolders)
  1184. settings.setValue("LastBPM", self.fLastTransportBPM)
  1185. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  1186. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  1187. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1188. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1189. def loadSettings(self, firstTime):
  1190. settings = QSettings()
  1191. if firstTime:
  1192. self.restoreGeometry(settings.value("Geometry", b""))
  1193. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1194. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1195. self.ui.toolBar.setEnabled(showToolbar)
  1196. self.ui.toolBar.setVisible(showToolbar)
  1197. #if settings.contains("SplitterState"):
  1198. #self.ui.splitter.restoreState(settings.value("SplitterState", b""))
  1199. #else:
  1200. #self.ui.splitter.setSizes([210, 99999])
  1201. showSidePanel = settings.value("ShowSidePanel", True, type=bool)
  1202. self.ui.act_settings_show_side_panel.setChecked(showSidePanel)
  1203. self.ui.dockWidget.setEnabled(showSidePanel)
  1204. self.ui.dockWidget.setVisible(showSidePanel)
  1205. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  1206. self.ui.cb_disk.setItemData(0, HOME)
  1207. for i in range(len(diskFolders)):
  1208. if i == 0: continue
  1209. folder = diskFolders[i]
  1210. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1211. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  1212. # self.setUnifiedTitleAndToolBarOnMac(True)
  1213. showMeters = settings.value("ShowMeters", True, type=bool)
  1214. self.ui.act_settings_show_meters.setChecked(showMeters)
  1215. self.ui.peak_in.setVisible(showMeters)
  1216. self.ui.peak_out.setVisible(showMeters)
  1217. showKeyboard = settings.value("ShowKeyboard", True, type=bool)
  1218. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  1219. self.ui.scrollArea.setVisible(showKeyboard)
  1220. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  1221. # TODO - complete this
  1222. self.fSavedSettings = {
  1223. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  1224. CARLA_KEY_MAIN_CONFIRM_EXIT: settings.value(CARLA_KEY_MAIN_CONFIRM_EXIT, CARLA_DEFAULT_MAIN_CONFIRM_EXIT, type=bool),
  1225. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  1226. CARLA_KEY_MAIN_USE_CUSTOM_SKINS: settings.value(CARLA_KEY_MAIN_USE_CUSTOM_SKINS, CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS, type=bool),
  1227. CARLA_KEY_MAIN_EXPERIMENTAL: settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool),
  1228. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  1229. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  1230. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  1231. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS: settings.value(CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS, CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS, type=bool),
  1232. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  1233. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=bool),
  1234. CARLA_KEY_CANVAS_FANCY_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_FANCY_EYE_CANDY, CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY, type=bool),
  1235. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  1236. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  1237. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  1238. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  1239. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black"),
  1240. }
  1241. settings = QSettings("falkTX", "Carla2")
  1242. if self.host.experimental and not self.host.isControl:
  1243. self.ui.act_add_jack.setVisible(settings.value(CARLA_KEY_EXPERIMENTAL_JACK_APPS,
  1244. CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS, type=bool))
  1245. else:
  1246. self.ui.act_add_jack.setVisible(False)
  1247. if not (self.host.isControl or self.host.isPlugin):
  1248. if self.ui.cb_transport_jack.isChecked():
  1249. transportMode = ENGINE_TRANSPORT_MODE_JACK
  1250. else:
  1251. transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  1252. transportExtra = ":link:" if self.ui.cb_transport_link.isChecked() else ""
  1253. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  1254. self.host.transportMode = transportMode
  1255. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, transportMode, transportExtra)
  1256. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY] else 0
  1257. setEngineSettings(self.host)
  1258. self.restartTimersIfNeeded()
  1259. # --------------------------------------------------------------------------------------------------------
  1260. # Settings (helpers)
  1261. def enableTransport(self, enabled):
  1262. self.ui.group_transport_controls.setEnabled(enabled)
  1263. self.ui.group_transport_settings.setEnabled(enabled)
  1264. @pyqtSlot()
  1265. def slot_restoreCanvasScrollbarValues(self):
  1266. settings = QSettings()
  1267. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  1268. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  1269. # --------------------------------------------------------------------------------------------------------
  1270. # Settings (menu actions)
  1271. @pyqtSlot(bool)
  1272. def slot_showSidePanel(self, yesNo):
  1273. self.ui.dockWidget.setEnabled(yesNo)
  1274. self.ui.dockWidget.setVisible(yesNo)
  1275. @pyqtSlot(bool)
  1276. def slot_showToolbar(self, yesNo):
  1277. self.ui.toolBar.setEnabled(yesNo)
  1278. self.ui.toolBar.setVisible(yesNo)
  1279. @pyqtSlot(bool)
  1280. def slot_showCanvasMeters(self, yesNo):
  1281. self.ui.peak_in.setVisible(yesNo)
  1282. self.ui.peak_out.setVisible(yesNo)
  1283. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1284. @pyqtSlot(bool)
  1285. def slot_showCanvasKeyboard(self, yesNo):
  1286. self.ui.scrollArea.setVisible(yesNo)
  1287. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1288. @pyqtSlot()
  1289. def slot_configureCarla(self):
  1290. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1291. if not dialog.exec_():
  1292. return
  1293. self.loadSettings(False)
  1294. patchcanvas.clear()
  1295. self.setupCanvas()
  1296. self.slot_miniCanvasCheckAll()
  1297. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1298. pass
  1299. elif self.host.is_engine_running():
  1300. self.host.patchbay_refresh(self.fExternalPatchbay)
  1301. for pitem in self.fPluginList:
  1302. if pitem is None:
  1303. break
  1304. pitem.setUsingSkins(self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  1305. pitem.recreateWidget()
  1306. # --------------------------------------------------------------------------------------------------------
  1307. # About (menu actions)
  1308. @pyqtSlot()
  1309. def slot_aboutCarla(self):
  1310. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1311. @pyqtSlot()
  1312. def slot_aboutQt(self):
  1313. QApplication.instance().aboutQt()
  1314. # --------------------------------------------------------------------------------------------------------
  1315. # Disk (menu actions)
  1316. @pyqtSlot(int)
  1317. def slot_diskFolderChanged(self, index):
  1318. if index < 0:
  1319. return
  1320. elif index == 0:
  1321. filename = HOME
  1322. self.ui.b_disk_remove.setEnabled(False)
  1323. else:
  1324. filename = self.ui.cb_disk.itemData(index)
  1325. self.ui.b_disk_remove.setEnabled(True)
  1326. self.fDirModel.setRootPath(filename)
  1327. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1328. @pyqtSlot()
  1329. def slot_diskFolderAdd(self):
  1330. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1331. if newPath:
  1332. if newPath[-1] == os.sep:
  1333. newPath = newPath[:-1]
  1334. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1335. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1336. self.ui.b_disk_remove.setEnabled(True)
  1337. @pyqtSlot()
  1338. def slot_diskFolderRemove(self):
  1339. index = self.ui.cb_disk.currentIndex()
  1340. if index <= 0:
  1341. return
  1342. self.ui.cb_disk.removeItem(index)
  1343. if self.ui.cb_disk.currentIndex() == 0:
  1344. self.ui.b_disk_remove.setEnabled(False)
  1345. @pyqtSlot(QModelIndex)
  1346. def slot_fileTreeDoubleClicked(self, modelIndex):
  1347. filename = self.fDirModel.filePath(modelIndex)
  1348. if not self.ui.listWidget.isDragUrlValid(filename):
  1349. return
  1350. if not self.host.load_file(filename):
  1351. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1352. self.tr("Failed to load file"),
  1353. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1354. # --------------------------------------------------------------------------------------------------------
  1355. # Transport
  1356. def refreshTransport(self, forced = False):
  1357. if not self.isVisible():
  1358. return
  1359. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  1360. return
  1361. timeInfo = self.host.get_transport_info()
  1362. playing = timeInfo['playing']
  1363. frame = timeInfo['frame']
  1364. bpm = timeInfo['bpm']
  1365. if playing != self.fLastTransportState or forced:
  1366. if playing:
  1367. icon = getIcon("media-playback-pause")
  1368. self.ui.b_transport_play.setChecked(True)
  1369. self.ui.b_transport_play.setIcon(icon)
  1370. #self.ui.b_transport_play.setText(self.tr("&Pause"))
  1371. else:
  1372. icon = getIcon("media-playback-start")
  1373. self.ui.b_transport_play.setChecked(False)
  1374. self.ui.b_transport_play.setIcon(icon)
  1375. #self.ui.b_play.setText(self.tr("&Play"))
  1376. self.fLastTransportState = playing
  1377. if frame != self.fLastTransportFrame or forced:
  1378. self.fLastTransportFrame = frame
  1379. time = frame / self.fSampleRate
  1380. secs = time % 60
  1381. mins = (time / 60) % 60
  1382. hrs = (time / 3600) % 60
  1383. self.ui.l_transport_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  1384. frame1 = frame % 1000
  1385. frame2 = (frame / 1000) % 1000
  1386. frame3 = (frame / 1000000) % 1000
  1387. self.ui.l_transport_frame.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  1388. bar = timeInfo['bar']
  1389. beat = timeInfo['beat']
  1390. tick = timeInfo['tick']
  1391. self.ui.l_transport_bbt.setText("%03i|%02i|%04i" % (bar, beat, tick))
  1392. if bpm != self.fLastTransportBPM or forced:
  1393. self.fLastTransportBPM = bpm
  1394. if bpm > 0.0:
  1395. self.ui.dsb_transport_bpm.blockSignals(True)
  1396. self.ui.dsb_transport_bpm.setValue(bpm)
  1397. self.ui.dsb_transport_bpm.blockSignals(False)
  1398. self.ui.dsb_transport_bpm.setStyleSheet("")
  1399. else:
  1400. self.ui.dsb_transport_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  1401. # --------------------------------------------------------------------------------------------------------
  1402. # Transport (menu actions)
  1403. @pyqtSlot(bool)
  1404. def slot_transportPlayPause(self, toggled):
  1405. if self.host.isPlugin or not self.host.is_engine_running():
  1406. return
  1407. if toggled:
  1408. self.host.transport_play()
  1409. else:
  1410. self.host.transport_pause()
  1411. self.refreshTransport()
  1412. @pyqtSlot()
  1413. def slot_transportStop(self):
  1414. if self.host.isPlugin or not self.host.is_engine_running():
  1415. return
  1416. self.host.transport_pause()
  1417. self.host.transport_relocate(0)
  1418. self.refreshTransport()
  1419. @pyqtSlot()
  1420. def slot_transportBackwards(self):
  1421. if self.host.isPlugin or not self.host.is_engine_running():
  1422. return
  1423. newFrame = self.host.get_current_transport_frame() - 100000
  1424. if newFrame < 0:
  1425. newFrame = 0
  1426. self.host.transport_relocate(newFrame)
  1427. @pyqtSlot(float)
  1428. def slot_transportBpmChanged(self, newValue):
  1429. self.host.transport_bpm(newValue)
  1430. @pyqtSlot()
  1431. def slot_transportForwards(self):
  1432. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  1433. return
  1434. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  1435. self.host.transport_relocate(newFrame)
  1436. @pyqtSlot(bool)
  1437. def slot_transportJackEnabled(self, clicked):
  1438. if not self.host.is_engine_running():
  1439. return
  1440. mode = ENGINE_TRANSPORT_MODE_JACK if clicked else ENGINE_TRANSPORT_MODE_INTERNAL
  1441. extra = ":link:" if self.ui.cb_transport_link.isChecked() else ""
  1442. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, mode, extra)
  1443. @pyqtSlot(bool)
  1444. def slot_transportLinkEnabled(self, clicked):
  1445. if not self.host.is_engine_running():
  1446. return
  1447. mode = ENGINE_TRANSPORT_MODE_JACK if self.ui.cb_transport_jack.isChecked() else ENGINE_TRANSPORT_MODE_INTERNAL
  1448. extra = ":link:" if clicked else ""
  1449. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, mode, extra)
  1450. # --------------------------------------------------------------------------------------------------------
  1451. # Canvas scrollbars
  1452. @pyqtSlot(int)
  1453. def slot_horizontalScrollBarChanged(self, value):
  1454. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1455. if maximum == 0:
  1456. xp = 0
  1457. else:
  1458. xp = float(value) / maximum
  1459. self.ui.miniCanvasPreview.setViewPosX(xp)
  1460. self.updateCanvasInitialPos()
  1461. @pyqtSlot(int)
  1462. def slot_verticalScrollBarChanged(self, value):
  1463. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1464. if maximum == 0:
  1465. yp = 0
  1466. else:
  1467. yp = float(value) / maximum
  1468. self.ui.miniCanvasPreview.setViewPosY(yp)
  1469. self.updateCanvasInitialPos()
  1470. # --------------------------------------------------------------------------------------------------------
  1471. # Canvas keyboard
  1472. @pyqtSlot(int)
  1473. def slot_noteOn(self, note):
  1474. for pluginId in self.fSelectedPlugins:
  1475. self.host.send_midi_note(pluginId, 0, note, 100)
  1476. pedit = self.getPluginEditDialog(pluginId)
  1477. pedit.noteOn(0, note, 100)
  1478. @pyqtSlot(int)
  1479. def slot_noteOff(self, note):
  1480. for pluginId in self.fSelectedPlugins:
  1481. self.host.send_midi_note(pluginId, 0, note, 0)
  1482. pedit = self.getPluginEditDialog(pluginId)
  1483. pedit.noteOff(0, note)
  1484. # --------------------------------------------------------------------------------------------------------
  1485. # Canvas keyboard (host callbacks)
  1486. @pyqtSlot(int, int, int, int)
  1487. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1488. if pluginId in self.fSelectedPlugins:
  1489. self.ui.keyboard.sendNoteOn(note, False)
  1490. @pyqtSlot(int, int, int)
  1491. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1492. if pluginId in self.fSelectedPlugins:
  1493. self.ui.keyboard.sendNoteOff(note, False)
  1494. # --------------------------------------------------------------------------------------------------------
  1495. @pyqtSlot(int)
  1496. def slot_handleUpdateCallback(self, pluginId):
  1497. pitem = self.getPluginItem(pluginId)
  1498. if pitem is None:
  1499. return
  1500. wasCompacted = pitem.isCompacted()
  1501. isCompacted = wasCompacted
  1502. for i in range(self.host.get_custom_data_count(pluginId)):
  1503. cdata = self.host.get_custom_data(pluginId, i)
  1504. if cdata['type'] == CUSTOM_DATA_TYPE_PROPERTY and cdata['key'] == "CarlaSkinIsCompacted":
  1505. isCompacted = bool(cdata['value'] == "true")
  1506. break
  1507. else:
  1508. return
  1509. if wasCompacted == isCompacted:
  1510. return
  1511. pitem.recreateWidget(True)
  1512. # --------------------------------------------------------------------------------------------------------
  1513. # MiniCanvas stuff
  1514. @pyqtSlot()
  1515. def slot_miniCanvasCheckAll(self):
  1516. self.slot_miniCanvasCheckSize()
  1517. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1518. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1519. @pyqtSlot()
  1520. def slot_miniCanvasCheckSize(self):
  1521. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1522. return
  1523. currentIndex = self.ui.tabWidget.currentIndex()
  1524. if currentIndex == 1:
  1525. width = self.ui.graphicsView.width()
  1526. height = self.ui.graphicsView.height()
  1527. else:
  1528. self.ui.tabWidget.blockSignals(True)
  1529. self.ui.tabWidget.setCurrentIndex(1)
  1530. width = self.ui.graphicsView.width()
  1531. height = self.ui.graphicsView.height()
  1532. self.ui.tabWidget.setCurrentIndex(currentIndex)
  1533. self.ui.tabWidget.blockSignals(False)
  1534. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1535. @pyqtSlot(float, float)
  1536. def slot_miniCanvasMoved(self, xp, yp):
  1537. hsb = self.ui.graphicsView.horizontalScrollBar()
  1538. vsb = self.ui.graphicsView.verticalScrollBar()
  1539. hsb.setValue(xp * hsb.maximum())
  1540. vsb.setValue(yp * vsb.maximum())
  1541. self.updateCanvasInitialPos()
  1542. # --------------------------------------------------------------------------------------------------------
  1543. # Timers
  1544. def startTimers(self):
  1545. if self.fIdleTimerFast == 0:
  1546. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1547. if self.fIdleTimerSlow == 0:
  1548. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1549. def restartTimersIfNeeded(self):
  1550. if self.fIdleTimerFast != 0:
  1551. self.killTimer(self.fIdleTimerFast)
  1552. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1553. if self.fIdleTimerSlow != 0:
  1554. self.killTimer(self.fIdleTimerSlow)
  1555. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1556. def killTimers(self):
  1557. if self.fIdleTimerFast != 0:
  1558. self.killTimer(self.fIdleTimerFast)
  1559. self.fIdleTimerFast = 0
  1560. if self.fIdleTimerSlow != 0:
  1561. self.killTimer(self.fIdleTimerSlow)
  1562. self.fIdleTimerSlow = 0
  1563. # --------------------------------------------------------------------------------------------------------
  1564. # Misc
  1565. @pyqtSlot(int)
  1566. def slot_tabChanged(self, index):
  1567. if index != 1:
  1568. return
  1569. self.ui.graphicsView.setFocus()
  1570. @pyqtSlot(int)
  1571. def slot_handleReloadAllCallback(self, pluginId):
  1572. if pluginId >= self.fPluginCount:
  1573. return
  1574. pitem = self.fPluginList[pluginId]
  1575. if pitem is None:
  1576. return
  1577. pitem.recreateWidget()
  1578. # --------------------------------------------------------------------------------------------------------
  1579. @pyqtSlot(int, int, str)
  1580. def slot_handleNSMCallback(self, value1, value2, valueStr):
  1581. # Error
  1582. if value1 == 0:
  1583. pass
  1584. # Reply
  1585. elif value1 == 1:
  1586. self.fFirstEngineInit = False
  1587. self.fSessionManagerName = valueStr
  1588. self.setProperWindowTitle()
  1589. # Open
  1590. elif value1 == 2:
  1591. self.fClientName = os.path.basename(valueStr)
  1592. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1593. self.setProperWindowTitle()
  1594. self.fCustomStopAction = self.CUSTOM_ACTION_PROJECT_LOAD
  1595. self.slot_engineStop(True)
  1596. return
  1597. # Save
  1598. elif value1 == 3:
  1599. self.saveProjectNow()
  1600. # Session is Loaded
  1601. elif value1 == 4:
  1602. pass
  1603. # Show Optional Gui
  1604. elif value1 == 5:
  1605. self.show()
  1606. # Hide Optional Gui
  1607. elif value1 == 6:
  1608. self.hide()
  1609. self.host.nsm_ready(value1)
  1610. # --------------------------------------------------------------------------------------------------------
  1611. def fixLogText(self, text):
  1612. return text.replace("\x1b[30;1m", "").replace("\x1b[31m", "").replace("\x1b[0m", "")
  1613. @pyqtSlot(int, int, int, float, str)
  1614. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1615. self.ui.text_logs.appendPlainText(self.fixLogText(valueStr))
  1616. @pyqtSlot(str)
  1617. def slot_handleInfoCallback(self, info):
  1618. QMessageBox.information(self, "Information", info)
  1619. @pyqtSlot(str)
  1620. def slot_handleErrorCallback(self, error):
  1621. QMessageBox.critical(self, "Error", error)
  1622. @pyqtSlot()
  1623. def slot_handleQuitCallback(self):
  1624. pass # TODO
  1625. # --------------------------------------------------------------------------------------------------------
  1626. @pyqtSlot()
  1627. def slot_handleSIGUSR1(self):
  1628. print("Got SIGUSR1 -> Saving project now")
  1629. self.slot_fileSave()
  1630. @pyqtSlot()
  1631. def slot_handleSIGTERM(self):
  1632. print("Got SIGTERM -> Closing now")
  1633. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1634. self.slot_engineStop(True)
  1635. # --------------------------------------------------------------------------------------------------------
  1636. # Internal stuff
  1637. def getExtraPtr(self, plugin):
  1638. ptype = plugin['type']
  1639. if ptype == PLUGIN_LADSPA:
  1640. uniqueId = plugin['uniqueId']
  1641. self.maybeLoadRDFs()
  1642. for rdfItem in self.fLadspaRdfList:
  1643. if rdfItem.UniqueID == uniqueId:
  1644. return pointer(rdfItem)
  1645. elif ptype == PLUGIN_SF2:
  1646. if plugin['name'].lower().endswith(" (16 outputs)"):
  1647. return self._true
  1648. return None
  1649. def maybeLoadRDFs(self):
  1650. if not self.fLadspaRdfNeedsUpdate:
  1651. return
  1652. self.fLadspaRdfNeedsUpdate = False
  1653. self.fLadspaRdfList = []
  1654. if not haveLRDF:
  1655. return
  1656. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1657. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1658. if os.path.exists(frLadspaFile):
  1659. frLadspa = open(frLadspaFile, 'r')
  1660. try:
  1661. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1662. except:
  1663. pass
  1664. frLadspa.close()
  1665. # --------------------------------------------------------------------------------------------------------
  1666. def getPluginCount(self):
  1667. return self.fPluginCount
  1668. def getPluginItem(self, pluginId):
  1669. if pluginId >= self.fPluginCount:
  1670. return None
  1671. pitem = self.fPluginList[pluginId]
  1672. if pitem is None:
  1673. return None
  1674. #if False:
  1675. #return CarlaRackItem(self, 0, False)
  1676. return pitem
  1677. def getPluginEditDialog(self, pluginId):
  1678. if pluginId >= self.fPluginCount:
  1679. return None
  1680. pitem = self.fPluginList[pluginId]
  1681. if pitem is None:
  1682. return None
  1683. if False:
  1684. return PluginEdit(self, self.host, 0)
  1685. return pitem.getEditDialog()
  1686. def getPluginSlotWidget(self, pluginId):
  1687. if pluginId >= self.fPluginCount:
  1688. return None
  1689. pitem = self.fPluginList[pluginId]
  1690. if pitem is None:
  1691. return None
  1692. #if False:
  1693. #return AbstractPluginSlot()
  1694. return pitem.getWidget()
  1695. # --------------------------------------------------------------------------------------------------------
  1696. def waitForPendingEvents(self):
  1697. pass
  1698. # --------------------------------------------------------------------------------------------------------
  1699. # show/hide event
  1700. def showEvent(self, event):
  1701. self.refreshTransport(True)
  1702. QMainWindow.showEvent(self, event)
  1703. # set our gui as parent for all plugins UIs
  1704. if self.host.manageUIs and not (self.host.isControl or self.host.isPlugin):
  1705. if MACOS:
  1706. nsViewPtr = int(self.winId())
  1707. winIdStr = "%x" % gCarla.utils.cocoa_get_window(nsViewPtr)
  1708. else:
  1709. winIdStr = "%x" % int(self.winId())
  1710. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1711. def hideEvent(self, event):
  1712. # disable parent
  1713. if not (self.host.isControl or self.host.isPlugin):
  1714. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1715. QMainWindow.hideEvent(self, event)
  1716. # --------------------------------------------------------------------------------------------------------
  1717. # resize event
  1718. def fixCanvasPreviewSize(self):
  1719. self.ui.patchbay.resize(self.ui.rack.size())
  1720. self.slot_miniCanvasCheckSize()
  1721. def resizeEvent(self, event):
  1722. QMainWindow.resizeEvent(self, event)
  1723. if self.ui.tabWidget.currentIndex() != 1:
  1724. size = self.ui.rack.size()
  1725. self.ui.patchbay.resize(size)
  1726. self.slot_miniCanvasCheckSize()
  1727. # --------------------------------------------------------------------------------------------------------
  1728. # timer event
  1729. def idleFast(self):
  1730. self.host.engine_idle()
  1731. self.refreshTransport()
  1732. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1733. return
  1734. for pitem in self.fPluginList:
  1735. if pitem is None:
  1736. break
  1737. pitem.getWidget().idleFast()
  1738. for pluginId in self.fSelectedPlugins:
  1739. self.fPeaksCleared = False
  1740. if self.ui.peak_in.isVisible():
  1741. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1742. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1743. if self.ui.peak_out.isVisible():
  1744. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1745. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1746. return
  1747. if self.fPeaksCleared:
  1748. return
  1749. self.fPeaksCleared = True
  1750. self.ui.peak_in.displayMeter(1, 0.0, True)
  1751. self.ui.peak_in.displayMeter(2, 0.0, True)
  1752. self.ui.peak_out.displayMeter(1, 0.0, True)
  1753. self.ui.peak_out.displayMeter(2, 0.0, True)
  1754. def idleSlow(self):
  1755. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1756. return
  1757. for pitem in self.fPluginList:
  1758. if pitem is None:
  1759. break
  1760. pitem.getWidget().idleSlow()
  1761. def timerEvent(self, event):
  1762. if event.timerId() == self.fIdleTimerFast:
  1763. self.idleFast()
  1764. elif event.timerId() == self.fIdleTimerSlow:
  1765. self.idleSlow()
  1766. QMainWindow.timerEvent(self, event)
  1767. # --------------------------------------------------------------------------------------------------------
  1768. # paint event
  1769. #def paintEvent(self, event):
  1770. #QMainWindow.paintEvent(self, event)
  1771. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1772. #return
  1773. #painter = QPainter(self)
  1774. #painter.setBrush(QColor(36, 36, 36))
  1775. #painter.setPen(QColor(62, 62, 62))
  1776. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1777. # --------------------------------------------------------------------------------------------------------
  1778. # close event
  1779. def shouldIgnoreClose(self):
  1780. if self.host.isControl or self.host.isPlugin:
  1781. return False
  1782. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  1783. return False
  1784. if self.fSavedSettings[CARLA_KEY_MAIN_CONFIRM_EXIT]:
  1785. return QMessageBox.question(self, self.tr("Quit"),
  1786. self.tr("Are you sure you want to quit Carla?"),
  1787. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No
  1788. return False
  1789. def closeEvent(self, event):
  1790. if self.shouldIgnoreClose():
  1791. event.ignore()
  1792. return
  1793. self.killTimers()
  1794. self.saveSettings()
  1795. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  1796. if not self.slot_engineStop(True):
  1797. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  1798. event.ignore()
  1799. return
  1800. QMainWindow.closeEvent(self, event)
  1801. # ------------------------------------------------------------------------------------------------
  1802. # Canvas callback
  1803. def canvasCallback(action, value1, value2, valueStr):
  1804. host = gCarla.gui.host
  1805. if action == patchcanvas.ACTION_GROUP_INFO:
  1806. pass
  1807. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1808. pass
  1809. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1810. groupId = value1
  1811. patchcanvas.splitGroup(groupId)
  1812. gCarla.gui.updateMiniCanvasLater()
  1813. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1814. groupId = value1
  1815. patchcanvas.joinGroup(groupId)
  1816. gCarla.gui.updateMiniCanvasLater()
  1817. elif action == patchcanvas.ACTION_PORT_INFO:
  1818. pass
  1819. elif action == patchcanvas.ACTION_PORT_RENAME:
  1820. pass
  1821. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1822. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1823. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1824. print("Connection failed:", host.get_last_error())
  1825. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1826. connectionId = value1
  1827. if not host.patchbay_disconnect(connectionId):
  1828. print("Disconnect failed:", host.get_last_error())
  1829. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1830. pluginId = value1
  1831. if not host.clone_plugin(pluginId):
  1832. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1833. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1834. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1835. pluginId = value1
  1836. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1837. if pwidget is not None:
  1838. pwidget.showEditDialog()
  1839. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1840. pluginId = value1
  1841. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1842. if pwidget is not None:
  1843. pwidget.showRenameDialog()
  1844. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  1845. pluginId = value1
  1846. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1847. if pwidget is not None:
  1848. pwidget.showReplaceDialog()
  1849. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1850. pluginId = value1
  1851. if not host.remove_plugin(pluginId):
  1852. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1853. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1854. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1855. pluginId = value1
  1856. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1857. if pwidget is not None:
  1858. pwidget.showCustomUI()
  1859. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  1860. gCarla.gui.showPluginActionsMenu()
  1861. # ------------------------------------------------------------------------------------------------------------
  1862. # Engine callback
  1863. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1864. # kdevelop likes this :)
  1865. if False: host = CarlaHostNull()
  1866. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1867. host.processMode = value1
  1868. host.transportMode = value2
  1869. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1870. host.processMode = value1
  1871. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1872. host.transportMode = value1
  1873. valueStr = charPtrToString(valueStr)
  1874. if action == ENGINE_CALLBACK_DEBUG:
  1875. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1876. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1877. host.PluginAddedCallback.emit(pluginId, valueStr)
  1878. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1879. host.PluginRemovedCallback.emit(pluginId)
  1880. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1881. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1882. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1883. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1884. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1885. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1886. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1887. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1888. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1889. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1890. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1891. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1892. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1893. host.ProgramChangedCallback.emit(pluginId, value1)
  1894. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1895. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1896. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1897. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1898. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1899. host.UiStateChangedCallback.emit(pluginId, value1)
  1900. elif action == ENGINE_CALLBACK_NOTE_ON:
  1901. host.NoteOnCallback.emit(pluginId, value1, value2, round(value3))
  1902. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1903. host.NoteOffCallback.emit(pluginId, value1, value2)
  1904. elif action == ENGINE_CALLBACK_UPDATE:
  1905. host.UpdateCallback.emit(pluginId)
  1906. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1907. host.ReloadInfoCallback.emit(pluginId)
  1908. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1909. host.ReloadParametersCallback.emit(pluginId)
  1910. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1911. host.ReloadProgramsCallback.emit(pluginId)
  1912. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1913. host.ReloadAllCallback.emit(pluginId)
  1914. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1915. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1916. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1917. host.PatchbayClientRemovedCallback.emit(pluginId)
  1918. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1919. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1920. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1921. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1922. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1923. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1924. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1925. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1926. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1927. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1928. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1929. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1930. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1931. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1932. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1933. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1934. host.EngineStartedCallback.emit(value1, value2, value3, valueStr)
  1935. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1936. host.EngineStoppedCallback.emit()
  1937. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1938. host.ProcessModeChangedCallback.emit(value1)
  1939. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1940. host.TransportModeChangedCallback.emit(value1)
  1941. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1942. host.BufferSizeChangedCallback.emit(value1)
  1943. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1944. host.SampleRateChangedCallback.emit(value3)
  1945. elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
  1946. host.ProjectLoadFinishedCallback.emit()
  1947. elif action == ENGINE_CALLBACK_NSM:
  1948. host.NSMCallback.emit(value1, value2, valueStr)
  1949. elif action == ENGINE_CALLBACK_IDLE:
  1950. QApplication.instance().processEvents()
  1951. elif action == ENGINE_CALLBACK_INFO:
  1952. host.InfoCallback.emit(valueStr)
  1953. elif action == ENGINE_CALLBACK_ERROR:
  1954. host.ErrorCallback.emit(valueStr)
  1955. elif action == ENGINE_CALLBACK_QUIT:
  1956. host.QuitCallback.emit()
  1957. # ------------------------------------------------------------------------------------------------------------
  1958. # File callback
  1959. def fileCallback(ptr, action, isDir, title, filter):
  1960. ret = ("", "") if config_UseQt5 else ""
  1961. title = charPtrToString(title)
  1962. filter = charPtrToString(filter)
  1963. if action == FILE_CALLBACK_OPEN:
  1964. ret = QFileDialog.getOpenFileName(gCarla.gui, title, "", filter) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1965. elif action == FILE_CALLBACK_SAVE:
  1966. ret = QFileDialog.getSaveFileName(gCarla.gui, title, "", filter, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1967. if config_UseQt5:
  1968. ret = ret[0]
  1969. if not ret:
  1970. return None
  1971. # FIXME
  1972. global fileRet
  1973. fileRet = c_char_p(ret.encode("utf-8"))
  1974. retval = cast(byref(fileRet), POINTER(c_uintptr))
  1975. return retval.contents.value
  1976. # ------------------------------------------------------------------------------------------------------------
  1977. # Init host
  1978. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  1979. pathBinaries, pathResources = getPaths(libPrefix)
  1980. # --------------------------------------------------------------------------------------------------------
  1981. # Check if we should open main lib as local or global
  1982. settings = QSettings("falkTX", "Carla2")
  1983. try:
  1984. loadGlobal = settings.value(CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL, CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL, type=bool)
  1985. except:
  1986. loadGlobal = CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL
  1987. # --------------------------------------------------------------------------------------------------------
  1988. # Fail if binary dir is not found
  1989. if not os.path.exists(pathBinaries):
  1990. if failError:
  1991. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  1992. sys.exit(1)
  1993. return
  1994. # --------------------------------------------------------------------------------------------------------
  1995. # Set Carla library name
  1996. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  1997. libname = os.path.join(pathBinaries, libname)
  1998. utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION))
  1999. # --------------------------------------------------------------------------------------------------------
  2000. # Print info
  2001. print("Carla %s started, status:" % VERSION)
  2002. print(" Python version: %s" % sys.version.split(" ",1)[0])
  2003. print(" Qt version: %s" % qVersion())
  2004. print(" PyQt version: %s" % PYQT_VERSION_STR)
  2005. print(" Binary dir: %s" % pathBinaries)
  2006. print(" Resources dir: %s" % pathResources)
  2007. # --------------------------------------------------------------------------------------------------------
  2008. # Init host
  2009. if failError:
  2010. # no try
  2011. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2012. else:
  2013. try:
  2014. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2015. except:
  2016. host = CarlaHostQtNull()
  2017. host.isControl = isControl
  2018. host.isPlugin = isPlugin
  2019. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  2020. host.set_file_callback(fileCallback)
  2021. # If it's a plugin the paths are already set
  2022. if not isPlugin:
  2023. host.pathBinaries = pathBinaries
  2024. host.pathResources = pathResources
  2025. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  2026. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  2027. if not isControl:
  2028. host.nsmOK = host.nsm_init(os.getpid(), initName)
  2029. # --------------------------------------------------------------------------------------------------------
  2030. # Init utils
  2031. gCarla.utils = CarlaUtils(utilsname)
  2032. gCarla.utils.set_process_name(os.path.basename(initName))
  2033. try:
  2034. sys.stdout.flush()
  2035. except:
  2036. pass
  2037. sys.stdout = CarlaPrint(False)
  2038. sys.stderr = CarlaPrint(True)
  2039. if config_UseQt5:
  2040. sys.excepthook = sys_excepthook
  2041. # --------------------------------------------------------------------------------------------------------
  2042. # Done
  2043. return host
  2044. # ------------------------------------------------------------------------------------------------------------
  2045. # Load host settings
  2046. def loadHostSettings(host):
  2047. # kdevelop likes this :)
  2048. if False: host = CarlaHostNull()
  2049. settings = QSettings("falkTX", "Carla2")
  2050. try:
  2051. host.experimental = settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool)
  2052. except:
  2053. host.experimental = CARLA_DEFAULT_MAIN_EXPERIMENTAL
  2054. try:
  2055. host.exportLV2 = settings.value(CARLA_KEY_EXPERIMENTAL_EXPORT_LV2, CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT, type=bool)
  2056. except:
  2057. host.exportLV2 = CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT
  2058. try:
  2059. host.manageUIs = settings.value(CARLA_KEY_ENGINE_MANAGE_UIS, CARLA_DEFAULT_MANAGE_UIS, type=bool)
  2060. except:
  2061. host.manageUIs = CARLA_DEFAULT_MANAGE_UIS
  2062. try:
  2063. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  2064. except:
  2065. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  2066. try:
  2067. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  2068. except:
  2069. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  2070. try:
  2071. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  2072. except:
  2073. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  2074. try:
  2075. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  2076. except:
  2077. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  2078. try:
  2079. host.preventBadBehaviour = settings.value(CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, type=bool)
  2080. except:
  2081. host.preventBadBehaviour = CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR
  2082. try:
  2083. host.showLogs = settings.value(CARLA_KEY_MAIN_SHOW_LOGS, CARLA_DEFAULT_MAIN_SHOW_LOGS, type=bool)
  2084. except:
  2085. host.showLogs = CARLA_DEFAULT_MAIN_SHOW_LOGS
  2086. try:
  2087. host.showPluginBridges = settings.value(CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES, type=bool)
  2088. except:
  2089. host.showPluginBridges = CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES
  2090. try:
  2091. host.showWineBridges = settings.value(CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES, type=bool)
  2092. except:
  2093. host.showWineBridges = CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES
  2094. try:
  2095. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  2096. except:
  2097. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  2098. try:
  2099. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  2100. except:
  2101. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  2102. if host.isPlugin:
  2103. return
  2104. # enums
  2105. if host.audioDriverForced is None:
  2106. try:
  2107. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  2108. except:
  2109. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  2110. if not host.processModeForced:
  2111. try:
  2112. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  2113. except:
  2114. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  2115. host.nextProcessMode = host.processMode
  2116. # --------------------------------------------------------------------------------------------------------
  2117. # fix things if needed
  2118. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  2119. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  2120. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  2121. if gCarla.nogui:
  2122. host.showLogs = False
  2123. # --------------------------------------------------------------------------------------------------------
  2124. # run headless host now if nogui option enabled
  2125. if gCarla.nogui:
  2126. runHostWithoutUI(host)
  2127. # ------------------------------------------------------------------------------------------------------------
  2128. # Set host settings
  2129. def setHostSettings(host):
  2130. # kdevelop likes this :)
  2131. if False: host = CarlaHostNull()
  2132. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  2133. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  2134. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  2135. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  2136. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  2137. host.set_engine_option(ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT, host.showLogs, "")
  2138. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  2139. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  2140. if host.isPlugin or host.is_engine_running():
  2141. return
  2142. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  2143. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, "")
  2144. # ------------------------------------------------------------------------------------------------------------
  2145. # Set Engine settings according to carla preferences. Returns selected audio driver.
  2146. def setEngineSettings(host):
  2147. # kdevelop likes this :)
  2148. if False: host = CarlaHostNull()
  2149. # --------------------------------------------------------------------------------------------------------
  2150. # do nothing if control
  2151. if host.isControl:
  2152. return "Control"
  2153. # --------------------------------------------------------------------------------------------------------
  2154. settings = QSettings("falkTX", "Carla2")
  2155. # --------------------------------------------------------------------------------------------------------
  2156. # main settings
  2157. setHostSettings(host)
  2158. # --------------------------------------------------------------------------------------------------------
  2159. # plugin paths
  2160. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  2161. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  2162. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  2163. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  2164. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  2165. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  2166. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  2167. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  2168. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  2169. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  2170. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  2171. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  2172. # --------------------------------------------------------------------------------------------------------
  2173. # don't continue if plugin
  2174. if host.isPlugin:
  2175. return "Plugin"
  2176. # --------------------------------------------------------------------------------------------------------
  2177. # wine settings
  2178. optWineExecutable = settings.value(CARLA_KEY_WINE_EXECUTABLE, CARLA_DEFAULT_WINE_EXECUTABLE, type=str)
  2179. optWineAutoPrefix = settings.value(CARLA_KEY_WINE_AUTO_PREFIX, CARLA_DEFAULT_WINE_AUTO_PREFIX, type=bool)
  2180. optWineFallbackPrefix = settings.value(CARLA_KEY_WINE_FALLBACK_PREFIX, CARLA_DEFAULT_WINE_FALLBACK_PREFIX, type=str)
  2181. optWineRtPrioEnabled = settings.value(CARLA_KEY_WINE_RT_PRIO_ENABLED, CARLA_DEFAULT_WINE_RT_PRIO_ENABLED, type=bool)
  2182. optWineBaseRtPrio = settings.value(CARLA_KEY_WINE_BASE_RT_PRIO, CARLA_DEFAULT_WINE_BASE_RT_PRIO, type=int)
  2183. optWineServerRtPrio = settings.value(CARLA_KEY_WINE_SERVER_RT_PRIO, CARLA_DEFAULT_WINE_SERVER_RT_PRIO, type=int)
  2184. host.set_engine_option(ENGINE_OPTION_WINE_EXECUTABLE, 0, optWineExecutable)
  2185. host.set_engine_option(ENGINE_OPTION_WINE_AUTO_PREFIX, 1 if optWineAutoPrefix else 0, "")
  2186. host.set_engine_option(ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, os.path.expanduser(optWineFallbackPrefix))
  2187. host.set_engine_option(ENGINE_OPTION_WINE_RT_PRIO_ENABLED, 1 if optWineRtPrioEnabled else 0, "")
  2188. host.set_engine_option(ENGINE_OPTION_WINE_BASE_RT_PRIO, optWineBaseRtPrio, "")
  2189. host.set_engine_option(ENGINE_OPTION_WINE_SERVER_RT_PRIO, optWineServerRtPrio, "")
  2190. # --------------------------------------------------------------------------------------------------------
  2191. # driver and device settings
  2192. # driver name
  2193. if host.audioDriverForced is not None:
  2194. audioDriver = host.audioDriverForced
  2195. else:
  2196. try:
  2197. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  2198. except:
  2199. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  2200. # driver options
  2201. try:
  2202. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  2203. except:
  2204. audioDevice = ""
  2205. try:
  2206. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  2207. except:
  2208. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  2209. try:
  2210. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  2211. except:
  2212. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  2213. try:
  2214. audioTripleBuffer = settings.value("%s%s/TripleBuffer" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER, type=int)
  2215. except:
  2216. audioTripleBuffer = CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER
  2217. # Only setup audio things if engine is not running
  2218. if not host.is_engine_running():
  2219. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  2220. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  2221. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  2222. host.set_engine_option(ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, audioTripleBuffer, "")
  2223. # --------------------------------------------------------------------------------------------------------
  2224. # fix things if needed
  2225. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  2226. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  2227. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")
  2228. # --------------------------------------------------------------------------------------------------------
  2229. # return selected driver name
  2230. return audioDriver
  2231. # ------------------------------------------------------------------------------------------------------------
  2232. # Run Carla without showing UI
  2233. def runHostWithoutUI(host):
  2234. # kdevelop likes this :)
  2235. if False: host = CarlaHostNull()
  2236. # --------------------------------------------------------------------------------------------------------
  2237. # Some initial checks
  2238. if not gCarla.nogui:
  2239. return
  2240. projectFile = getInitialProjectFile(QCoreApplication.instance(), True)
  2241. if not projectFile:
  2242. print("Carla no-gui mode can only be used together with a project file.")
  2243. sys.exit(1)
  2244. # --------------------------------------------------------------------------------------------------------
  2245. # Additional imports
  2246. from time import sleep
  2247. # --------------------------------------------------------------------------------------------------------
  2248. # Init engine
  2249. audioDriver = setEngineSettings(host)
  2250. if not host.engine_init(audioDriver, "Carla"):
  2251. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  2252. sys.exit(1)
  2253. if not host.load_project(projectFile):
  2254. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  2255. host.engine_close()
  2256. sys.exit(1)
  2257. # --------------------------------------------------------------------------------------------------------
  2258. # Idle
  2259. print("Carla ready!")
  2260. while host.is_engine_running() and not gCarla.term:
  2261. host.engine_idle()
  2262. sleep(0.0333) # 30 Hz
  2263. # --------------------------------------------------------------------------------------------------------
  2264. # Stop
  2265. host.engine_close()
  2266. sys.exit(0)
  2267. # ------------------------------------------------------------------------------------------------------------