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.

2842 lines
109KB

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