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.

727 lines
25KB

  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. try:
  20. from PyQt5.QtWidgets import QGraphicsView
  21. except:
  22. from PyQt4.QtGui import QGraphicsView
  23. #QPrinter, QPrintDialog
  24. #QImage
  25. # ------------------------------------------------------------------------------------------------------------
  26. # Imports (Custom Stuff)
  27. import patchcanvas
  28. from carla_widgets import *
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Try Import OpenGL
  31. try:
  32. try:
  33. from PyQt5.QtOpenGL import QGLWidget
  34. except:
  35. from PyQt4.QtOpenGL import QGLWidget
  36. hasGL = True
  37. except:
  38. hasGL = False
  39. # ------------------------------------------------------------------------------------------------
  40. # Patchbay widget
  41. class CarlaPatchbayW(QGraphicsView):
  42. def __init__(self, parent, doSetup = True):
  43. QGraphicsView.__init__(self, parent)
  44. # -------------------------------------------------------------
  45. # Internal stuff
  46. self.fParent = parent
  47. self.fPluginCount = 0
  48. self.fPluginList = []
  49. # -------------------------------------------------------------
  50. # Set-up Canvas
  51. self.scene = patchcanvas.PatchScene(self, self) # FIXME?
  52. self.setScene(self.scene)
  53. self.setRenderHint(QPainter.Antialiasing, bool(parent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  54. if parent.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  55. self.setViewport(QGLWidget(self))
  56. self.setRenderHint(QPainter.HighQualityAntialiasing, parent.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  57. pOptions = patchcanvas.options_t()
  58. pOptions.theme_name = parent.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  59. pOptions.auto_hide_groups = parent.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  60. pOptions.use_bezier_lines = parent.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  61. pOptions.antialiasing = parent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  62. pOptions.eyecandy = parent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
  63. pFeatures = patchcanvas.features_t()
  64. pFeatures.group_info = False
  65. pFeatures.group_rename = False
  66. pFeatures.port_info = False
  67. pFeatures.port_rename = False
  68. pFeatures.handle_group_pos = True
  69. patchcanvas.setOptions(pOptions)
  70. patchcanvas.setFeatures(pFeatures)
  71. patchcanvas.init("Carla2", self.scene, CanvasCallback, False)
  72. tryCanvasSize = parent.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  73. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  74. canvasWidth = int(tryCanvasSize[0])
  75. canvasHeight = int(tryCanvasSize[1])
  76. else:
  77. canvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  78. canvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  79. patchcanvas.setCanvasSize(0, 0, canvasWidth, canvasHeight)
  80. patchcanvas.setInitialPos(canvasWidth / 2, canvasHeight / 2)
  81. self.setSceneRect(0, 0, canvasWidth, canvasHeight)
  82. # -------------------------------------------------------------
  83. # Connect actions to functions
  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. #self.ui.miniCanvasPreview-miniCanvasMoved(double, double)"), SLOT("slot_miniCanvasMoved(double, double)"))
  104. #self.ui.graphicsView.horizontalScrollBar()-valueChanged.connect(self.slot_horizontalScrollBarChanged)
  105. #self.ui.graphicsView.verticalScrollBar()-valueChanged.connect(self.slot_verticalScrollBarChanged)
  106. #self.scene-sceneGroupMoved(int, int, QPointF)"), SLOT("slot_canvasItemMoved(int, int, QPointF)"))
  107. #self.scene-scaleChanged(double)"), SLOT("slot_canvasScaleChanged(double)"))
  108. parent.ParameterValueChangedCallback.connect(self.slot_handleParameterValueChangedCallback)
  109. parent.ParameterDefaultChangedCallback.connect(self.slot_handleParameterDefaultChangedCallback)
  110. parent.ParameterMidiChannelChangedCallback.connect(self.slot_handleParameterMidiChannelChangedCallback)
  111. parent.ParameterMidiCcChangedCallback.connect(self.slot_handleParameterMidiCcChangedCallback)
  112. parent.ProgramChangedCallback.connect(self.slot_handleProgramChangedCallback)
  113. parent.MidiProgramChangedCallback.connect(self.slot_handleMidiProgramChangedCallback)
  114. parent.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  115. parent.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  116. parent.ShowGuiCallback.connect(self.slot_handleShowGuiCallback)
  117. parent.UpdateCallback.connect(self.slot_handleUpdateCallback)
  118. parent.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  119. parent.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  120. parent.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  121. parent.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  122. parent.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  123. parent.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  124. parent.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  125. parent.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  126. parent.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  127. parent.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  128. parent.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  129. parent.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  130. parent.PatchbayIconChangedCallback.connect(self.slot_handlePatchbayIconChangedCallback)
  131. # -----------------------------------------------------------------
  132. def getPluginCount(self):
  133. return self.fPluginCount
  134. # -----------------------------------------------------------------
  135. def addPlugin(self, pluginId, isProjectLoading):
  136. pitem = PluginEdit(self, pluginId)
  137. self.fPluginList.append(pitem)
  138. self.fPluginCount += 1
  139. def removePlugin(self, pluginId):
  140. if pluginId >= self.fPluginCount:
  141. return
  142. pitem = self.fPluginList[pluginId]
  143. if pitem is None:
  144. return
  145. self.fPluginCount -= 1
  146. self.fPluginList.pop(pluginId)
  147. pitem.close()
  148. del pitem
  149. # push all plugins 1 slot back
  150. for i in range(pluginId, self.fPluginCount):
  151. self.fPluginList[i].fPluginId = i # FIXME ?
  152. def renamePlugin(self, pluginId, newName):
  153. if pluginId >= self.fPluginCount:
  154. return
  155. pitem = self.fPluginList[pluginId]
  156. if pitem is None:
  157. return
  158. pitem.setName(newName)
  159. def removeAllPlugins(self):
  160. for i in range(self.fPluginCount):
  161. pitem = self.fPluginList[i]
  162. if pitem is None:
  163. break
  164. pitem.close()
  165. del pitem
  166. self.fPluginCount = 0
  167. self.fPluginList = []
  168. # -----------------------------------------------------------------
  169. def engineStarted(self):
  170. pass
  171. def engineStopped(self):
  172. patchcanvas.clear()
  173. def engineChanged(self):
  174. pass
  175. # -----------------------------------------------------------------
  176. def idleFast(self):
  177. pass
  178. def idleSlow(self):
  179. for i in range(self.fPluginCount):
  180. pitem = self.fPluginList[i]
  181. if pitem is None:
  182. break
  183. pitem.idleSlow()
  184. # -----------------------------------------------------------------
  185. def saveSettings(self, settings):
  186. pass
  187. # -----------------------------------------------------------------
  188. def recheckPluginHints(self, hints):
  189. pass
  190. # -----------------------------------------------------------------
  191. @pyqtSlot()
  192. def slot_pluginsEnable(self):
  193. if not Carla.host.is_engine_running():
  194. return
  195. for i in range(self.fPluginCount):
  196. Carla.host.set_active(i, True)
  197. @pyqtSlot()
  198. def slot_pluginsDisable(self):
  199. if not Carla.host.is_engine_running():
  200. return
  201. for i in range(self.fPluginCount):
  202. Carla.host.set_active(i, False)
  203. @pyqtSlot()
  204. def slot_pluginsVolume100(self):
  205. if not Carla.host.is_engine_running():
  206. return
  207. for i in range(self.fPluginCount):
  208. pitem = self.fPluginList[i]
  209. if pitem is None:
  210. break
  211. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  212. pitem.setParameterValue(PARAMETER_VOLUME, 1.0)
  213. Carla.host.set_volume(i, 1.0)
  214. @pyqtSlot()
  215. def slot_pluginsMute(self):
  216. if not Carla.host.is_engine_running():
  217. return
  218. for i in range(self.fPluginCount):
  219. pitem = self.fPluginList[i]
  220. if pitem is None:
  221. break
  222. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  223. pitem.setParameterValue(PARAMETER_VOLUME, 0.0)
  224. Carla.host.set_volume(i, 0.0)
  225. @pyqtSlot()
  226. def slot_pluginsWet100(self):
  227. if not Carla.host.is_engine_running():
  228. return
  229. for i in range(self.fPluginCount):
  230. pitem = self.fPluginList[i]
  231. if pitem is None:
  232. break
  233. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  234. pitem.setParameterValue(PARAMETER_DRYWET, 1.0)
  235. Carla.host.set_drywet(i, 1.0)
  236. @pyqtSlot()
  237. def slot_pluginsBypass(self):
  238. if not Carla.host.is_engine_running():
  239. return
  240. for i in range(self.fPluginCount):
  241. pitem = self.fPluginList[i]
  242. if pitem is None:
  243. break
  244. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  245. pitem.setParameterValue(PARAMETER_DRYWET, 0.0)
  246. Carla.host.set_drywet(i, 0.0)
  247. @pyqtSlot()
  248. def slot_pluginsCenter(self):
  249. if not Carla.host.is_engine_running():
  250. return
  251. for i in range(self.fPluginCount):
  252. pitem = self.fPluginList[i]
  253. if pitem is None:
  254. break
  255. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE:
  256. pitem.setParameterValue(PARAMETER_BALANCE_LEFT, -1.0)
  257. pitem.setParameterValue(PARAMETER_BALANCE_RIGHT, 1.0)
  258. Carla.host.set_balance_left(i, -1.0)
  259. Carla.host.set_balance_right(i, 1.0)
  260. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_PANNING:
  261. pitem.setParameterValue(PARAMETER_PANNING, 1.0)
  262. Carla.host.set_panning(i, 1.0)
  263. # -----------------------------------------------------------------
  264. @pyqtSlot()
  265. def slot_configureCarla(self):
  266. if self.fParent is None or not self.fParent.openSettingsWindow(True, hasGL):
  267. return
  268. self.fParent.loadSettings(False)
  269. patchcanvas.clear()
  270. pOptions = patchcanvas.options_t()
  271. pOptions.theme_name = self.fParent.fSavedSettings["Canvas/Theme"]
  272. pOptions.auto_hide_groups = self.fParent.fSavedSettings["Canvas/AutoHideGroups"]
  273. pOptions.use_bezier_lines = self.fParent.fSavedSettings["Canvas/UseBezierLines"]
  274. pOptions.antialiasing = self.fParent.fSavedSettings["Canvas/Antialiasing"]
  275. pOptions.eyecandy = self.fParent.fSavedSettings["Canvas/EyeCandy"]
  276. pFeatures = patchcanvas.features_t()
  277. pFeatures.group_info = False
  278. pFeatures.group_rename = False
  279. pFeatures.port_info = False
  280. pFeatures.port_rename = False
  281. pFeatures.handle_group_pos = True
  282. patchcanvas.setOptions(pOptions)
  283. patchcanvas.setFeatures(pFeatures)
  284. patchcanvas.init("Carla2", self.scene, CanvasCallback, False)
  285. if Carla.host.is_engine_running():
  286. Carla.host.patchbay_refresh()
  287. # -----------------------------------------------------------------
  288. @pyqtSlot(int, int, float)
  289. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  290. if pluginId >= self.fPluginCount:
  291. return
  292. pitem = self.fPluginList[pluginId]
  293. if pitem is None:
  294. return
  295. pitem.setParameterValue(index, value)
  296. @pyqtSlot(int, int, float)
  297. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  298. if pluginId >= self.fPluginCount:
  299. return
  300. pitem = self.fPluginList[pluginId]
  301. if pitem is None:
  302. return
  303. pitem.setParameterDefault(index, value)
  304. @pyqtSlot(int, int, int)
  305. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  306. if pluginId >= self.fPluginCount:
  307. return
  308. pitem = self.fPluginList[pluginId]
  309. if pitem is None:
  310. return
  311. pitem.setParameterMidiChannel(index, channel)
  312. @pyqtSlot(int, int, int)
  313. def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
  314. if pluginId >= self.fPluginCount:
  315. return
  316. pitem = self.fPluginList[pluginId]
  317. if pitem is None:
  318. return
  319. pitem.setParameterMidiControl(index, cc)
  320. # -----------------------------------------------------------------
  321. @pyqtSlot(int, int)
  322. def slot_handleProgramChangedCallback(self, pluginId, index):
  323. if pluginId >= self.fPluginCount:
  324. return
  325. pitem = self.fPluginList[pluginId]
  326. if pitem is None:
  327. return
  328. pitem.setProgram(index)
  329. @pyqtSlot(int, int)
  330. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  331. if pluginId >= self.fPluginCount:
  332. return
  333. pitem = self.fPluginList[pluginId]
  334. if pitem is None:
  335. return
  336. pitem.setMidiProgram(index)
  337. # -----------------------------------------------------------------
  338. @pyqtSlot(int, int, int, int)
  339. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  340. if pluginId >= self.fPluginCount:
  341. return
  342. pitem = self.fPluginList[pluginId]
  343. if pitem is None:
  344. return
  345. pitem.sendNoteOn(channel, note)
  346. @pyqtSlot(int, int, int)
  347. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  348. if pluginId >= self.fPluginCount:
  349. return
  350. pitem = self.fPluginList[pluginId]
  351. if pitem is None:
  352. return
  353. pitem.sendNoteOff(channel, note)
  354. # -----------------------------------------------------------------
  355. @pyqtSlot(int, int)
  356. def slot_handleShowGuiCallback(self, pluginId, state):
  357. pass
  358. # -----------------------------------------------------------------
  359. @pyqtSlot(int)
  360. def slot_handleUpdateCallback(self, pluginId):
  361. if pluginId >= self.fPluginCount:
  362. return
  363. pitem = self.fPluginList[pluginId]
  364. if pitem is None:
  365. return
  366. pitem.updateInfo()
  367. @pyqtSlot(int)
  368. def slot_handleReloadInfoCallback(self, pluginId):
  369. if pluginId >= self.fPluginCount:
  370. return
  371. pitem = self.fPluginList[pluginId]
  372. if pitem is None:
  373. return
  374. pitem.reloadInfo()
  375. @pyqtSlot(int)
  376. def slot_handleReloadParametersCallback(self, pluginId):
  377. if pluginId >= self.fPluginCount:
  378. return
  379. pitem = self.fPluginList[pluginId]
  380. if pitem is None:
  381. return
  382. pitem.reloadParameters()
  383. @pyqtSlot(int)
  384. def slot_handleReloadProgramsCallback(self, pluginId):
  385. if pluginId >= self.fPluginCount:
  386. return
  387. pitem = self.fPluginList[pluginId]
  388. if pitem is None:
  389. return
  390. pitem.reloadPrograms()
  391. @pyqtSlot(int)
  392. def slot_handleReloadAllCallback(self, pluginId):
  393. if pluginId >= self.fPluginCount:
  394. return
  395. pitem = self.fPluginList[pluginId]
  396. if pitem is None:
  397. return
  398. pitem.reloadAll()
  399. # -----------------------------------------------------------------
  400. @pyqtSlot(int, int, str)
  401. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, clientName):
  402. pcSplit = patchcanvas.SPLIT_UNDEF
  403. pcIcon = patchcanvas.ICON_APPLICATION
  404. if clientIcon == PATCHBAY_ICON_HARDWARE:
  405. pcSplit = patchcanvas.SPLIT_YES
  406. pcIcon = patchcanvas.ICON_HARDWARE
  407. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  408. pcIcon = patchcanvas.ICON_DISTRHO
  409. elif clientIcon == PATCHBAY_ICON_FILE:
  410. pcIcon = patchcanvas.ICON_FILE
  411. elif clientIcon == PATCHBAY_ICON_PLUGIN:
  412. pcIcon = patchcanvas.ICON_PLUGIN
  413. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  414. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  415. @pyqtSlot(int, str)
  416. def slot_handlePatchbayClientRemovedCallback(self, clientId, clientName):
  417. #if not self.fEngineStarted: return
  418. patchcanvas.removeGroup(clientId)
  419. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  420. @pyqtSlot(int, str)
  421. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  422. patchcanvas.renameGroup(clientId, newClientName)
  423. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  424. @pyqtSlot(int, int, int, str)
  425. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  426. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  427. portMode = patchcanvas.PORT_MODE_INPUT
  428. elif (portFlags & PATCHBAY_PORT_IS_OUTPUT):
  429. portMode = patchcanvas.PORT_MODE_OUTPUT
  430. else:
  431. portMode = patchcanvas.PORT_MODE_NULL
  432. if (portFlags & PATCHBAY_PORT_IS_AUDIO):
  433. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  434. elif (portFlags & PATCHBAY_PORT_IS_MIDI):
  435. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  436. else:
  437. portType = patchcanvas.PORT_TYPE_NULL
  438. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  439. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  440. @pyqtSlot(int, int, str)
  441. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId, fullPortName):
  442. #if not self.fEngineStarted: return
  443. patchcanvas.removePort(portId)
  444. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  445. @pyqtSlot(int, int, str)
  446. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  447. patchcanvas.renamePort(portId, newPortName)
  448. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  449. @pyqtSlot(int, int, int)
  450. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  451. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  452. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  453. @pyqtSlot(int)
  454. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId):
  455. #if not self.fEngineStarted: return
  456. patchcanvas.disconnectPorts(connectionId)
  457. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  458. @pyqtSlot(int, int)
  459. def slot_handlePatchbayIconChangedCallback(self, clientId, clientIcon):
  460. pcIcon = patchcanvas.ICON_APPLICATION
  461. if clientIcon == PATCHBAY_ICON_HARDWARE:
  462. pcIcon = patchcanvas.ICON_HARDWARE
  463. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  464. pcIcon = patchcanvas.ICON_DISTRHO
  465. elif clientIcon == PATCHBAY_ICON_FILE:
  466. pcIcon = patchcanvas.ICON_FILE
  467. elif clientIcon == PATCHBAY_ICON_PLUGIN:
  468. pcIcon = patchcanvas.ICON_PLUGIN
  469. patchcanvas.setGroupIcon(clientId, pcIcon)
  470. # -----------------------------------------------------------------
  471. @pyqtSlot()
  472. def slot_canvasArrange(self):
  473. patchcanvas.arrange()
  474. @pyqtSlot()
  475. def slot_canvasRefresh(self):
  476. patchcanvas.clear()
  477. if Carla.host.is_engine_running():
  478. Carla.host.patchbay_refresh()
  479. #QTimer.singleShot(1000 if self.fSavedSettings['Canvas/EyeCandy'] else 0, self.ui.miniCanvasPreview, SLOT("update()"))
  480. @pyqtSlot()
  481. def slot_canvasZoomFit(self):
  482. self.scene.zoom_fit()
  483. @pyqtSlot()
  484. def slot_canvasZoomIn(self):
  485. self.scene.zoom_in()
  486. @pyqtSlot()
  487. def slot_canvasZoomOut(self):
  488. self.scene.zoom_out()
  489. @pyqtSlot()
  490. def slot_canvasZoomReset(self):
  491. self.scene.zoom_reset()
  492. @pyqtSlot()
  493. def slot_canvasPrint(self):
  494. self.scene.clearSelection()
  495. self.fExportPrinter = QPrinter()
  496. dialog = QPrintDialog(self.fExportPrinter, self)
  497. if dialog.exec_():
  498. painter = QPainter(self.fExportPrinter)
  499. painter.save()
  500. painter.setRenderHint(QPainter.Antialiasing)
  501. painter.setRenderHint(QPainter.TextAntialiasing)
  502. self.scene.render(painter)
  503. painter.restore()
  504. @pyqtSlot()
  505. def slot_canvasSaveImage(self):
  506. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  507. if newPath:
  508. self.scene.clearSelection()
  509. # FIXME - must be a better way...
  510. if newPath.endswith((".jpg", ".jpG", ".jPG", ".JPG", ".JPg", ".Jpg")):
  511. imgFormat = "JPG"
  512. elif newPath.endswith((".png", ".pnG", ".pNG", ".PNG", ".PNg", ".Png")):
  513. imgFormat = "PNG"
  514. else:
  515. # File-dialog may not auto-add the extension
  516. imgFormat = "PNG"
  517. newPath += ".png"
  518. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  519. painter = QPainter(self.fExportImage)
  520. painter.save()
  521. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  522. painter.setRenderHint(QPainter.TextAntialiasing)
  523. self.scene.render(painter)
  524. self.fExportImage.save(newPath, imgFormat, 100)
  525. painter.restore()
  526. # ------------------------------------------------------------------------------------------------
  527. # Canvas callback
  528. def CanvasCallback(action, value1, value2, valueStr):
  529. if action == patchcanvas.ACTION_GROUP_INFO:
  530. pass
  531. elif action == patchcanvas.ACTION_GROUP_RENAME:
  532. pass
  533. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  534. groupId = value1
  535. patchcanvas.splitGroup(groupId)
  536. Carla.gui.ui.miniCanvasPreview.update()
  537. elif action == patchcanvas.ACTION_GROUP_JOIN:
  538. groupId = value1
  539. patchcanvas.joinGroup(groupId)
  540. Carla.gui.ui.miniCanvasPreview.update()
  541. elif action == patchcanvas.ACTION_PORT_INFO:
  542. pass
  543. elif action == patchcanvas.ACTION_PORT_RENAME:
  544. pass
  545. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  546. portIdA = value1
  547. portIdB = value2
  548. if not Carla.host.patchbay_connect(portIdA, portIdB):
  549. print("Connection failed:", cString(Carla.host.get_last_error()))
  550. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  551. connectionId = value1
  552. if not Carla.host.patchbay_disconnect(connectionId):
  553. print("Disconnect failed:", cString(Carla.host.get_last_error()))