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.

1117 lines
39KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla patchbay widget code
  4. # Copyright (C) 2011-2014 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 (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import QPointF, QTimer
  24. from PyQt5.QtGui import QImage
  25. from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
  26. from PyQt5.QtWidgets import QFrame, QGraphicsView, QGridLayout
  27. else:
  28. from PyQt4.QtCore import QPointF, QTimer
  29. from PyQt4.QtGui import QFrame, QGraphicsView, QGridLayout, QImage, QPrinter, QPrintDialog
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (Custom Stuff)
  32. import patchcanvas
  33. from carla_widgets import *
  34. from digitalpeakmeter import DigitalPeakMeter
  35. from pixmapkeyboard import PixmapKeyboardHArea
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Try Import OpenGL
  38. try:
  39. if config_UseQt5:
  40. from PyQt5.QtOpenGL import QGLWidget
  41. else:
  42. from PyQt4.QtOpenGL import QGLWidget
  43. hasGL = True
  44. except:
  45. hasGL = False
  46. # ------------------------------------------------------------------------------------------------------------
  47. # Carla Canvas defaults
  48. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  49. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  50. # ------------------------------------------------------------------------------------------------
  51. # Patchbay info class, used in main carla as replacement for PluginEdit
  52. class PluginInfo(object):
  53. def __init__(self, parent, pluginId):
  54. object.__init__(self)
  55. self.fPluginId = pluginId
  56. #------------------------------------------------------------------
  57. def setId(self, idx):
  58. self.fPluginId = idx
  59. #------------------------------------------------------------------
  60. def close(self):
  61. pass
  62. def setName(self, name):
  63. pass
  64. def setParameterValue(self, parameterId, value):
  65. pass
  66. def reloadAll(self):
  67. pass
  68. def idleSlow(self):
  69. pass
  70. # ------------------------------------------------------------------------------------------------
  71. # Patchbay widget
  72. class CarlaPatchbayW(QFrame):
  73. def __init__(self, parent, doSetup = True, onlyPatchbay = True, is3D = False):
  74. QFrame.__init__(self, parent)
  75. self.fLayout = QGridLayout(self)
  76. self.fLayout.setContentsMargins(0, 0, 0, 0)
  77. self.fLayout.setSpacing(1)
  78. self.setLayout(self.fLayout)
  79. self.fView = QGraphicsView(self)
  80. self.fKeys = PixmapKeyboardHArea(self)
  81. self.fPeaksIn = DigitalPeakMeter(self)
  82. self.fPeaksOut = DigitalPeakMeter(self)
  83. self.fPeaksCleared = True
  84. self.fPeaksIn.setColor(DigitalPeakMeter.BLUE)
  85. self.fPeaksIn.setChannels(2)
  86. self.fPeaksIn.setOrientation(DigitalPeakMeter.VERTICAL)
  87. self.fPeaksIn.setFixedWidth(25)
  88. self.fPeaksOut.setColor(DigitalPeakMeter.GREEN)
  89. self.fPeaksOut.setChannels(2)
  90. self.fPeaksOut.setOrientation(DigitalPeakMeter.VERTICAL)
  91. self.fPeaksOut.setFixedWidth(25)
  92. self.fLayout.addWidget(self.fPeaksIn, 0, 0)
  93. self.fLayout.addWidget(self.fView, 0, 1) # self.fViewWidget if is3D else
  94. self.fLayout.addWidget(self.fPeaksOut, 0, 2)
  95. self.fLayout.addWidget(self.fKeys, 1, 0, 1, 0)
  96. # -------------------------------------------------------------
  97. # Internal stuff
  98. self.fParent = parent
  99. self.fPluginCount = 0
  100. self.fPluginList = []
  101. self.fIsOnlyPatchbay = onlyPatchbay
  102. self.fSelectedPlugins = []
  103. self.fCanvasWidth = 0
  104. self.fCanvasHeight = 0
  105. # -------------------------------------------------------------
  106. # Set-up Canvas Preview
  107. self.fMiniCanvasPreview = self.fParent.ui.miniCanvasPreview
  108. self.fMiniCanvasPreview.setRealParent(self)
  109. self.fMovingViaMiniCanvas = False
  110. # -------------------------------------------------------------
  111. # Set-up Canvas
  112. self.scene = patchcanvas.PatchScene(self, self.fView)
  113. self.fView.setScene(self.scene)
  114. self.fView.setRenderHint(QPainter.Antialiasing, bool(parent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  115. if parent.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL: # and not is3D:
  116. self.fViewWidget = QGLWidget(self)
  117. self.fView.setViewport(self.fViewWidget)
  118. self.fView.setRenderHint(QPainter.HighQualityAntialiasing, parent.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  119. self.setupCanvas()
  120. QTimer.singleShot(100, self.slot_restoreScrollbarValues)
  121. # -------------------------------------------------------------
  122. # Connect actions to functions
  123. parent.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  124. parent.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  125. self.fView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  126. self.fView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  127. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  128. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  129. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  130. self.fMiniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  131. self.fKeys.keyboard.noteOn.connect(self.slot_noteOn)
  132. self.fKeys.keyboard.noteOff.connect(self.slot_noteOff)
  133. # -------------------------------------------------------------
  134. # Load Settings
  135. settings = QSettings()
  136. showMeters = settings.value("ShowMeters", False, type=bool)
  137. self.fParent.ui.act_settings_show_meters.setChecked(showMeters)
  138. self.fPeaksIn.setVisible(showMeters)
  139. self.fPeaksOut.setVisible(showMeters)
  140. showKeyboard = settings.value("ShowKeyboard", not(MACOS or WINDOWS), type=bool)
  141. self.fParent.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  142. self.fKeys.setVisible(showKeyboard)
  143. # -------------------------------------------------------------
  144. # Connect actions to functions (part 2)
  145. if not doSetup: return
  146. parent.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  147. parent.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  148. parent.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  149. parent.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  150. parent.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  151. parent.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  152. parent.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  153. parent.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  154. parent.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  155. parent.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  156. parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  157. parent.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  158. parent.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  159. parent.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  160. parent.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  161. parent.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  162. parent.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  163. parent.ui.act_canvas_print.triggered.connect(self.slot_canvasPrint)
  164. parent.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  165. parent.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  166. parent.ParameterValueChangedCallback.connect(self.slot_handleParameterValueChangedCallback)
  167. parent.ParameterDefaultChangedCallback.connect(self.slot_handleParameterDefaultChangedCallback)
  168. parent.ParameterMidiChannelChangedCallback.connect(self.slot_handleParameterMidiChannelChangedCallback)
  169. parent.ParameterMidiCcChangedCallback.connect(self.slot_handleParameterMidiCcChangedCallback)
  170. parent.ProgramChangedCallback.connect(self.slot_handleProgramChangedCallback)
  171. parent.MidiProgramChangedCallback.connect(self.slot_handleMidiProgramChangedCallback)
  172. parent.OptionChangedCallback.connect(self.slot_handleOptionChangedCallback)
  173. parent.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  174. parent.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  175. parent.UpdateCallback.connect(self.slot_handleUpdateCallback)
  176. parent.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  177. parent.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  178. parent.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  179. parent.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  180. parent.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  181. parent.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  182. parent.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  183. parent.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  184. parent.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  185. parent.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  186. parent.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  187. parent.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  188. parent.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  189. # -----------------------------------------------------------------
  190. def getPluginCount(self):
  191. return self.fPluginCount
  192. # -----------------------------------------------------------------
  193. def addPlugin(self, pluginId, isProjectLoading):
  194. if self.fIsOnlyPatchbay:
  195. pitem = PluginEdit(self, pluginId)
  196. else:
  197. pitem = PluginInfo(self, pluginId)
  198. self.fPluginList.append(pitem)
  199. self.fPluginCount += 1
  200. if self.fIsOnlyPatchbay and not isProjectLoading:
  201. gCarla.host.set_active(pluginId, True)
  202. def removePlugin(self, pluginId):
  203. patchcanvas.handlePluginRemoved(pluginId)
  204. if pluginId in self.fSelectedPlugins:
  205. self.clearSideStuff()
  206. if pluginId >= self.fPluginCount:
  207. return
  208. pitem = self.fPluginList[pluginId]
  209. if pitem is None:
  210. return
  211. self.fPluginCount -= 1
  212. self.fPluginList.pop(pluginId)
  213. pitem.close()
  214. del pitem
  215. # push all plugins 1 slot back
  216. for i in range(pluginId, self.fPluginCount):
  217. pitem = self.fPluginList[i]
  218. pitem.setId(i)
  219. def renamePlugin(self, pluginId, newName):
  220. if pluginId >= self.fPluginCount:
  221. return
  222. pitem = self.fPluginList[pluginId]
  223. if pitem is None:
  224. return
  225. pitem.setName(newName)
  226. def disablePlugin(self, pluginId, errorMsg):
  227. if pluginId >= self.fPluginCount:
  228. return
  229. pitem = self.fPluginList[pluginId]
  230. if pitem is None:
  231. return
  232. def removeAllPlugins(self):
  233. for pitem in self.fPluginList:
  234. if pitem is None:
  235. break
  236. pitem.close()
  237. del pitem
  238. self.fPluginCount = 0
  239. self.fPluginList = []
  240. self.clearSideStuff()
  241. patchcanvas.handlePluginRemoved(0)
  242. # -----------------------------------------------------------------
  243. def engineStarted(self):
  244. pass
  245. def engineStopped(self):
  246. patchcanvas.clear()
  247. def engineChanged(self):
  248. pass
  249. # -----------------------------------------------------------------
  250. def idleFast(self):
  251. if self.fPluginCount == 0:
  252. return
  253. for pluginId in self.fSelectedPlugins:
  254. self.fPeaksCleared = False
  255. if self.fPeaksIn.isVisible():
  256. self.fPeaksIn.displayMeter(1, gCarla.host.get_input_peak_value(pluginId, True))
  257. self.fPeaksIn.displayMeter(2, gCarla.host.get_input_peak_value(pluginId, False))
  258. if self.fPeaksOut.isVisible():
  259. self.fPeaksOut.displayMeter(1, gCarla.host.get_output_peak_value(pluginId, True))
  260. self.fPeaksOut.displayMeter(2, gCarla.host.get_output_peak_value(pluginId, False))
  261. return
  262. if self.fPeaksCleared:
  263. return
  264. self.fPeaksCleared = True
  265. self.fPeaksIn.displayMeter(1, 0.0, True)
  266. self.fPeaksIn.displayMeter(2, 0.0, True)
  267. self.fPeaksOut.displayMeter(1, 0.0, True)
  268. self.fPeaksOut.displayMeter(2, 0.0, True)
  269. def idleSlow(self):
  270. for pitem in self.fPluginList:
  271. if pitem is None:
  272. break
  273. pitem.idleSlow()
  274. # -----------------------------------------------------------------
  275. def projectLoadingStarted(self):
  276. pass
  277. def projectLoadingFinished(self):
  278. QTimer.singleShot(1000, self.slot_canvasRefresh)
  279. # -----------------------------------------------------------------
  280. def saveSettings(self, settings):
  281. settings.setValue("ShowMeters", self.fParent.ui.act_settings_show_meters.isChecked())
  282. settings.setValue("ShowKeyboard", self.fParent.ui.act_settings_show_keyboard.isChecked())
  283. settings.setValue("HorizontalScrollBarValue", self.fView.horizontalScrollBar().value())
  284. settings.setValue("VerticalScrollBarValue", self.fView.verticalScrollBar().value())
  285. def showEditDialog(self, pluginId):
  286. if pluginId >= self.fPluginCount:
  287. return
  288. pitem = self.fPluginList[pluginId]
  289. if pitem is None:
  290. return
  291. pitem.show()
  292. # -----------------------------------------------------------------
  293. # called by PluginEdit to plugin skin parent, ignored here
  294. def editDialogChanged(self, visible):
  295. pass
  296. def recheckPluginHints(self, hints):
  297. pass
  298. def notePressed(self, note):
  299. pass
  300. def noteReleased(self, note):
  301. pass
  302. # -----------------------------------------------------------------
  303. def clearSideStuff(self):
  304. self.scene.clearSelection()
  305. self.fSelectedPlugins = []
  306. self.fKeys.keyboard.allNotesOff(False)
  307. self.fKeys.setEnabled(False)
  308. self.fPeaksCleared = True
  309. self.fPeaksIn.displayMeter(1, 0.0, True)
  310. self.fPeaksIn.displayMeter(2, 0.0, True)
  311. self.fPeaksOut.displayMeter(1, 0.0, True)
  312. self.fPeaksOut.displayMeter(2, 0.0, True)
  313. def setupCanvas(self):
  314. pOptions = patchcanvas.options_t()
  315. pOptions.theme_name = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  316. pOptions.auto_hide_groups = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  317. pOptions.use_bezier_lines = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  318. pOptions.antialiasing = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  319. pOptions.eyecandy = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
  320. pFeatures = patchcanvas.features_t()
  321. pFeatures.group_info = False
  322. pFeatures.group_rename = False
  323. pFeatures.port_info = False
  324. pFeatures.port_rename = False
  325. pFeatures.handle_group_pos = True
  326. patchcanvas.setOptions(pOptions)
  327. patchcanvas.setFeatures(pFeatures)
  328. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  329. tryCanvasSize = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  330. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  331. self.fCanvasWidth = int(tryCanvasSize[0])
  332. self.fCanvasHeight = int(tryCanvasSize[1])
  333. else:
  334. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  335. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  336. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  337. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  338. self.fView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  339. self.themeData = [self.fCanvasWidth, self.fCanvasHeight, patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color()]
  340. def updateCanvasInitialPos(self):
  341. x = self.fView.horizontalScrollBar().value() + self.width()/4
  342. y = self.fView.verticalScrollBar().value() + self.height()/4
  343. patchcanvas.setInitialPos(x, y)
  344. # -----------------------------------------------------------------
  345. @pyqtSlot(bool)
  346. def slot_showCanvasMeters(self, yesNo):
  347. self.fPeaksIn.setVisible(yesNo)
  348. self.fPeaksOut.setVisible(yesNo)
  349. @pyqtSlot(bool)
  350. def slot_showCanvasKeyboard(self, yesNo):
  351. self.fKeys.setVisible(yesNo)
  352. # -----------------------------------------------------------------
  353. @pyqtSlot()
  354. def slot_miniCanvasCheckAll(self):
  355. self.slot_miniCanvasCheckSize()
  356. self.slot_horizontalScrollBarChanged(self.fView.horizontalScrollBar().value())
  357. self.slot_verticalScrollBarChanged(self.fView.verticalScrollBar().value())
  358. @pyqtSlot()
  359. def slot_miniCanvasCheckSize(self):
  360. self.fMiniCanvasPreview.setViewSize(float(self.width()) / self.fCanvasWidth, float(self.height()) / self.fCanvasHeight)
  361. @pyqtSlot(int)
  362. def slot_horizontalScrollBarChanged(self, value):
  363. if self.fMovingViaMiniCanvas: return
  364. maximum = self.fView.horizontalScrollBar().maximum()
  365. if maximum == 0:
  366. xp = 0
  367. else:
  368. xp = float(value) / maximum
  369. self.fMiniCanvasPreview.setViewPosX(xp)
  370. self.updateCanvasInitialPos()
  371. @pyqtSlot(int)
  372. def slot_verticalScrollBarChanged(self, value):
  373. if self.fMovingViaMiniCanvas: return
  374. maximum = self.fView.verticalScrollBar().maximum()
  375. if maximum == 0:
  376. yp = 0
  377. else:
  378. yp = float(value) / maximum
  379. self.fMiniCanvasPreview.setViewPosY(yp)
  380. self.updateCanvasInitialPos()
  381. @pyqtSlot()
  382. def slot_restoreScrollbarValues(self):
  383. settings = QSettings()
  384. self.fView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.fView.horizontalScrollBar().maximum()/2, type=int))
  385. self.fView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.fView.verticalScrollBar().maximum()/2, type=int))
  386. # -----------------------------------------------------------------
  387. @pyqtSlot(float)
  388. def slot_canvasScaleChanged(self, scale):
  389. self.fMiniCanvasPreview.setViewScale(scale)
  390. @pyqtSlot(int, int, QPointF)
  391. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  392. self.fMiniCanvasPreview.update()
  393. @pyqtSlot(list)
  394. def slot_canvasPluginSelected(self, pluginList):
  395. self.fKeys.keyboard.allNotesOff(False)
  396. self.fKeys.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  397. self.fSelectedPlugins = pluginList
  398. @pyqtSlot(float, float)
  399. def slot_miniCanvasMoved(self, xp, yp):
  400. self.fMovingViaMiniCanvas = True
  401. self.fView.horizontalScrollBar().setValue(xp * self.fView.horizontalScrollBar().maximum())
  402. self.fView.verticalScrollBar().setValue(yp * self.fView.verticalScrollBar().maximum())
  403. self.fMovingViaMiniCanvas = False
  404. self.updateCanvasInitialPos()
  405. # -----------------------------------------------------------------
  406. @pyqtSlot(int)
  407. def slot_noteOn(self, note):
  408. for pluginId in self.fSelectedPlugins:
  409. gCarla.host.send_midi_note(pluginId, 0, note, 100)
  410. @pyqtSlot(int)
  411. def slot_noteOff(self, note):
  412. for pluginId in self.fSelectedPlugins:
  413. gCarla.host.send_midi_note(pluginId, 0, note, 0)
  414. # -----------------------------------------------------------------
  415. @pyqtSlot()
  416. def slot_pluginsEnable(self):
  417. if not gCarla.host.is_engine_running():
  418. return
  419. for i in range(self.fPluginCount):
  420. gCarla.host.set_active(i, True)
  421. @pyqtSlot()
  422. def slot_pluginsDisable(self):
  423. if not gCarla.host.is_engine_running():
  424. return
  425. for i in range(self.fPluginCount):
  426. gCarla.host.set_active(i, False)
  427. @pyqtSlot()
  428. def slot_pluginsVolume100(self):
  429. if not gCarla.host.is_engine_running():
  430. return
  431. for i in range(self.fPluginCount):
  432. pitem = self.fPluginList[i]
  433. if pitem is None:
  434. break
  435. if pitem.getHints() & PLUGIN_CAN_VOLUME:
  436. pitem.setParameterValue(PARAMETER_VOLUME, 1.0)
  437. gCarla.host.set_volume(i, 1.0)
  438. @pyqtSlot()
  439. def slot_pluginsMute(self):
  440. if not gCarla.host.is_engine_running():
  441. return
  442. for i in range(self.fPluginCount):
  443. pitem = self.fPluginList[i]
  444. if pitem is None:
  445. break
  446. if pitem.getHints() & PLUGIN_CAN_VOLUME:
  447. pitem.setParameterValue(PARAMETER_VOLUME, 0.0)
  448. gCarla.host.set_volume(i, 0.0)
  449. @pyqtSlot()
  450. def slot_pluginsWet100(self):
  451. if not gCarla.host.is_engine_running():
  452. return
  453. for i in range(self.fPluginCount):
  454. pitem = self.fPluginList[i]
  455. if pitem is None:
  456. break
  457. if pitem.getHints() & PLUGIN_CAN_DRYWET:
  458. pitem.setParameterValue(PARAMETER_DRYWET, 1.0)
  459. gCarla.host.set_drywet(i, 1.0)
  460. @pyqtSlot()
  461. def slot_pluginsBypass(self):
  462. if not gCarla.host.is_engine_running():
  463. return
  464. for i in range(self.fPluginCount):
  465. pitem = self.fPluginList[i]
  466. if pitem is None:
  467. break
  468. if pitem.getHints() & PLUGIN_CAN_DRYWET:
  469. pitem.setParameterValue(PARAMETER_DRYWET, 0.0)
  470. gCarla.host.set_drywet(i, 0.0)
  471. @pyqtSlot()
  472. def slot_pluginsCenter(self):
  473. if not gCarla.host.is_engine_running():
  474. return
  475. for i in range(self.fPluginCount):
  476. pitem = self.fPluginList[i]
  477. if pitem is None:
  478. break
  479. if pitem.getHints() & PLUGIN_CAN_BALANCE:
  480. pitem.setParameterValue(PARAMETER_BALANCE_LEFT, -1.0)
  481. pitem.setParameterValue(PARAMETER_BALANCE_RIGHT, 1.0)
  482. gCarla.host.set_balance_left(i, -1.0)
  483. gCarla.host.set_balance_right(i, 1.0)
  484. if pitem.getHints() & PLUGIN_CAN_PANNING:
  485. pitem.setParameterValue(PARAMETER_PANNING, 0.0)
  486. gCarla.host.set_panning(i, 0.0)
  487. # -----------------------------------------------------------------
  488. @pyqtSlot()
  489. def slot_configureCarla(self):
  490. if self.fParent is None or not self.fParent.openSettingsWindow(True, hasGL):
  491. return
  492. self.fParent.loadSettings(False)
  493. patchcanvas.clear()
  494. self.setupCanvas()
  495. self.fParent.updateContainer(self.themeData)
  496. self.slot_miniCanvasCheckAll()
  497. if gCarla.host.is_engine_running():
  498. gCarla.host.patchbay_refresh(gCarla.externalPatchbay)
  499. # -----------------------------------------------------------------
  500. @pyqtSlot(int, int, float)
  501. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  502. if pluginId >= self.fPluginCount:
  503. return
  504. pitem = self.fPluginList[pluginId]
  505. if pitem is None:
  506. return
  507. pitem.setParameterValue(index, value)
  508. @pyqtSlot(int, int, float)
  509. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  510. if pluginId >= self.fPluginCount:
  511. return
  512. pitem = self.fPluginList[pluginId]
  513. if pitem is None:
  514. return
  515. pitem.setParameterDefault(index, value)
  516. @pyqtSlot(int, int, int)
  517. def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
  518. if pluginId >= self.fPluginCount:
  519. return
  520. pitem = self.fPluginList[pluginId]
  521. if pitem is None:
  522. return
  523. pitem.setParameterMidiControl(index, cc)
  524. @pyqtSlot(int, int, int)
  525. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  526. if pluginId >= self.fPluginCount:
  527. return
  528. pitem = self.fPluginList[pluginId]
  529. if pitem is None:
  530. return
  531. pitem.setParameterMidiChannel(index, channel)
  532. # -----------------------------------------------------------------
  533. @pyqtSlot(int, int)
  534. def slot_handleProgramChangedCallback(self, pluginId, index):
  535. if pluginId >= self.fPluginCount:
  536. return
  537. pitem = self.fPluginList[pluginId]
  538. if pitem is None:
  539. return
  540. pitem.setProgram(index)
  541. @pyqtSlot(int, int)
  542. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  543. if pluginId >= self.fPluginCount:
  544. return
  545. pitem = self.fPluginList[pluginId]
  546. if pitem is None:
  547. return
  548. pitem.setMidiProgram(index)
  549. # -----------------------------------------------------------------
  550. @pyqtSlot(int, int, bool)
  551. def slot_handleOptionChangedCallback(self, pluginId, option, yesNo):
  552. if pluginId >= self.fPluginCount:
  553. return
  554. pitem = self.fPluginList[pluginId]
  555. if pitem is None:
  556. return
  557. pitem.setOption(option, yesNo)
  558. # -----------------------------------------------------------------
  559. @pyqtSlot(int, int, int, int)
  560. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  561. if pluginId in self.fSelectedPlugins:
  562. self.fKeys.keyboard.sendNoteOn(note, False)
  563. if not self.fIsOnlyPatchbay:
  564. return
  565. if pluginId >= self.fPluginCount:
  566. return
  567. pitem = self.fPluginList[pluginId]
  568. if pitem is None:
  569. return
  570. pitem.sendNoteOn(channel, note)
  571. @pyqtSlot(int, int, int)
  572. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  573. if pluginId in self.fSelectedPlugins:
  574. self.fKeys.keyboard.sendNoteOff(note, False)
  575. if not self.fIsOnlyPatchbay:
  576. return
  577. if pluginId >= self.fPluginCount:
  578. return
  579. pitem = self.fPluginList[pluginId]
  580. if pitem is None:
  581. return
  582. pitem.sendNoteOff(channel, note)
  583. # -----------------------------------------------------------------
  584. @pyqtSlot(int)
  585. def slot_handleUpdateCallback(self, pluginId):
  586. if pluginId >= self.fPluginCount:
  587. return
  588. pitem = self.fPluginList[pluginId]
  589. if pitem is None:
  590. return
  591. pitem.updateInfo()
  592. @pyqtSlot(int)
  593. def slot_handleReloadInfoCallback(self, pluginId):
  594. if pluginId >= self.fPluginCount:
  595. return
  596. pitem = self.fPluginList[pluginId]
  597. if pitem is None:
  598. return
  599. pitem.reloadInfo()
  600. @pyqtSlot(int)
  601. def slot_handleReloadParametersCallback(self, pluginId):
  602. if pluginId >= self.fPluginCount:
  603. return
  604. pitem = self.fPluginList[pluginId]
  605. if pitem is None:
  606. return
  607. pitem.reloadParameters()
  608. @pyqtSlot(int)
  609. def slot_handleReloadProgramsCallback(self, pluginId):
  610. if pluginId >= self.fPluginCount:
  611. return
  612. pitem = self.fPluginList[pluginId]
  613. if pitem is None:
  614. return
  615. pitem.reloadPrograms()
  616. @pyqtSlot(int)
  617. def slot_handleReloadAllCallback(self, pluginId):
  618. if pluginId >= self.fPluginCount:
  619. return
  620. pitem = self.fPluginList[pluginId]
  621. if pitem is None:
  622. return
  623. pitem.reloadAll()
  624. # -----------------------------------------------------------------
  625. @pyqtSlot(int, int, int, str)
  626. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  627. pcSplit = patchcanvas.SPLIT_UNDEF
  628. pcIcon = patchcanvas.ICON_APPLICATION
  629. if clientIcon == PATCHBAY_ICON_PLUGIN:
  630. pcIcon = patchcanvas.ICON_PLUGIN
  631. if clientIcon == PATCHBAY_ICON_HARDWARE:
  632. pcIcon = patchcanvas.ICON_HARDWARE
  633. elif clientIcon == PATCHBAY_ICON_CARLA:
  634. pass
  635. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  636. pcIcon = patchcanvas.ICON_DISTRHO
  637. elif clientIcon == PATCHBAY_ICON_FILE:
  638. pcIcon = patchcanvas.ICON_FILE
  639. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  640. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  641. if pluginId < 0:
  642. return
  643. if pluginId >= self.fPluginCount:
  644. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  645. return
  646. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(gCarla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  647. @pyqtSlot(int)
  648. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  649. #if not self.fEngineStarted: return
  650. patchcanvas.removeGroup(clientId)
  651. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  652. @pyqtSlot(int, str)
  653. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  654. patchcanvas.renameGroup(clientId, newClientName)
  655. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  656. @pyqtSlot(int, int, int)
  657. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  658. pcIcon = patchcanvas.ICON_APPLICATION
  659. if clientIcon == PATCHBAY_ICON_PLUGIN:
  660. pcIcon = patchcanvas.ICON_PLUGIN
  661. if clientIcon == PATCHBAY_ICON_HARDWARE:
  662. pcIcon = patchcanvas.ICON_HARDWARE
  663. elif clientIcon == PATCHBAY_ICON_CARLA:
  664. pass
  665. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  666. pcIcon = patchcanvas.ICON_DISTRHO
  667. elif clientIcon == PATCHBAY_ICON_FILE:
  668. pcIcon = patchcanvas.ICON_FILE
  669. patchcanvas.setGroupIcon(clientId, pcIcon)
  670. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  671. if pluginId < 0:
  672. return
  673. if pluginId >= self.fPluginCount:
  674. print("sorry, can't map this plugin to canvas client", pluginId, self.getPluginCount())
  675. return
  676. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(gCarla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  677. @pyqtSlot(int, int, int, str)
  678. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  679. isAlternate = False
  680. if (portFlags & PATCHBAY_PORT_IS_INPUT):
  681. portMode = patchcanvas.PORT_MODE_INPUT
  682. else:
  683. portMode = patchcanvas.PORT_MODE_OUTPUT
  684. if (portFlags & PATCHBAY_PORT_TYPE_AUDIO):
  685. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  686. elif (portFlags & PATCHBAY_PORT_TYPE_CV):
  687. isAlternate = True
  688. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  689. elif (portFlags & PATCHBAY_PORT_TYPE_MIDI):
  690. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  691. else:
  692. portType = patchcanvas.PORT_TYPE_NULL
  693. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  694. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  695. @pyqtSlot(int, int)
  696. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  697. #if not self.fEngineStarted: return
  698. patchcanvas.removePort(groupId, portId)
  699. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  700. @pyqtSlot(int, int, str)
  701. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  702. patchcanvas.renamePort(groupId, portId, newPortName)
  703. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  704. @pyqtSlot(int, int, int, int, int)
  705. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  706. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  707. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  708. @pyqtSlot(int, int, int)
  709. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  710. #if not self.fEngineStarted: return
  711. patchcanvas.disconnectPorts(connectionId)
  712. QTimer.singleShot(0, self.fMiniCanvasPreview.update)
  713. # -----------------------------------------------------------------
  714. @pyqtSlot()
  715. def slot_canvasArrange(self):
  716. patchcanvas.arrange()
  717. @pyqtSlot()
  718. def slot_canvasShowInternal(self):
  719. gCarla.externalPatchbay = False
  720. self.fParent.ui.act_canvas_show_internal.blockSignals(True)
  721. self.fParent.ui.act_canvas_show_external.blockSignals(True)
  722. self.fParent.ui.act_canvas_show_internal.setChecked(True)
  723. self.fParent.ui.act_canvas_show_external.setChecked(False)
  724. self.fParent.ui.act_canvas_show_internal.blockSignals(False)
  725. self.fParent.ui.act_canvas_show_external.blockSignals(False)
  726. self.slot_canvasRefresh()
  727. @pyqtSlot()
  728. def slot_canvasShowExternal(self):
  729. gCarla.externalPatchbay = True
  730. self.fParent.ui.act_canvas_show_internal.blockSignals(True)
  731. self.fParent.ui.act_canvas_show_external.blockSignals(True)
  732. self.fParent.ui.act_canvas_show_internal.setChecked(False)
  733. self.fParent.ui.act_canvas_show_external.setChecked(True)
  734. self.fParent.ui.act_canvas_show_internal.blockSignals(False)
  735. self.fParent.ui.act_canvas_show_external.blockSignals(False)
  736. self.slot_canvasRefresh()
  737. @pyqtSlot()
  738. def slot_canvasRefresh(self):
  739. patchcanvas.clear()
  740. if gCarla.host is not None and gCarla.host.is_engine_running():
  741. gCarla.host.patchbay_refresh(gCarla.externalPatchbay)
  742. for pitem in self.fPluginList:
  743. if pitem is None:
  744. break
  745. pitem.reloadAll()
  746. QTimer.singleShot(1000 if self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] else 0, self.fMiniCanvasPreview.update)
  747. @pyqtSlot()
  748. def slot_canvasZoomFit(self):
  749. self.scene.zoom_fit()
  750. @pyqtSlot()
  751. def slot_canvasZoomIn(self):
  752. self.scene.zoom_in()
  753. @pyqtSlot()
  754. def slot_canvasZoomOut(self):
  755. self.scene.zoom_out()
  756. @pyqtSlot()
  757. def slot_canvasZoomReset(self):
  758. self.scene.zoom_reset()
  759. @pyqtSlot()
  760. def slot_canvasPrint(self):
  761. self.scene.clearSelection()
  762. self.fExportPrinter = QPrinter()
  763. dialog = QPrintDialog(self.fExportPrinter, self)
  764. if dialog.exec_():
  765. painter = QPainter(self.fExportPrinter)
  766. painter.save()
  767. painter.setRenderHint(QPainter.Antialiasing)
  768. painter.setRenderHint(QPainter.TextAntialiasing)
  769. self.scene.render(painter)
  770. painter.restore()
  771. @pyqtSlot()
  772. def slot_canvasSaveImage(self):
  773. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  774. if config_UseQt5:
  775. newPath = newPath[0]
  776. if not newPath:
  777. return
  778. self.scene.clearSelection()
  779. if newPath.lower().endswith((".jpg",)):
  780. imgFormat = "JPG"
  781. elif newPath.lower().endswith((".png",)):
  782. imgFormat = "PNG"
  783. else:
  784. # File-dialog may not auto-add the extension
  785. imgFormat = "PNG"
  786. newPath += ".png"
  787. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  788. painter = QPainter(self.fExportImage)
  789. painter.save()
  790. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  791. painter.setRenderHint(QPainter.TextAntialiasing)
  792. self.scene.render(painter)
  793. self.fExportImage.save(newPath, imgFormat, 100)
  794. painter.restore()
  795. # -----------------------------------------------------------------
  796. def resizeEvent(self, event):
  797. QFrame.resizeEvent(self, event)
  798. self.slot_miniCanvasCheckSize()
  799. # ------------------------------------------------------------------------------------------------
  800. # Canvas callback
  801. def canvasCallback(action, value1, value2, valueStr):
  802. if action == patchcanvas.ACTION_GROUP_INFO:
  803. pass
  804. elif action == patchcanvas.ACTION_GROUP_RENAME:
  805. pass
  806. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  807. groupId = value1
  808. patchcanvas.splitGroup(groupId)
  809. gCarla.gui.ui.miniCanvasPreview.update()
  810. elif action == patchcanvas.ACTION_GROUP_JOIN:
  811. groupId = value1
  812. patchcanvas.joinGroup(groupId)
  813. gCarla.gui.ui.miniCanvasPreview.update()
  814. elif action == patchcanvas.ACTION_PORT_INFO:
  815. pass
  816. elif action == patchcanvas.ACTION_PORT_RENAME:
  817. pass
  818. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  819. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  820. if not gCarla.host.patchbay_connect(gOut, pOut, gIn, pIn):
  821. print("Connection failed:", gCarla.host.get_last_error())
  822. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  823. connectionId = value1
  824. if not gCarla.host.patchbay_disconnect(connectionId):
  825. print("Disconnect failed:", gCarla.host.get_last_error())
  826. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  827. pluginId = value1
  828. gCarla.host.clone_plugin(pluginId)
  829. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  830. pluginId = value1
  831. gCarla.gui.fContainer.showEditDialog(pluginId)
  832. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  833. pluginId = value1
  834. newName = valueStr
  835. gCarla.host.rename_plugin(pluginId, newName)
  836. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  837. pluginId = value1
  838. gCarla.host.remove_plugin(pluginId)
  839. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  840. pluginId = value1
  841. gCarla.host.show_custom_ui(pluginId, True)