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.

2854 lines
110KB

  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. settings = QSettings("falkTX", "Carla2")
  1170. if self.host.experimental:
  1171. self.ui.act_add_jack.setVisible(settings.value(CARLA_KEY_EXPERIMENTAL_JACK_APPS,
  1172. CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS, type=bool))
  1173. else:
  1174. self.ui.act_add_jack.setVisible(False)
  1175. if not (self.host.isControl or self.host.isPlugin):
  1176. if self.host.experimental:
  1177. if settings.value(CARLA_KEY_EXPERIMENTAL_TRANSPORT, CARLA_DEFAULT_EXPERIMENTAL_TRANSPORT, type=bool):
  1178. if self.ui.cb_transport_jack.isChecked():
  1179. transportMode = ENGINE_TRANSPORT_MODE_JACK
  1180. else:
  1181. transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  1182. transportExtra = ":link:" if self.ui.cb_transport_link.isChecked() else ""
  1183. else:
  1184. # Stop transport if becoming disabled
  1185. if self.ui.w_transport.isEnabled() and self.host.is_engine_running():
  1186. self.host.transport_pause()
  1187. self.host.transport_relocate(0)
  1188. self.host.transport_pause()
  1189. transportMode = ENGINE_TRANSPORT_MODE_DISABLED
  1190. transportExtra = ""
  1191. self.ui.w_transport.setEnabled(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  1192. self.host.transportMode = transportMode
  1193. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, transportMode, transportExtra)
  1194. else:
  1195. self.ui.w_transport.setEnabled(False)
  1196. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY] else 0
  1197. setEngineSettings(self.host)
  1198. self.restartTimersIfNeeded()
  1199. # --------------------------------------------------------------------------------------------------------
  1200. # Settings (helpers)
  1201. @pyqtSlot()
  1202. def slot_restoreCanvasScrollbarValues(self):
  1203. settings = QSettings()
  1204. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  1205. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  1206. # --------------------------------------------------------------------------------------------------------
  1207. # Settings (menu actions)
  1208. @pyqtSlot(bool)
  1209. def slot_showSidePanel(self, yesNo):
  1210. self.ui.dockWidget.setEnabled(yesNo)
  1211. self.ui.dockWidget.setVisible(yesNo)
  1212. @pyqtSlot(bool)
  1213. def slot_showToolbar(self, yesNo):
  1214. self.ui.toolBar.setEnabled(yesNo)
  1215. self.ui.toolBar.setVisible(yesNo)
  1216. @pyqtSlot(bool)
  1217. def slot_showCanvasMeters(self, yesNo):
  1218. self.ui.peak_in.setVisible(yesNo)
  1219. self.ui.peak_out.setVisible(yesNo)
  1220. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1221. @pyqtSlot(bool)
  1222. def slot_showCanvasKeyboard(self, yesNo):
  1223. self.ui.scrollArea.setVisible(yesNo)
  1224. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1225. @pyqtSlot()
  1226. def slot_configureCarla(self):
  1227. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1228. if not dialog.exec_():
  1229. return
  1230. self.loadSettings(False)
  1231. patchcanvas.clear()
  1232. self.setupCanvas()
  1233. self.slot_miniCanvasCheckAll()
  1234. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1235. pass
  1236. elif self.host.is_engine_running():
  1237. self.host.patchbay_refresh(self.fExternalPatchbay)
  1238. for pitem in self.fPluginList:
  1239. if pitem is None:
  1240. break
  1241. pitem.setUsingSkins(self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  1242. pitem.recreateWidget()
  1243. # --------------------------------------------------------------------------------------------------------
  1244. # About (menu actions)
  1245. @pyqtSlot()
  1246. def slot_aboutCarla(self):
  1247. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1248. @pyqtSlot()
  1249. def slot_aboutQt(self):
  1250. QApplication.instance().aboutQt()
  1251. # --------------------------------------------------------------------------------------------------------
  1252. # Disk (menu actions)
  1253. @pyqtSlot(int)
  1254. def slot_diskFolderChanged(self, index):
  1255. if index < 0:
  1256. return
  1257. elif index == 0:
  1258. filename = HOME
  1259. self.ui.b_disk_remove.setEnabled(False)
  1260. else:
  1261. filename = self.ui.cb_disk.itemData(index)
  1262. self.ui.b_disk_remove.setEnabled(True)
  1263. self.fDirModel.setRootPath(filename)
  1264. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1265. @pyqtSlot()
  1266. def slot_diskFolderAdd(self):
  1267. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1268. if newPath:
  1269. if newPath[-1] == os.sep:
  1270. newPath = newPath[:-1]
  1271. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1272. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1273. self.ui.b_disk_remove.setEnabled(True)
  1274. @pyqtSlot()
  1275. def slot_diskFolderRemove(self):
  1276. index = self.ui.cb_disk.currentIndex()
  1277. if index <= 0:
  1278. return
  1279. self.ui.cb_disk.removeItem(index)
  1280. if self.ui.cb_disk.currentIndex() == 0:
  1281. self.ui.b_disk_remove.setEnabled(False)
  1282. @pyqtSlot(QModelIndex)
  1283. def slot_fileTreeDoubleClicked(self, modelIndex):
  1284. filename = self.fDirModel.filePath(modelIndex)
  1285. if not self.ui.listWidget.isDragUrlValid(filename):
  1286. return
  1287. if not self.host.load_file(filename):
  1288. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1289. self.tr("Failed to load file"),
  1290. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1291. # --------------------------------------------------------------------------------------------------------
  1292. # Transport
  1293. def refreshTransport(self, forced = False):
  1294. if not self.isVisible():
  1295. return
  1296. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  1297. return
  1298. timeInfo = self.host.get_transport_info()
  1299. playing = timeInfo['playing']
  1300. frame = timeInfo['frame']
  1301. bpm = timeInfo['bpm']
  1302. if playing != self.fLastTransportState or forced:
  1303. if playing:
  1304. icon = getIcon("media-playback-pause")
  1305. self.ui.b_transport_play.setChecked(True)
  1306. self.ui.b_transport_play.setIcon(icon)
  1307. #self.ui.b_transport_play.setText(self.tr("&Pause"))
  1308. else:
  1309. icon = getIcon("media-playback-start")
  1310. self.ui.b_transport_play.setChecked(False)
  1311. self.ui.b_transport_play.setIcon(icon)
  1312. #self.ui.b_play.setText(self.tr("&Play"))
  1313. self.fLastTransportState = playing
  1314. if frame != self.fLastTransportFrame or forced:
  1315. self.fLastTransportFrame = frame
  1316. time = frame / self.fSampleRate
  1317. secs = time % 60
  1318. mins = (time / 60) % 60
  1319. hrs = (time / 3600) % 60
  1320. self.ui.l_transport_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  1321. frame1 = frame % 1000
  1322. frame2 = (frame / 1000) % 1000
  1323. frame3 = (frame / 1000000) % 1000
  1324. self.ui.l_transport_frame.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  1325. bar = timeInfo['bar']
  1326. beat = timeInfo['beat']
  1327. tick = timeInfo['tick']
  1328. self.ui.l_transport_bbt.setText("%03i|%02i|%04i" % (bar, beat, tick))
  1329. if bpm != self.fLastTransportBPM or forced:
  1330. self.fLastTransportBPM = bpm
  1331. if bpm > 0.0:
  1332. self.ui.dsb_transport_bpm.blockSignals(True)
  1333. self.ui.dsb_transport_bpm.setValue(bpm)
  1334. self.ui.dsb_transport_bpm.blockSignals(False)
  1335. self.ui.dsb_transport_bpm.setStyleSheet("")
  1336. else:
  1337. self.ui.dsb_transport_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  1338. # --------------------------------------------------------------------------------------------------------
  1339. # Transport (menu actions)
  1340. @pyqtSlot(bool)
  1341. def slot_transportPlayPause(self, toggled):
  1342. if self.host.isPlugin or not self.host.is_engine_running():
  1343. return
  1344. if toggled:
  1345. self.host.transport_play()
  1346. else:
  1347. self.host.transport_pause()
  1348. self.refreshTransport()
  1349. @pyqtSlot()
  1350. def slot_transportStop(self):
  1351. if self.host.isPlugin or not self.host.is_engine_running():
  1352. return
  1353. self.host.transport_pause()
  1354. self.host.transport_relocate(0)
  1355. self.refreshTransport()
  1356. @pyqtSlot()
  1357. def slot_transportBackwards(self):
  1358. if self.host.isPlugin or not self.host.is_engine_running():
  1359. return
  1360. newFrame = self.host.get_current_transport_frame() - 100000
  1361. if newFrame < 0:
  1362. newFrame = 0
  1363. self.host.transport_relocate(newFrame)
  1364. @pyqtSlot(float)
  1365. def slot_transportBpmChanged(self, newValue):
  1366. self.host.transport_bpm(newValue)
  1367. @pyqtSlot()
  1368. def slot_transportForwards(self):
  1369. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  1370. return
  1371. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  1372. self.host.transport_relocate(newFrame)
  1373. @pyqtSlot(bool)
  1374. def slot_transportJackEnabled(self, clicked):
  1375. if not self.host.is_engine_running():
  1376. return
  1377. mode = ENGINE_TRANSPORT_MODE_JACK if clicked else ENGINE_TRANSPORT_MODE_INTERNAL
  1378. extra = ":link:" if self.ui.cb_transport_link.isChecked() else ""
  1379. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, mode, extra)
  1380. @pyqtSlot(bool)
  1381. def slot_transportLinkEnabled(self, clicked):
  1382. if not self.host.is_engine_running():
  1383. return
  1384. mode = ENGINE_TRANSPORT_MODE_JACK if self.ui.cb_transport_jack.isChecked() else ENGINE_TRANSPORT_MODE_INTERNAL
  1385. extra = ":link:" if clicked else ""
  1386. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, mode, extra)
  1387. # --------------------------------------------------------------------------------------------------------
  1388. # Canvas scrollbars
  1389. @pyqtSlot(int)
  1390. def slot_horizontalScrollBarChanged(self, value):
  1391. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1392. if maximum == 0:
  1393. xp = 0
  1394. else:
  1395. xp = float(value) / maximum
  1396. self.ui.miniCanvasPreview.setViewPosX(xp)
  1397. self.updateCanvasInitialPos()
  1398. @pyqtSlot(int)
  1399. def slot_verticalScrollBarChanged(self, value):
  1400. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1401. if maximum == 0:
  1402. yp = 0
  1403. else:
  1404. yp = float(value) / maximum
  1405. self.ui.miniCanvasPreview.setViewPosY(yp)
  1406. self.updateCanvasInitialPos()
  1407. # --------------------------------------------------------------------------------------------------------
  1408. # Canvas keyboard
  1409. @pyqtSlot(int)
  1410. def slot_noteOn(self, note):
  1411. for pluginId in self.fSelectedPlugins:
  1412. self.host.send_midi_note(pluginId, 0, note, 100)
  1413. pedit = self.getPluginEditDialog(pluginId)
  1414. pedit.noteOn(0, note, 100)
  1415. @pyqtSlot(int)
  1416. def slot_noteOff(self, note):
  1417. for pluginId in self.fSelectedPlugins:
  1418. self.host.send_midi_note(pluginId, 0, note, 0)
  1419. pedit = self.getPluginEditDialog(pluginId)
  1420. pedit.noteOff(0, note)
  1421. # --------------------------------------------------------------------------------------------------------
  1422. # Canvas keyboard (host callbacks)
  1423. @pyqtSlot(int, int, int, int)
  1424. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1425. if pluginId in self.fSelectedPlugins:
  1426. self.ui.keyboard.sendNoteOn(note, False)
  1427. @pyqtSlot(int, int, int)
  1428. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1429. if pluginId in self.fSelectedPlugins:
  1430. self.ui.keyboard.sendNoteOff(note, False)
  1431. # --------------------------------------------------------------------------------------------------------
  1432. @pyqtSlot(int)
  1433. def slot_handleUpdateCallback(self, pluginId):
  1434. pitem = self.getPluginItem(pluginId)
  1435. if pitem is None:
  1436. return
  1437. wasCompacted = pitem.isCompacted()
  1438. isCompacted = wasCompacted
  1439. for i in range(self.host.get_custom_data_count(pluginId)):
  1440. cdata = self.host.get_custom_data(pluginId, i)
  1441. if cdata['type'] == CUSTOM_DATA_TYPE_PROPERTY and cdata['key'] == "CarlaSkinIsCompacted":
  1442. isCompacted = bool(cdata['value'] == "true")
  1443. break
  1444. else:
  1445. return
  1446. if wasCompacted == isCompacted:
  1447. return
  1448. pitem.recreateWidget(True)
  1449. # --------------------------------------------------------------------------------------------------------
  1450. # MiniCanvas stuff
  1451. @pyqtSlot()
  1452. def slot_miniCanvasCheckAll(self):
  1453. self.slot_miniCanvasCheckSize()
  1454. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1455. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1456. @pyqtSlot()
  1457. def slot_miniCanvasCheckSize(self):
  1458. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1459. return
  1460. currentIndex = self.ui.tabWidget.currentIndex()
  1461. if currentIndex == 1:
  1462. width = self.ui.graphicsView.width()
  1463. height = self.ui.graphicsView.height()
  1464. else:
  1465. self.ui.tabWidget.blockSignals(True)
  1466. self.ui.tabWidget.setCurrentIndex(1)
  1467. width = self.ui.graphicsView.width()
  1468. height = self.ui.graphicsView.height()
  1469. self.ui.tabWidget.setCurrentIndex(currentIndex)
  1470. self.ui.tabWidget.blockSignals(False)
  1471. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1472. @pyqtSlot(float, float)
  1473. def slot_miniCanvasMoved(self, xp, yp):
  1474. hsb = self.ui.graphicsView.horizontalScrollBar()
  1475. vsb = self.ui.graphicsView.verticalScrollBar()
  1476. hsb.setValue(xp * hsb.maximum())
  1477. vsb.setValue(yp * vsb.maximum())
  1478. self.updateCanvasInitialPos()
  1479. # --------------------------------------------------------------------------------------------------------
  1480. # Timers
  1481. def startTimers(self):
  1482. if self.fIdleTimerFast == 0:
  1483. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1484. if self.fIdleTimerSlow == 0:
  1485. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1486. def restartTimersIfNeeded(self):
  1487. if self.fIdleTimerFast != 0:
  1488. self.killTimer(self.fIdleTimerFast)
  1489. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1490. if self.fIdleTimerSlow != 0:
  1491. self.killTimer(self.fIdleTimerSlow)
  1492. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1493. def killTimers(self):
  1494. if self.fIdleTimerFast != 0:
  1495. self.killTimer(self.fIdleTimerFast)
  1496. self.fIdleTimerFast = 0
  1497. if self.fIdleTimerSlow != 0:
  1498. self.killTimer(self.fIdleTimerSlow)
  1499. self.fIdleTimerSlow = 0
  1500. # --------------------------------------------------------------------------------------------------------
  1501. # Misc
  1502. @pyqtSlot(int)
  1503. def slot_tabChanged(self, index):
  1504. if index != 1:
  1505. return
  1506. self.ui.graphicsView.setFocus()
  1507. @pyqtSlot(int)
  1508. def slot_handleReloadAllCallback(self, pluginId):
  1509. if pluginId >= self.fPluginCount:
  1510. return
  1511. pitem = self.fPluginList[pluginId]
  1512. if pitem is None:
  1513. return
  1514. pitem.recreateWidget()
  1515. # --------------------------------------------------------------------------------------------------------
  1516. @pyqtSlot(int, int, str)
  1517. def slot_handleNSMCallback(self, value1, value2, valueStr):
  1518. # Error
  1519. if value1 == 0:
  1520. pass
  1521. # Reply
  1522. elif value1 == 1:
  1523. self.fFirstEngineInit = False
  1524. self.fSessionManagerName = valueStr
  1525. self.setProperWindowTitle()
  1526. # Open
  1527. elif value1 == 2:
  1528. self.fClientName = os.path.basename(valueStr)
  1529. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1530. self.setProperWindowTitle()
  1531. self.fCustomStopAction = 2
  1532. self.slot_engineStop(True)
  1533. return
  1534. # Save
  1535. elif value1 == 3:
  1536. self.saveProjectNow()
  1537. # Session is Loaded
  1538. elif value1 == 4:
  1539. pass
  1540. # Show Optional Gui
  1541. elif value1 == 5:
  1542. self.show()
  1543. # Hide Optional Gui
  1544. elif value1 == 6:
  1545. self.hide()
  1546. self.host.nsm_ready(value1)
  1547. # --------------------------------------------------------------------------------------------------------
  1548. def fixLogText(self, text):
  1549. return text.replace("\x1b[30;1m", "").replace("\x1b[31m", "").replace("\x1b[0m", "")
  1550. @pyqtSlot(int, int, int, float, str)
  1551. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1552. self.ui.text_logs.appendPlainText(self.fixLogText(valueStr))
  1553. @pyqtSlot(str)
  1554. def slot_handleInfoCallback(self, info):
  1555. QMessageBox.information(self, "Information", info)
  1556. @pyqtSlot(str)
  1557. def slot_handleErrorCallback(self, error):
  1558. QMessageBox.critical(self, "Error", error)
  1559. @pyqtSlot()
  1560. def slot_handleQuitCallback(self):
  1561. pass # TODO
  1562. # --------------------------------------------------------------------------------------------------------
  1563. @pyqtSlot()
  1564. def slot_handleSIGUSR1(self):
  1565. print("Got SIGUSR1 -> Saving project now")
  1566. self.slot_fileSave()
  1567. @pyqtSlot()
  1568. def slot_handleSIGTERM(self):
  1569. print("Got SIGTERM -> Closing now")
  1570. self.fCustomStopAction = 1
  1571. self.slot_engineStop(True)
  1572. # --------------------------------------------------------------------------------------------------------
  1573. # Internal stuff
  1574. def getExtraPtr(self, plugin):
  1575. ptype = plugin['type']
  1576. if ptype == PLUGIN_LADSPA:
  1577. uniqueId = plugin['uniqueId']
  1578. self.maybeLoadRDFs()
  1579. for rdfItem in self.fLadspaRdfList:
  1580. if rdfItem.UniqueID == uniqueId:
  1581. return pointer(rdfItem)
  1582. elif ptype in (PLUGIN_GIG, PLUGIN_SF2):
  1583. if plugin['name'].lower().endswith(" (16 outputs)"):
  1584. return self._true
  1585. return None
  1586. def maybeLoadRDFs(self):
  1587. if not self.fLadspaRdfNeedsUpdate:
  1588. return
  1589. self.fLadspaRdfNeedsUpdate = False
  1590. self.fLadspaRdfList = []
  1591. if not haveLRDF:
  1592. return
  1593. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1594. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1595. if os.path.exists(frLadspaFile):
  1596. frLadspa = open(frLadspaFile, 'r')
  1597. try:
  1598. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1599. except:
  1600. pass
  1601. frLadspa.close()
  1602. # --------------------------------------------------------------------------------------------------------
  1603. def getPluginItem(self, pluginId):
  1604. if pluginId >= self.fPluginCount:
  1605. return None
  1606. pitem = self.fPluginList[pluginId]
  1607. if pitem is None:
  1608. return None
  1609. #if False:
  1610. #return CarlaRackItem(self, 0, False)
  1611. return pitem
  1612. def getPluginEditDialog(self, pluginId):
  1613. if pluginId >= self.fPluginCount:
  1614. return None
  1615. pitem = self.fPluginList[pluginId]
  1616. if pitem is None:
  1617. return None
  1618. if False:
  1619. return PluginEdit(self, self.host, 0)
  1620. return pitem.getEditDialog()
  1621. def getPluginSlotWidget(self, pluginId):
  1622. if pluginId >= self.fPluginCount:
  1623. return None
  1624. pitem = self.fPluginList[pluginId]
  1625. if pitem is None:
  1626. return None
  1627. #if False:
  1628. #return AbstractPluginSlot()
  1629. return pitem.getWidget()
  1630. # --------------------------------------------------------------------------------------------------------
  1631. def waitForPendingEvents(self):
  1632. pass
  1633. # --------------------------------------------------------------------------------------------------------
  1634. # show/hide event
  1635. def showEvent(self, event):
  1636. self.refreshTransport(True)
  1637. QMainWindow.showEvent(self, event)
  1638. # set our gui as parent for all plugins UIs
  1639. if self.host.manageUIs and not (self.host.isControl or self.host.isPlugin):
  1640. if MACOS:
  1641. nsViewPtr = int(self.winId())
  1642. winIdStr = "%x" % gCarla.utils.cocoa_get_window(nsViewPtr)
  1643. else:
  1644. winIdStr = "%x" % int(self.winId())
  1645. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1646. def hideEvent(self, event):
  1647. # disable parent
  1648. if not (self.host.isControl or self.host.isPlugin):
  1649. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1650. QMainWindow.hideEvent(self, event)
  1651. # --------------------------------------------------------------------------------------------------------
  1652. # resize event
  1653. def fixCanvasPreviewSize(self):
  1654. self.ui.patchbay.resize(self.ui.rack.size())
  1655. self.slot_miniCanvasCheckSize()
  1656. def resizeEvent(self, event):
  1657. QMainWindow.resizeEvent(self, event)
  1658. if self.ui.tabWidget.currentIndex() != 1:
  1659. size = self.ui.rack.size()
  1660. self.ui.patchbay.resize(size)
  1661. self.slot_miniCanvasCheckSize()
  1662. # --------------------------------------------------------------------------------------------------------
  1663. # timer event
  1664. def idleFast(self):
  1665. self.host.engine_idle()
  1666. self.refreshTransport()
  1667. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1668. return
  1669. for pitem in self.fPluginList:
  1670. if pitem is None:
  1671. break
  1672. pitem.getWidget().idleFast()
  1673. for pluginId in self.fSelectedPlugins:
  1674. self.fPeaksCleared = False
  1675. if self.ui.peak_in.isVisible():
  1676. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1677. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1678. if self.ui.peak_out.isVisible():
  1679. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1680. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1681. return
  1682. if self.fPeaksCleared:
  1683. return
  1684. self.fPeaksCleared = True
  1685. self.ui.peak_in.displayMeter(1, 0.0, True)
  1686. self.ui.peak_in.displayMeter(2, 0.0, True)
  1687. self.ui.peak_out.displayMeter(1, 0.0, True)
  1688. self.ui.peak_out.displayMeter(2, 0.0, True)
  1689. def idleSlow(self):
  1690. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1691. return
  1692. for pitem in self.fPluginList:
  1693. if pitem is None:
  1694. break
  1695. pitem.getWidget().idleSlow()
  1696. def timerEvent(self, event):
  1697. if event.timerId() == self.fIdleTimerFast:
  1698. self.idleFast()
  1699. elif event.timerId() == self.fIdleTimerSlow:
  1700. self.idleSlow()
  1701. QMainWindow.timerEvent(self, event)
  1702. # --------------------------------------------------------------------------------------------------------
  1703. # paint event
  1704. #def paintEvent(self, event):
  1705. #QMainWindow.paintEvent(self, event)
  1706. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1707. #return
  1708. #painter = QPainter(self)
  1709. #painter.setBrush(QColor(36, 36, 36))
  1710. #painter.setPen(QColor(62, 62, 62))
  1711. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1712. # --------------------------------------------------------------------------------------------------------
  1713. # close event
  1714. def closeEvent(self, event):
  1715. self.killTimers()
  1716. self.saveSettings()
  1717. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  1718. if not self.slot_engineStop(True):
  1719. self.fCustomStopAction = 1
  1720. event.ignore()
  1721. return
  1722. QMainWindow.closeEvent(self, event)
  1723. # ------------------------------------------------------------------------------------------------
  1724. # Canvas callback
  1725. def canvasCallback(action, value1, value2, valueStr):
  1726. host = gCarla.gui.host
  1727. if action == patchcanvas.ACTION_GROUP_INFO:
  1728. pass
  1729. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1730. pass
  1731. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1732. groupId = value1
  1733. patchcanvas.splitGroup(groupId)
  1734. gCarla.gui.updateMiniCanvasLater()
  1735. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1736. groupId = value1
  1737. patchcanvas.joinGroup(groupId)
  1738. gCarla.gui.updateMiniCanvasLater()
  1739. elif action == patchcanvas.ACTION_PORT_INFO:
  1740. pass
  1741. elif action == patchcanvas.ACTION_PORT_RENAME:
  1742. pass
  1743. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1744. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1745. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1746. print("Connection failed:", host.get_last_error())
  1747. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1748. connectionId = value1
  1749. if not host.patchbay_disconnect(connectionId):
  1750. print("Disconnect failed:", host.get_last_error())
  1751. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1752. pluginId = value1
  1753. if not host.clone_plugin(pluginId):
  1754. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1755. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1756. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1757. pluginId = value1
  1758. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1759. if pwidget is not None:
  1760. pwidget.showEditDialog()
  1761. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1762. pluginId = value1
  1763. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1764. if pwidget is not None:
  1765. pwidget.showRenameDialog()
  1766. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  1767. pluginId = value1
  1768. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1769. if pwidget is not None:
  1770. pwidget.showReplaceDialog()
  1771. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1772. pluginId = value1
  1773. if not host.remove_plugin(pluginId):
  1774. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1775. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1776. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1777. pluginId = value1
  1778. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1779. if pwidget is not None:
  1780. pwidget.showCustomUI()
  1781. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  1782. gCarla.gui.showPluginActionsMenu()
  1783. # ------------------------------------------------------------------------------------------------------------
  1784. # Engine callback
  1785. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1786. # kdevelop likes this :)
  1787. if False: host = CarlaHostNull()
  1788. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1789. host.processMode = value1
  1790. host.transportMode = value2
  1791. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1792. host.processMode = value1
  1793. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1794. host.transportMode = value1
  1795. valueStr = charPtrToString(valueStr)
  1796. if action == ENGINE_CALLBACK_DEBUG:
  1797. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1798. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1799. host.PluginAddedCallback.emit(pluginId, valueStr)
  1800. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1801. host.PluginRemovedCallback.emit(pluginId)
  1802. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1803. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1804. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1805. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1806. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1807. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1808. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1809. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1810. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1811. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1812. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1813. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1814. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1815. host.ProgramChangedCallback.emit(pluginId, value1)
  1816. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1817. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1818. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1819. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1820. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1821. host.UiStateChangedCallback.emit(pluginId, value1)
  1822. elif action == ENGINE_CALLBACK_NOTE_ON:
  1823. host.NoteOnCallback.emit(pluginId, value1, value2, round(value3))
  1824. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1825. host.NoteOffCallback.emit(pluginId, value1, value2)
  1826. elif action == ENGINE_CALLBACK_UPDATE:
  1827. host.UpdateCallback.emit(pluginId)
  1828. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1829. host.ReloadInfoCallback.emit(pluginId)
  1830. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1831. host.ReloadParametersCallback.emit(pluginId)
  1832. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1833. host.ReloadProgramsCallback.emit(pluginId)
  1834. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1835. host.ReloadAllCallback.emit(pluginId)
  1836. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1837. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1838. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1839. host.PatchbayClientRemovedCallback.emit(pluginId)
  1840. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1841. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1842. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1843. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1844. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1845. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1846. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1847. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1848. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1849. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1850. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1851. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1852. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1853. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1854. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1855. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1856. host.EngineStartedCallback.emit(value1, value2, valueStr)
  1857. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1858. host.EngineStoppedCallback.emit()
  1859. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1860. host.ProcessModeChangedCallback.emit(value1)
  1861. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1862. host.TransportModeChangedCallback.emit(value1)
  1863. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1864. host.BufferSizeChangedCallback.emit(value1)
  1865. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1866. host.SampleRateChangedCallback.emit(value3)
  1867. elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
  1868. host.ProjectLoadFinishedCallback.emit()
  1869. elif action == ENGINE_CALLBACK_NSM:
  1870. host.NSMCallback.emit(value1, value2, valueStr)
  1871. elif action == ENGINE_CALLBACK_IDLE:
  1872. QApplication.instance().processEvents()
  1873. elif action == ENGINE_CALLBACK_INFO:
  1874. host.InfoCallback.emit(valueStr)
  1875. elif action == ENGINE_CALLBACK_ERROR:
  1876. host.ErrorCallback.emit(valueStr)
  1877. elif action == ENGINE_CALLBACK_QUIT:
  1878. host.QuitCallback.emit()
  1879. # ------------------------------------------------------------------------------------------------------------
  1880. # File callback
  1881. def fileCallback(ptr, action, isDir, title, filter):
  1882. ret = ("", "") if config_UseQt5 else ""
  1883. if action == FILE_CALLBACK_DEBUG:
  1884. pass
  1885. elif action == FILE_CALLBACK_OPEN:
  1886. ret = QFileDialog.getOpenFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter) ) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1887. elif action == FILE_CALLBACK_SAVE:
  1888. ret = QFileDialog.getSaveFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter), QFileDialog.ShowDirsOnly if isDir else 0x0)
  1889. if config_UseQt5:
  1890. ret = ret[0]
  1891. if not ret:
  1892. return None
  1893. # FIXME
  1894. global fileRet
  1895. fileRet = c_char_p(ret.encode("utf-8"))
  1896. retval = cast(byref(fileRet), POINTER(c_uintptr))
  1897. return retval.contents.value
  1898. # ------------------------------------------------------------------------------------------------------------
  1899. # Init host
  1900. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  1901. pathBinaries, pathResources = getPaths(libPrefix)
  1902. # --------------------------------------------------------------------------------------------------------
  1903. # Check if we should open main lib as local or global
  1904. settings = QSettings("falkTX", "Carla2")
  1905. try:
  1906. loadGlobal = settings.value(CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL, CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL, type=bool)
  1907. except:
  1908. loadGlobal = CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL
  1909. # --------------------------------------------------------------------------------------------------------
  1910. # Fail if binary dir is not found
  1911. if not os.path.exists(pathBinaries):
  1912. if failError:
  1913. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  1914. sys.exit(1)
  1915. return
  1916. # --------------------------------------------------------------------------------------------------------
  1917. # Set Carla library name
  1918. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  1919. libname = os.path.join(pathBinaries, libname)
  1920. utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION))
  1921. # --------------------------------------------------------------------------------------------------------
  1922. # Print info
  1923. print("Carla %s started, status:" % VERSION)
  1924. print(" Python version: %s" % sys.version.split(" ",1)[0])
  1925. print(" Qt version: %s" % qVersion())
  1926. print(" PyQt version: %s" % PYQT_VERSION_STR)
  1927. print(" Binary dir: %s" % pathBinaries)
  1928. print(" Resources dir: %s" % pathResources)
  1929. # --------------------------------------------------------------------------------------------------------
  1930. # Init host
  1931. if failError:
  1932. # no try
  1933. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  1934. else:
  1935. try:
  1936. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  1937. except:
  1938. host = CarlaHostQtNull()
  1939. host.isControl = isControl
  1940. host.isPlugin = isPlugin
  1941. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  1942. host.set_file_callback(fileCallback)
  1943. # If it's a plugin the paths are already set
  1944. if not isPlugin:
  1945. host.pathBinaries = pathBinaries
  1946. host.pathResources = pathResources
  1947. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  1948. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  1949. if not isControl:
  1950. host.nsmOK = host.nsm_init(os.getpid(), initName)
  1951. # --------------------------------------------------------------------------------------------------------
  1952. # Init utils
  1953. gCarla.utils = CarlaUtils(utilsname)
  1954. gCarla.utils.set_process_name(os.path.basename(initName))
  1955. try:
  1956. sys.stdout.flush()
  1957. except:
  1958. pass
  1959. sys.stdout = CarlaPrint(False)
  1960. sys.stderr = CarlaPrint(True)
  1961. if config_UseQt5:
  1962. sys.excepthook = sys_excepthook
  1963. # --------------------------------------------------------------------------------------------------------
  1964. # Done
  1965. return host
  1966. # ------------------------------------------------------------------------------------------------------------
  1967. # Load host settings
  1968. def loadHostSettings(host):
  1969. # kdevelop likes this :)
  1970. if False: host = CarlaHostNull()
  1971. settings = QSettings("falkTX", "Carla2")
  1972. try:
  1973. host.experimental = settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool)
  1974. except:
  1975. host.experimental = CARLA_DEFAULT_MAIN_EXPERIMENTAL
  1976. try:
  1977. host.exportLV2 = settings.value(CARLA_KEY_EXPERIMENTAL_EXPORT_LV2, CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT, type=bool)
  1978. except:
  1979. host.exportLV2 = CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT
  1980. try:
  1981. host.manageUIs = settings.value(CARLA_KEY_ENGINE_MANAGE_UIS, CARLA_DEFAULT_MANAGE_UIS, type=bool)
  1982. except:
  1983. host.manageUIs = CARLA_DEFAULT_MANAGE_UIS
  1984. try:
  1985. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  1986. except:
  1987. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  1988. try:
  1989. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  1990. except:
  1991. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  1992. try:
  1993. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  1994. except:
  1995. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  1996. try:
  1997. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  1998. except:
  1999. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  2000. try:
  2001. host.preventBadBehaviour = settings.value(CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, type=bool)
  2002. except:
  2003. host.preventBadBehaviour = CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR
  2004. try:
  2005. host.showLogs = settings.value(CARLA_KEY_MAIN_SHOW_LOGS, CARLA_DEFAULT_MAIN_SHOW_LOGS, type=bool)
  2006. except:
  2007. host.showLogs = CARLA_DEFAULT_MAIN_SHOW_LOGS
  2008. try:
  2009. host.showPluginBridges = settings.value(CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES, type=bool)
  2010. except:
  2011. host.showPluginBridges = CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES
  2012. try:
  2013. host.showWineBridges = settings.value(CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES, type=bool)
  2014. except:
  2015. host.showWineBridges = CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES
  2016. try:
  2017. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  2018. except:
  2019. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  2020. try:
  2021. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  2022. except:
  2023. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  2024. if host.isPlugin:
  2025. return
  2026. # enums
  2027. if host.audioDriverForced is None:
  2028. try:
  2029. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  2030. except:
  2031. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  2032. if not host.processModeForced:
  2033. try:
  2034. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  2035. except:
  2036. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  2037. host.nextProcessMode = host.processMode
  2038. # --------------------------------------------------------------------------------------------------------
  2039. # fix things if needed
  2040. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  2041. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  2042. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  2043. if gCarla.nogui:
  2044. host.showLogs = False
  2045. # --------------------------------------------------------------------------------------------------------
  2046. # run headless host now if nogui option enabled
  2047. if gCarla.nogui:
  2048. runHostWithoutUI(host)
  2049. # ------------------------------------------------------------------------------------------------------------
  2050. # Set host settings
  2051. def setHostSettings(host):
  2052. # kdevelop likes this :)
  2053. if False: host = CarlaHostNull()
  2054. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  2055. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  2056. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  2057. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  2058. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  2059. host.set_engine_option(ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT, host.showLogs, "")
  2060. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  2061. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  2062. if host.isPlugin:
  2063. return
  2064. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  2065. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, "")
  2066. # ------------------------------------------------------------------------------------------------------------
  2067. # Set Engine settings according to carla preferences. Returns selected audio driver.
  2068. def setEngineSettings(host):
  2069. # kdevelop likes this :)
  2070. if False: host = CarlaHostNull()
  2071. # --------------------------------------------------------------------------------------------------------
  2072. # do nothing if control
  2073. if host.isControl:
  2074. return "Control"
  2075. # --------------------------------------------------------------------------------------------------------
  2076. settings = QSettings("falkTX", "Carla2")
  2077. # --------------------------------------------------------------------------------------------------------
  2078. # main settings
  2079. setHostSettings(host)
  2080. # --------------------------------------------------------------------------------------------------------
  2081. # plugin paths
  2082. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  2083. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  2084. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  2085. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  2086. GIG_PATH = toList(settings.value(CARLA_KEY_PATHS_GIG, CARLA_DEFAULT_GIG_PATH))
  2087. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  2088. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  2089. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  2090. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  2091. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  2092. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  2093. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_GIG, splitter.join(GIG_PATH))
  2094. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  2095. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  2096. # --------------------------------------------------------------------------------------------------------
  2097. # don't continue if plugin
  2098. if host.isPlugin:
  2099. return "Plugin"
  2100. # --------------------------------------------------------------------------------------------------------
  2101. # driver and device settings
  2102. # driver name
  2103. if host.audioDriverForced is not None:
  2104. audioDriver = host.audioDriverForced
  2105. else:
  2106. try:
  2107. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  2108. except:
  2109. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  2110. # driver options
  2111. try:
  2112. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  2113. except:
  2114. audioDevice = ""
  2115. try:
  2116. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  2117. except:
  2118. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  2119. try:
  2120. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  2121. except:
  2122. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  2123. try:
  2124. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  2125. except:
  2126. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  2127. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  2128. host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  2129. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  2130. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  2131. # --------------------------------------------------------------------------------------------------------
  2132. # fix things if needed
  2133. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  2134. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  2135. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")
  2136. # --------------------------------------------------------------------------------------------------------
  2137. # wine settings
  2138. optWineExecutable = settings.value(CARLA_KEY_WINE_EXECUTABLE, CARLA_DEFAULT_WINE_EXECUTABLE, type=str)
  2139. optWineAutoPrefix = settings.value(CARLA_KEY_WINE_AUTO_PREFIX, CARLA_DEFAULT_WINE_AUTO_PREFIX, type=bool)
  2140. optWineFallbackPrefix = settings.value(CARLA_KEY_WINE_FALLBACK_PREFIX, CARLA_DEFAULT_WINE_FALLBACK_PREFIX, type=str)
  2141. optWineRtPrioEnabled = settings.value(CARLA_KEY_WINE_RT_PRIO_ENABLED, CARLA_DEFAULT_WINE_RT_PRIO_ENABLED, type=bool)
  2142. optWineBaseRtPrio = settings.value(CARLA_KEY_WINE_BASE_RT_PRIO, CARLA_DEFAULT_WINE_BASE_RT_PRIO, type=int)
  2143. optWineServerRtPrio = settings.value(CARLA_KEY_WINE_SERVER_RT_PRIO, CARLA_DEFAULT_WINE_SERVER_RT_PRIO, type=int)
  2144. host.set_engine_option(ENGINE_OPTION_WINE_EXECUTABLE, 0, optWineExecutable)
  2145. host.set_engine_option(ENGINE_OPTION_WINE_AUTO_PREFIX, 1 if optWineAutoPrefix else 0, "")
  2146. host.set_engine_option(ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, os.path.expanduser(optWineFallbackPrefix))
  2147. host.set_engine_option(ENGINE_OPTION_WINE_RT_PRIO_ENABLED, 1 if optWineRtPrioEnabled else 0, "")
  2148. host.set_engine_option(ENGINE_OPTION_WINE_BASE_RT_PRIO, optWineBaseRtPrio, "")
  2149. host.set_engine_option(ENGINE_OPTION_WINE_SERVER_RT_PRIO, optWineServerRtPrio, "")
  2150. # --------------------------------------------------------------------------------------------------------
  2151. # return selected driver name
  2152. return audioDriver
  2153. # ------------------------------------------------------------------------------------------------------------
  2154. # Run Carla without showing UI
  2155. def runHostWithoutUI(host):
  2156. # kdevelop likes this :)
  2157. if False: host = CarlaHostNull()
  2158. # --------------------------------------------------------------------------------------------------------
  2159. # Some initial checks
  2160. if not gCarla.nogui:
  2161. return
  2162. projectFile = getInitialProjectFile(QCoreApplication.instance(), True)
  2163. if not projectFile:
  2164. print("Carla no-gui mode can only be used together with a project file.")
  2165. sys.exit(1)
  2166. # --------------------------------------------------------------------------------------------------------
  2167. # Additional imports
  2168. from time import sleep
  2169. # --------------------------------------------------------------------------------------------------------
  2170. # Init engine
  2171. audioDriver = setEngineSettings(host)
  2172. if not host.engine_init(audioDriver, "Carla"):
  2173. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  2174. sys.exit(1)
  2175. if not host.load_project(projectFile):
  2176. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  2177. host.engine_close()
  2178. sys.exit(1)
  2179. # --------------------------------------------------------------------------------------------------------
  2180. # Idle
  2181. while host.is_engine_running() and not gCarla.term:
  2182. host.engine_idle()
  2183. sleep(0.5)
  2184. # --------------------------------------------------------------------------------------------------------
  2185. # Stop
  2186. host.engine_close()
  2187. sys.exit(0)
  2188. # ------------------------------------------------------------------------------------------------------------