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.

2009 lines
74KB

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