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.

1014 lines
35KB

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