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.

2109 lines
78KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla plugin/slot skin code
  4. # Copyright (C) 2013-2020 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 PyQt5.QtCore import Qt, QRectF, QLineF, QTimer
  20. from PyQt5.QtGui import QColor, QFont, QFontDatabase, QPainter, QPainterPath, QPen
  21. from PyQt5.QtWidgets import QColorDialog, QFrame, QLineEdit, QPushButton
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. import ui_carla_plugin_calf
  25. import ui_carla_plugin_classic
  26. import ui_carla_plugin_compact
  27. import ui_carla_plugin_default
  28. import ui_carla_plugin_presets
  29. from carla_backend import *
  30. from carla_shared import *
  31. from carla_widgets import *
  32. from widgets.digitalpeakmeter import DigitalPeakMeter
  33. from widgets.paramspinbox import CustomInputDialog
  34. from widgets.scalabledial import ScalableDial
  35. # ------------------------------------------------------------------------------------------------------------
  36. # Plugin Skin Rules (WORK IN PROGRESS)
  37. # Base is a QFrame (NoFrame, Plain, 0-size lines), with "PluginWidget" as object name.
  38. # Spacing of the top-most layout must be 1px.
  39. # Top and bottom margins must be 3px (can be split between different Qt layouts).
  40. # Left and right margins must be 6px (can be split between different Qt layouts).
  41. # If the left or right side has built-in margins, say a transparent svg border,
  42. # those margins must be taken into consideration.
  43. #
  44. # There's a top and bottom layout, separated by a horizontal line.
  45. # Compacted skins do not have the bottom layout and separating line.
  46. # T O P A R E A
  47. #
  48. # -----------------------------------------------------------------
  49. # | <> | <> [ WIDGETS ] [ LEDS ] |
  50. # | BUTTONS <> | <> PLUGIN NAME < spacer > [ WIDGETS ] [ LEDS ] |
  51. # | <> | <> [ WIDGETS ] [ LEDS ] |
  52. # -----------------------------------------------------------------
  53. #
  54. # Buttons area has size fixed. (TBA)
  55. # Spacers at the left of the plugin name must be 8x1 in size (fixed).
  56. # The line before the plugin name must be height-10px (fixed).
  57. # WIDGETS area can be extended to the left, if using meters they should have 80px.
  58. # WIDGETS margins are 4px for left+right and 2px for top+bottom, with 4px spacing.
  59. # ------------------------------------------------------------------------------------------------------------
  60. # Try to "shortify" a parameter name
  61. def getParameterShortName(paramName):
  62. paramName = paramName.split("/",1)[0].split(" (",1)[0].split(" [",1)[0].strip()
  63. paramLow = paramName.lower()
  64. # Cut useless prefix
  65. if paramLow.startswith("compressor "):
  66. paramName = paramName.replace("ompressor ", ".", 1)
  67. paramLow = paramName.lower()
  68. elif paramLow.startswith("room "):
  69. paramName = paramName.split(" ",1)[1]
  70. paramLow = paramName.lower()
  71. # Cut useless suffix
  72. if paramLow.endswith(" level"):
  73. paramName = paramName.rsplit(" ",1)[0]
  74. paramLow = paramName.lower()
  75. elif paramLow.endswith(" time"):
  76. paramName = paramName.rsplit(" ",1)[0]
  77. paramLow = paramName.lower()
  78. # Cut generic names
  79. if "attack" in paramLow:
  80. paramName = paramName.replace("ttack", "tk")
  81. elif "bandwidth" in paramLow:
  82. paramName = paramName.replace("andwidth", "w")
  83. elif "damping" in paramLow:
  84. paramName = paramName.replace("amping", "amp")
  85. elif "distortion" in paramLow:
  86. paramName = paramName.replace("istortion", "ist")
  87. elif "feedback" in paramLow:
  88. paramName = paramName.replace("eedback", "b")
  89. elif "frequency" in paramLow:
  90. paramName = paramName.replace("requency", "req")
  91. elif "input" in paramLow:
  92. paramName = paramName.replace("nput", "n")
  93. elif "makeup" in paramLow:
  94. paramName = paramName.replace("akeup", "kUp" if "Make" in paramName else "kup")
  95. elif "output" in paramLow:
  96. paramName = paramName.replace("utput", "ut")
  97. elif "random" in paramLow:
  98. paramName = paramName.replace("andom", "nd")
  99. elif "threshold" in paramLow:
  100. paramName = paramName.replace("hreshold", "hres")
  101. # remove space if last char from 1st word is lowercase and the first char from the 2nd is uppercase,
  102. # or if 2nd is a number
  103. if " " in paramName:
  104. name1, name2 = paramName.split(" ", 1)
  105. if (name1[-1].islower() and name2[0].isupper()) or name2.isdigit():
  106. paramName = paramName.replace(" ", "", 1)
  107. # cut stuff if too big
  108. if len(paramName) > 7:
  109. paramName = paramName.replace("a","").replace("e","").replace("i","").replace("o","").replace("u","")
  110. if len(paramName) > 7:
  111. paramName = paramName[:7]
  112. return paramName.strip()
  113. # ------------------------------------------------------------------------------------------------------------
  114. # Get RGB colors for a plugin category
  115. def getColorFromCategory(category):
  116. r = 40
  117. g = 40
  118. b = 40
  119. if category == PLUGIN_CATEGORY_MODULATOR:
  120. r += 10
  121. elif category == PLUGIN_CATEGORY_EQ:
  122. g += 10
  123. elif category == PLUGIN_CATEGORY_FILTER:
  124. b += 10
  125. elif category == PLUGIN_CATEGORY_DELAY:
  126. r += 15
  127. b -= 15
  128. elif category == PLUGIN_CATEGORY_DISTORTION:
  129. g += 10
  130. b += 10
  131. elif category == PLUGIN_CATEGORY_DYNAMICS:
  132. r += 10
  133. b += 10
  134. elif category == PLUGIN_CATEGORY_UTILITY:
  135. r += 10
  136. g += 10
  137. return (r, g, b)
  138. # ------------------------------------------------------------------------------------------------------------
  139. #
  140. def setScalableDialStyle(widget, parameterId, parameterCount, whiteLabels, skinStyle):
  141. if skinStyle.startswith("calf"):
  142. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_NO_GRADIENT)
  143. widget.setImage(7)
  144. elif skinStyle.startswith("openav"):
  145. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_NO_GRADIENT)
  146. if parameterId == PARAMETER_DRYWET:
  147. widget.setImage(13)
  148. elif parameterId == PARAMETER_VOLUME:
  149. widget.setImage(12)
  150. else:
  151. widget.setImage(11)
  152. else:
  153. if parameterId == PARAMETER_DRYWET:
  154. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_CARLA_WET)
  155. elif parameterId == PARAMETER_VOLUME:
  156. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_CARLA_VOL)
  157. else:
  158. _r = 255 - int((float(parameterId)/float(parameterCount))*200.0)
  159. _g = 55 + int((float(parameterId)/float(parameterCount))*200.0)
  160. _b = 0 #(r-40)*4
  161. widget.setCustomPaintColor(QColor(_r, _g, _b))
  162. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_COLOR)
  163. if whiteLabels:
  164. colorEnabled = QColor("#BBB")
  165. colorDisabled = QColor("#555")
  166. else:
  167. colorEnabled = QColor("#111")
  168. colorDisabled = QColor("#AAA")
  169. widget.setLabelColor(colorEnabled, colorDisabled)
  170. widget.setImage(3)
  171. # ------------------------------------------------------------------------------------------------------------
  172. # Abstract plugin slot
  173. class AbstractPluginSlot(QFrame, PluginEditParentMeta):
  174. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  175. QFrame.__init__(self, parent)
  176. self.host = host
  177. self.fParent = parent
  178. # -------------------------------------------------------------
  179. # Get plugin info
  180. self.fPluginId = pluginId
  181. self.fPluginInfo = host.get_plugin_info(self.fPluginId)
  182. self.fSkinColor = skinColor
  183. self.fSkinStyle = skinStyle
  184. self.fDarkStyle = QColor(skinColor[0], skinColor[1], skinColor[2]).blackF() > 0.4
  185. # -------------------------------------------------------------
  186. # Internal stuff
  187. self.fIsActive = False
  188. self.fIsSelected = False
  189. self.fLastGreenLedState = False
  190. self.fLastBlueLedState = False
  191. self.fParameterIconTimer = ICON_STATE_NULL
  192. self.fParameterList = [] # index, widget
  193. audioCountInfo = host.get_audio_port_count_info(self.fPluginId)
  194. self.fPeaksInputCount = audioCountInfo['ins']
  195. self.fPeaksOutputCount = audioCountInfo['outs']
  196. if self.fPeaksInputCount > 2:
  197. self.fPeaksInputCount = 2
  198. if self.fPeaksOutputCount > 2:
  199. self.fPeaksOutputCount = 2
  200. self.fAdjustViewableKnobCountScheduled = False
  201. # used during testing
  202. self.fIdleTimerId = 0
  203. # -------------------------------------------------------------
  204. # Set-up GUI
  205. self.fEditDialog = PluginEdit(self, host, self.fPluginId)
  206. # -------------------------------------------------------------
  207. # Set-up common widgets (as none)
  208. self.b_enable = None
  209. self.b_gui = None
  210. self.b_edit = None
  211. self.b_remove = None
  212. self.cb_presets = None
  213. self.label_name = None
  214. self.label_presets = None
  215. self.label_type = None
  216. self.led_control = None
  217. self.led_midi = None
  218. self.led_audio_in = None
  219. self.led_audio_out = None
  220. self.peak_in = None
  221. self.peak_out = None
  222. self.w_knobs_left = None
  223. self.w_knobs_right = None
  224. self.spacer_knobs = None
  225. # -------------------------------------------------------------
  226. # Set-up connections
  227. self.customContextMenuRequested.connect(self.slot_showCustomMenu)
  228. host.PluginRenamedCallback.connect(self.slot_handlePluginRenamedCallback)
  229. host.PluginUnavailableCallback.connect(self.slot_handlePluginUnavailableCallback)
  230. host.ParameterValueChangedCallback.connect(self.slot_handleParameterValueChangedCallback)
  231. host.ParameterDefaultChangedCallback.connect(self.slot_handleParameterDefaultChangedCallback)
  232. host.ParameterMappedControlIndexChangedCallback.connect(self.slot_handleParameterMappedControlIndexChangedCallback)
  233. host.ParameterMappedRangeChangedCallback.connect(self.slot_handleParameterMappedRangeChangedCallback)
  234. host.ParameterMidiChannelChangedCallback.connect(self.slot_handleParameterMidiChannelChangedCallback)
  235. host.ProgramChangedCallback.connect(self.slot_handleProgramChangedCallback)
  236. host.MidiProgramChangedCallback.connect(self.slot_handleMidiProgramChangedCallback)
  237. host.OptionChangedCallback.connect(self.slot_handleOptionChangedCallback)
  238. host.UiStateChangedCallback.connect(self.slot_handleUiStateChangedCallback)
  239. # Prepare resources
  240. self.sel_pen = QPen(Qt.cyan, 1, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin)
  241. self.sel_pen.setDashPattern([2.0, 4.0])
  242. self.sel_side_pen = QPen(Qt.cyan, 2, Qt.SolidLine, Qt.FlatCap)
  243. self.shadow_pen = QPen(Qt.black, 1)
  244. # -----------------------------------------------------------------
  245. @pyqtSlot(int, str)
  246. def slot_handlePluginRenamedCallback(self, pluginId, newName):
  247. if self.fPluginId == pluginId:
  248. self.setName(newName)
  249. @pyqtSlot(int, str)
  250. def slot_handlePluginUnavailableCallback(self, pluginId, errorMsg):
  251. if self.fPluginId == pluginId:
  252. pass
  253. @pyqtSlot(int, int, float)
  254. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  255. if self.fPluginId == pluginId:
  256. self.setParameterValue(index, value, True)
  257. @pyqtSlot(int, int, float)
  258. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  259. if self.fPluginId == pluginId:
  260. self.setParameterDefault(index, value)
  261. @pyqtSlot(int, int, int)
  262. def slot_handleParameterMappedControlIndexChangedCallback(self, pluginId, index, ctrl):
  263. if self.fPluginId == pluginId:
  264. self.setParameterMappedControlIndex(index, ctrl)
  265. @pyqtSlot(int, int, float, float)
  266. def slot_handleParameterMappedRangeChangedCallback(self, pluginId, index, minimum, maximum):
  267. if self.fPluginId == pluginId:
  268. self.setParameterMappedRange(index, minimum, maximum)
  269. @pyqtSlot(int, int, int)
  270. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  271. if self.fPluginId == pluginId:
  272. self.setParameterMidiChannel(index, channel)
  273. @pyqtSlot(int, int)
  274. def slot_handleProgramChangedCallback(self, pluginId, index):
  275. if self.fPluginId == pluginId:
  276. self.setProgram(index, True)
  277. @pyqtSlot(int, int)
  278. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  279. if self.fPluginId == pluginId:
  280. self.setMidiProgram(index, True)
  281. @pyqtSlot(int, int, bool)
  282. def slot_handleOptionChangedCallback(self, pluginId, option, yesNo):
  283. if self.fPluginId == pluginId:
  284. self.setOption(option, yesNo)
  285. @pyqtSlot(int, int)
  286. def slot_handleUiStateChangedCallback(self, pluginId, state):
  287. if self.fPluginId == pluginId:
  288. self.customUiStateChanged(state)
  289. # ------------------------------------------------------------------
  290. def ready(self):
  291. self.fIsActive = bool(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_ACTIVE) >= 0.5)
  292. isCalfSkin = self.fSkinStyle.startswith("calf") and not isinstance(self, PluginSlot_Compact)
  293. imageSuffix = "white" if self.fDarkStyle else "black"
  294. whiteLabels = self.fDarkStyle
  295. if self.fSkinStyle.startswith("calf") or self.fSkinStyle.startswith("openav") or self.fSkinStyle in (
  296. "3bandeq", "3bandsplitter", "pingpongpan", "nekobi", "calf_black", "zynfx"):
  297. imageSuffix = "white"
  298. whiteLabels = True
  299. if self.b_enable is not None:
  300. self.b_enable.setChecked(self.fIsActive)
  301. self.b_enable.clicked.connect(self.slot_enableClicked)
  302. if isCalfSkin:
  303. self.b_enable.setPixmaps(":/bitmaps/button_calf3.png",
  304. ":/bitmaps/button_calf3_down.png",
  305. ":/bitmaps/button_calf3.png")
  306. else:
  307. self.b_enable.setSvgs(":/scalable/button_off.svg",
  308. ":/scalable/button_on.svg",
  309. ":/scalable/button_off.svg")
  310. if self.b_gui is not None:
  311. self.b_gui.clicked.connect(self.slot_showCustomUi)
  312. self.b_gui.setEnabled(bool(self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI))
  313. if isCalfSkin:
  314. self.b_gui.setPixmaps(":/bitmaps/button_calf2.png",
  315. ":/bitmaps/button_calf2_down.png",
  316. ":/bitmaps/button_calf2_hover.png")
  317. elif self.fPluginInfo['iconName'] == "distrho" or self.fSkinStyle in ("3bandeq", "3bandsplitter", "pingpongpan", "nekobi"):
  318. self.b_gui.setPixmaps(":/bitmaps/button_distrho-{}.png".format(imageSuffix),
  319. ":/bitmaps/button_distrho_down-{}.png".format(imageSuffix),
  320. ":/bitmaps/button_distrho_hover-{}.png".format(imageSuffix))
  321. elif self.fPluginInfo['iconName'] == "file":
  322. self.b_gui.setSvgs(":/scalable/button_file-{}.svg".format(imageSuffix),
  323. ":/scalable/button_file_down-{}.svg".format(imageSuffix),
  324. ":/scalable/button_file_hover-{}.svg".format(imageSuffix))
  325. else:
  326. if imageSuffix == "black": # TODO
  327. self.b_gui.setSvgs(":/bitmaps/button_gui-{}.png".format(imageSuffix),
  328. ":/bitmaps/button_gui_down-{}.png".format(imageSuffix),
  329. ":/bitmaps/button_gui_hover-{}.png".format(imageSuffix))
  330. else:
  331. self.b_gui.setSvgs(":/scalable/button_gui-{}.svg".format(imageSuffix),
  332. ":/scalable/button_gui_down-{}.svg".format(imageSuffix),
  333. ":/scalable/button_gui_hover-{}.svg".format(imageSuffix))
  334. if self.b_edit is not None:
  335. self.b_edit.clicked.connect(self.slot_showEditDialog)
  336. if isCalfSkin:
  337. self.b_edit.setPixmaps(":/bitmaps/button_calf2.png",
  338. ":/bitmaps/button_calf2_down.png",
  339. ":/bitmaps/button_calf2_hover.png")
  340. else:
  341. self.b_edit.setSvgs(":/scalable/button_edit-{}.svg".format(imageSuffix),
  342. ":/scalable/button_edit_down-{}.svg".format(imageSuffix),
  343. ":/scalable/button_edit_hover-{}.svg".format(imageSuffix))
  344. else:
  345. # Edit button *must* be available
  346. self.b_edit = QPushButton(self)
  347. self.b_edit.setCheckable(True)
  348. self.b_edit.hide()
  349. if self.b_remove is not None:
  350. self.b_remove.clicked.connect(self.slot_removePlugin)
  351. if self.label_name is not None:
  352. self.label_name.setEnabled(self.fIsActive)
  353. self.label_name.setText(self.fPluginInfo['name'])
  354. nameFont = self.label_name.font()
  355. if self.fSkinStyle.startswith("calf"):
  356. nameFont.setBold(True)
  357. nameFont.setPixelSize(12)
  358. elif self.fSkinStyle.startswith("openav"):
  359. QFontDatabase.addApplicationFont(":/fonts/uranium.ttf")
  360. nameFont.setFamily("Uranium")
  361. nameFont.setPixelSize(15)
  362. nameFont.setCapitalization(QFont.AllUppercase)
  363. else:
  364. nameFont.setBold(True)
  365. nameFont.setPixelSize(11)
  366. self.label_name.setFont(nameFont)
  367. if self.label_presets is not None:
  368. presetFont = self.label_presets.font()
  369. presetFont.setBold(True)
  370. presetFont.setPixelSize(10)
  371. self.label_presets.setFont(presetFont)
  372. if self.label_type is not None:
  373. self.label_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  374. if self.led_control is not None:
  375. self.led_control.setColor(self.led_control.YELLOW)
  376. self.led_control.setEnabled(False)
  377. if self.led_midi is not None:
  378. self.led_midi.setColor(self.led_midi.RED)
  379. self.led_midi.setEnabled(False)
  380. if self.led_audio_in is not None:
  381. self.led_audio_in.setColor(self.led_audio_in.GREEN)
  382. self.led_audio_in.setEnabled(False)
  383. if self.led_audio_out is not None:
  384. self.led_audio_out.setColor(self.led_audio_out.BLUE)
  385. self.led_audio_out.setEnabled(False)
  386. if self.peak_in is not None:
  387. self.peak_in.setChannelCount(self.fPeaksInputCount)
  388. self.peak_in.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  389. self.peak_in.setMeterOrientation(DigitalPeakMeter.HORIZONTAL)
  390. if self.fSkinStyle.startswith("calf"):
  391. self.peak_in.setMeterStyle(DigitalPeakMeter.STYLE_CALF)
  392. elif self.fSkinStyle == "rncbc":
  393. self.peak_in.setMeterStyle(DigitalPeakMeter.STYLE_RNCBC)
  394. elif self.fSkinStyle.startswith("openav") or self.fSkinStyle == "zynfx":
  395. self.peak_in.setMeterStyle(DigitalPeakMeter.STYLE_OPENAV)
  396. if self.fPeaksInputCount == 0 and not isinstance(self, PluginSlot_Classic):
  397. self.peak_in.hide()
  398. if self.peak_out is not None:
  399. self.peak_out.setChannelCount(self.fPeaksOutputCount)
  400. self.peak_out.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  401. self.peak_out.setMeterOrientation(DigitalPeakMeter.HORIZONTAL)
  402. if self.fSkinStyle.startswith("calf"):
  403. self.peak_out.setMeterStyle(DigitalPeakMeter.STYLE_CALF)
  404. elif self.fSkinStyle == "rncbc":
  405. self.peak_out.setMeterStyle(DigitalPeakMeter.STYLE_RNCBC)
  406. elif self.fSkinStyle.startswith("openav") or self.fSkinStyle == "zynfx":
  407. self.peak_out.setMeterStyle(DigitalPeakMeter.STYLE_OPENAV)
  408. if self.fPeaksOutputCount == 0 and not isinstance(self, PluginSlot_Classic):
  409. self.peak_out.hide()
  410. # -------------------------------------------------------------
  411. if self.fSkinStyle == "openav":
  412. styleSheet = """
  413. QFrame#PluginWidget {
  414. background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  415. stop: 0 #383838, stop: %f #111111, stop: 1.0 #111111);
  416. }
  417. QLabel#label_name { color: #FFFFFF; }
  418. QLabel#label_name:disabled { color: #505050; }
  419. """ % (0.95 if isinstance(self, PluginSlot_Compact) else 0.35)
  420. elif self.fSkinStyle == "openav-old":
  421. styleSheet = """
  422. QFrame#PluginWidget {
  423. background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
  424. stop: 0 #303030, stop: %f #111111, stop: 1.0 #111111);
  425. }
  426. QLabel#label_name { color: #FF5100; }
  427. QLabel#label_name:disabled { color: #505050; }
  428. """ % (0.95 if isinstance(self, PluginSlot_Compact) else 0.35)
  429. else:
  430. colorEnabled = "#BBB"
  431. colorDisabled = "#555"
  432. if self.fSkinStyle in ("3bandeq", "calf_black", "calf_blue", "nekobi", "zynfx"):
  433. styleSheet2 = "background-image: url(:/bitmaps/background_%s.png);" % self.fSkinStyle
  434. else:
  435. styleSheet2 = "background-color: rgb(200, 200, 200);"
  436. styleSheet2 += "background-image: url(:/bitmaps/background_noise1.png);"
  437. if not self.fDarkStyle:
  438. colorEnabled = "#111"
  439. colorDisabled = "#AAA"
  440. styleSheet = """
  441. QFrame#PluginWidget {
  442. %s
  443. background-repeat: repeat-xy;
  444. }
  445. QLabel#label_name,
  446. QLabel#label_audio_in,
  447. QLabel#label_audio_out,
  448. QLabel#label_midi,
  449. QLabel#label_presets { color: %s; }
  450. QLabel#label_name:disabled { color: %s; }
  451. """ % (styleSheet2, colorEnabled, colorDisabled)
  452. styleSheet += """
  453. QComboBox#cb_presets,
  454. QLabel#label_audio_in,
  455. QLabel#label_audio_out,
  456. QLabel#label_midi { font-size: 10px; }
  457. """
  458. self.setStyleSheet(styleSheet)
  459. # -------------------------------------------------------------
  460. # Set-up parameters
  461. if self.w_knobs_left is not None:
  462. parameterCount = self.host.get_parameter_count(self.fPluginId)
  463. index = 0
  464. layout = self.w_knobs_left.layout()
  465. for i in range(parameterCount):
  466. # 50 should be enough for everybody, right?
  467. if index >= 50:
  468. break
  469. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  470. paramData = self.host.get_parameter_data(self.fPluginId, i)
  471. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  472. isInteger = (paramData['hints'] & PARAMETER_IS_INTEGER) != 0
  473. if paramData['type'] != PARAMETER_INPUT:
  474. continue
  475. if paramData['hints'] & PARAMETER_IS_BOOLEAN:
  476. continue
  477. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  478. continue
  479. if (paramData['hints'] & PARAMETER_USES_SCALEPOINTS) != 0 and not isInteger:
  480. # NOTE: we assume integer scalepoints are continuous
  481. continue
  482. if isInteger and paramRanges['max']-paramRanges['min'] <= 3:
  483. continue
  484. if paramInfo['name'].startswith("unused"):
  485. continue
  486. paramName = getParameterShortName(paramInfo['name'])
  487. widget = ScalableDial(self, i)
  488. widget.setLabel(paramName)
  489. widget.setMinimum(paramRanges['min'])
  490. widget.setMaximum(paramRanges['max'])
  491. widget.hide()
  492. if isInteger:
  493. widget.setPrecision(paramRanges['max']-paramRanges['min'], True)
  494. setScalableDialStyle(widget, i, parameterCount, whiteLabels, self.fSkinStyle)
  495. index += 1
  496. self.fParameterList.append([i, widget])
  497. layout.addWidget(widget)
  498. if self.w_knobs_right is not None and (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) != 0:
  499. widget = ScalableDial(self, PARAMETER_DRYWET)
  500. widget.setLabel("Dry/Wet")
  501. widget.setMinimum(0.0)
  502. widget.setMaximum(1.0)
  503. setScalableDialStyle(widget, PARAMETER_DRYWET, 0, whiteLabels, self.fSkinStyle)
  504. self.fParameterList.append([PARAMETER_DRYWET, widget])
  505. self.w_knobs_right.layout().addWidget(widget)
  506. if self.w_knobs_right is not None and (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) != 0:
  507. widget = ScalableDial(self, PARAMETER_VOLUME)
  508. widget.setLabel("Volume")
  509. widget.setMinimum(0.0)
  510. widget.setMaximum(1.27)
  511. setScalableDialStyle(widget, PARAMETER_VOLUME, 0, whiteLabels, self.fSkinStyle)
  512. self.fParameterList.append([PARAMETER_VOLUME, widget])
  513. self.w_knobs_right.layout().addWidget(widget)
  514. for paramIndex, paramWidget in self.fParameterList:
  515. paramWidget.setContextMenuPolicy(Qt.CustomContextMenu)
  516. paramWidget.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  517. paramWidget.dragStateChanged.connect(self.slot_parameterDragStateChanged)
  518. paramWidget.realValueChanged.connect(self.slot_parameterValueChanged)
  519. paramWidget.blockSignals(True)
  520. paramWidget.setValue(self.host.get_internal_parameter_value(self.fPluginId, paramIndex))
  521. paramWidget.blockSignals(False)
  522. # -------------------------------------------------------------
  523. self.setWindowTitle(self.fPluginInfo['name'])
  524. if not self.fAdjustViewableKnobCountScheduled:
  525. self.fAdjustViewableKnobCountScheduled = True
  526. QTimer.singleShot(5, self.adjustViewableKnobCount)
  527. # -----------------------------------------------------------------
  528. def getFixedHeight(self):
  529. return 32
  530. def getHints(self):
  531. return self.fPluginInfo['hints']
  532. def getPluginId(self):
  533. return self.fPluginId
  534. # -----------------------------------------------------------------
  535. def setPluginId(self, idx):
  536. self.fPluginId = idx
  537. self.fEditDialog.setPluginId(idx)
  538. def setName(self, name):
  539. self.fPluginInfo['name'] = name
  540. self.fEditDialog.setName(name)
  541. if self.label_name is not None:
  542. self.label_name.setText(name)
  543. def setSelected(self, yesNo):
  544. if self.fIsSelected == yesNo:
  545. return
  546. self.fIsSelected = yesNo
  547. self.update()
  548. # -----------------------------------------------------------------
  549. def setActive(self, active, sendCallback=False, sendHost=True):
  550. self.fIsActive = active
  551. if sendCallback:
  552. self.fParameterIconTimer = ICON_STATE_ON
  553. self.activeChanged(active)
  554. if sendHost:
  555. self.host.set_active(self.fPluginId, active)
  556. if active:
  557. self.fEditDialog.clearNotes()
  558. self.midiActivityChanged(False)
  559. if self.label_name is not None:
  560. self.label_name.setEnabled(self.fIsActive)
  561. # called from rack, checks if param is possible first
  562. def setInternalParameter(self, parameterId, value):
  563. if parameterId <= PARAMETER_MAX or parameterId >= PARAMETER_NULL:
  564. return
  565. elif parameterId == PARAMETER_ACTIVE:
  566. return self.setActive(bool(value), True, True)
  567. elif parameterId == PARAMETER_DRYWET:
  568. if (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) == 0: return
  569. self.host.set_drywet(self.fPluginId, value)
  570. elif parameterId == PARAMETER_VOLUME:
  571. if (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) == 0: return
  572. self.host.set_volume(self.fPluginId, value)
  573. elif parameterId == PARAMETER_BALANCE_LEFT:
  574. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  575. self.host.set_balance_left(self.fPluginId, value)
  576. elif parameterId == PARAMETER_BALANCE_RIGHT:
  577. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  578. self.host.set_balance_right(self.fPluginId, value)
  579. elif parameterId == PARAMETER_PANNING:
  580. if (self.fPluginInfo['hints'] & PLUGIN_CAN_PANNING) == 0: return
  581. self.host.set_panning(self.fPluginId, value)
  582. elif parameterId == PARAMETER_CTRL_CHANNEL:
  583. self.host.set_ctrl_channel(self.fPluginId, value)
  584. self.fEditDialog.setParameterValue(parameterId, value)
  585. # -----------------------------------------------------------------
  586. def setParameterValue(self, parameterId, value, sendCallback):
  587. if parameterId == PARAMETER_ACTIVE:
  588. return self.setActive(bool(value), True, False)
  589. self.fEditDialog.setParameterValue(parameterId, value)
  590. if sendCallback:
  591. self.fParameterIconTimer = ICON_STATE_ON
  592. self.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  593. def setParameterDefault(self, parameterId, value):
  594. self.fEditDialog.setParameterDefault(parameterId, value)
  595. def setParameterMappedControlIndex(self, parameterId, control):
  596. self.fEditDialog.setParameterMappedControlIndex(parameterId, control)
  597. def setParameterMappedRange(self, parameterId, minimum, maximum):
  598. self.fEditDialog.setParameterMappedRange(parameterId, minimum, maximum)
  599. def setParameterMidiChannel(self, parameterId, channel):
  600. self.fEditDialog.setParameterMidiChannel(parameterId, channel)
  601. # -----------------------------------------------------------------
  602. def setProgram(self, index, sendCallback):
  603. self.fEditDialog.setProgram(index)
  604. if sendCallback:
  605. self.fParameterIconTimer = ICON_STATE_ON
  606. self.editDialogProgramChanged(self.fPluginId, index)
  607. self.updateParameterValues()
  608. def setMidiProgram(self, index, sendCallback):
  609. self.fEditDialog.setMidiProgram(index)
  610. if sendCallback:
  611. self.fParameterIconTimer = ICON_STATE_ON
  612. self.editDialogMidiProgramChanged(self.fPluginId, index)
  613. self.updateParameterValues()
  614. # -----------------------------------------------------------------
  615. def setOption(self, option, yesNo):
  616. self.fEditDialog.setOption(option, yesNo)
  617. # -----------------------------------------------------------------
  618. def showCustomUI(self):
  619. self.host.show_custom_ui(self.fPluginId, True)
  620. if self.b_gui is not None:
  621. self.b_gui.setChecked(True)
  622. def showEditDialog(self):
  623. self.fEditDialog.show()
  624. self.fEditDialog.activateWindow()
  625. if self.b_edit is not None:
  626. self.b_edit.setChecked(True)
  627. def showRenameDialog(self):
  628. oldName = self.fPluginInfo['name']
  629. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  630. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  631. return
  632. newName = newNameTry[0]
  633. if not self.host.rename_plugin(self.fPluginId, newName):
  634. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  635. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  636. return
  637. def showReplaceDialog(self):
  638. data = gCarla.gui.showAddPluginDialog()
  639. if data is None:
  640. return
  641. btype, ptype, filename, label, uniqueId, extraPtr = data
  642. if not self.host.replace_plugin(self.fPluginId):
  643. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  644. return
  645. ok = self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, PLUGIN_OPTIONS_NULL)
  646. self.host.replace_plugin(self.host.get_max_plugin_number())
  647. if not ok:
  648. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  649. # -----------------------------------------------------------------
  650. def activeChanged(self, onOff):
  651. self.fIsActive = onOff
  652. if self.b_enable is None:
  653. return
  654. self.b_enable.blockSignals(True)
  655. self.b_enable.setChecked(onOff)
  656. self.b_enable.blockSignals(False)
  657. def customUiStateChanged(self, state):
  658. if self.b_gui is None:
  659. return
  660. self.b_gui.blockSignals(True)
  661. if state == 0:
  662. self.b_gui.setChecked(False)
  663. self.b_gui.setEnabled(True)
  664. elif state == 1:
  665. self.b_gui.setChecked(True)
  666. self.b_gui.setEnabled(True)
  667. elif state == -1:
  668. self.b_gui.setChecked(False)
  669. self.b_gui.setEnabled(False)
  670. self.b_gui.blockSignals(False)
  671. def parameterActivityChanged(self, onOff):
  672. if self.led_control is None:
  673. return
  674. self.led_control.setChecked(onOff)
  675. def midiActivityChanged(self, onOff):
  676. if self.led_midi is None:
  677. return
  678. self.led_midi.setChecked(onOff)
  679. def optionChanged(self, option, yesNo):
  680. pass
  681. # -----------------------------------------------------------------
  682. # PluginEdit callbacks
  683. def editDialogVisibilityChanged(self, pluginId, visible):
  684. if self.b_edit is None:
  685. return
  686. self.b_edit.blockSignals(True)
  687. self.b_edit.setChecked(visible)
  688. self.b_edit.blockSignals(False)
  689. def editDialogPluginHintsChanged(self, pluginId, hints):
  690. self.fPluginInfo['hints'] = hints
  691. for paramIndex, paramWidget in self.fParameterList:
  692. if paramIndex == PARAMETER_DRYWET:
  693. paramWidget.setVisible(hints & PLUGIN_CAN_DRYWET)
  694. elif paramIndex == PARAMETER_VOLUME:
  695. paramWidget.setVisible(hints & PLUGIN_CAN_VOLUME)
  696. if self.b_gui is not None:
  697. self.b_gui.setEnabled(bool(hints & PLUGIN_HAS_CUSTOM_UI))
  698. def editDialogParameterValueChanged(self, pluginId, parameterId, value):
  699. for paramIndex, paramWidget in self.fParameterList:
  700. if paramIndex != parameterId:
  701. continue
  702. paramWidget.blockSignals(True)
  703. paramWidget.setValue(value)
  704. paramWidget.blockSignals(False)
  705. break
  706. def editDialogProgramChanged(self, pluginId, index):
  707. if self.cb_presets is None:
  708. return
  709. self.cb_presets.blockSignals(True)
  710. self.cb_presets.setCurrentIndex(index)
  711. self.cb_presets.blockSignals(False)
  712. # FIXME
  713. self.updateParameterValues()
  714. def editDialogMidiProgramChanged(self, pluginId, index):
  715. if self.cb_presets is None:
  716. return
  717. self.cb_presets.blockSignals(True)
  718. self.cb_presets.setCurrentIndex(index)
  719. self.cb_presets.blockSignals(False)
  720. # FIXME
  721. self.updateParameterValues()
  722. def editDialogNotePressed(self, pluginId, note):
  723. pass
  724. def editDialogNoteReleased(self, pluginId, note):
  725. pass
  726. def editDialogMidiActivityChanged(self, pluginId, onOff):
  727. self.midiActivityChanged(onOff)
  728. # -----------------------------------------------------------------
  729. def idleFast(self):
  730. # Input peaks
  731. if self.fPeaksInputCount > 0:
  732. if self.fPeaksInputCount > 1:
  733. peak1 = self.host.get_input_peak_value(self.fPluginId, True)
  734. peak2 = self.host.get_input_peak_value(self.fPluginId, False)
  735. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  736. if self.peak_in is not None:
  737. self.peak_in.displayMeter(1, peak1)
  738. self.peak_in.displayMeter(2, peak2)
  739. else:
  740. peak = self.host.get_input_peak_value(self.fPluginId, True)
  741. ledState = bool(peak != 0.0)
  742. if self.peak_in is not None:
  743. self.peak_in.displayMeter(1, peak)
  744. if self.fLastGreenLedState != ledState and self.led_audio_in is not None:
  745. self.fLastGreenLedState = ledState
  746. self.led_audio_in.setChecked(ledState)
  747. # Output peaks
  748. if self.fPeaksOutputCount > 0:
  749. if self.fPeaksOutputCount > 1:
  750. peak1 = self.host.get_output_peak_value(self.fPluginId, True)
  751. peak2 = self.host.get_output_peak_value(self.fPluginId, False)
  752. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  753. if self.peak_out is not None:
  754. self.peak_out.displayMeter(1, peak1)
  755. self.peak_out.displayMeter(2, peak2)
  756. else:
  757. peak = self.host.get_output_peak_value(self.fPluginId, True)
  758. ledState = bool(peak != 0.0)
  759. if self.peak_out is not None:
  760. self.peak_out.displayMeter(1, peak)
  761. if self.fLastBlueLedState != ledState and self.led_audio_out is not None:
  762. self.fLastBlueLedState = ledState
  763. self.led_audio_out.setChecked(ledState)
  764. def idleSlow(self):
  765. if self.fParameterIconTimer == ICON_STATE_ON:
  766. self.parameterActivityChanged(True)
  767. self.fParameterIconTimer = ICON_STATE_WAIT
  768. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  769. self.fParameterIconTimer = ICON_STATE_OFF
  770. elif self.fParameterIconTimer == ICON_STATE_OFF:
  771. self.parameterActivityChanged(False)
  772. self.fParameterIconTimer = ICON_STATE_NULL
  773. self.fEditDialog.idleSlow()
  774. # -----------------------------------------------------------------
  775. def drawOutline(self, painter):
  776. painter.save()
  777. painter.setBrush(Qt.transparent)
  778. w = float(self.width())
  779. h = float(self.height())
  780. painter.setPen(self.shadow_pen)
  781. painter.drawLine(QLineF(0.5, h-1, w-1, h-1))
  782. if self.fIsSelected:
  783. painter.setCompositionMode(QPainter.CompositionMode_Plus)
  784. painter.setPen(self.sel_pen)
  785. painter.drawRect(QRectF(0.5, 0.5, w-1, h-1))
  786. sidelines = [QLineF(1, 1, 1, h-1), QLineF(w-1, 1, w-1, h-1)]
  787. painter.setPen(self.sel_side_pen)
  788. painter.drawLines(sidelines)
  789. painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
  790. painter.restore()
  791. def updateParameterValues(self):
  792. for paramIndex, paramWidget in self.fParameterList:
  793. if paramIndex < 0:
  794. continue
  795. paramWidget.blockSignals(True)
  796. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramIndex))
  797. paramWidget.blockSignals(False)
  798. # -----------------------------------------------------------------
  799. @pyqtSlot(bool)
  800. def slot_enableClicked(self, yesNo):
  801. self.setActive(yesNo, False, True)
  802. @pyqtSlot()
  803. def slot_showCustomMenu(self):
  804. menu = QMenu(self)
  805. # -------------------------------------------------------------
  806. # Expand/Minimize and Tweaks
  807. actCompact = menu.addAction(self.tr("Expand") if isinstance(self, PluginSlot_Compact) else self.tr("Minimize"))
  808. actColor = menu.addAction(self.tr("Change Color..."))
  809. actSkin = menu.addAction(self.tr("Change Skin..."))
  810. menu.addSeparator()
  811. # -------------------------------------------------------------
  812. # Find in patchbay, if possible
  813. if self.host.processMode in (ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,
  814. ENGINE_PROCESS_MODE_PATCHBAY):
  815. actFindInPatchbay = menu.addAction(self.tr("Find plugin in patchbay"))
  816. menu.addSeparator()
  817. else:
  818. actFindInPatchbay = None
  819. # -------------------------------------------------------------
  820. # Move up and down
  821. actMoveUp = menu.addAction(self.tr("Move Up"))
  822. actMoveDown = menu.addAction(self.tr("Move Down"))
  823. if self.fPluginId == 0:
  824. actMoveUp.setEnabled(False)
  825. if self.fPluginId >= self.fParent.getPluginCount():
  826. actMoveDown.setEnabled(False)
  827. # -------------------------------------------------------------
  828. # Bypass and Enable/Disable
  829. actBypass = menu.addAction(self.tr("Bypass"))
  830. actEnable = menu.addAction(self.tr("Disable") if self.fIsActive else self.tr("Enable"))
  831. menu.addSeparator()
  832. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  833. actBypass.setCheckable(True)
  834. actBypass.setChecked(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_DRYWET) == 0.0)
  835. else:
  836. actBypass.setVisible(False)
  837. # -------------------------------------------------------------
  838. # Reset and Randomize parameters
  839. actReset = menu.addAction(self.tr("Reset parameters"))
  840. actRandom = menu.addAction(self.tr("Randomize parameters"))
  841. menu.addSeparator()
  842. # -------------------------------------------------------------
  843. # Edit and Show Custom UI
  844. actEdit = menu.addAction(self.tr("Edit"))
  845. actGui = menu.addAction(self.tr("Show Custom UI"))
  846. menu.addSeparator()
  847. if self.b_edit is not None:
  848. actEdit.setCheckable(True)
  849. actEdit.setChecked(self.b_edit.isChecked())
  850. else:
  851. actEdit.setVisible(False)
  852. if self.b_gui is not None:
  853. actGui.setCheckable(True)
  854. actGui.setChecked(self.b_gui.isChecked())
  855. actGui.setEnabled(self.b_gui.isEnabled())
  856. else:
  857. actGui.setVisible(False)
  858. # -------------------------------------------------------------
  859. # Other stuff
  860. actClone = menu.addAction(self.tr("Clone"))
  861. actRename = menu.addAction(self.tr("Rename..."))
  862. actReplace = menu.addAction(self.tr("Replace..."))
  863. actRemove = menu.addAction(self.tr("Remove"))
  864. if self.fIdleTimerId != 0:
  865. actRemove.setVisible(False)
  866. if self.host.exportLV2:
  867. menu.addSeparator()
  868. actExportLV2 = menu.addAction(self.tr("Export LV2..."))
  869. else:
  870. actExportLV2 = None
  871. # -------------------------------------------------------------
  872. # exec
  873. actSel = menu.exec_(QCursor.pos())
  874. if not actSel:
  875. return
  876. # -------------------------------------------------------------
  877. # Expand/Minimize
  878. elif actSel == actCompact:
  879. # FIXME
  880. gCarla.gui.compactPlugin(self.fPluginId)
  881. # -------------------------------------------------------------
  882. # Tweaks
  883. elif actSel == actColor:
  884. initial = QColor(self.fSkinColor[0], self.fSkinColor[1], self.fSkinColor[2])
  885. color = QColorDialog.getColor(initial, self, self.tr("Change Color"), QColorDialog.DontUseNativeDialog)
  886. if not color.isValid():
  887. return
  888. color = color.getRgb()[0:3]
  889. colorStr = "%i;%i;%i" % color
  890. gCarla.gui.changePluginColor(self.fPluginId, color, colorStr)
  891. elif actSel == actSkin:
  892. skinList = [
  893. "default",
  894. "3bandeq",
  895. "rncbc",
  896. "calf_black",
  897. "calf_blue",
  898. "classic",
  899. "openav-old",
  900. "openav",
  901. "zynfx",
  902. "presets",
  903. "mpresets",
  904. ]
  905. try:
  906. index = skinList.index(self.fSkinStyle)
  907. except:
  908. index = 0
  909. skin = QInputDialog.getItem(self, self.tr("Change Skin"),
  910. self.tr("Change Skin to:"),
  911. skinList, index, False)
  912. if not all(skin):
  913. return
  914. gCarla.gui.changePluginSkin(self.fPluginId, skin[0])
  915. # -------------------------------------------------------------
  916. # Find in patchbay
  917. elif actSel == actFindInPatchbay:
  918. gCarla.gui.findPluginInPatchbay(self.fPluginId)
  919. # -------------------------------------------------------------
  920. # Move up and down
  921. elif actSel == actMoveUp:
  922. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId-1)
  923. elif actSel == actMoveDown:
  924. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId+1)
  925. # -------------------------------------------------------------
  926. # Bypass and Enable/Disable
  927. elif actSel == actBypass:
  928. value = 0.0 if actBypass.isChecked() else 1.0
  929. self.host.set_drywet(self.fPluginId, value)
  930. self.setParameterValue(PARAMETER_DRYWET, value, True)
  931. elif actSel == actEnable:
  932. self.setActive(not self.fIsActive, True, True)
  933. # -------------------------------------------------------------
  934. # Reset and Randomize parameters
  935. elif actSel == actReset:
  936. self.host.reset_parameters(self.fPluginId)
  937. elif actSel == actRandom:
  938. self.host.randomize_parameters(self.fPluginId)
  939. # -------------------------------------------------------------
  940. # Edit and Show Custom UI
  941. elif actSel == actEdit:
  942. self.b_edit.click()
  943. elif actSel == actGui:
  944. self.b_gui.click()
  945. # -------------------------------------------------------------
  946. # Clone
  947. elif actSel == actClone:
  948. if not self.host.clone_plugin(self.fPluginId):
  949. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  950. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  951. # -------------------------------------------------------------
  952. # Rename
  953. elif actSel == actRename:
  954. self.showRenameDialog()
  955. # -------------------------------------------------------------
  956. # Replace
  957. elif actSel == actReplace:
  958. self.showReplaceDialog()
  959. # -------------------------------------------------------------
  960. # Remove
  961. elif actSel == actRemove:
  962. if not self.host.remove_plugin(self.fPluginId):
  963. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  964. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  965. # -------------------------------------------------------------
  966. # Export LV2
  967. elif actSel == actExportLV2:
  968. filepath = QInputDialog.getItem(self, self.tr("Export LV2 Plugin"),
  969. self.tr("Select LV2 Path where plugin will be exported to:"),
  970. CARLA_DEFAULT_LV2_PATH, editable=False)
  971. if not all(filepath):
  972. return
  973. plugname = self.fPluginInfo['name']
  974. filepath = os.path.join(filepath[0], plugname.replace(" ","_"))
  975. if not filepath.endswith(".lv2"):
  976. filepath += ".lv2"
  977. if os.path.exists(filepath):
  978. if QMessageBox.question(self, self.tr("Export to LV2"),
  979. self.tr("Plugin bundle already exists, overwrite?")) == QMessageBox.Ok:
  980. return
  981. if not self.host.export_plugin_lv2(self.fPluginId, filepath):
  982. return CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  983. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  984. QMessageBox.information(self, self.tr("Plugin exported"),
  985. self.tr("Plugin exported successfully, saved in folder:\n%s" % filepath))
  986. # -------------------------------------------------------------
  987. @pyqtSlot()
  988. def slot_knobCustomMenu(self):
  989. sender = self.sender()
  990. index = sender.fIndex
  991. minimum = sender.fMinimum
  992. maximum = sender.fMaximum
  993. current = sender.fRealValue
  994. label = sender.fLabel
  995. if index in (PARAMETER_NULL, PARAMETER_CTRL_CHANNEL) or index <= PARAMETER_MAX:
  996. return
  997. elif index in (PARAMETER_DRYWET, PARAMETER_VOLUME):
  998. default = 1.0
  999. elif index == PARAMETER_BALANCE_LEFT:
  1000. default = -1.0
  1001. elif index == PARAMETER_BALANCE_RIGHT:
  1002. default = 1.0
  1003. elif index == PARAMETER_PANNING:
  1004. default = 0.0
  1005. else:
  1006. default = self.host.get_default_parameter_value(self.fPluginId, index)
  1007. if index < PARAMETER_NULL:
  1008. # show in integer percentage
  1009. textReset = self.tr("Reset (%i%%)" % round(default*100.0))
  1010. textMinim = self.tr("Set to Minimum (%i%%)" % round(minimum*100.0))
  1011. textMaxim = self.tr("Set to Maximum (%i%%)" % round(maximum*100.0))
  1012. else:
  1013. # show in full float value
  1014. textReset = self.tr("Reset (%f)" % default)
  1015. textMinim = self.tr("Set to Minimum (%f)" % minimum)
  1016. textMaxim = self.tr("Set to Maximum (%f)" % maximum)
  1017. menu = QMenu(self)
  1018. actReset = menu.addAction(textReset)
  1019. menu.addSeparator()
  1020. actMinimum = menu.addAction(textMinim)
  1021. actCenter = menu.addAction(self.tr("Set to Center"))
  1022. actMaximum = menu.addAction(textMaxim)
  1023. menu.addSeparator()
  1024. actSet = menu.addAction(self.tr("Set value..."))
  1025. if index > PARAMETER_NULL or index not in (PARAMETER_BALANCE_LEFT, PARAMETER_BALANCE_RIGHT, PARAMETER_PANNING):
  1026. menu.removeAction(actCenter)
  1027. actSelected = menu.exec_(QCursor.pos())
  1028. if actSelected == actSet:
  1029. if index < PARAMETER_NULL:
  1030. value, ok = QInputDialog.getInt(self, self.tr("Set value"), label, round(current*100), round(minimum*100), round(maximum*100), 1)
  1031. if not ok:
  1032. return
  1033. value = float(value)/100.0
  1034. else:
  1035. paramInfo = self.host.get_parameter_info(self.fPluginId, index)
  1036. paramRanges = self.host.get_parameter_ranges(self.fPluginId, index)
  1037. scalePoints = []
  1038. for i in range(paramInfo['scalePointCount']):
  1039. scalePoints.append(self.host.get_parameter_scalepoint_info(self.fPluginId, index, i))
  1040. prefix = ""
  1041. suffix = paramInfo['unit'].strip()
  1042. if suffix == "(coef)":
  1043. prefix = "* "
  1044. suffix = ""
  1045. else:
  1046. suffix = " " + suffix
  1047. dialog = CustomInputDialog(self, label, current, minimum, maximum,
  1048. paramRanges['step'], paramRanges['stepSmall'], scalePoints, prefix, suffix)
  1049. if not dialog.exec_():
  1050. return
  1051. value = dialog.returnValue()
  1052. elif actSelected == actMinimum:
  1053. value = minimum
  1054. elif actSelected == actMaximum:
  1055. value = maximum
  1056. elif actSelected == actReset:
  1057. value = default
  1058. elif actSelected == actCenter:
  1059. value = 0.0
  1060. else:
  1061. return
  1062. sender.setValue(value, True)
  1063. # -----------------------------------------------------------------
  1064. @pyqtSlot(bool)
  1065. def slot_showCustomUi(self, show):
  1066. self.host.show_custom_ui(self.fPluginId, show)
  1067. @pyqtSlot(bool)
  1068. def slot_showEditDialog(self, show):
  1069. self.fEditDialog.setVisible(show)
  1070. @pyqtSlot()
  1071. def slot_removePlugin(self):
  1072. if not self.host.remove_plugin(self.fPluginId):
  1073. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1074. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1075. # -----------------------------------------------------------------
  1076. @pyqtSlot(bool)
  1077. def slot_parameterDragStateChanged(self, touch):
  1078. index = self.sender().getIndex()
  1079. if index >= 0:
  1080. self.host.set_parameter_touch(self.fPluginId, index, touch)
  1081. @pyqtSlot(float)
  1082. def slot_parameterValueChanged(self, value):
  1083. index = self.sender().getIndex()
  1084. if index < 0:
  1085. self.setInternalParameter(index, value)
  1086. else:
  1087. self.host.set_parameter_value(self.fPluginId, index, value)
  1088. self.setParameterValue(index, value, False)
  1089. @pyqtSlot(int)
  1090. def slot_programChanged(self, index):
  1091. self.host.set_program(self.fPluginId, index)
  1092. self.setProgram(index, False)
  1093. @pyqtSlot(int)
  1094. def slot_midiProgramChanged(self, index):
  1095. self.host.set_midi_program(self.fPluginId, index)
  1096. self.setMidiProgram(index, False)
  1097. # -----------------------------------------------------------------
  1098. def adjustViewableKnobCount(self):
  1099. if self.w_knobs_left is None or self.spacer_knobs is None:
  1100. return
  1101. curWidth = 2
  1102. maxWidth = self.w_knobs_left.width() + self.spacer_knobs.geometry().width() + 2
  1103. plen = len(self.fParameterList)
  1104. for i in range(plen):
  1105. index, widget = self.fParameterList[i]
  1106. if index < 0:
  1107. break
  1108. curWidth += widget.width() + 4
  1109. if curWidth + widget.width() * 2 + 8 < maxWidth:
  1110. #if not widget.isVisible():
  1111. widget.show()
  1112. continue
  1113. for i2 in range(i, plen):
  1114. index2, widget2 = self.fParameterList[i2]
  1115. if index2 < 0:
  1116. break
  1117. #if widget2.isVisible():
  1118. widget2.hide()
  1119. break
  1120. self.fAdjustViewableKnobCountScheduled = False
  1121. def testTimer(self):
  1122. self.fIdleTimerId = self.startTimer(25)
  1123. # -----------------------------------------------------------------
  1124. def mouseDoubleClickEvent(self, event):
  1125. QFrame.mouseDoubleClickEvent(self, event)
  1126. # FIXME
  1127. gCarla.gui.compactPlugin(self.fPluginId)
  1128. def closeEvent(self, event):
  1129. if self.fIdleTimerId != 0:
  1130. self.killTimer(self.fIdleTimerId)
  1131. self.fIdleTimerId = 0
  1132. self.host.engine_close()
  1133. QFrame.closeEvent(self, event)
  1134. def resizeEvent(self, event):
  1135. if not self.fAdjustViewableKnobCountScheduled:
  1136. self.fAdjustViewableKnobCountScheduled = True
  1137. QTimer.singleShot(100, self.adjustViewableKnobCount)
  1138. QFrame.resizeEvent(self, event)
  1139. def timerEvent(self, event):
  1140. if event.timerId() == self.fIdleTimerId:
  1141. self.host.engine_idle()
  1142. self.idleFast()
  1143. self.idleSlow()
  1144. QFrame.timerEvent(self, event)
  1145. def paintEvent(self, event):
  1146. painter = QPainter(self)
  1147. # Colorization
  1148. if self.fSkinColor != (0,0,0):
  1149. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  1150. r,g,b = self.fSkinColor
  1151. painter.setBrush(QColor(r,g,b))
  1152. painter.setPen(Qt.NoPen)
  1153. painter.drawRect(QRectF(0,0,self.width(),self.height()))
  1154. painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
  1155. self.drawOutline(painter)
  1156. QFrame.paintEvent(self, event)
  1157. # ------------------------------------------------------------------------------------------------------------
  1158. class PluginSlot_Calf(AbstractPluginSlot):
  1159. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1160. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1161. self.ui = ui_carla_plugin_calf.Ui_PluginWidget()
  1162. self.ui.setupUi(self)
  1163. audioCount = self.host.get_audio_port_count_info(self.fPluginId)
  1164. midiCount = self.host.get_midi_port_count_info(self.fPluginId)
  1165. # -------------------------------------------------------------
  1166. # Internal stuff
  1167. self.fButtonFont = self.ui.b_gui.font()
  1168. self.fButtonFont.setBold(False)
  1169. self.fButtonFont.setPixelSize(10)
  1170. self.fButtonColorOn = QColor( 18, 41, 87)
  1171. self.fButtonColorOff = QColor(150, 150, 150)
  1172. # -------------------------------------------------------------
  1173. # Set-up GUI
  1174. self.ui.label_active.setFont(self.fButtonFont)
  1175. self.ui.b_remove.setPixmaps(":/bitmaps/button_calf1.png",
  1176. ":/bitmaps/button_calf1_down.png",
  1177. ":/bitmaps/button_calf1_hover.png")
  1178. self.ui.b_edit.setTopText(self.tr("Edit"), self.fButtonColorOn, self.fButtonFont)
  1179. self.ui.b_remove.setTopText(self.tr("Remove"), self.fButtonColorOn, self.fButtonFont)
  1180. if self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI:
  1181. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1182. else:
  1183. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1184. if audioCount['ins'] == 0:
  1185. self.ui.label_audio_in.hide()
  1186. if audioCount['outs'] == 0:
  1187. self.ui.label_audio_out.hide()
  1188. if midiCount['ins'] == 0:
  1189. self.ui.label_midi.hide()
  1190. self.ui.led_midi.hide()
  1191. if self.fIdleTimerId != 0:
  1192. self.ui.b_remove.setEnabled(False)
  1193. self.ui.b_remove.setVisible(False)
  1194. # -------------------------------------------------------------
  1195. self.b_enable = self.ui.b_enable
  1196. self.b_gui = self.ui.b_gui
  1197. self.b_edit = self.ui.b_edit
  1198. self.b_remove = self.ui.b_remove
  1199. self.label_name = self.ui.label_name
  1200. self.led_midi = self.ui.led_midi
  1201. self.peak_in = self.ui.peak_in
  1202. self.peak_out = self.ui.peak_out
  1203. self.w_knobs_left = self.ui.w_knobs
  1204. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1205. self.ready()
  1206. self.ui.led_midi.setColor(self.ui.led_midi.CALF)
  1207. # -----------------------------------------------------------------
  1208. def getFixedHeight(self):
  1209. return 94 if max(self.peak_in.channelCount(), self.peak_out.channelCount()) < 2 else 106
  1210. # -----------------------------------------------------------------
  1211. def editDialogPluginHintsChanged(self, pluginId, hints):
  1212. if hints & PLUGIN_HAS_CUSTOM_UI:
  1213. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1214. else:
  1215. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1216. AbstractPluginSlot.editDialogPluginHintsChanged(self, pluginId, hints)
  1217. # -----------------------------------------------------------------
  1218. def paintEvent(self, event):
  1219. isBlack = bool(self.fSkinStyle == "calf_black")
  1220. painter = QPainter(self)
  1221. painter.setBrush(Qt.transparent)
  1222. painter.setPen(QPen(QColor(20, 20, 20) if isBlack else QColor(75, 86, 99), 1))
  1223. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1224. painter.setPen(QPen(QColor(45, 45, 45) if isBlack else QColor(86, 99, 114), 1))
  1225. painter.drawLine(0, 0, self.width(), 0)
  1226. AbstractPluginSlot.paintEvent(self, event)
  1227. # ------------------------------------------------------------------------------------------------------------
  1228. class PluginSlot_Classic(AbstractPluginSlot):
  1229. def __init__(self, parent, host, pluginId):
  1230. AbstractPluginSlot.__init__(self, parent, host, pluginId, (0,0,0), "classic")
  1231. self.ui = ui_carla_plugin_classic.Ui_PluginWidget()
  1232. self.ui.setupUi(self)
  1233. # -------------------------------------------------------------
  1234. # Internal stuff
  1235. self.fColorTop = QColor(60, 60, 60)
  1236. self.fColorBottom = QColor(47, 47, 47)
  1237. self.fColorSeprtr = QColor(70, 70, 70)
  1238. # -------------------------------------------------------------
  1239. self.b_enable = self.ui.b_enable
  1240. self.b_gui = self.ui.b_gui
  1241. self.b_edit = self.ui.b_edit
  1242. self.label_name = self.ui.label_name
  1243. self.led_control = self.ui.led_control
  1244. self.led_midi = self.ui.led_midi
  1245. self.led_audio_in = self.ui.led_audio_in
  1246. self.led_audio_out = self.ui.led_audio_out
  1247. self.peak_in = self.ui.peak_in
  1248. self.peak_out = self.ui.peak_out
  1249. self.ready()
  1250. # -----------------------------------------------------------------
  1251. def getFixedHeight(self):
  1252. return 36
  1253. # -----------------------------------------------------------------
  1254. def paintEvent(self, event):
  1255. painter = QPainter(self)
  1256. painter.save()
  1257. areaX = self.ui.area_right.x()+7
  1258. width = self.width()
  1259. height = self.height()
  1260. painter.setPen(QPen(QColor(17, 17, 17), 1))
  1261. painter.setBrush(QColor(17, 17, 17))
  1262. painter.drawRect(0, 0, width, height)
  1263. painter.setPen(self.fColorSeprtr.lighter(110))
  1264. painter.setBrush(self.fColorBottom)
  1265. painter.setRenderHint(QPainter.Antialiasing, True)
  1266. # name -> leds arc
  1267. path = QPainterPath()
  1268. path.moveTo(areaX-20, height-4)
  1269. path.cubicTo(areaX, height-5, areaX-20, 4.75, areaX, 4.75)
  1270. path.lineTo(areaX, height-5)
  1271. painter.drawPath(path)
  1272. painter.setPen(self.fColorSeprtr)
  1273. painter.setRenderHint(QPainter.Antialiasing, False)
  1274. # separator lines
  1275. painter.drawLine(0, height-5, areaX-20, height-5)
  1276. painter.drawLine(areaX, 4, width, 4)
  1277. painter.setPen(self.fColorBottom)
  1278. painter.setBrush(self.fColorBottom)
  1279. # top, bottom and left lines
  1280. painter.drawLine(0, 0, width, 0)
  1281. painter.drawRect(0, height-4, areaX, 4)
  1282. painter.drawRoundedRect(areaX-20, height-5, areaX, 5, 22, 22)
  1283. painter.drawLine(0, 0, 0, height)
  1284. # fill the rest
  1285. painter.drawRect(areaX-1, 5, width, height)
  1286. # bottom 1px line
  1287. painter.setPen(self.fColorSeprtr)
  1288. painter.drawLine(0, height-1, width, height-1)
  1289. painter.restore()
  1290. AbstractPluginSlot.paintEvent(self, event)
  1291. # ------------------------------------------------------------------------------------------------------------
  1292. class PluginSlot_Compact(AbstractPluginSlot):
  1293. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1294. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1295. self.ui = ui_carla_plugin_compact.Ui_PluginWidget()
  1296. self.ui.setupUi(self)
  1297. self.b_enable = self.ui.b_enable
  1298. self.b_gui = self.ui.b_gui
  1299. self.b_edit = self.ui.b_edit
  1300. self.label_name = self.ui.label_name
  1301. self.led_control = self.ui.led_control
  1302. self.led_midi = self.ui.led_midi
  1303. self.led_audio_in = self.ui.led_audio_in
  1304. self.led_audio_out = self.ui.led_audio_out
  1305. self.peak_in = self.ui.peak_in
  1306. self.peak_out = self.ui.peak_out
  1307. self.ready()
  1308. # -----------------------------------------------------------------
  1309. def getFixedHeight(self):
  1310. if self.fSkinStyle == "calf_blue":
  1311. return 36
  1312. return 30
  1313. # ------------------------------------------------------------------------------------------------------------
  1314. class PluginSlot_Default(AbstractPluginSlot):
  1315. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1316. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1317. self.ui = ui_carla_plugin_default.Ui_PluginWidget()
  1318. self.ui.setupUi(self)
  1319. # -------------------------------------------------------------
  1320. self.b_enable = self.ui.b_enable
  1321. self.b_gui = self.ui.b_gui
  1322. self.b_edit = self.ui.b_edit
  1323. self.label_name = self.ui.label_name
  1324. self.led_control = self.ui.led_control
  1325. self.led_midi = self.ui.led_midi
  1326. self.led_audio_in = self.ui.led_audio_in
  1327. self.led_audio_out = self.ui.led_audio_out
  1328. self.peak_in = self.ui.peak_in
  1329. self.peak_out = self.ui.peak_out
  1330. self.w_knobs_left = self.ui.w_knobs_left
  1331. self.w_knobs_right = self.ui.w_knobs_right
  1332. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1333. self.ready()
  1334. # -----------------------------------------------------------------
  1335. def getFixedHeight(self):
  1336. return 80
  1337. # -----------------------------------------------------------------
  1338. def paintEvent(self, event):
  1339. painter = QPainter(self)
  1340. painter.setBrush(Qt.transparent)
  1341. painter.setPen(QPen(QColor(42, 42, 42), 1))
  1342. painter.drawRect(0, 1, self.width()-1, self.getFixedHeight()-3)
  1343. painter.setPen(QPen(QColor(60, 60, 60), 1))
  1344. painter.drawLine(0, 0, self.width(), 0)
  1345. AbstractPluginSlot.paintEvent(self, event)
  1346. # ------------------------------------------------------------------------------------------------------------
  1347. class PluginSlot_Presets(AbstractPluginSlot):
  1348. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1349. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1350. self.ui = ui_carla_plugin_presets.Ui_PluginWidget()
  1351. self.ui.setupUi(self)
  1352. usingMidiPrograms = bool(skinStyle != "presets")
  1353. # -------------------------------------------------------------
  1354. # Set-up programs
  1355. if usingMidiPrograms:
  1356. programCount = self.host.get_midi_program_count(self.fPluginId)
  1357. else:
  1358. programCount = self.host.get_program_count(self.fPluginId)
  1359. if programCount > 0:
  1360. self.ui.cb_presets.setEnabled(True)
  1361. self.ui.label_presets.setEnabled(True)
  1362. for i in range(programCount):
  1363. if usingMidiPrograms:
  1364. progName = self.host.get_midi_program_data(self.fPluginId, i)['name']
  1365. else:
  1366. progName = self.host.get_program_name(self.fPluginId, i)
  1367. self.ui.cb_presets.addItem(progName)
  1368. if usingMidiPrograms:
  1369. curProg = self.host.get_current_midi_program_index(self.fPluginId)
  1370. else:
  1371. curProg = self.host.get_current_program_index(self.fPluginId)
  1372. self.ui.cb_presets.setCurrentIndex(curProg)
  1373. else:
  1374. self.ui.cb_presets.setEnabled(False)
  1375. self.ui.cb_presets.setVisible(False)
  1376. self.ui.label_presets.setEnabled(False)
  1377. self.ui.label_presets.setVisible(False)
  1378. # -------------------------------------------------------------
  1379. self.b_enable = self.ui.b_enable
  1380. self.b_gui = self.ui.b_gui
  1381. self.b_edit = self.ui.b_edit
  1382. self.cb_presets = self.ui.cb_presets
  1383. self.label_name = self.ui.label_name
  1384. self.label_presets = self.ui.label_presets
  1385. self.led_control = self.ui.led_control
  1386. self.led_midi = self.ui.led_midi
  1387. self.led_audio_in = self.ui.led_audio_in
  1388. self.led_audio_out = self.ui.led_audio_out
  1389. self.peak_in = self.ui.peak_in
  1390. self.peak_out = self.ui.peak_out
  1391. if skinStyle == "zynfx":
  1392. self.setupZynFxParams()
  1393. else:
  1394. self.w_knobs_left = self.ui.w_knobs_left
  1395. self.w_knobs_right = self.ui.w_knobs_right
  1396. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1397. self.ready()
  1398. if usingMidiPrograms:
  1399. self.ui.cb_presets.currentIndexChanged.connect(self.slot_midiProgramChanged)
  1400. else:
  1401. self.ui.cb_presets.currentIndexChanged.connect(self.slot_programChanged)
  1402. # -------------------------------------------------------------
  1403. def setupZynFxParams(self):
  1404. parameterCount = min(self.host.get_parameter_count(self.fPluginId), 8)
  1405. for i in range(parameterCount):
  1406. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  1407. paramData = self.host.get_parameter_data(self.fPluginId, i)
  1408. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  1409. if paramData['type'] != PARAMETER_INPUT:
  1410. continue
  1411. if paramData['hints'] & PARAMETER_IS_BOOLEAN:
  1412. continue
  1413. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1414. continue
  1415. paramName = paramInfo['name']
  1416. if paramName.startswith("unused"):
  1417. continue
  1418. # real zyn fx plugins
  1419. if self.fPluginInfo['label'] == "zynalienwah":
  1420. if i == 0: paramName = "Freq"
  1421. elif i == 1: paramName = "Rnd"
  1422. elif i == 2: paramName = "L type" # combobox
  1423. elif i == 3: paramName = "St.df"
  1424. elif i == 5: paramName = "Fb"
  1425. elif i == 7: paramName = "L/R"
  1426. elif self.fPluginInfo['label'] == "zynchorus":
  1427. if i == 0: paramName = "Freq"
  1428. elif i == 1: paramName = "Rnd"
  1429. elif i == 2: paramName = "L type" # combobox
  1430. elif i == 3: paramName = "St.df"
  1431. elif i == 6: paramName = "Fb"
  1432. elif i == 7: paramName = "L/R"
  1433. elif i == 8: paramName = "Flngr" # button
  1434. elif i == 9: paramName = "Subst" # button
  1435. elif self.fPluginInfo['label'] == "zyndistortion":
  1436. if i == 0: paramName = "LRc."
  1437. elif i == 4: paramName = "Neg." # button
  1438. elif i == 5: paramName = "LPF"
  1439. elif i == 6: paramName = "HPF"
  1440. elif i == 7: paramName = "St." # button
  1441. elif i == 8: paramName = "PF" # button
  1442. elif self.fPluginInfo['label'] == "zyndynamicfilter":
  1443. if i == 0: paramName = "Freq"
  1444. elif i == 1: paramName = "Rnd"
  1445. elif i == 2: paramName = "L type" # combobox
  1446. elif i == 3: paramName = "St.df"
  1447. elif i == 4: paramName = "LfoD"
  1448. elif i == 5: paramName = "A.S."
  1449. elif i == 6: paramName = "A.Inv." # button
  1450. elif i == 7: paramName = "A.M."
  1451. elif self.fPluginInfo['label'] == "zynecho":
  1452. if i == 1: paramName = "LRdl."
  1453. elif i == 2: paramName = "LRc."
  1454. elif i == 3: paramName = "Fb."
  1455. elif i == 4: paramName = "Damp"
  1456. elif self.fPluginInfo['label'] == "zynphaser":
  1457. if i == 0: paramName = "Freq"
  1458. elif i == 1: paramName = "Rnd"
  1459. elif i == 2: paramName = "L type" # combobox
  1460. elif i == 3: paramName = "St.df"
  1461. elif i == 5: paramName = "Fb"
  1462. elif i == 7: paramName = "L/R"
  1463. elif i == 8: paramName = "Subst" # button
  1464. elif i == 9: paramName = "Phase"
  1465. elif i == 11: paramName = "Dist"
  1466. elif self.fPluginInfo['label'] == "zynreverb":
  1467. if i == 2: paramName = "I.delfb"
  1468. elif i == 5: paramName = "LPF"
  1469. elif i == 6: paramName = "HPF"
  1470. elif i == 9: paramName = "R.S."
  1471. elif i == 10: paramName = "I.del"
  1472. else:
  1473. paramName = getParameterShortName(paramName)
  1474. widget = ScalableDial(self, i)
  1475. widget.setLabel(paramName)
  1476. widget.setMinimum(paramRanges['min'])
  1477. widget.setMaximum(paramRanges['max'])
  1478. widget.setImage(3)
  1479. widget.setCustomPaintColor(QColor(83, 173, 10))
  1480. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_COLOR)
  1481. widget.forceWhiteLabelGradientText()
  1482. widget.hide()
  1483. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1484. widget.setEnabled(False)
  1485. self.fParameterList.append([i, widget])
  1486. self.ui.w_knobs_left.layout().addWidget(widget)
  1487. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  1488. widget = ScalableDial(self, PARAMETER_DRYWET)
  1489. widget.setLabel("Wet")
  1490. widget.setMinimum(0.0)
  1491. widget.setMaximum(1.0)
  1492. widget.setImage(3)
  1493. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_CARLA_WET)
  1494. widget.forceWhiteLabelGradientText()
  1495. self.fParameterList.append([PARAMETER_DRYWET, widget])
  1496. self.ui.w_knobs_right.layout().addWidget(widget)
  1497. if self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  1498. widget = ScalableDial(self, PARAMETER_VOLUME)
  1499. widget.setLabel("Volume")
  1500. widget.setMinimum(0.0)
  1501. widget.setMaximum(1.27)
  1502. widget.setImage(3)
  1503. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_CARLA_VOL)
  1504. widget.forceWhiteLabelGradientText()
  1505. self.fParameterList.append([PARAMETER_VOLUME, widget])
  1506. self.ui.w_knobs_right.layout().addWidget(widget)
  1507. # -----------------------------------------------------------------
  1508. def getFixedHeight(self):
  1509. return 80
  1510. # -----------------------------------------------------------------
  1511. def paintEvent(self, event):
  1512. painter = QPainter(self)
  1513. painter.setBrush(Qt.transparent)
  1514. painter.setPen(QPen(QColor(50, 50, 50), 1))
  1515. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1516. painter.setPen(QPen(QColor(64, 64, 64), 1))
  1517. painter.drawLine(0, 0, self.width(), 0)
  1518. AbstractPluginSlot.paintEvent(self, event)
  1519. # ------------------------------------------------------------------------------------------------------------
  1520. def getColorAndSkinStyle(host, pluginId):
  1521. pluginInfo = host.get_plugin_info(pluginId)
  1522. pluginName = host.get_real_plugin_name(pluginId)
  1523. pluginLabel = pluginInfo['label'].lower()
  1524. pluginMaker = pluginInfo['maker']
  1525. uniqueId = pluginInfo['uniqueId']
  1526. if pluginInfo['type'] in (PLUGIN_VST2, PLUGIN_VST3, PLUGIN_AU):
  1527. progCount = host.get_program_count(pluginId)
  1528. else:
  1529. progCount = host.get_midi_program_count(pluginId)
  1530. colorCategory = getColorFromCategory(pluginInfo['category'])
  1531. colorNone = (0,0,0)
  1532. # Samplers
  1533. if pluginInfo['type'] == PLUGIN_SF2:
  1534. return (colorCategory, "sf2")
  1535. if pluginInfo['type'] == PLUGIN_SFZ:
  1536. return (colorCategory, "sfz")
  1537. # Calf
  1538. if pluginName.split(" ", 1)[0].lower() == "calf":
  1539. return (colorNone, "calf_black" if "mono" in pluginLabel else "calf_blue")
  1540. # OpenAV
  1541. if pluginMaker == "OpenAV Productions":
  1542. return (colorNone, "openav-old")
  1543. if pluginMaker == "OpenAV":
  1544. return (colorNone, "openav")
  1545. # ZynFX
  1546. if pluginInfo['type'] == PLUGIN_INTERNAL:
  1547. if pluginLabel.startswith("zyn") and pluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1548. return (colorNone, "zynfx")
  1549. if pluginInfo['type'] == PLUGIN_LADSPA:
  1550. if pluginLabel.startswith("zyn") and pluginMaker.startswith("Josep Andreu"):
  1551. return (colorNone, "zynfx")
  1552. if pluginInfo['type'] == PLUGIN_LV2:
  1553. if pluginLabel.startswith("http://kxstudio.sf.net/carla/plugins/zyn") and pluginName != "ZynAddSubFX":
  1554. return (colorNone, "zynfx")
  1555. # Presets
  1556. if progCount > 1 and (pluginInfo['hints'] & PLUGIN_USES_MULTI_PROGS) == 0:
  1557. if pluginInfo['type'] in (PLUGIN_VST2, PLUGIN_VST3, PLUGIN_AU):
  1558. return (colorCategory, "presets")
  1559. return (colorCategory, "mpresets")
  1560. # DISTRHO Plugins (needs to be last)
  1561. if pluginMaker.startswith("falkTX, ") or pluginMaker == "DISTRHO" or pluginLabel.startswith("http://distrho.sf.net/plugins/"):
  1562. return (colorNone, pluginLabel.replace("http://distrho.sf.net/plugins/",""))
  1563. return (colorCategory, "default")
  1564. def createPluginSlot(parent, host, pluginId, options):
  1565. skinColor, skinStyle = getColorAndSkinStyle(host, pluginId)
  1566. if options['color'] is not None:
  1567. skinColor = options['color']
  1568. if options['skin']:
  1569. skinStyle = options['skin']
  1570. if skinStyle == "classic":
  1571. return PluginSlot_Classic(parent, host, pluginId)
  1572. if "compact" in skinStyle or options['compact']:
  1573. return PluginSlot_Compact(parent, host, pluginId, skinColor, skinStyle)
  1574. if skinStyle.startswith("calf"):
  1575. return PluginSlot_Calf(parent, host, pluginId, skinColor, skinStyle)
  1576. if skinStyle in ("mpresets", "presets", "zynfx"):
  1577. return PluginSlot_Presets(parent, host, pluginId, skinColor, skinStyle)
  1578. return PluginSlot_Default(parent, host, pluginId, skinColor, skinStyle)
  1579. # ------------------------------------------------------------------------------------------------------------
  1580. # Main Testing
  1581. if __name__ == '__main__':
  1582. from carla_app import CarlaApplication
  1583. from carla_host import initHost, loadHostSettings
  1584. import resources_rc
  1585. app = CarlaApplication("Carla-Skins")
  1586. host = initHost("Skins", None, False, False, False)
  1587. loadHostSettings(host)
  1588. host.engine_init("JACK", "Carla-Widgets")
  1589. host.add_plugin(BINARY_NATIVE, PLUGIN_INTERNAL, "", "", "zynreverb", 0, None, PLUGIN_OPTIONS_NULL)
  1590. #host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, PLUGIN_OPTIONS_NULL)
  1591. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://www.openavproductions.com/sorcer", 0, None, PLUGIN_OPTIONS_NULL)
  1592. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://calf.sourceforge.net/plugins/Compressor", 0, None, PLUGIN_OPTIONS_NULL)
  1593. host.set_active(0, True)
  1594. #gui = createPluginSlot(None, host, 0, True)
  1595. gui = PluginSlot_Compact(None, host, 0, (0, 0, 0), "default")
  1596. gui.testTimer()
  1597. gui.show()
  1598. app.exec_()