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.

993 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. Carla.host.set_active(pluginId, True)
  166. def removePlugin(self, pluginId):
  167. if not self.fIsOnlyPatchbay:
  168. self.fPluginCount -= 1
  169. return
  170. if pluginId >= self.fPluginCount:
  171. return
  172. pitem = self.fPluginList[pluginId]
  173. if pitem is None:
  174. return
  175. self.fPluginCount -= 1
  176. self.fPluginList.pop(pluginId)
  177. pitem.close()
  178. del pitem
  179. # push all plugins 1 slot back
  180. for i in range(pluginId, self.fPluginCount):
  181. pitem = self.fPluginList[i]
  182. pitem.setId(i)
  183. def renamePlugin(self, pluginId, newName):
  184. if pluginId >= self.fPluginCount:
  185. return
  186. pitem = self.fPluginList[pluginId]
  187. if pitem is None:
  188. return
  189. pitem.setName(newName)
  190. def disablePlugin(self, pluginId, errorMsg):
  191. if pluginId >= self.fPluginCount:
  192. return
  193. pitem = self.fPluginList[pluginId]
  194. if pitem is None:
  195. return
  196. def removeAllPlugins(self):
  197. for i in range(self.fPluginCount):
  198. pitem = self.fPluginList[i]
  199. if pitem is None:
  200. break
  201. pitem.close()
  202. del pitem
  203. self.fPluginCount = 0
  204. self.fPluginList = []
  205. # -----------------------------------------------------------------
  206. def engineStarted(self):
  207. pass
  208. def engineStopped(self):
  209. patchcanvas.clear()
  210. def engineChanged(self):
  211. pass
  212. # -----------------------------------------------------------------
  213. def idleFast(self):
  214. for pluginId in self.fSelectedPlugins:
  215. self.fPeaksCleared = False
  216. if self.fPeaksIn.isVisible():
  217. self.fPeaksIn.displayMeter(1, Carla.host.get_input_peak_value(pluginId, True))
  218. self.fPeaksIn.displayMeter(2, Carla.host.get_input_peak_value(pluginId, False))
  219. if self.fPeaksOut.isVisible():
  220. self.fPeaksOut.displayMeter(1, Carla.host.get_output_peak_value(pluginId, True))
  221. self.fPeaksOut.displayMeter(2, Carla.host.get_output_peak_value(pluginId, False))
  222. return
  223. if self.fPeaksCleared:
  224. return
  225. self.fPeaksCleared = True
  226. self.fPeaksIn.displayMeter(1, 0.0, True)
  227. self.fPeaksIn.displayMeter(2, 0.0, True)
  228. self.fPeaksOut.displayMeter(1, 0.0, True)
  229. self.fPeaksOut.displayMeter(2, 0.0, True)
  230. def idleSlow(self):
  231. for i in range(self.fPluginCount):
  232. pitem = self.fPluginList[i]
  233. if pitem is None:
  234. break
  235. pitem.idleSlow()
  236. # -----------------------------------------------------------------
  237. def projectLoaded(self):
  238. QTimer.singleShot(1000, self.slot_canvasRefresh)
  239. def saveSettings(self, settings):
  240. settings.setValue("ShowMeters", self.fPeaksIn.isVisible())
  241. settings.setValue("ShowKeyboard", self.fKeys.isVisible())
  242. settings.setValue("HorizontalScrollBarValue", self.fView.horizontalScrollBar().value())
  243. settings.setValue("VerticalScrollBarValue", self.fView.verticalScrollBar().value())
  244. def showEditDialog(self, pluginId):
  245. if pluginId >= self.fPluginCount:
  246. return
  247. pitem = self.fPluginList[pluginId]
  248. if pitem is None:
  249. return
  250. pitem.show()
  251. # -----------------------------------------------------------------
  252. # called by PluginEdit to plugin skin parent, ignored here
  253. def editDialogChanged(self, visible):
  254. pass
  255. def recheckPluginHints(self, hints):
  256. pass
  257. # -----------------------------------------------------------------
  258. def setupCanvas(self):
  259. pOptions = patchcanvas.options_t()
  260. pOptions.theme_name = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  261. pOptions.auto_hide_groups = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  262. pOptions.use_bezier_lines = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  263. pOptions.antialiasing = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  264. pOptions.eyecandy = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
  265. pFeatures = patchcanvas.features_t()
  266. pFeatures.group_info = False
  267. pFeatures.group_rename = False
  268. pFeatures.port_info = False
  269. pFeatures.port_rename = False
  270. pFeatures.handle_group_pos = True
  271. patchcanvas.setOptions(pOptions)
  272. patchcanvas.setFeatures(pFeatures)
  273. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  274. tryCanvasSize = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  275. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  276. self.fCanvasWidth = int(tryCanvasSize[0])
  277. self.fCanvasHeight = int(tryCanvasSize[1])
  278. else:
  279. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  280. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  281. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  282. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  283. self.fView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  284. self.themeData = [self.fCanvasWidth, self.fCanvasHeight, patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color()]
  285. def updateCanvasInitialPos(self):
  286. x = self.fView.horizontalScrollBar().value() + self.width()/4
  287. y = self.fView.verticalScrollBar().value() + self.height()/4
  288. patchcanvas.setInitialPos(x, y)
  289. # -----------------------------------------------------------------
  290. @pyqtSlot(bool)
  291. def slot_showCanvasMeters(self, yesNo):
  292. self.fPeaksIn.setVisible(yesNo)
  293. self.fPeaksOut.setVisible(yesNo)
  294. @pyqtSlot(bool)
  295. def slot_showCanvasKeyboard(self, yesNo):
  296. self.fKeys.setVisible(yesNo)
  297. # -----------------------------------------------------------------
  298. @pyqtSlot()
  299. def slot_miniCanvasCheckAll(self):
  300. self.slot_miniCanvasCheckSize()
  301. self.slot_horizontalScrollBarChanged(self.fView.horizontalScrollBar().value())
  302. self.slot_verticalScrollBarChanged(self.fView.verticalScrollBar().value())
  303. @pyqtSlot()
  304. def slot_miniCanvasCheckSize(self):
  305. self.fMiniCanvasPreview.setViewSize(float(self.width()) / self.fCanvasWidth, float(self.height()) / self.fCanvasHeight)
  306. @pyqtSlot(int)
  307. def slot_horizontalScrollBarChanged(self, value):
  308. if self.fMovingViaMiniCanvas: return
  309. maximum = self.fView.horizontalScrollBar().maximum()
  310. if maximum == 0:
  311. xp = 0
  312. else:
  313. xp = float(value) / maximum
  314. self.fMiniCanvasPreview.setViewPosX(xp)
  315. self.updateCanvasInitialPos()
  316. @pyqtSlot(int)
  317. def slot_verticalScrollBarChanged(self, value):
  318. if self.fMovingViaMiniCanvas: return
  319. maximum = self.fView.verticalScrollBar().maximum()
  320. if maximum == 0:
  321. yp = 0
  322. else:
  323. yp = float(value) / maximum
  324. self.fMiniCanvasPreview.setViewPosY(yp)
  325. self.updateCanvasInitialPos()
  326. @pyqtSlot()
  327. def slot_restoreScrollbarValues(self):
  328. settings = QSettings()
  329. self.fView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.fView.horizontalScrollBar().maximum()/2, type=int))
  330. self.fView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.fView.verticalScrollBar().maximum()/2, type=int))
  331. # -----------------------------------------------------------------
  332. @pyqtSlot(float)
  333. def slot_canvasScaleChanged(self, scale):
  334. self.fMiniCanvasPreview.setViewScale(scale)
  335. @pyqtSlot(int, int, QPointF)
  336. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  337. self.fMiniCanvasPreview.update()
  338. @pyqtSlot(list)
  339. def slot_canvasPluginSelected(self, pluginList):
  340. self.fKeys.keyboard.allNotesOff(False)
  341. self.fKeys.setEnabled(len(pluginList) != 0)
  342. self.fSelectedPlugins = pluginList
  343. @pyqtSlot(float, float)
  344. def slot_miniCanvasMoved(self, xp, yp):
  345. self.fMovingViaMiniCanvas = True
  346. self.fView.horizontalScrollBar().setValue(xp * self.fView.horizontalScrollBar().maximum())
  347. self.fView.verticalScrollBar().setValue(yp * self.fView.verticalScrollBar().maximum())
  348. self.fMovingViaMiniCanvas = False
  349. self.updateCanvasInitialPos()
  350. # -----------------------------------------------------------------
  351. @pyqtSlot(int)
  352. def slot_noteOn(self, note):
  353. for pluginId in self.fSelectedPlugins:
  354. Carla.host.send_midi_note(pluginId, 0, note, 100)
  355. @pyqtSlot(int)
  356. def slot_noteOff(self, note):
  357. for pluginId in self.fSelectedPlugins:
  358. Carla.host.send_midi_note(pluginId, 0, note, 0)
  359. # -----------------------------------------------------------------
  360. @pyqtSlot()
  361. def slot_pluginsEnable(self):
  362. if not Carla.host.is_engine_running():
  363. return
  364. for i in range(self.fPluginCount):
  365. Carla.host.set_active(i, True)
  366. @pyqtSlot()
  367. def slot_pluginsDisable(self):
  368. if not Carla.host.is_engine_running():
  369. return
  370. for i in range(self.fPluginCount):
  371. Carla.host.set_active(i, False)
  372. @pyqtSlot()
  373. def slot_pluginsVolume100(self):
  374. if not Carla.host.is_engine_running():
  375. return
  376. for i in range(self.fPluginCount):
  377. pitem = self.fPluginList[i]
  378. if pitem is None:
  379. break
  380. if pitem.getHints() & PLUGIN_CAN_VOLUME:
  381. pitem.setParameterValue(PARAMETER_VOLUME, 1.0)
  382. Carla.host.set_volume(i, 1.0)
  383. @pyqtSlot()
  384. def slot_pluginsMute(self):
  385. if not Carla.host.is_engine_running():
  386. return
  387. for i in range(self.fPluginCount):
  388. pitem = self.fPluginList[i]
  389. if pitem is None:
  390. break
  391. if pitem.getHints() & PLUGIN_CAN_VOLUME:
  392. pitem.setParameterValue(PARAMETER_VOLUME, 0.0)
  393. Carla.host.set_volume(i, 0.0)
  394. @pyqtSlot()
  395. def slot_pluginsWet100(self):
  396. if not Carla.host.is_engine_running():
  397. return
  398. for i in range(self.fPluginCount):
  399. pitem = self.fPluginList[i]
  400. if pitem is None:
  401. break
  402. if pitem.getHints() & PLUGIN_CAN_DRYWET:
  403. pitem.setParameterValue(PARAMETER_DRYWET, 1.0)
  404. Carla.host.set_drywet(i, 1.0)
  405. @pyqtSlot()
  406. def slot_pluginsBypass(self):
  407. if not Carla.host.is_engine_running():
  408. return
  409. for i in range(self.fPluginCount):
  410. pitem = self.fPluginList[i]
  411. if pitem is None:
  412. break
  413. if pitem.getHints() & PLUGIN_CAN_DRYWET:
  414. pitem.setParameterValue(PARAMETER_DRYWET, 0.0)
  415. Carla.host.set_drywet(i, 0.0)
  416. @pyqtSlot()
  417. def slot_pluginsCenter(self):
  418. if not Carla.host.is_engine_running():
  419. return
  420. for i in range(self.fPluginCount):
  421. pitem = self.fPluginList[i]
  422. if pitem is None:
  423. break
  424. if pitem.getHints() & PLUGIN_CAN_BALANCE:
  425. pitem.setParameterValue(PARAMETER_BALANCE_LEFT, -1.0)
  426. pitem.setParameterValue(PARAMETER_BALANCE_RIGHT, 1.0)
  427. Carla.host.set_balance_left(i, -1.0)
  428. Carla.host.set_balance_right(i, 1.0)
  429. if pitem.getHints() & PLUGIN_CAN_PANNING:
  430. pitem.setParameterValue(PARAMETER_PANNING, 0.0)
  431. Carla.host.set_panning(i, 0.0)
  432. # -----------------------------------------------------------------
  433. @pyqtSlot()
  434. def slot_configureCarla(self):
  435. if self.fParent is None or not self.fParent.openSettingsWindow(True, hasGL):
  436. return
  437. self.fParent.loadSettings(False)
  438. patchcanvas.clear()
  439. self.setupCanvas()
  440. self.fParent.updateContainer(self.themeData)
  441. self.slot_miniCanvasCheckAll()
  442. if Carla.host.is_engine_running():
  443. Carla.host.patchbay_refresh()
  444. # -----------------------------------------------------------------
  445. @pyqtSlot(int, int, float)
  446. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  447. if pluginId >= self.fPluginCount:
  448. return
  449. pitem = self.fPluginList[pluginId]
  450. if pitem is None:
  451. return
  452. pitem.setParameterValue(index, value)
  453. @pyqtSlot(int, int, float)
  454. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  455. if pluginId >= self.fPluginCount:
  456. return
  457. pitem = self.fPluginList[pluginId]
  458. if pitem is None:
  459. return
  460. pitem.setParameterDefault(index, value)
  461. @pyqtSlot(int, int, int)
  462. def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
  463. if pluginId >= self.fPluginCount:
  464. return
  465. pitem = self.fPluginList[pluginId]
  466. if pitem is None:
  467. return
  468. pitem.setParameterMidiControl(index, cc)
  469. @pyqtSlot(int, int, int)
  470. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  471. if pluginId >= self.fPluginCount:
  472. return
  473. pitem = self.fPluginList[pluginId]
  474. if pitem is None:
  475. return
  476. pitem.setParameterMidiChannel(index, channel)
  477. # -----------------------------------------------------------------
  478. @pyqtSlot(int, int)
  479. def slot_handleProgramChangedCallback(self, pluginId, index):
  480. if pluginId >= self.fPluginCount:
  481. return
  482. pitem = self.fPluginList[pluginId]
  483. if pitem is None:
  484. return
  485. pitem.setProgram(index)
  486. @pyqtSlot(int, int)
  487. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  488. if pluginId >= self.fPluginCount:
  489. return
  490. pitem = self.fPluginList[pluginId]
  491. if pitem is None:
  492. return
  493. pitem.setMidiProgram(index)
  494. # -----------------------------------------------------------------
  495. @pyqtSlot(int, int, int, int)
  496. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  497. if pluginId in self.fSelectedPlugins:
  498. self.fKeys.keyboard.sendNoteOn(note, False)
  499. if not self.fIsOnlyPatchbay:
  500. return
  501. if pluginId >= self.fPluginCount:
  502. return
  503. pitem = self.fPluginList[pluginId]
  504. if pitem is None:
  505. return
  506. pitem.sendNoteOn(channel, note)
  507. @pyqtSlot(int, int, int)
  508. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  509. if pluginId in self.fSelectedPlugins:
  510. self.fKeys.keyboard.sendNoteOff(note, False)
  511. if not self.fIsOnlyPatchbay:
  512. return
  513. if pluginId >= self.fPluginCount:
  514. return
  515. pitem = self.fPluginList[pluginId]
  516. if pitem is None:
  517. return
  518. pitem.sendNoteOff(channel, note)
  519. # -----------------------------------------------------------------
  520. @pyqtSlot(int)
  521. def slot_handleUpdateCallback(self, pluginId):
  522. if pluginId >= self.fPluginCount:
  523. return
  524. pitem = self.fPluginList[pluginId]
  525. if pitem is None:
  526. return
  527. pitem.updateInfo()
  528. @pyqtSlot(int)
  529. def slot_handleReloadInfoCallback(self, pluginId):
  530. if pluginId >= self.fPluginCount:
  531. return
  532. pitem = self.fPluginList[pluginId]
  533. if pitem is None:
  534. return
  535. pitem.reloadInfo()
  536. @pyqtSlot(int)
  537. def slot_handleReloadParametersCallback(self, pluginId):
  538. if pluginId >= self.fPluginCount:
  539. return
  540. pitem = self.fPluginList[pluginId]
  541. if pitem is None:
  542. return
  543. pitem.reloadParameters()
  544. @pyqtSlot(int)
  545. def slot_handleReloadProgramsCallback(self, pluginId):
  546. if pluginId >= self.fPluginCount:
  547. return
  548. pitem = self.fPluginList[pluginId]
  549. if pitem is None:
  550. return
  551. pitem.reloadPrograms()
  552. @pyqtSlot(int)
  553. def slot_handleReloadAllCallback(self, pluginId):
  554. if pluginId >= self.fPluginCount:
  555. return
  556. pitem = self.fPluginList[pluginId]
  557. if pitem is None:
  558. return
  559. pitem.reloadAll()
  560. # -----------------------------------------------------------------
  561. @pyqtSlot(int, int, int, str)
  562. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  563. pcSplit = patchcanvas.SPLIT_UNDEF
  564. pcIcon = patchcanvas.ICON_APPLICATION
  565. if clientIcon == PATCHBAY_ICON_PLUGIN:
  566. pcIcon = patchcanvas.ICON_PLUGIN
  567. if clientIcon == PATCHBAY_ICON_HARDWARE:
  568. pcIcon = patchcanvas.ICON_HARDWARE
  569. elif clientIcon == PATCHBAY_ICON_CARLA:
  570. pass
  571. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  572. pcIcon = patchcanvas.ICON_DISTRHO
  573. elif clientIcon == PATCHBAY_ICON_FILE:
  574. pcIcon = patchcanvas.ICON_FILE
  575. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  576. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  577. if pluginId < 0:
  578. return
  579. if pluginId >= self.fPluginCount:
  580. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  581. return
  582. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(Carla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  583. @pyqtSlot(int)
  584. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  585. #if not self.fEngineStarted: return
  586. patchcanvas.removeGroup(clientId)
  587. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  588. @pyqtSlot(int, str)
  589. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  590. patchcanvas.renameGroup(clientId, newClientName)
  591. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  592. @pyqtSlot(int, int, int)
  593. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  594. pcIcon = patchcanvas.ICON_APPLICATION
  595. if clientIcon == PATCHBAY_ICON_PLUGIN:
  596. pcIcon = patchcanvas.ICON_PLUGIN
  597. if clientIcon == PATCHBAY_ICON_HARDWARE:
  598. pcIcon = patchcanvas.ICON_HARDWARE
  599. elif clientIcon == PATCHBAY_ICON_CARLA:
  600. pass
  601. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  602. pcIcon = patchcanvas.ICON_DISTRHO
  603. elif clientIcon == PATCHBAY_ICON_FILE:
  604. pcIcon = patchcanvas.ICON_FILE
  605. patchcanvas.setGroupIcon(clientId, pcIcon)
  606. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  607. if pluginId < 0:
  608. return
  609. if pluginId >= self.fPluginCount:
  610. print("sorry, can't map this plugin to canvas client", pluginId, self.getPluginCount())
  611. return
  612. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(Carla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  613. @pyqtSlot(int, int, int, str)
  614. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  615. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  616. portMode = patchcanvas.PORT_MODE_INPUT
  617. else:
  618. portMode = patchcanvas.PORT_MODE_OUTPUT
  619. if (portFlags & PATCHBAY_PORT_TYPE_AUDIO):
  620. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  621. elif (portFlags & PATCHBAY_PORT_TYPE_CV):
  622. portType = patchcanvas.PORT_TYPE_AUDIO_JACK # TODO
  623. elif (portFlags & PATCHBAY_PORT_TYPE_MIDI):
  624. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  625. else:
  626. portType = patchcanvas.PORT_TYPE_NULL
  627. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  628. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  629. @pyqtSlot(int, int)
  630. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  631. #if not self.fEngineStarted: return
  632. patchcanvas.removePort(portId)
  633. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  634. @pyqtSlot(int, int, str)
  635. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  636. patchcanvas.renamePort(portId, newPortName)
  637. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  638. @pyqtSlot(int, int, int)
  639. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  640. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  641. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  642. @pyqtSlot(int, int, int)
  643. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  644. #if not self.fEngineStarted: return
  645. patchcanvas.disconnectPorts(connectionId)
  646. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  647. # -----------------------------------------------------------------
  648. @pyqtSlot()
  649. def slot_canvasArrange(self):
  650. patchcanvas.arrange()
  651. @pyqtSlot()
  652. def slot_canvasRefresh(self):
  653. patchcanvas.clear()
  654. if Carla.host.is_engine_running():
  655. Carla.host.patchbay_refresh()
  656. QTimer.singleShot(1000 if self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] else 0, self.fMiniCanvasPreview.update)
  657. @pyqtSlot()
  658. def slot_canvasZoomFit(self):
  659. self.scene.zoom_fit()
  660. @pyqtSlot()
  661. def slot_canvasZoomIn(self):
  662. self.scene.zoom_in()
  663. @pyqtSlot()
  664. def slot_canvasZoomOut(self):
  665. self.scene.zoom_out()
  666. @pyqtSlot()
  667. def slot_canvasZoomReset(self):
  668. self.scene.zoom_reset()
  669. @pyqtSlot()
  670. def slot_canvasPrint(self):
  671. self.scene.clearSelection()
  672. self.fExportPrinter = QPrinter()
  673. dialog = QPrintDialog(self.fExportPrinter, self)
  674. if dialog.exec_():
  675. painter = QPainter(self.fExportPrinter)
  676. painter.save()
  677. painter.setRenderHint(QPainter.Antialiasing)
  678. painter.setRenderHint(QPainter.TextAntialiasing)
  679. self.scene.render(painter)
  680. painter.restore()
  681. @pyqtSlot()
  682. def slot_canvasSaveImage(self):
  683. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  684. if newPath:
  685. self.scene.clearSelection()
  686. if newPath.lower().endswith((".jpg",)):
  687. imgFormat = "JPG"
  688. elif newPath.lower().endswith((".png",)):
  689. imgFormat = "PNG"
  690. else:
  691. # File-dialog may not auto-add the extension
  692. imgFormat = "PNG"
  693. newPath += ".png"
  694. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  695. painter = QPainter(self.fExportImage)
  696. painter.save()
  697. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  698. painter.setRenderHint(QPainter.TextAntialiasing)
  699. self.scene.render(painter)
  700. self.fExportImage.save(newPath, imgFormat, 100)
  701. painter.restore()
  702. # -----------------------------------------------------------------
  703. def resizeEvent(self, event):
  704. QFrame.resizeEvent(self, event)
  705. self.slot_miniCanvasCheckSize()
  706. # ------------------------------------------------------------------------------------------------
  707. # Canvas callback
  708. def canvasCallback(action, value1, value2, valueStr):
  709. if action == patchcanvas.ACTION_GROUP_INFO:
  710. pass
  711. elif action == patchcanvas.ACTION_GROUP_RENAME:
  712. pass
  713. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  714. groupId = value1
  715. patchcanvas.splitGroup(groupId)
  716. Carla.gui.ui.miniCanvasPreview.update()
  717. elif action == patchcanvas.ACTION_GROUP_JOIN:
  718. groupId = value1
  719. patchcanvas.joinGroup(groupId)
  720. Carla.gui.ui.miniCanvasPreview.update()
  721. elif action == patchcanvas.ACTION_PORT_INFO:
  722. pass
  723. elif action == patchcanvas.ACTION_PORT_RENAME:
  724. pass
  725. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  726. portIdA = value1
  727. portIdB = value2
  728. if not Carla.host.patchbay_connect(portIdA, portIdB):
  729. print("Connection failed:", Carla.host.get_last_error())
  730. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  731. connectionId = value1
  732. if not Carla.host.patchbay_disconnect(connectionId):
  733. print("Disconnect failed:", Carla.host.get_last_error())
  734. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  735. pluginId = value1
  736. Carla.host.clone_plugin(pluginId)
  737. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  738. pluginId = value1
  739. Carla.gui.fContainer.showEditDialog(pluginId)
  740. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  741. pluginId = value1
  742. newName = valueStr
  743. Carla.host.rename_plugin(pluginId, newName)
  744. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  745. pluginId = value1
  746. Carla.host.remove_plugin(pluginId)
  747. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  748. pluginId = value1
  749. Carla.host.show_custom_ui(pluginId, True)