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.

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