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.

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