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.

920 lines
32KB

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