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.

1157 lines
40KB

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