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.

931 lines
33KB

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