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.

703 lines
24KB

  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, clientName):
  402. patchcanvas.addGroup(clientId, clientName)
  403. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  404. @pyqtSlot(int, str)
  405. def slot_handlePatchbayClientRemovedCallback(self, clientId, clientName):
  406. #if not self.fEngineStarted: return
  407. patchcanvas.removeGroup(clientId)
  408. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  409. @pyqtSlot(int, str)
  410. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  411. patchcanvas.renameGroup(clientId, newClientName)
  412. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  413. @pyqtSlot(int, int, int, str)
  414. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  415. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  416. portMode = patchcanvas.PORT_MODE_INPUT
  417. elif (portFlags & PATCHBAY_PORT_IS_OUTPUT):
  418. portMode = patchcanvas.PORT_MODE_OUTPUT
  419. else:
  420. portMode = patchcanvas.PORT_MODE_NULL
  421. if (portFlags & PATCHBAY_PORT_IS_AUDIO):
  422. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  423. elif (portFlags & PATCHBAY_PORT_IS_MIDI):
  424. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  425. else:
  426. portType = patchcanvas.PORT_TYPE_NULL
  427. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  428. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  429. @pyqtSlot(int, int, str)
  430. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId, fullPortName):
  431. #if not self.fEngineStarted: return
  432. patchcanvas.removePort(portId)
  433. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  434. @pyqtSlot(int, int, str)
  435. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  436. patchcanvas.renamePort(portId, newPortName)
  437. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  438. @pyqtSlot(int, int, int)
  439. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  440. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  441. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  442. @pyqtSlot(int)
  443. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId):
  444. #if not self.fEngineStarted: return
  445. patchcanvas.disconnectPorts(connectionId)
  446. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  447. @pyqtSlot(int, int)
  448. def slot_handlePatchbayIconChangedCallback(self, clientId, icon):
  449. patchcanvas.setGroupIcon(clientId, icon)
  450. # -----------------------------------------------------------------
  451. @pyqtSlot()
  452. def slot_canvasArrange(self):
  453. patchcanvas.arrange()
  454. @pyqtSlot()
  455. def slot_canvasRefresh(self):
  456. patchcanvas.clear()
  457. if Carla.host.is_engine_running():
  458. Carla.host.patchbay_refresh()
  459. #QTimer.singleShot(1000 if self.fSavedSettings['Canvas/EyeCandy'] else 0, self.ui.miniCanvasPreview, SLOT("update()"))
  460. @pyqtSlot()
  461. def slot_canvasZoomFit(self):
  462. self.scene.zoom_fit()
  463. @pyqtSlot()
  464. def slot_canvasZoomIn(self):
  465. self.scene.zoom_in()
  466. @pyqtSlot()
  467. def slot_canvasZoomOut(self):
  468. self.scene.zoom_out()
  469. @pyqtSlot()
  470. def slot_canvasZoomReset(self):
  471. self.scene.zoom_reset()
  472. @pyqtSlot()
  473. def slot_canvasPrint(self):
  474. self.scene.clearSelection()
  475. self.fExportPrinter = QPrinter()
  476. dialog = QPrintDialog(self.fExportPrinter, self)
  477. if dialog.exec_():
  478. painter = QPainter(self.fExportPrinter)
  479. painter.save()
  480. painter.setRenderHint(QPainter.Antialiasing)
  481. painter.setRenderHint(QPainter.TextAntialiasing)
  482. self.scene.render(painter)
  483. painter.restore()
  484. @pyqtSlot()
  485. def slot_canvasSaveImage(self):
  486. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  487. if newPath:
  488. self.scene.clearSelection()
  489. # FIXME - must be a better way...
  490. if newPath.endswith((".jpg", ".jpG", ".jPG", ".JPG", ".JPg", ".Jpg")):
  491. imgFormat = "JPG"
  492. elif newPath.endswith((".png", ".pnG", ".pNG", ".PNG", ".PNg", ".Png")):
  493. imgFormat = "PNG"
  494. else:
  495. # File-dialog may not auto-add the extension
  496. imgFormat = "PNG"
  497. newPath += ".png"
  498. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  499. painter = QPainter(self.fExportImage)
  500. painter.save()
  501. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  502. painter.setRenderHint(QPainter.TextAntialiasing)
  503. self.scene.render(painter)
  504. self.fExportImage.save(newPath, imgFormat, 100)
  505. painter.restore()
  506. # ------------------------------------------------------------------------------------------------
  507. # Canvas callback
  508. def CanvasCallback(action, value1, value2, valueStr):
  509. if action == patchcanvas.ACTION_GROUP_INFO:
  510. pass
  511. elif action == patchcanvas.ACTION_GROUP_RENAME:
  512. pass
  513. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  514. groupId = value1
  515. patchcanvas.splitGroup(groupId)
  516. Carla.gui.ui.miniCanvasPreview.update()
  517. elif action == patchcanvas.ACTION_GROUP_JOIN:
  518. groupId = value1
  519. patchcanvas.joinGroup(groupId)
  520. Carla.gui.ui.miniCanvasPreview.update()
  521. elif action == patchcanvas.ACTION_PORT_INFO:
  522. pass
  523. elif action == patchcanvas.ACTION_PORT_RENAME:
  524. pass
  525. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  526. portIdA = value1
  527. portIdB = value2
  528. if not Carla.host.patchbay_connect(portIdA, portIdB):
  529. print("Connection failed:", cString(Carla.host.get_last_error()))
  530. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  531. connectionId = value1
  532. if not Carla.host.patchbay_disconnect(connectionId):
  533. print("Disconnect failed:", cString(Carla.host.get_last_error()))