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.

2719 lines
104KB

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