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.

2110 lines
79KB

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