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.

1030 lines
36KB

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