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.

2800 lines
108KB

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