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.

2669 lines
102KB

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