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.

706 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 disablePlugin(self, pluginId, errorMsg):
  160. pass
  161. def removeAllPlugins(self):
  162. for i in range(self.fPluginCount):
  163. pitem = self.fPluginList[i]
  164. if pitem is None:
  165. break
  166. pitem.close()
  167. del pitem
  168. self.fPluginCount = 0
  169. self.fPluginList = []
  170. # -----------------------------------------------------------------
  171. def engineStarted(self):
  172. pass
  173. def engineStopped(self):
  174. patchcanvas.clear()
  175. def engineChanged(self):
  176. pass
  177. # -----------------------------------------------------------------
  178. def idleFast(self):
  179. pass
  180. def idleSlow(self):
  181. for i in range(self.fPluginCount):
  182. pitem = self.fPluginList[i]
  183. if pitem is None:
  184. break
  185. pitem.idleSlow()
  186. # -----------------------------------------------------------------
  187. def saveSettings(self, settings):
  188. pass
  189. # -----------------------------------------------------------------
  190. def recheckPluginHints(self, hints):
  191. pass
  192. # -----------------------------------------------------------------
  193. @pyqtSlot()
  194. def slot_pluginsEnable(self):
  195. if not Carla.host.is_engine_running():
  196. return
  197. for i in range(self.fPluginCount):
  198. Carla.host.set_active(i, True)
  199. @pyqtSlot()
  200. def slot_pluginsDisable(self):
  201. if not Carla.host.is_engine_running():
  202. return
  203. for i in range(self.fPluginCount):
  204. Carla.host.set_active(i, False)
  205. @pyqtSlot()
  206. def slot_pluginsVolume100(self):
  207. if not Carla.host.is_engine_running():
  208. return
  209. for i in range(self.fPluginCount):
  210. pitem = self.fPluginList[i]
  211. if pitem is None:
  212. break
  213. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  214. pitem.setParameterValue(PARAMETER_VOLUME, 1.0)
  215. Carla.host.set_volume(i, 1.0)
  216. @pyqtSlot()
  217. def slot_pluginsMute(self):
  218. if not Carla.host.is_engine_running():
  219. return
  220. for i in range(self.fPluginCount):
  221. pitem = self.fPluginList[i]
  222. if pitem is None:
  223. break
  224. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  225. pitem.setParameterValue(PARAMETER_VOLUME, 0.0)
  226. Carla.host.set_volume(i, 0.0)
  227. @pyqtSlot()
  228. def slot_pluginsWet100(self):
  229. if not Carla.host.is_engine_running():
  230. return
  231. for i in range(self.fPluginCount):
  232. pitem = self.fPluginList[i]
  233. if pitem is None:
  234. break
  235. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  236. pitem.setParameterValue(PARAMETER_DRYWET, 1.0)
  237. Carla.host.set_drywet(i, 1.0)
  238. @pyqtSlot()
  239. def slot_pluginsBypass(self):
  240. if not Carla.host.is_engine_running():
  241. return
  242. for i in range(self.fPluginCount):
  243. pitem = self.fPluginList[i]
  244. if pitem is None:
  245. break
  246. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  247. pitem.setParameterValue(PARAMETER_DRYWET, 0.0)
  248. Carla.host.set_drywet(i, 0.0)
  249. @pyqtSlot()
  250. def slot_pluginsCenter(self):
  251. if not Carla.host.is_engine_running():
  252. return
  253. for i in range(self.fPluginCount):
  254. pitem = self.fPluginList[i]
  255. if pitem is None:
  256. break
  257. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE:
  258. pitem.setParameterValue(PARAMETER_BALANCE_LEFT, -1.0)
  259. pitem.setParameterValue(PARAMETER_BALANCE_RIGHT, 1.0)
  260. Carla.host.set_balance_left(i, -1.0)
  261. Carla.host.set_balance_right(i, 1.0)
  262. if pitem.fPluginInfo['hints'] & PLUGIN_CAN_PANNING:
  263. pitem.setParameterValue(PARAMETER_PANNING, 1.0)
  264. Carla.host.set_panning(i, 1.0)
  265. # -----------------------------------------------------------------
  266. @pyqtSlot()
  267. def slot_configureCarla(self):
  268. if self.fParent is None or not self.fParent.openSettingsWindow(True, hasGL):
  269. return
  270. self.fParent.loadSettings(False)
  271. patchcanvas.clear()
  272. pOptions = patchcanvas.options_t()
  273. pOptions.theme_name = self.fParent.fSavedSettings["Canvas/Theme"]
  274. pOptions.auto_hide_groups = self.fParent.fSavedSettings["Canvas/AutoHideGroups"]
  275. pOptions.use_bezier_lines = self.fParent.fSavedSettings["Canvas/UseBezierLines"]
  276. pOptions.antialiasing = self.fParent.fSavedSettings["Canvas/Antialiasing"]
  277. pOptions.eyecandy = self.fParent.fSavedSettings["Canvas/EyeCandy"]
  278. pFeatures = patchcanvas.features_t()
  279. pFeatures.group_info = False
  280. pFeatures.group_rename = False
  281. pFeatures.port_info = False
  282. pFeatures.port_rename = False
  283. pFeatures.handle_group_pos = True
  284. patchcanvas.setOptions(pOptions)
  285. patchcanvas.setFeatures(pFeatures)
  286. patchcanvas.init("Carla2", self.scene, CanvasCallback, False)
  287. if Carla.host.is_engine_running():
  288. Carla.host.patchbay_refresh()
  289. # -----------------------------------------------------------------
  290. @pyqtSlot(int, int, float)
  291. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  292. if pluginId >= self.fPluginCount:
  293. return
  294. pitem = self.fPluginList[pluginId]
  295. if pitem is None:
  296. return
  297. pitem.setParameterValue(index, value)
  298. @pyqtSlot(int, int, float)
  299. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  300. if pluginId >= self.fPluginCount:
  301. return
  302. pitem = self.fPluginList[pluginId]
  303. if pitem is None:
  304. return
  305. pitem.setParameterDefault(index, value)
  306. @pyqtSlot(int, int, int)
  307. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  308. if pluginId >= self.fPluginCount:
  309. return
  310. pitem = self.fPluginList[pluginId]
  311. if pitem is None:
  312. return
  313. pitem.setParameterMidiChannel(index, channel)
  314. @pyqtSlot(int, int, int)
  315. def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
  316. if pluginId >= self.fPluginCount:
  317. return
  318. pitem = self.fPluginList[pluginId]
  319. if pitem is None:
  320. return
  321. pitem.setParameterMidiControl(index, cc)
  322. # -----------------------------------------------------------------
  323. @pyqtSlot(int, int)
  324. def slot_handleProgramChangedCallback(self, pluginId, index):
  325. if pluginId >= self.fPluginCount:
  326. return
  327. pitem = self.fPluginList[pluginId]
  328. if pitem is None:
  329. return
  330. pitem.setProgram(index)
  331. @pyqtSlot(int, int)
  332. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  333. if pluginId >= self.fPluginCount:
  334. return
  335. pitem = self.fPluginList[pluginId]
  336. if pitem is None:
  337. return
  338. pitem.setMidiProgram(index)
  339. # -----------------------------------------------------------------
  340. @pyqtSlot(int, int, int, int)
  341. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  342. if pluginId >= self.fPluginCount:
  343. return
  344. pitem = self.fPluginList[pluginId]
  345. if pitem is None:
  346. return
  347. pitem.sendNoteOn(channel, note)
  348. @pyqtSlot(int, int, int)
  349. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  350. if pluginId >= self.fPluginCount:
  351. return
  352. pitem = self.fPluginList[pluginId]
  353. if pitem is None:
  354. return
  355. pitem.sendNoteOff(channel, note)
  356. # -----------------------------------------------------------------
  357. @pyqtSlot(int, int)
  358. def slot_handleShowGuiCallback(self, pluginId, state):
  359. pass
  360. # -----------------------------------------------------------------
  361. @pyqtSlot(int)
  362. def slot_handleUpdateCallback(self, pluginId):
  363. if pluginId >= self.fPluginCount:
  364. return
  365. pitem = self.fPluginList[pluginId]
  366. if pitem is None:
  367. return
  368. pitem.updateInfo()
  369. @pyqtSlot(int)
  370. def slot_handleReloadInfoCallback(self, pluginId):
  371. if pluginId >= self.fPluginCount:
  372. return
  373. pitem = self.fPluginList[pluginId]
  374. if pitem is None:
  375. return
  376. pitem.reloadInfo()
  377. @pyqtSlot(int)
  378. def slot_handleReloadParametersCallback(self, pluginId):
  379. if pluginId >= self.fPluginCount:
  380. return
  381. pitem = self.fPluginList[pluginId]
  382. if pitem is None:
  383. return
  384. pitem.reloadParameters()
  385. @pyqtSlot(int)
  386. def slot_handleReloadProgramsCallback(self, pluginId):
  387. if pluginId >= self.fPluginCount:
  388. return
  389. pitem = self.fPluginList[pluginId]
  390. if pitem is None:
  391. return
  392. pitem.reloadPrograms()
  393. @pyqtSlot(int)
  394. def slot_handleReloadAllCallback(self, pluginId):
  395. if pluginId >= self.fPluginCount:
  396. return
  397. pitem = self.fPluginList[pluginId]
  398. if pitem is None:
  399. return
  400. pitem.reloadAll()
  401. # -----------------------------------------------------------------
  402. @pyqtSlot(int, int, str)
  403. def slot_handlePatchbayClientAddedCallback(self, clientId, clientName):
  404. patchcanvas.addGroup(clientId, clientName)
  405. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  406. @pyqtSlot(int, str)
  407. def slot_handlePatchbayClientRemovedCallback(self, clientId, clientName):
  408. #if not self.fEngineStarted: return
  409. patchcanvas.removeGroup(clientId)
  410. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  411. @pyqtSlot(int, str)
  412. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  413. patchcanvas.renameGroup(clientId, newClientName)
  414. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  415. @pyqtSlot(int, int, int, str)
  416. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  417. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  418. portMode = patchcanvas.PORT_MODE_INPUT
  419. elif (portFlags & PATCHBAY_PORT_IS_OUTPUT):
  420. portMode = patchcanvas.PORT_MODE_OUTPUT
  421. else:
  422. portMode = patchcanvas.PORT_MODE_NULL
  423. if (portFlags & PATCHBAY_PORT_IS_AUDIO):
  424. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  425. elif (portFlags & PATCHBAY_PORT_IS_MIDI):
  426. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  427. else:
  428. portType = patchcanvas.PORT_TYPE_NULL
  429. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  430. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  431. @pyqtSlot(int, int, str)
  432. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId, fullPortName):
  433. #if not self.fEngineStarted: return
  434. patchcanvas.removePort(portId)
  435. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  436. @pyqtSlot(int, int, str)
  437. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  438. patchcanvas.renamePort(portId, newPortName)
  439. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  440. @pyqtSlot(int, int, int)
  441. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  442. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  443. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  444. @pyqtSlot(int)
  445. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId):
  446. #if not self.fEngineStarted: return
  447. patchcanvas.disconnectPorts(connectionId)
  448. #QTimer.singleShot(0, self.ui.miniCanvasPreview, SLOT("update()"))
  449. @pyqtSlot(int, int)
  450. def slot_handlePatchbayIconChangedCallback(self, clientId, icon):
  451. patchcanvas.setGroupIcon(clientId, icon)
  452. # -----------------------------------------------------------------
  453. @pyqtSlot()
  454. def slot_canvasArrange(self):
  455. patchcanvas.arrange()
  456. @pyqtSlot()
  457. def slot_canvasRefresh(self):
  458. patchcanvas.clear()
  459. if Carla.host.is_engine_running():
  460. Carla.host.patchbay_refresh()
  461. #QTimer.singleShot(1000 if self.fSavedSettings['Canvas/EyeCandy'] else 0, self.ui.miniCanvasPreview, SLOT("update()"))
  462. @pyqtSlot()
  463. def slot_canvasZoomFit(self):
  464. self.scene.zoom_fit()
  465. @pyqtSlot()
  466. def slot_canvasZoomIn(self):
  467. self.scene.zoom_in()
  468. @pyqtSlot()
  469. def slot_canvasZoomOut(self):
  470. self.scene.zoom_out()
  471. @pyqtSlot()
  472. def slot_canvasZoomReset(self):
  473. self.scene.zoom_reset()
  474. @pyqtSlot()
  475. def slot_canvasPrint(self):
  476. self.scene.clearSelection()
  477. self.fExportPrinter = QPrinter()
  478. dialog = QPrintDialog(self.fExportPrinter, self)
  479. if dialog.exec_():
  480. painter = QPainter(self.fExportPrinter)
  481. painter.save()
  482. painter.setRenderHint(QPainter.Antialiasing)
  483. painter.setRenderHint(QPainter.TextAntialiasing)
  484. self.scene.render(painter)
  485. painter.restore()
  486. @pyqtSlot()
  487. def slot_canvasSaveImage(self):
  488. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  489. if newPath:
  490. self.scene.clearSelection()
  491. # FIXME - must be a better way...
  492. if newPath.endswith((".jpg", ".jpG", ".jPG", ".JPG", ".JPg", ".Jpg")):
  493. imgFormat = "JPG"
  494. elif newPath.endswith((".png", ".pnG", ".pNG", ".PNG", ".PNg", ".Png")):
  495. imgFormat = "PNG"
  496. else:
  497. # File-dialog may not auto-add the extension
  498. imgFormat = "PNG"
  499. newPath += ".png"
  500. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  501. painter = QPainter(self.fExportImage)
  502. painter.save()
  503. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  504. painter.setRenderHint(QPainter.TextAntialiasing)
  505. self.scene.render(painter)
  506. self.fExportImage.save(newPath, imgFormat, 100)
  507. painter.restore()
  508. # ------------------------------------------------------------------------------------------------
  509. # Canvas callback
  510. def CanvasCallback(action, value1, value2, valueStr):
  511. if action == patchcanvas.ACTION_GROUP_INFO:
  512. pass
  513. elif action == patchcanvas.ACTION_GROUP_RENAME:
  514. pass
  515. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  516. groupId = value1
  517. patchcanvas.splitGroup(groupId)
  518. Carla.gui.ui.miniCanvasPreview.update()
  519. elif action == patchcanvas.ACTION_GROUP_JOIN:
  520. groupId = value1
  521. patchcanvas.joinGroup(groupId)
  522. Carla.gui.ui.miniCanvasPreview.update()
  523. elif action == patchcanvas.ACTION_PORT_INFO:
  524. pass
  525. elif action == patchcanvas.ACTION_PORT_RENAME:
  526. pass
  527. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  528. portIdA = value1
  529. portIdB = value2
  530. if not Carla.host.patchbay_connect(portIdA, portIdB):
  531. print("Connection failed:", cString(Carla.host.get_last_error()))
  532. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  533. connectionId = value1
  534. if not Carla.host.patchbay_disconnect(connectionId):
  535. print("Disconnect failed:", cString(Carla.host.get_last_error()))