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.

2738 lines
105KB

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