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.

3226 lines
126KB

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