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 31KB

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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. @pyqtSlot(int, int, int)
  432. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  433. if pluginId >= self.fPluginCount:
  434. return
  435. pitem = self.fPluginList[pluginId]
  436. if pitem is None:
  437. return
  438. pitem.sendNoteOff(channel, note)
  439. # -----------------------------------------------------------------
  440. @pyqtSlot(int)
  441. def slot_handleUpdateCallback(self, pluginId):
  442. if pluginId >= self.fPluginCount:
  443. return
  444. pitem = self.fPluginList[pluginId]
  445. if pitem is None:
  446. return
  447. pitem.updateInfo()
  448. @pyqtSlot(int)
  449. def slot_handleReloadInfoCallback(self, pluginId):
  450. if pluginId >= self.fPluginCount:
  451. return
  452. pitem = self.fPluginList[pluginId]
  453. if pitem is None:
  454. return
  455. pitem.reloadInfo()
  456. @pyqtSlot(int)
  457. def slot_handleReloadParametersCallback(self, pluginId):
  458. if pluginId >= self.fPluginCount:
  459. return
  460. pitem = self.fPluginList[pluginId]
  461. if pitem is None:
  462. return
  463. pitem.reloadParameters()
  464. @pyqtSlot(int)
  465. def slot_handleReloadProgramsCallback(self, pluginId):
  466. if pluginId >= self.fPluginCount:
  467. return
  468. pitem = self.fPluginList[pluginId]
  469. if pitem is None:
  470. return
  471. pitem.reloadPrograms()
  472. @pyqtSlot(int)
  473. def slot_handleReloadAllCallback(self, pluginId):
  474. if pluginId >= self.fPluginCount:
  475. return
  476. pitem = self.fPluginList[pluginId]
  477. if pitem is None:
  478. return
  479. pitem.reloadAll()
  480. # -----------------------------------------------------------------
  481. @pyqtSlot(int, int, int, str)
  482. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  483. pcSplit = patchcanvas.SPLIT_UNDEF
  484. pcIcon = patchcanvas.ICON_APPLICATION
  485. if clientIcon == PATCHBAY_ICON_PLUGIN:
  486. pcIcon = patchcanvas.ICON_PLUGIN
  487. if clientIcon == PATCHBAY_ICON_HARDWARE:
  488. pcIcon = patchcanvas.ICON_HARDWARE
  489. elif clientIcon == PATCHBAY_ICON_CARLA:
  490. pass
  491. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  492. pcIcon = patchcanvas.ICON_DISTRHO
  493. elif clientIcon == PATCHBAY_ICON_FILE:
  494. pcIcon = patchcanvas.ICON_FILE
  495. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  496. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  497. if pluginId < 0:
  498. return
  499. if pluginId >= self.getPluginCount():
  500. print("sorry, can't map this plugin to canvas client", pluginId, self.getPluginCount())
  501. return
  502. pitem = self.fPluginList[pluginId]
  503. if pitem is None:
  504. return
  505. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(pitem.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI))
  506. @pyqtSlot(int)
  507. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  508. #if not self.fEngineStarted: return
  509. patchcanvas.removeGroup(clientId)
  510. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  511. @pyqtSlot(int, str)
  512. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  513. patchcanvas.renameGroup(clientId, newClientName)
  514. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  515. @pyqtSlot(int, int, int)
  516. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  517. pcIcon = patchcanvas.ICON_APPLICATION
  518. if clientIcon == PATCHBAY_ICON_PLUGIN:
  519. pcIcon = patchcanvas.ICON_PLUGIN
  520. if clientIcon == PATCHBAY_ICON_HARDWARE:
  521. pcIcon = patchcanvas.ICON_HARDWARE
  522. elif clientIcon == PATCHBAY_ICON_CARLA:
  523. pass
  524. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  525. pcIcon = patchcanvas.ICON_DISTRHO
  526. elif clientIcon == PATCHBAY_ICON_FILE:
  527. pcIcon = patchcanvas.ICON_FILE
  528. patchcanvas.setGroupIcon(clientId, pcIcon)
  529. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  530. if pluginId < 0:
  531. return
  532. if pluginId >= self.getPluginCount():
  533. print("sorry, can't map this plugin to canvas client", pluginId, self.getPluginCount())
  534. return
  535. pitem = self.fPluginList[pluginId]
  536. if pitem is None:
  537. return
  538. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(pitem.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI))
  539. @pyqtSlot(int, int, int, str)
  540. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  541. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  542. portMode = patchcanvas.PORT_MODE_INPUT
  543. else:
  544. portMode = patchcanvas.PORT_MODE_OUTPUT
  545. if (portFlags & PATCHBAY_PORT_TYPE_AUDIO):
  546. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  547. elif (portFlags & PATCHBAY_PORT_TYPE_CV):
  548. portType = patchcanvas.PORT_TYPE_AUDIO_JACK # TODO
  549. elif (portFlags & PATCHBAY_PORT_TYPE_MIDI):
  550. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  551. else:
  552. portType = patchcanvas.PORT_TYPE_NULL
  553. patchcanvas.addPort(clientId, portId, portName, portMode, portType)
  554. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  555. @pyqtSlot(int, int)
  556. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  557. #if not self.fEngineStarted: return
  558. patchcanvas.removePort(portId)
  559. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  560. @pyqtSlot(int, int, str)
  561. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  562. patchcanvas.renamePort(portId, newPortName)
  563. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  564. @pyqtSlot(int, int, int)
  565. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, portOutId, portInId):
  566. patchcanvas.connectPorts(connectionId, portOutId, portInId)
  567. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  568. @pyqtSlot(int, int, int)
  569. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  570. #if not self.fEngineStarted: return
  571. patchcanvas.disconnectPorts(connectionId)
  572. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  573. # -----------------------------------------------------------------
  574. @pyqtSlot()
  575. def slot_canvasArrange(self):
  576. patchcanvas.arrange()
  577. @pyqtSlot()
  578. def slot_canvasRefresh(self):
  579. patchcanvas.clear()
  580. if Carla.host.is_engine_running():
  581. Carla.host.patchbay_refresh()
  582. QTimer.singleShot(1000 if self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] else 0, self.fMiniCanvasPreview.update)
  583. @pyqtSlot()
  584. def slot_canvasZoomFit(self):
  585. self.scene.zoom_fit()
  586. @pyqtSlot()
  587. def slot_canvasZoomIn(self):
  588. self.scene.zoom_in()
  589. @pyqtSlot()
  590. def slot_canvasZoomOut(self):
  591. self.scene.zoom_out()
  592. @pyqtSlot()
  593. def slot_canvasZoomReset(self):
  594. self.scene.zoom_reset()
  595. @pyqtSlot()
  596. def slot_canvasPrint(self):
  597. self.scene.clearSelection()
  598. self.fExportPrinter = QPrinter()
  599. dialog = QPrintDialog(self.fExportPrinter, self)
  600. if dialog.exec_():
  601. painter = QPainter(self.fExportPrinter)
  602. painter.save()
  603. painter.setRenderHint(QPainter.Antialiasing)
  604. painter.setRenderHint(QPainter.TextAntialiasing)
  605. self.scene.render(painter)
  606. painter.restore()
  607. @pyqtSlot()
  608. def slot_canvasSaveImage(self):
  609. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  610. if newPath:
  611. self.scene.clearSelection()
  612. if newPath.lower().endswith((".jpg",)):
  613. imgFormat = "JPG"
  614. elif newPath.lower().endswith((".png",)):
  615. imgFormat = "PNG"
  616. else:
  617. # File-dialog may not auto-add the extension
  618. imgFormat = "PNG"
  619. newPath += ".png"
  620. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  621. painter = QPainter(self.fExportImage)
  622. painter.save()
  623. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  624. painter.setRenderHint(QPainter.TextAntialiasing)
  625. self.scene.render(painter)
  626. self.fExportImage.save(newPath, imgFormat, 100)
  627. painter.restore()
  628. # -----------------------------------------------------------------
  629. def resizeEvent(self, event):
  630. QFrame.resizeEvent(self, event)
  631. self.slot_miniCanvasCheckSize()
  632. # ------------------------------------------------------------------------------------------------
  633. # Canvas callback
  634. def canvasCallback(action, value1, value2, valueStr):
  635. if action == patchcanvas.ACTION_GROUP_INFO:
  636. pass
  637. elif action == patchcanvas.ACTION_GROUP_RENAME:
  638. pass
  639. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  640. groupId = value1
  641. patchcanvas.splitGroup(groupId)
  642. Carla.gui.ui.miniCanvasPreview.update()
  643. elif action == patchcanvas.ACTION_GROUP_JOIN:
  644. groupId = value1
  645. patchcanvas.joinGroup(groupId)
  646. Carla.gui.ui.miniCanvasPreview.update()
  647. elif action == patchcanvas.ACTION_PORT_INFO:
  648. pass
  649. elif action == patchcanvas.ACTION_PORT_RENAME:
  650. pass
  651. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  652. portIdA = value1
  653. portIdB = value2
  654. if not Carla.host.patchbay_connect(portIdA, portIdB):
  655. print("Connection failed:", Carla.host.get_last_error())
  656. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  657. connectionId = value1
  658. if not Carla.host.patchbay_disconnect(connectionId):
  659. print("Disconnect failed:", Carla.host.get_last_error())
  660. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  661. pluginId = value1
  662. Carla.host.clone_plugin(pluginId)
  663. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  664. pluginId = value1
  665. # TODO
  666. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  667. pluginId = value1
  668. newName = valueStr
  669. Carla.host.rename_plugin(pluginId, newName)
  670. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  671. pluginId = value1
  672. Carla.host.remove_plugin(pluginId)
  673. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  674. pluginId = value1
  675. Carla.host.show_custom_ui(pluginId, True)