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.

2801 lines
108KB

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