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.

1126 lines
39KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla patchbay widget code
  4. # Copyright (C) 2011-2014 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 QPointF, QTimer
  24. from PyQt5.QtGui import QImage
  25. from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
  26. from PyQt5.QtWidgets import QFrame, QGraphicsView, QGridLayout
  27. else:
  28. from PyQt4.QtCore import QPointF, QTimer
  29. from PyQt4.QtGui import QFrame, QGraphicsView, QGridLayout, QImage, QPrinter, QPrintDialog
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (Custom Stuff)
  32. import patchcanvas
  33. from carla_widgets import *
  34. from digitalpeakmeter import DigitalPeakMeter
  35. from pixmapkeyboard import PixmapKeyboardHArea
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Try Import OpenGL
  38. try:
  39. if config_UseQt5:
  40. from PyQt5.QtOpenGL import QGLWidget
  41. else:
  42. from PyQt4.QtOpenGL import QGLWidget
  43. hasGL = True
  44. except:
  45. hasGL = False
  46. # ------------------------------------------------------------------------------------------------------------
  47. # Carla Canvas defaults
  48. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  49. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  50. # ------------------------------------------------------------------------------------------------
  51. # Patchbay info class, used in main carla as replacement for PluginEdit
  52. class PluginInfo(object):
  53. def __init__(self, parent, pluginId):
  54. object.__init__(self)
  55. self.fPluginId = pluginId
  56. #------------------------------------------------------------------
  57. def setId(self, idx):
  58. self.fPluginId = idx
  59. #------------------------------------------------------------------
  60. def close(self):
  61. pass
  62. def setName(self, name):
  63. pass
  64. def setParameterValue(self, parameterId, value):
  65. pass
  66. def reloadAll(self):
  67. pass
  68. def idleSlow(self):
  69. pass
  70. # ------------------------------------------------------------------------------------------------
  71. # Patchbay widget
  72. class CarlaPatchbayW(QFrame, PluginEditParentMeta, metaclass=PyQtMetaClass):
  73. def __init__(self, parent, doSetup = True, onlyPatchbay = True, is3D = False):
  74. QFrame.__init__(self, parent)
  75. self.fLayout = QGridLayout(self)
  76. self.fLayout.setContentsMargins(0, 0, 0, 0)
  77. self.fLayout.setSpacing(1)
  78. self.setLayout(self.fLayout)
  79. self.fView = QGraphicsView(self)
  80. self.fKeys = PixmapKeyboardHArea(self)
  81. self.fPeaksIn = DigitalPeakMeter(self)
  82. self.fPeaksOut = DigitalPeakMeter(self)
  83. self.fPeaksCleared = True
  84. self.fPeaksIn.setColor(DigitalPeakMeter.BLUE)
  85. self.fPeaksIn.setChannels(2)
  86. self.fPeaksIn.setOrientation(DigitalPeakMeter.VERTICAL)
  87. self.fPeaksIn.setFixedWidth(25)
  88. self.fPeaksOut.setColor(DigitalPeakMeter.GREEN)
  89. self.fPeaksOut.setChannels(2)
  90. self.fPeaksOut.setOrientation(DigitalPeakMeter.VERTICAL)
  91. self.fPeaksOut.setFixedWidth(25)
  92. self.fLayout.addWidget(self.fPeaksIn, 0, 0)
  93. self.fLayout.addWidget(self.fView, 0, 1) # self.fViewWidget if is3D else
  94. self.fLayout.addWidget(self.fPeaksOut, 0, 2)
  95. self.fLayout.addWidget(self.fKeys, 1, 0, 1, 0)
  96. # -------------------------------------------------------------
  97. # Internal stuff
  98. self.fParent = parent
  99. self.fPluginCount = 0
  100. self.fPluginList = []
  101. self.fIsOnlyPatchbay = onlyPatchbay
  102. self.fSelectedPlugins = []
  103. self.fCanvasWidth = 0
  104. self.fCanvasHeight = 0
  105. # -------------------------------------------------------------
  106. # Set-up Canvas Preview
  107. self.fMiniCanvasPreview = self.fParent.ui.miniCanvasPreview
  108. self.fMiniCanvasPreview.setRealParent(self)
  109. self.fMovingViaMiniCanvas = False
  110. # -------------------------------------------------------------
  111. # Set-up Canvas
  112. self.scene = patchcanvas.PatchScene(self, self.fView)
  113. self.fView.setScene(self.scene)
  114. self.fView.setRenderHint(QPainter.Antialiasing, bool(parent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  115. if parent.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL: # and not is3D:
  116. self.fViewWidget = QGLWidget(self)
  117. self.fView.setViewport(self.fViewWidget)
  118. self.fView.setRenderHint(QPainter.HighQualityAntialiasing, parent.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  119. self.setupCanvas()
  120. QTimer.singleShot(100, self.slot_restoreScrollbarValues)
  121. # -------------------------------------------------------------
  122. # Connect actions to functions
  123. parent.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  124. parent.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  125. self.fView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  126. self.fView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  127. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  128. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  129. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  130. self.fMiniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  131. self.fKeys.keyboard.noteOn.connect(self.slot_noteOn)
  132. self.fKeys.keyboard.noteOff.connect(self.slot_noteOff)
  133. # -------------------------------------------------------------
  134. # Load Settings
  135. settings = QSettings()
  136. showMeters = settings.value("ShowMeters", False, type=bool)
  137. self.fParent.ui.act_settings_show_meters.setChecked(showMeters)
  138. self.fPeaksIn.setVisible(showMeters)
  139. self.fPeaksOut.setVisible(showMeters)
  140. showKeyboard = settings.value("ShowKeyboard", not(MACOS or WINDOWS), type=bool)
  141. self.fParent.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  142. self.fKeys.setVisible(showKeyboard)
  143. # -------------------------------------------------------------
  144. # Connect actions to functions (part 2)
  145. if not doSetup: return
  146. parent.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  147. parent.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  148. parent.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  149. parent.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  150. parent.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  151. parent.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  152. parent.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  153. parent.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  154. parent.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  155. parent.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  156. parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  157. parent.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  158. parent.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  159. parent.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  160. parent.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  161. parent.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  162. parent.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  163. parent.ui.act_canvas_print.triggered.connect(self.slot_canvasPrint)
  164. parent.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  165. parent.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  166. parent.ParameterValueChangedCallback.connect(self.slot_handleParameterValueChangedCallback)
  167. parent.ParameterDefaultChangedCallback.connect(self.slot_handleParameterDefaultChangedCallback)
  168. parent.ParameterMidiChannelChangedCallback.connect(self.slot_handleParameterMidiChannelChangedCallback)
  169. parent.ParameterMidiCcChangedCallback.connect(self.slot_handleParameterMidiCcChangedCallback)
  170. parent.ProgramChangedCallback.connect(self.slot_handleProgramChangedCallback)
  171. parent.MidiProgramChangedCallback.connect(self.slot_handleMidiProgramChangedCallback)
  172. parent.OptionChangedCallback.connect(self.slot_handleOptionChangedCallback)
  173. parent.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  174. parent.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  175. parent.UpdateCallback.connect(self.slot_handleUpdateCallback)
  176. parent.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  177. parent.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  178. parent.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  179. parent.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  180. parent.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  181. parent.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  182. parent.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  183. parent.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  184. parent.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  185. parent.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  186. parent.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  187. parent.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  188. parent.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  189. # -----------------------------------------------------------------
  190. def getPluginCount(self):
  191. return self.fPluginCount
  192. # -----------------------------------------------------------------
  193. def addPlugin(self, pluginId, isProjectLoading):
  194. if self.fIsOnlyPatchbay:
  195. pitem = PluginEdit(self, gCarla.host, pluginId)
  196. else:
  197. pitem = PluginInfo(self, pluginId)
  198. self.fPluginList.append(pitem)
  199. self.fPluginCount += 1
  200. if self.fIsOnlyPatchbay and not isProjectLoading:
  201. gCarla.host.set_active(pluginId, True)
  202. def removePlugin(self, pluginId):
  203. patchcanvas.handlePluginRemoved(pluginId)
  204. if pluginId in self.fSelectedPlugins:
  205. self.clearSideStuff()
  206. if pluginId >= self.fPluginCount:
  207. return
  208. pitem = self.fPluginList[pluginId]
  209. if pitem is None:
  210. return
  211. self.fPluginCount -= 1
  212. self.fPluginList.pop(pluginId)
  213. pitem.close()
  214. del pitem
  215. # push all plugins 1 slot back
  216. for i in range(pluginId, self.fPluginCount):
  217. pitem = self.fPluginList[i]
  218. pitem.setId(i)
  219. def renamePlugin(self, pluginId, newName):
  220. if pluginId >= self.fPluginCount:
  221. return
  222. pitem = self.fPluginList[pluginId]
  223. if pitem is None:
  224. return
  225. pitem.setName(newName)
  226. def disablePlugin(self, pluginId, errorMsg):
  227. if pluginId >= self.fPluginCount:
  228. return
  229. pitem = self.fPluginList[pluginId]
  230. if pitem is None:
  231. return
  232. def removeAllPlugins(self):
  233. for pitem in self.fPluginList:
  234. if pitem is None:
  235. break
  236. pitem.close()
  237. del pitem
  238. self.fPluginCount = 0
  239. self.fPluginList = []
  240. self.clearSideStuff()
  241. patchcanvas.handlePluginRemoved(0)
  242. # -----------------------------------------------------------------
  243. def engineStarted(self):
  244. pass
  245. def engineStopped(self):
  246. patchcanvas.clear()
  247. def engineChanged(self):
  248. pass
  249. # -----------------------------------------------------------------
  250. def idleFast(self):
  251. if self.fPluginCount == 0:
  252. return
  253. for pluginId in self.fSelectedPlugins:
  254. self.fPeaksCleared = False
  255. if self.fPeaksIn.isVisible():
  256. self.fPeaksIn.displayMeter(1, gCarla.host.get_input_peak_value(pluginId, True))
  257. self.fPeaksIn.displayMeter(2, gCarla.host.get_input_peak_value(pluginId, False))
  258. if self.fPeaksOut.isVisible():
  259. self.fPeaksOut.displayMeter(1, gCarla.host.get_output_peak_value(pluginId, True))
  260. self.fPeaksOut.displayMeter(2, gCarla.host.get_output_peak_value(pluginId, False))
  261. return
  262. if self.fPeaksCleared:
  263. return
  264. self.fPeaksCleared = True
  265. self.fPeaksIn.displayMeter(1, 0.0, True)
  266. self.fPeaksIn.displayMeter(2, 0.0, True)
  267. self.fPeaksOut.displayMeter(1, 0.0, True)
  268. self.fPeaksOut.displayMeter(2, 0.0, True)
  269. def idleSlow(self):
  270. for pitem in self.fPluginList:
  271. if pitem is None:
  272. break
  273. pitem.idleSlow()
  274. # -----------------------------------------------------------------
  275. def projectLoadingStarted(self):
  276. pass
  277. def projectLoadingFinished(self):
  278. QTimer.singleShot(1000, self.slot_canvasRefresh)
  279. # -----------------------------------------------------------------
  280. def saveSettings(self, settings):
  281. settings.setValue("ShowMeters", self.fParent.ui.act_settings_show_meters.isChecked())
  282. settings.setValue("ShowKeyboard", self.fParent.ui.act_settings_show_keyboard.isChecked())
  283. settings.setValue("HorizontalScrollBarValue", self.fView.horizontalScrollBar().value())
  284. settings.setValue("VerticalScrollBarValue", self.fView.verticalScrollBar().value())
  285. def showEditDialog(self, pluginId):
  286. if pluginId >= self.fPluginCount:
  287. return
  288. pitem = self.fPluginList[pluginId]
  289. if pitem is None:
  290. return
  291. pitem.show()
  292. # -----------------------------------------------------------------
  293. # called by PluginEdit to plugin skin parent, ignored here
  294. def editDialogChanged(self, visible):
  295. pass
  296. def pluginHintsChanged(self, hints):
  297. pass
  298. def parameterValueChanged(self, parameterId, value):
  299. pass
  300. def programChanged(self, index):
  301. pass
  302. def midiProgramChanged(self, index):
  303. pass
  304. def notePressed(self, note):
  305. pass
  306. def noteReleased(self, note):
  307. pass
  308. # -----------------------------------------------------------------
  309. def clearSideStuff(self):
  310. self.scene.clearSelection()
  311. self.fSelectedPlugins = []
  312. self.fKeys.keyboard.allNotesOff(False)
  313. self.fKeys.setEnabled(False)
  314. self.fPeaksCleared = True
  315. self.fPeaksIn.displayMeter(1, 0.0, True)
  316. self.fPeaksIn.displayMeter(2, 0.0, True)
  317. self.fPeaksOut.displayMeter(1, 0.0, True)
  318. self.fPeaksOut.displayMeter(2, 0.0, True)
  319. def setupCanvas(self):
  320. pOptions = patchcanvas.options_t()
  321. pOptions.theme_name = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  322. pOptions.auto_hide_groups = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  323. pOptions.use_bezier_lines = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  324. pOptions.antialiasing = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  325. pOptions.eyecandy = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
  326. pFeatures = patchcanvas.features_t()
  327. pFeatures.group_info = False
  328. pFeatures.group_rename = False
  329. pFeatures.port_info = False
  330. pFeatures.port_rename = False
  331. pFeatures.handle_group_pos = True
  332. patchcanvas.setOptions(pOptions)
  333. patchcanvas.setFeatures(pFeatures)
  334. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  335. tryCanvasSize = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  336. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  337. self.fCanvasWidth = int(tryCanvasSize[0])
  338. self.fCanvasHeight = int(tryCanvasSize[1])
  339. else:
  340. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  341. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  342. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  343. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  344. self.fView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  345. self.themeData = [self.fCanvasWidth, self.fCanvasHeight, patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color()]
  346. def updateCanvasInitialPos(self):
  347. x = self.fView.horizontalScrollBar().value() + self.width()/4
  348. y = self.fView.verticalScrollBar().value() + self.height()/4
  349. patchcanvas.setInitialPos(x, y)
  350. # -----------------------------------------------------------------
  351. @pyqtSlot(bool)
  352. def slot_showCanvasMeters(self, yesNo):
  353. self.fPeaksIn.setVisible(yesNo)
  354. self.fPeaksOut.setVisible(yesNo)
  355. @pyqtSlot(bool)
  356. def slot_showCanvasKeyboard(self, yesNo):
  357. self.fKeys.setVisible(yesNo)
  358. # -----------------------------------------------------------------
  359. @pyqtSlot()
  360. def slot_miniCanvasCheckAll(self):
  361. self.slot_miniCanvasCheckSize()
  362. self.slot_horizontalScrollBarChanged(self.fView.horizontalScrollBar().value())
  363. self.slot_verticalScrollBarChanged(self.fView.verticalScrollBar().value())
  364. @pyqtSlot()
  365. def slot_miniCanvasCheckSize(self):
  366. self.fMiniCanvasPreview.setViewSize(float(self.width()) / self.fCanvasWidth, float(self.height()) / self.fCanvasHeight)
  367. @pyqtSlot(int)
  368. def slot_horizontalScrollBarChanged(self, value):
  369. if self.fMovingViaMiniCanvas: return
  370. maximum = self.fView.horizontalScrollBar().maximum()
  371. if maximum == 0:
  372. xp = 0
  373. else:
  374. xp = float(value) / maximum
  375. self.fMiniCanvasPreview.setViewPosX(xp)
  376. self.updateCanvasInitialPos()
  377. @pyqtSlot(int)
  378. def slot_verticalScrollBarChanged(self, value):
  379. if self.fMovingViaMiniCanvas: return
  380. maximum = self.fView.verticalScrollBar().maximum()
  381. if maximum == 0:
  382. yp = 0
  383. else:
  384. yp = float(value) / maximum
  385. self.fMiniCanvasPreview.setViewPosY(yp)
  386. self.updateCanvasInitialPos()
  387. @pyqtSlot()
  388. def slot_restoreScrollbarValues(self):
  389. settings = QSettings()
  390. self.fView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.fView.horizontalScrollBar().maximum()/2, type=int))
  391. self.fView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.fView.verticalScrollBar().maximum()/2, type=int))
  392. # -----------------------------------------------------------------
  393. @pyqtSlot(float)
  394. def slot_canvasScaleChanged(self, scale):
  395. self.fMiniCanvasPreview.setViewScale(scale)
  396. @pyqtSlot(int, int, QPointF)
  397. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  398. self.fMiniCanvasPreview.update()
  399. @pyqtSlot(list)
  400. def slot_canvasPluginSelected(self, pluginList):
  401. self.fKeys.keyboard.allNotesOff(False)
  402. self.fKeys.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  403. self.fSelectedPlugins = pluginList
  404. @pyqtSlot(float, float)
  405. def slot_miniCanvasMoved(self, xp, yp):
  406. self.fMovingViaMiniCanvas = True
  407. self.fView.horizontalScrollBar().setValue(xp * self.fView.horizontalScrollBar().maximum())
  408. self.fView.verticalScrollBar().setValue(yp * self.fView.verticalScrollBar().maximum())
  409. self.fMovingViaMiniCanvas = False
  410. self.updateCanvasInitialPos()
  411. # -----------------------------------------------------------------
  412. @pyqtSlot(int)
  413. def slot_noteOn(self, note):
  414. for pluginId in self.fSelectedPlugins:
  415. gCarla.host.send_midi_note(pluginId, 0, note, 100)
  416. @pyqtSlot(int)
  417. def slot_noteOff(self, note):
  418. for pluginId in self.fSelectedPlugins:
  419. gCarla.host.send_midi_note(pluginId, 0, note, 0)
  420. # -----------------------------------------------------------------
  421. @pyqtSlot()
  422. def slot_pluginsEnable(self):
  423. if not gCarla.host.is_engine_running():
  424. return
  425. for i in range(self.fPluginCount):
  426. gCarla.host.set_active(i, True)
  427. @pyqtSlot()
  428. def slot_pluginsDisable(self):
  429. if not gCarla.host.is_engine_running():
  430. return
  431. for i in range(self.fPluginCount):
  432. gCarla.host.set_active(i, False)
  433. @pyqtSlot()
  434. def slot_pluginsVolume100(self):
  435. if not gCarla.host.is_engine_running():
  436. return
  437. for i in range(self.fPluginCount):
  438. pitem = self.fPluginList[i]
  439. if pitem is None:
  440. break
  441. if pitem.getHints() & PLUGIN_CAN_VOLUME:
  442. pitem.setParameterValue(PARAMETER_VOLUME, 1.0)
  443. gCarla.host.set_volume(i, 1.0)
  444. @pyqtSlot()
  445. def slot_pluginsMute(self):
  446. if not gCarla.host.is_engine_running():
  447. return
  448. for i in range(self.fPluginCount):
  449. pitem = self.fPluginList[i]
  450. if pitem is None:
  451. break
  452. if pitem.getHints() & PLUGIN_CAN_VOLUME:
  453. pitem.setParameterValue(PARAMETER_VOLUME, 0.0)
  454. gCarla.host.set_volume(i, 0.0)
  455. @pyqtSlot()
  456. def slot_pluginsWet100(self):
  457. if not gCarla.host.is_engine_running():
  458. return
  459. for i in range(self.fPluginCount):
  460. pitem = self.fPluginList[i]
  461. if pitem is None:
  462. break
  463. if pitem.getHints() & PLUGIN_CAN_DRYWET:
  464. pitem.setParameterValue(PARAMETER_DRYWET, 1.0)
  465. gCarla.host.set_drywet(i, 1.0)
  466. @pyqtSlot()
  467. def slot_pluginsBypass(self):
  468. if not gCarla.host.is_engine_running():
  469. return
  470. for i in range(self.fPluginCount):
  471. pitem = self.fPluginList[i]
  472. if pitem is None:
  473. break
  474. if pitem.getHints() & PLUGIN_CAN_DRYWET:
  475. pitem.setParameterValue(PARAMETER_DRYWET, 0.0)
  476. gCarla.host.set_drywet(i, 0.0)
  477. @pyqtSlot()
  478. def slot_pluginsCenter(self):
  479. if not gCarla.host.is_engine_running():
  480. return
  481. for i in range(self.fPluginCount):
  482. pitem = self.fPluginList[i]
  483. if pitem is None:
  484. break
  485. if pitem.getHints() & PLUGIN_CAN_BALANCE:
  486. pitem.setParameterValue(PARAMETER_BALANCE_LEFT, -1.0)
  487. pitem.setParameterValue(PARAMETER_BALANCE_RIGHT, 1.0)
  488. gCarla.host.set_balance_left(i, -1.0)
  489. gCarla.host.set_balance_right(i, 1.0)
  490. if pitem.getHints() & PLUGIN_CAN_PANNING:
  491. pitem.setParameterValue(PARAMETER_PANNING, 0.0)
  492. gCarla.host.set_panning(i, 0.0)
  493. # -----------------------------------------------------------------
  494. @pyqtSlot()
  495. def slot_configureCarla(self):
  496. if self.fParent is None or not self.fParent.openSettingsWindow(True, hasGL):
  497. return
  498. self.fParent.loadSettings(False)
  499. patchcanvas.clear()
  500. self.setupCanvas()
  501. self.fParent.updateContainer(self.themeData)
  502. self.slot_miniCanvasCheckAll()
  503. if gCarla.host is not None and gCarla.host.is_engine_running():
  504. gCarla.host.patchbay_refresh(gCarla.externalPatchbay)
  505. # -----------------------------------------------------------------
  506. @pyqtSlot(int, int, float)
  507. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  508. if pluginId >= self.fPluginCount:
  509. return
  510. pitem = self.fPluginList[pluginId]
  511. if pitem is None:
  512. return
  513. pitem.setParameterValue(index, value)
  514. @pyqtSlot(int, int, float)
  515. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  516. if pluginId >= self.fPluginCount:
  517. return
  518. pitem = self.fPluginList[pluginId]
  519. if pitem is None:
  520. return
  521. pitem.setParameterDefault(index, value)
  522. @pyqtSlot(int, int, int)
  523. def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
  524. if pluginId >= self.fPluginCount:
  525. return
  526. pitem = self.fPluginList[pluginId]
  527. if pitem is None:
  528. return
  529. pitem.setParameterMidiControl(index, cc)
  530. @pyqtSlot(int, int, int)
  531. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  532. if pluginId >= self.fPluginCount:
  533. return
  534. pitem = self.fPluginList[pluginId]
  535. if pitem is None:
  536. return
  537. pitem.setParameterMidiChannel(index, channel)
  538. # -----------------------------------------------------------------
  539. @pyqtSlot(int, int)
  540. def slot_handleProgramChangedCallback(self, pluginId, index):
  541. if pluginId >= self.fPluginCount:
  542. return
  543. pitem = self.fPluginList[pluginId]
  544. if pitem is None:
  545. return
  546. pitem.setProgram(index)
  547. @pyqtSlot(int, int)
  548. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  549. if pluginId >= self.fPluginCount:
  550. return
  551. pitem = self.fPluginList[pluginId]
  552. if pitem is None:
  553. return
  554. pitem.setMidiProgram(index)
  555. # -----------------------------------------------------------------
  556. @pyqtSlot(int, int, bool)
  557. def slot_handleOptionChangedCallback(self, pluginId, option, yesNo):
  558. if pluginId >= self.fPluginCount:
  559. return
  560. pitem = self.fPluginList[pluginId]
  561. if pitem is None:
  562. return
  563. pitem.setOption(option, yesNo)
  564. # -----------------------------------------------------------------
  565. @pyqtSlot(int, int, int, int)
  566. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  567. if pluginId in self.fSelectedPlugins:
  568. self.fKeys.keyboard.sendNoteOn(note, False)
  569. if not self.fIsOnlyPatchbay:
  570. return
  571. if pluginId >= self.fPluginCount:
  572. return
  573. pitem = self.fPluginList[pluginId]
  574. if pitem is None:
  575. return
  576. pitem.sendNoteOn(channel, note)
  577. @pyqtSlot(int, int, int)
  578. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  579. if pluginId in self.fSelectedPlugins:
  580. self.fKeys.keyboard.sendNoteOff(note, False)
  581. if not self.fIsOnlyPatchbay:
  582. return
  583. if pluginId >= self.fPluginCount:
  584. return
  585. pitem = self.fPluginList[pluginId]
  586. if pitem is None:
  587. return
  588. pitem.sendNoteOff(channel, note)
  589. # -----------------------------------------------------------------
  590. @pyqtSlot(int)
  591. def slot_handleUpdateCallback(self, pluginId):
  592. if pluginId >= self.fPluginCount:
  593. return
  594. pitem = self.fPluginList[pluginId]
  595. if pitem is None:
  596. return
  597. pitem.updateInfo()
  598. @pyqtSlot(int)
  599. def slot_handleReloadInfoCallback(self, pluginId):
  600. if pluginId >= self.fPluginCount:
  601. return
  602. pitem = self.fPluginList[pluginId]
  603. if pitem is None:
  604. return
  605. pitem.reloadInfo()
  606. @pyqtSlot(int)
  607. def slot_handleReloadParametersCallback(self, pluginId):
  608. if pluginId >= self.fPluginCount:
  609. return
  610. pitem = self.fPluginList[pluginId]
  611. if pitem is None:
  612. return
  613. pitem.reloadParameters()
  614. @pyqtSlot(int)
  615. def slot_handleReloadProgramsCallback(self, pluginId):
  616. if pluginId >= self.fPluginCount:
  617. return
  618. pitem = self.fPluginList[pluginId]
  619. if pitem is None:
  620. return
  621. pitem.reloadPrograms()
  622. @pyqtSlot(int)
  623. def slot_handleReloadAllCallback(self, pluginId):
  624. if pluginId >= self.fPluginCount:
  625. return
  626. pitem = self.fPluginList[pluginId]
  627. if pitem is None:
  628. return
  629. pitem.reloadAll()
  630. # -----------------------------------------------------------------
  631. @pyqtSlot(int, int, int, str)
  632. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  633. pcSplit = patchcanvas.SPLIT_UNDEF
  634. pcIcon = patchcanvas.ICON_APPLICATION
  635. if clientIcon == PATCHBAY_ICON_PLUGIN:
  636. pcIcon = patchcanvas.ICON_PLUGIN
  637. if clientIcon == PATCHBAY_ICON_HARDWARE:
  638. pcIcon = patchcanvas.ICON_HARDWARE
  639. elif clientIcon == PATCHBAY_ICON_CARLA:
  640. pass
  641. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  642. pcIcon = patchcanvas.ICON_DISTRHO
  643. elif clientIcon == PATCHBAY_ICON_FILE:
  644. pcIcon = patchcanvas.ICON_FILE
  645. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  646. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  647. if pluginId < 0:
  648. return
  649. if pluginId >= self.fPluginCount:
  650. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  651. return
  652. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(gCarla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  653. @pyqtSlot(int)
  654. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  655. #if not self.fEngineStarted: return
  656. patchcanvas.removeGroup(clientId)
  657. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  658. @pyqtSlot(int, str)
  659. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  660. patchcanvas.renameGroup(clientId, newClientName)
  661. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  662. @pyqtSlot(int, int, int)
  663. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  664. pcIcon = patchcanvas.ICON_APPLICATION
  665. if clientIcon == PATCHBAY_ICON_PLUGIN:
  666. pcIcon = patchcanvas.ICON_PLUGIN
  667. if clientIcon == PATCHBAY_ICON_HARDWARE:
  668. pcIcon = patchcanvas.ICON_HARDWARE
  669. elif clientIcon == PATCHBAY_ICON_CARLA:
  670. pass
  671. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  672. pcIcon = patchcanvas.ICON_DISTRHO
  673. elif clientIcon == PATCHBAY_ICON_FILE:
  674. pcIcon = patchcanvas.ICON_FILE
  675. patchcanvas.setGroupIcon(clientId, pcIcon)
  676. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  677. if pluginId < 0:
  678. return
  679. if pluginId >= self.fPluginCount:
  680. print("sorry, can't map this plugin to canvas client", pluginId, self.getPluginCount())
  681. return
  682. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(gCarla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  683. @pyqtSlot(int, int, int, str)
  684. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  685. isAlternate = False
  686. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  687. portMode = patchcanvas.PORT_MODE_INPUT
  688. else:
  689. portMode = patchcanvas.PORT_MODE_OUTPUT
  690. if (portFlags & PATCHBAY_PORT_TYPE_AUDIO):
  691. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  692. elif (portFlags & PATCHBAY_PORT_TYPE_CV):
  693. isAlternate = True
  694. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  695. elif (portFlags & PATCHBAY_PORT_TYPE_MIDI):
  696. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  697. else:
  698. portType = patchcanvas.PORT_TYPE_NULL
  699. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  700. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  701. @pyqtSlot(int, int)
  702. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  703. #if not self.fEngineStarted: return
  704. patchcanvas.removePort(groupId, portId)
  705. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  706. @pyqtSlot(int, int, str)
  707. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  708. patchcanvas.renamePort(groupId, portId, newPortName)
  709. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  710. @pyqtSlot(int, int, int, int, int)
  711. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  712. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  713. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  714. @pyqtSlot(int, int, int)
  715. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  716. #if not self.fEngineStarted: return
  717. patchcanvas.disconnectPorts(connectionId)
  718. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  719. # -----------------------------------------------------------------
  720. @pyqtSlot()
  721. def slot_canvasArrange(self):
  722. patchcanvas.arrange()
  723. @pyqtSlot()
  724. def slot_canvasShowInternal(self):
  725. gCarla.externalPatchbay = False
  726. self.fParent.ui.act_canvas_show_internal.blockSignals(True)
  727. self.fParent.ui.act_canvas_show_external.blockSignals(True)
  728. self.fParent.ui.act_canvas_show_internal.setChecked(True)
  729. self.fParent.ui.act_canvas_show_external.setChecked(False)
  730. self.fParent.ui.act_canvas_show_internal.blockSignals(False)
  731. self.fParent.ui.act_canvas_show_external.blockSignals(False)
  732. self.slot_canvasRefresh()
  733. @pyqtSlot()
  734. def slot_canvasShowExternal(self):
  735. gCarla.externalPatchbay = True
  736. self.fParent.ui.act_canvas_show_internal.blockSignals(True)
  737. self.fParent.ui.act_canvas_show_external.blockSignals(True)
  738. self.fParent.ui.act_canvas_show_internal.setChecked(False)
  739. self.fParent.ui.act_canvas_show_external.setChecked(True)
  740. self.fParent.ui.act_canvas_show_internal.blockSignals(False)
  741. self.fParent.ui.act_canvas_show_external.blockSignals(False)
  742. self.slot_canvasRefresh()
  743. @pyqtSlot()
  744. def slot_canvasRefresh(self):
  745. patchcanvas.clear()
  746. if gCarla.host is not None and gCarla.host.is_engine_running():
  747. gCarla.host.patchbay_refresh(gCarla.externalPatchbay)
  748. for pitem in self.fPluginList:
  749. if pitem is None:
  750. break
  751. pitem.reloadAll()
  752. QTimer.singleShot(1000 if self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] else 0, self.fMiniCanvasPreview.update)
  753. @pyqtSlot()
  754. def slot_canvasZoomFit(self):
  755. self.scene.zoom_fit()
  756. @pyqtSlot()
  757. def slot_canvasZoomIn(self):
  758. self.scene.zoom_in()
  759. @pyqtSlot()
  760. def slot_canvasZoomOut(self):
  761. self.scene.zoom_out()
  762. @pyqtSlot()
  763. def slot_canvasZoomReset(self):
  764. self.scene.zoom_reset()
  765. @pyqtSlot()
  766. def slot_canvasPrint(self):
  767. self.scene.clearSelection()
  768. self.fExportPrinter = QPrinter()
  769. dialog = QPrintDialog(self.fExportPrinter, self)
  770. if dialog.exec_():
  771. painter = QPainter(self.fExportPrinter)
  772. painter.save()
  773. painter.setRenderHint(QPainter.Antialiasing)
  774. painter.setRenderHint(QPainter.TextAntialiasing)
  775. self.scene.render(painter)
  776. painter.restore()
  777. @pyqtSlot()
  778. def slot_canvasSaveImage(self):
  779. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  780. if config_UseQt5:
  781. newPath = newPath[0]
  782. if not newPath:
  783. return
  784. self.scene.clearSelection()
  785. if newPath.lower().endswith((".jpg",)):
  786. imgFormat = "JPG"
  787. elif newPath.lower().endswith((".png",)):
  788. imgFormat = "PNG"
  789. else:
  790. # File-dialog may not auto-add the extension
  791. imgFormat = "PNG"
  792. newPath += ".png"
  793. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  794. painter = QPainter(self.fExportImage)
  795. painter.save()
  796. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  797. painter.setRenderHint(QPainter.TextAntialiasing)
  798. self.scene.render(painter)
  799. self.fExportImage.save(newPath, imgFormat, 100)
  800. painter.restore()
  801. # -----------------------------------------------------------------
  802. def resizeEvent(self, event):
  803. QFrame.resizeEvent(self, event)
  804. self.slot_miniCanvasCheckSize()
  805. # ------------------------------------------------------------------------------------------------
  806. # Canvas callback
  807. def canvasCallback(action, value1, value2, valueStr):
  808. if action == patchcanvas.ACTION_GROUP_INFO:
  809. pass
  810. elif action == patchcanvas.ACTION_GROUP_RENAME:
  811. pass
  812. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  813. groupId = value1
  814. patchcanvas.splitGroup(groupId)
  815. gCarla.gui.ui.miniCanvasPreview.update()
  816. elif action == patchcanvas.ACTION_GROUP_JOIN:
  817. groupId = value1
  818. patchcanvas.joinGroup(groupId)
  819. gCarla.gui.ui.miniCanvasPreview.update()
  820. elif action == patchcanvas.ACTION_PORT_INFO:
  821. pass
  822. elif action == patchcanvas.ACTION_PORT_RENAME:
  823. pass
  824. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  825. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  826. if not gCarla.host.patchbay_connect(gOut, pOut, gIn, pIn):
  827. print("Connection failed:", gCarla.host.get_last_error())
  828. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  829. connectionId = value1
  830. if not gCarla.host.patchbay_disconnect(connectionId):
  831. print("Disconnect failed:", gCarla.host.get_last_error())
  832. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  833. pluginId = value1
  834. gCarla.host.clone_plugin(pluginId)
  835. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  836. pluginId = value1
  837. gCarla.gui.fContainer.showEditDialog(pluginId)
  838. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  839. pluginId = value1
  840. newName = valueStr
  841. gCarla.host.rename_plugin(pluginId, newName)
  842. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  843. pluginId = value1
  844. gCarla.host.remove_plugin(pluginId)
  845. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  846. pluginId = value1
  847. gCarla.host.show_custom_ui(pluginId, True)