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.

904 lines
31KB

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