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.

carla_patchbay.py 28KB

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