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".format(imageSuffix),
  311. ":/bitmaps/button_distrho_down-{}.png".format(imageSuffix),
  312. ":/bitmaps/button_distrho_hover-{}.png".format(imageSuffix))
  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. colorEnabled = "#BBB"
  418. colorDisabled = "#555"
  419. if self.fSkinStyle in ("3bandeq", "calf_black", "calf_blue", "nekobi", "zynfx"):
  420. styleSheet2 = "background-image: url(:/bitmaps/background_%s.png);" % self.fSkinStyle
  421. else:
  422. styleSheet2 = "background-color: rgb(%i, %i, %i);" % self.fSkinColor
  423. styleSheet2 += "background-image: url(:/bitmaps/background_noise1.png);"
  424. if not self.fDarkStyle:
  425. colorEnabled = "#111"
  426. colorDisabled = "#AAA"
  427. styleSheet = """
  428. QFrame#PluginWidget {
  429. %s
  430. background-repeat: repeat-xy;
  431. }
  432. QLabel#label_name,
  433. QLabel#label_audio_in,
  434. QLabel#label_audio_out,
  435. QLabel#label_midi,
  436. QLabel#label_presets { color: %s; }
  437. QLabel#label_name:disabled { color: %s; }
  438. """ % (styleSheet2, colorEnabled, colorDisabled)
  439. styleSheet += """
  440. QComboBox#cb_presets,
  441. QLabel#label_audio_in,
  442. QLabel#label_audio_out,
  443. QLabel#label_midi { font-size: 10px; }
  444. """
  445. self.setStyleSheet(styleSheet)
  446. # -------------------------------------------------------------
  447. # Set-up parameters
  448. if self.w_knobs_left is not None:
  449. parameterCount = self.host.get_parameter_count(self.fPluginId)
  450. if "calf" in self.fSkinStyle:
  451. maxWidgets = 7
  452. else:
  453. maxWidgets = 8
  454. index = 0
  455. for i in range(parameterCount):
  456. if index >= maxWidgets:
  457. break
  458. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  459. paramData = self.host.get_parameter_data(self.fPluginId, i)
  460. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  461. isInteger = (paramData['hints'] & PARAMETER_IS_INTEGER) != 0
  462. if paramData['type'] != PARAMETER_INPUT:
  463. continue
  464. if paramData['hints'] & PARAMETER_IS_BOOLEAN:
  465. continue
  466. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  467. continue
  468. if (paramData['hints'] & PARAMETER_USES_SCALEPOINTS) != 0 and not isInteger:
  469. # NOTE: we assume integer scalepoints are continuous
  470. continue
  471. if isInteger and paramRanges['max']-paramRanges['min'] <= 3:
  472. continue
  473. if paramInfo['name'].startswith("unused"):
  474. continue
  475. paramName = getParameterShortName(paramInfo['name'])
  476. widget = PixmapDial(self, i)
  477. widget.setLabel(paramName)
  478. widget.setMinimum(paramRanges['min'])
  479. widget.setMaximum(paramRanges['max'])
  480. if isInteger:
  481. widget.setPrecision(paramRanges['max']-paramRanges['min'], True)
  482. setPixmapDialStyle(widget, i, parameterCount, self.fDarkStyle, self.fSkinStyle)
  483. index += 1
  484. self.fParameterList.append([i, widget])
  485. self.w_knobs_left.layout().addWidget(widget)
  486. if self.w_knobs_right is not None and (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) != 0:
  487. widget = PixmapDial(self, PARAMETER_DRYWET)
  488. widget.setLabel("Dry/Wet")
  489. widget.setMinimum(0.0)
  490. widget.setMaximum(1.0)
  491. setPixmapDialStyle(widget, PARAMETER_DRYWET, 0, self.fDarkStyle, self.fSkinStyle)
  492. self.fParameterList.append([PARAMETER_DRYWET, widget])
  493. self.w_knobs_right.layout().addWidget(widget)
  494. if self.w_knobs_right is not None and (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) != 0:
  495. widget = PixmapDial(self, PARAMETER_VOLUME)
  496. widget.setLabel("Volume")
  497. widget.setMinimum(0.0)
  498. widget.setMaximum(1.27)
  499. setPixmapDialStyle(widget, PARAMETER_VOLUME, 0, self.fDarkStyle, self.fSkinStyle)
  500. self.fParameterList.append([PARAMETER_VOLUME, widget])
  501. self.w_knobs_right.layout().addWidget(widget)
  502. for paramIndex, paramWidget in self.fParameterList:
  503. paramWidget.setContextMenuPolicy(Qt.CustomContextMenu)
  504. paramWidget.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  505. paramWidget.realValueChanged.connect(self.slot_parameterValueChanged)
  506. paramWidget.blockSignals(True)
  507. paramWidget.setValue(self.host.get_internal_parameter_value(self.fPluginId, paramIndex))
  508. paramWidget.blockSignals(False)
  509. # -------------------------------------------------------------
  510. self.setWindowTitle(self.fPluginInfo['name'])
  511. #------------------------------------------------------------------
  512. def getFixedHeight(self):
  513. return 32
  514. def getHints(self):
  515. return self.fPluginInfo['hints']
  516. def getPluginId(self):
  517. return self.fPluginId
  518. #------------------------------------------------------------------
  519. def setPluginId(self, idx):
  520. self.fPluginId = idx
  521. self.fEditDialog.setPluginId(idx)
  522. def setName(self, name):
  523. self.fPluginInfo['name'] = name
  524. self.fEditDialog.setName(name)
  525. if self.label_name is not None:
  526. self.label_name.setText(name)
  527. def setSelected(self, yesNo):
  528. if self.fIsSelected == yesNo:
  529. return
  530. self.fIsSelected = yesNo
  531. self.update()
  532. #------------------------------------------------------------------
  533. def setActive(self, active, sendCallback=False, sendHost=True):
  534. self.fIsActive = active
  535. if sendCallback:
  536. self.fParameterIconTimer = ICON_STATE_ON
  537. self.activeChanged(active)
  538. if sendHost:
  539. self.host.set_active(self.fPluginId, active)
  540. if active:
  541. self.fEditDialog.clearNotes()
  542. self.midiActivityChanged(False)
  543. if self.label_name is not None:
  544. self.label_name.setEnabled(self.fIsActive)
  545. # called from rack, checks if param is possible first
  546. def setInternalParameter(self, parameterId, value):
  547. if parameterId <= PARAMETER_MAX or parameterId >= PARAMETER_NULL:
  548. return
  549. elif parameterId == PARAMETER_ACTIVE:
  550. return self.setActive(bool(value), True, True)
  551. elif parameterId == PARAMETER_DRYWET:
  552. if (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) == 0: return
  553. self.host.set_drywet(self.fPluginId, value)
  554. elif parameterId == PARAMETER_VOLUME:
  555. if (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) == 0: return
  556. self.host.set_volume(self.fPluginId, value)
  557. elif parameterId == PARAMETER_BALANCE_LEFT:
  558. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  559. self.host.set_balance_left(self.fPluginId, value)
  560. elif parameterId == PARAMETER_BALANCE_RIGHT:
  561. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  562. self.host.set_balance_right(self.fPluginId, value)
  563. elif parameterId == PARAMETER_PANNING:
  564. if (self.fPluginInfo['hints'] & PLUGIN_CAN_PANNING) == 0: return
  565. self.host.set_panning(self.fPluginId, value)
  566. elif parameterId == PARAMETER_CTRL_CHANNEL:
  567. self.host.set_ctrl_channel(self.fPluginId, value)
  568. self.fEditDialog.setParameterValue(parameterId, value)
  569. #------------------------------------------------------------------
  570. def setParameterValue(self, parameterId, value, sendCallback):
  571. if parameterId == PARAMETER_ACTIVE:
  572. return self.setActive(bool(value), True, False)
  573. self.fEditDialog.setParameterValue(parameterId, value)
  574. if sendCallback:
  575. self.fParameterIconTimer = ICON_STATE_ON
  576. self.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  577. def setParameterDefault(self, parameterId, value):
  578. self.fEditDialog.setParameterDefault(parameterId, value)
  579. def setParameterMidiControl(self, parameterId, control):
  580. self.fEditDialog.setParameterMidiControl(parameterId, control)
  581. def setParameterMidiChannel(self, parameterId, channel):
  582. self.fEditDialog.setParameterMidiChannel(parameterId, channel)
  583. #------------------------------------------------------------------
  584. def setProgram(self, index, sendCallback):
  585. self.fEditDialog.setProgram(index)
  586. if sendCallback:
  587. self.fParameterIconTimer = ICON_STATE_ON
  588. self.editDialogProgramChanged(self.fPluginId, index)
  589. self.updateParameterValues()
  590. def setMidiProgram(self, index, sendCallback):
  591. self.fEditDialog.setMidiProgram(index)
  592. if sendCallback:
  593. self.fParameterIconTimer = ICON_STATE_ON
  594. self.editDialogMidiProgramChanged(self.fPluginId, index)
  595. self.updateParameterValues()
  596. #------------------------------------------------------------------
  597. def setOption(self, option, yesNo):
  598. self.fEditDialog.setOption(option, yesNo)
  599. #------------------------------------------------------------------
  600. def showCustomUI(self):
  601. self.host.show_custom_ui(self.fPluginId, True)
  602. if self.b_gui is not None:
  603. self.b_gui.setChecked(True)
  604. def showEditDialog(self):
  605. self.fEditDialog.show()
  606. self.fEditDialog.activateWindow()
  607. if self.b_edit is not None:
  608. self.b_edit.setChecked(True)
  609. def showRenameDialog(self):
  610. oldName = self.fPluginInfo['name']
  611. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  612. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  613. return
  614. newName = newNameTry[0]
  615. if not self.host.rename_plugin(self.fPluginId, newName):
  616. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  617. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  618. return
  619. self.setName(newName)
  620. def showReplaceDialog(self):
  621. data = gCarla.gui.showAddPluginDialog()
  622. if data is None:
  623. return
  624. btype, ptype, filename, label, uniqueId, extraPtr = data
  625. if not self.host.replace_plugin(self.fPluginId):
  626. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  627. return
  628. ok = self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0)
  629. self.host.replace_plugin(self.host.get_max_plugin_number())
  630. if not ok:
  631. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  632. #------------------------------------------------------------------
  633. def activeChanged(self, onOff):
  634. self.fIsActive = onOff
  635. if self.b_enable is None:
  636. return
  637. self.b_enable.blockSignals(True)
  638. self.b_enable.setChecked(onOff)
  639. self.b_enable.blockSignals(False)
  640. def customUiStateChanged(self, state):
  641. if self.b_gui is None:
  642. return
  643. self.b_gui.blockSignals(True)
  644. if state == 0:
  645. self.b_gui.setChecked(False)
  646. self.b_gui.setEnabled(True)
  647. elif state == 1:
  648. self.b_gui.setChecked(True)
  649. self.b_gui.setEnabled(True)
  650. elif state == -1:
  651. self.b_gui.setChecked(False)
  652. self.b_gui.setEnabled(False)
  653. self.b_gui.blockSignals(False)
  654. def parameterActivityChanged(self, onOff):
  655. if self.led_control is None:
  656. return
  657. self.led_control.setChecked(onOff)
  658. def midiActivityChanged(self, onOff):
  659. if self.led_midi is None:
  660. return
  661. self.led_midi.setChecked(onOff)
  662. def optionChanged(self, option, yesNo):
  663. pass
  664. # -----------------------------------------------------------------
  665. # PluginEdit callbacks
  666. def editDialogVisibilityChanged(self, pluginId, visible):
  667. if self.b_edit is None:
  668. return
  669. self.b_edit.blockSignals(True)
  670. self.b_edit.setChecked(visible)
  671. self.b_edit.blockSignals(False)
  672. def editDialogPluginHintsChanged(self, pluginId, hints):
  673. self.fPluginInfo['hints'] = hints
  674. for paramIndex, paramWidget in self.fParameterList:
  675. if paramIndex == PARAMETER_DRYWET:
  676. paramWidget.setVisible(hints & PLUGIN_CAN_DRYWET)
  677. elif paramIndex == PARAMETER_VOLUME:
  678. paramWidget.setVisible(hints & PLUGIN_CAN_VOLUME)
  679. if self.b_gui is not None:
  680. self.b_gui.setEnabled(bool(hints & PLUGIN_HAS_CUSTOM_UI))
  681. def editDialogParameterValueChanged(self, pluginId, parameterId, value):
  682. for paramIndex, paramWidget in self.fParameterList:
  683. if paramIndex != parameterId:
  684. continue
  685. paramWidget.blockSignals(True)
  686. paramWidget.setValue(value)
  687. paramWidget.blockSignals(False)
  688. break
  689. def editDialogProgramChanged(self, pluginId, index):
  690. if self.cb_presets is None:
  691. return
  692. self.cb_presets.blockSignals(True)
  693. self.cb_presets.setCurrentIndex(index)
  694. self.cb_presets.blockSignals(False)
  695. # FIXME
  696. self.updateParameterValues()
  697. def editDialogMidiProgramChanged(self, pluginId, index):
  698. if self.cb_presets is None:
  699. return
  700. self.cb_presets.blockSignals(True)
  701. self.cb_presets.setCurrentIndex(index)
  702. self.cb_presets.blockSignals(False)
  703. # FIXME
  704. self.updateParameterValues()
  705. def editDialogNotePressed(self, pluginId, note):
  706. pass
  707. def editDialogNoteReleased(self, pluginId, note):
  708. pass
  709. def editDialogMidiActivityChanged(self, pluginId, onOff):
  710. self.midiActivityChanged(onOff)
  711. #------------------------------------------------------------------
  712. def idleFast(self):
  713. # Input peaks
  714. if self.fPeaksInputCount > 0:
  715. if self.fPeaksInputCount > 1:
  716. peak1 = self.host.get_input_peak_value(self.fPluginId, True)
  717. peak2 = self.host.get_input_peak_value(self.fPluginId, False)
  718. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  719. if self.peak_in is not None:
  720. self.peak_in.displayMeter(1, peak1)
  721. self.peak_in.displayMeter(2, peak2)
  722. else:
  723. peak = self.host.get_input_peak_value(self.fPluginId, True)
  724. ledState = bool(peak != 0.0)
  725. if self.peak_in is not None:
  726. self.peak_in.displayMeter(1, peak)
  727. if self.fLastGreenLedState != ledState and self.led_audio_in is not None:
  728. self.fLastGreenLedState = ledState
  729. self.led_audio_in.setChecked(ledState)
  730. # Output peaks
  731. if self.fPeaksOutputCount > 0:
  732. if self.fPeaksOutputCount > 1:
  733. peak1 = self.host.get_output_peak_value(self.fPluginId, True)
  734. peak2 = self.host.get_output_peak_value(self.fPluginId, False)
  735. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  736. if self.peak_out is not None:
  737. self.peak_out.displayMeter(1, peak1)
  738. self.peak_out.displayMeter(2, peak2)
  739. else:
  740. peak = self.host.get_output_peak_value(self.fPluginId, True)
  741. ledState = bool(peak != 0.0)
  742. if self.peak_out is not None:
  743. self.peak_out.displayMeter(1, peak)
  744. if self.fLastBlueLedState != ledState and self.led_audio_out is not None:
  745. self.fLastBlueLedState = ledState
  746. self.led_audio_out.setChecked(ledState)
  747. def idleSlow(self):
  748. if self.fParameterIconTimer == ICON_STATE_ON:
  749. self.parameterActivityChanged(True)
  750. self.fParameterIconTimer = ICON_STATE_WAIT
  751. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  752. self.fParameterIconTimer = ICON_STATE_OFF
  753. elif self.fParameterIconTimer == ICON_STATE_OFF:
  754. self.parameterActivityChanged(False)
  755. self.fParameterIconTimer = ICON_STATE_NULL
  756. self.fEditDialog.idleSlow()
  757. #------------------------------------------------------------------
  758. def drawOutline(self):
  759. painter = QPainter(self)
  760. if self.fIsSelected:
  761. painter.setPen(QPen(Qt.cyan, 4))
  762. painter.setBrush(Qt.transparent)
  763. painter.drawRect(0, 0, self.width(), self.height())
  764. else:
  765. painter.setPen(QPen(Qt.black, 1))
  766. painter.setBrush(Qt.black)
  767. painter.drawLine(0, self.height()-1, self.width(), self.height()-1)
  768. def updateParameterValues(self):
  769. for paramIndex, paramWidget in self.fParameterList:
  770. if paramIndex < 0:
  771. continue
  772. paramWidget.blockSignals(True)
  773. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramIndex))
  774. paramWidget.blockSignals(False)
  775. #------------------------------------------------------------------
  776. @pyqtSlot(bool)
  777. def slot_enableClicked(self, yesNo):
  778. self.setActive(yesNo, False, True)
  779. @pyqtSlot()
  780. def slot_showCustomMenu(self):
  781. menu = QMenu(self)
  782. # -------------------------------------------------------------
  783. # Expand/Minimize
  784. actCompact = menu.addAction(self.tr("Expand") if isinstance(self, PluginSlot_Compact) else self.tr("Minimize"))
  785. actColor = menu.addAction(self.tr("Change Color..."))
  786. actSkin = menu.addAction(self.tr("Change Skin..."))
  787. menu.addSeparator()
  788. if isinstance(self, PluginSlot_Classic):
  789. actCompact.setEnabled(False)
  790. actColor.setEnabled(False)
  791. elif self.fSkinStyle in ("openav", "openav-old", "3bandeq", "calf_black", "calf_blue", "nekobi", "zynfx"):
  792. actColor.setEnabled(False)
  793. # -------------------------------------------------------------
  794. # Move up and down
  795. actMoveUp = menu.addAction(self.tr("Move Up"))
  796. actMoveDown = menu.addAction(self.tr("Move Down"))
  797. if self.fPluginId == 0:
  798. actMoveUp.setEnabled(False)
  799. if self.fPluginId >= self.fParent.getPluginCount():
  800. actMoveDown.setEnabled(False)
  801. # -------------------------------------------------------------
  802. # Bypass and Enable/Disable
  803. actBypass = menu.addAction(self.tr("Bypass"))
  804. actEnable = menu.addAction(self.tr("Disable") if self.fIsActive else self.tr("Enable"))
  805. menu.addSeparator()
  806. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  807. actBypass.setCheckable(True)
  808. actBypass.setChecked(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_DRYWET) == 0.0)
  809. else:
  810. actBypass.setVisible(False)
  811. # -------------------------------------------------------------
  812. # Reset and Randomize parameters
  813. actReset = menu.addAction(self.tr("Reset parameters"))
  814. actRandom = menu.addAction(self.tr("Randomize parameters"))
  815. menu.addSeparator()
  816. # -------------------------------------------------------------
  817. # Edit and Show Custom UI
  818. actEdit = menu.addAction(self.tr("Edit"))
  819. actGui = menu.addAction(self.tr("Show Custom UI"))
  820. menu.addSeparator()
  821. if self.b_edit is not None:
  822. actEdit.setCheckable(True)
  823. actEdit.setChecked(self.b_edit.isChecked())
  824. else:
  825. actEdit.setVisible(False)
  826. if self.b_gui is not None:
  827. actGui.setCheckable(True)
  828. actGui.setChecked(self.b_gui.isChecked())
  829. actGui.setEnabled(self.b_gui.isEnabled())
  830. else:
  831. actGui.setVisible(False)
  832. # -------------------------------------------------------------
  833. # Other stuff
  834. actClone = menu.addAction(self.tr("Clone"))
  835. actRename = menu.addAction(self.tr("Rename..."))
  836. actReplace = menu.addAction(self.tr("Replace..."))
  837. actRemove = menu.addAction(self.tr("Remove"))
  838. if self.fIdleTimerId != 0:
  839. actRemove.setVisible(False)
  840. if self.host.exportLV2:
  841. menu.addSeparator()
  842. actExportLV2 = menu.addAction(self.tr("Export LV2..."))
  843. else:
  844. actExportLV2 = None
  845. # -------------------------------------------------------------
  846. # exec
  847. actSel = menu.exec_(QCursor.pos())
  848. if not actSel:
  849. return
  850. # -------------------------------------------------------------
  851. # Expand/Minimize
  852. elif actSel == actCompact:
  853. # FIXME
  854. gCarla.gui.compactPlugin(self.fPluginId)
  855. # -------------------------------------------------------------
  856. # Tweaks
  857. elif actSel == actColor:
  858. initial = QColor(self.fSkinColor[0], self.fSkinColor[1], self.fSkinColor[2])
  859. color = QColorDialog.getColor(initial, self, self.tr("Change Color"), QColorDialog.DontUseNativeDialog)
  860. if not color.isValid():
  861. return
  862. color = (color.red(), color.green(), color.blue())
  863. colorStr = "%i;%i;%i" % color
  864. gCarla.gui.changePluginColor(self.fPluginId, color, colorStr)
  865. elif actSel == actSkin:
  866. skinList = [
  867. "default",
  868. "3bandeq",
  869. "rncbc",
  870. "calf_black",
  871. "calf_blue",
  872. "classic",
  873. "openav-old",
  874. "openav",
  875. "zynfx",
  876. "presets",
  877. "mpresets",
  878. ]
  879. try:
  880. index = skinList.index(self.fSkinStyle)
  881. except:
  882. index = 0
  883. skin = QInputDialog.getItem(self, self.tr("Change Skin"),
  884. self.tr("Change Skin to:"),
  885. skinList, index, False)
  886. if not all(skin):
  887. return
  888. gCarla.gui.changePluginSkin(self.fPluginId, skin[0])
  889. # -------------------------------------------------------------
  890. # Move up and down
  891. elif actSel == actMoveUp:
  892. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId-1)
  893. elif actSel == actMoveDown:
  894. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId+1)
  895. # -------------------------------------------------------------
  896. # Bypass and Enable/Disable
  897. elif actSel == actBypass:
  898. value = 0.0 if actBypass.isChecked() else 1.0
  899. self.host.set_drywet(self.fPluginId, value)
  900. self.setParameterValue(PARAMETER_DRYWET, value, True)
  901. elif actSel == actEnable:
  902. self.setActive(not self.fIsActive, True, True)
  903. # -------------------------------------------------------------
  904. # Reset and Randomize parameters
  905. elif actSel == actReset:
  906. self.host.reset_parameters(self.fPluginId)
  907. elif actSel == actRandom:
  908. self.host.randomize_parameters(self.fPluginId)
  909. # -------------------------------------------------------------
  910. # Edit and Show Custom UI
  911. elif actSel == actEdit:
  912. self.b_edit.click()
  913. elif actSel == actGui:
  914. self.b_gui.click()
  915. # -------------------------------------------------------------
  916. # Clone
  917. elif actSel == actClone:
  918. if not self.host.clone_plugin(self.fPluginId):
  919. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  920. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  921. # -------------------------------------------------------------
  922. # Rename
  923. elif actSel == actRename:
  924. self.showRenameDialog()
  925. # -------------------------------------------------------------
  926. # Replace
  927. elif actSel == actReplace:
  928. self.showReplaceDialog()
  929. # -------------------------------------------------------------
  930. # Remove
  931. elif actSel == actRemove:
  932. if not self.host.remove_plugin(self.fPluginId):
  933. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  934. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  935. # -------------------------------------------------------------
  936. # Export LV2
  937. elif actSel == actExportLV2:
  938. filepath = QInputDialog.getItem(self, self.tr("Export LV2 Plugin"),
  939. self.tr("Select LV2 Path where plugin will be exported to:"),
  940. CARLA_DEFAULT_LV2_PATH, editable=False)
  941. if not all(filepath):
  942. return
  943. plugname = self.fPluginInfo['name']
  944. filepath = os.path.join(filepath[0], plugname.replace(" ","_"))
  945. if not filepath.endswith(".lv2"):
  946. filepath += ".lv2"
  947. if os.path.exists(filepath):
  948. if QMessageBox.question(self, self.tr("Export to LV2"),
  949. self.tr("Plugin bundle already exists, overwrite?")) == QMessageBox.Ok:
  950. return
  951. if not self.host.export_plugin_lv2(self.fPluginId, filepath):
  952. return CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  953. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  954. QMessageBox.information(self, self.tr("Plugin exported"),
  955. self.tr("Plugin exported successfully, saved in folder:\n%s" % filepath))
  956. # -------------------------------------------------------------
  957. @pyqtSlot()
  958. def slot_knobCustomMenu(self):
  959. sender = self.sender()
  960. index = sender.fIndex
  961. minimum = sender.fMinimum
  962. maximum = sender.fMaximum
  963. current = sender.fRealValue
  964. label = sender.fLabel
  965. if index in (PARAMETER_NULL, PARAMETER_CTRL_CHANNEL) or index <= PARAMETER_MAX:
  966. return
  967. elif index in (PARAMETER_DRYWET, PARAMETER_VOLUME):
  968. default = 1.0
  969. elif index == PARAMETER_BALANCE_LEFT:
  970. default = -1.0
  971. elif index == PARAMETER_BALANCE_RIGHT:
  972. default = 1.0
  973. elif index == PARAMETER_PANNING:
  974. default = 0.0
  975. else:
  976. default = self.host.get_default_parameter_value(self.fPluginId, index)
  977. if index < PARAMETER_NULL:
  978. # show in integer percentage
  979. textReset = self.tr("Reset (%i%%)" % round(default*100.0))
  980. textMinim = self.tr("Set to Minimum (%i%%)" % round(minimum*100.0))
  981. textMaxim = self.tr("Set to Maximum (%i%%)" % round(maximum*100.0))
  982. else:
  983. # show in full float value
  984. textReset = self.tr("Reset (%f)" % default)
  985. textMinim = self.tr("Set to Minimum (%f)" % minimum)
  986. textMaxim = self.tr("Set to Maximum (%f)" % maximum)
  987. menu = QMenu(self)
  988. actReset = menu.addAction(textReset)
  989. menu.addSeparator()
  990. actMinimum = menu.addAction(textMinim)
  991. actCenter = menu.addAction(self.tr("Set to Center"))
  992. actMaximum = menu.addAction(textMaxim)
  993. menu.addSeparator()
  994. actSet = menu.addAction(self.tr("Set value..."))
  995. if index > PARAMETER_NULL or index not in (PARAMETER_BALANCE_LEFT, PARAMETER_BALANCE_RIGHT, PARAMETER_PANNING):
  996. menu.removeAction(actCenter)
  997. actSelected = menu.exec_(QCursor.pos())
  998. if actSelected == actSet:
  999. if index < PARAMETER_NULL:
  1000. value, ok = QInputDialog.getInt(self, self.tr("Set value"), label, round(current*100), round(minimum*100), round(maximum*100), 1)
  1001. if not ok:
  1002. return
  1003. value = float(value)/100.0
  1004. else:
  1005. paramInfo = self.host.get_parameter_info(self.fPluginId, index)
  1006. paramRanges = self.host.get_parameter_ranges(self.fPluginId, index)
  1007. scalePoints = []
  1008. for i in range(paramInfo['scalePointCount']):
  1009. scalePoints.append(self.host.get_parameter_scalepoint_info(self.fPluginId, index, i))
  1010. dialog = CustomInputDialog(self, label, current, minimum, maximum,
  1011. paramRanges['step'], paramRanges['stepSmall'], scalePoints)
  1012. if not dialog.exec_():
  1013. return
  1014. value = dialog.returnValue()
  1015. elif actSelected == actMinimum:
  1016. value = minimum
  1017. elif actSelected == actMaximum:
  1018. value = maximum
  1019. elif actSelected == actReset:
  1020. value = default
  1021. elif actSelected == actCenter:
  1022. value = 0.0
  1023. else:
  1024. return
  1025. sender.setValue(value, True)
  1026. #------------------------------------------------------------------
  1027. @pyqtSlot(bool)
  1028. def slot_showCustomUi(self, show):
  1029. self.host.show_custom_ui(self.fPluginId, show)
  1030. @pyqtSlot(bool)
  1031. def slot_showEditDialog(self, show):
  1032. self.fEditDialog.setVisible(show)
  1033. @pyqtSlot()
  1034. def slot_removePlugin(self):
  1035. if not self.host.remove_plugin(self.fPluginId):
  1036. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1037. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1038. #------------------------------------------------------------------
  1039. @pyqtSlot(float)
  1040. def slot_parameterValueChanged(self, value):
  1041. index = self.sender().getIndex()
  1042. if index < 0:
  1043. self.setInternalParameter(index, value)
  1044. else:
  1045. self.host.set_parameter_value(self.fPluginId, index, value)
  1046. self.setParameterValue(index, value, False)
  1047. @pyqtSlot(int)
  1048. def slot_programChanged(self, index):
  1049. self.host.set_program(self.fPluginId, index)
  1050. self.setProgram(index, False)
  1051. @pyqtSlot(int)
  1052. def slot_midiProgramChanged(self, index):
  1053. self.host.set_midi_program(self.fPluginId, index)
  1054. self.setMidiProgram(index, False)
  1055. #------------------------------------------------------------------
  1056. def testTimer(self):
  1057. self.fIdleTimerId = self.startTimer(25)
  1058. #------------------------------------------------------------------
  1059. def mouseDoubleClickEvent(self, event):
  1060. QFrame.mouseDoubleClickEvent(self, event)
  1061. # FIXME
  1062. gCarla.gui.compactPlugin(self.fPluginId)
  1063. def closeEvent(self, event):
  1064. if self.fIdleTimerId != 0:
  1065. self.killTimer(self.fIdleTimerId)
  1066. self.fIdleTimerId = 0
  1067. self.host.engine_close()
  1068. QFrame.closeEvent(self, event)
  1069. def timerEvent(self, event):
  1070. if event.timerId() == self.fIdleTimerId:
  1071. self.host.engine_idle()
  1072. self.idleFast()
  1073. self.idleSlow()
  1074. QFrame.timerEvent(self, event)
  1075. def paintEvent(self, event):
  1076. self.drawOutline()
  1077. QFrame.paintEvent(self, event)
  1078. # ------------------------------------------------------------------------------------------------------------
  1079. class PluginSlot_Calf(AbstractPluginSlot):
  1080. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1081. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1082. self.ui = ui_carla_plugin_calf.Ui_PluginWidget()
  1083. self.ui.setupUi(self)
  1084. audioCount = self.host.get_audio_port_count_info(self.fPluginId)
  1085. midiCount = self.host.get_midi_port_count_info(self.fPluginId)
  1086. # -------------------------------------------------------------
  1087. # Internal stuff
  1088. self.fButtonFont = self.ui.b_gui.font()
  1089. self.fButtonFont.setBold(False)
  1090. self.fButtonFont.setPixelSize(10)
  1091. self.fButtonColorOn = QColor( 18, 41, 87)
  1092. self.fButtonColorOff = QColor(150, 150, 150)
  1093. # -------------------------------------------------------------
  1094. # Set-up GUI
  1095. self.ui.label_active.setFont(self.fButtonFont)
  1096. self.ui.b_remove.setPixmaps(":/bitmaps/button_calf1.png", ":/bitmaps/button_calf1_down.png", ":/bitmaps/button_calf1_hover.png")
  1097. self.ui.b_edit.setTopText(self.tr("Edit"), self.fButtonColorOn, self.fButtonFont)
  1098. self.ui.b_remove.setTopText(self.tr("Remove"), self.fButtonColorOn, self.fButtonFont)
  1099. if self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI:
  1100. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1101. else:
  1102. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1103. if audioCount['ins'] == 0:
  1104. self.ui.label_audio_in.hide()
  1105. if audioCount['outs'] == 0:
  1106. self.ui.label_audio_out.hide()
  1107. if midiCount['ins'] == 0:
  1108. self.ui.label_midi.hide()
  1109. self.ui.led_midi.hide()
  1110. if self.fIdleTimerId != 0:
  1111. self.ui.b_remove.setEnabled(False)
  1112. self.ui.b_remove.setVisible(False)
  1113. # -------------------------------------------------------------
  1114. self.b_enable = self.ui.b_enable
  1115. self.b_gui = self.ui.b_gui
  1116. self.b_edit = self.ui.b_edit
  1117. self.b_remove = self.ui.b_remove
  1118. self.label_name = self.ui.label_name
  1119. self.led_midi = self.ui.led_midi
  1120. self.peak_in = self.ui.peak_in
  1121. self.peak_out = self.ui.peak_out
  1122. self.w_knobs_left = self.ui.w_knobs
  1123. self.ready()
  1124. self.ui.led_midi.setColor(self.ui.led_midi.CALF)
  1125. #------------------------------------------------------------------
  1126. def getFixedHeight(self):
  1127. return 94 if max(self.peak_in.channelCount(), self.peak_out.channelCount()) < 2 else 106
  1128. #------------------------------------------------------------------
  1129. def editDialogPluginHintsChanged(self, pluginId, hints):
  1130. if hints & PLUGIN_HAS_CUSTOM_UI:
  1131. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1132. else:
  1133. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1134. AbstractPluginSlot.editDialogPluginHintsChanged(self, pluginId, hints)
  1135. #------------------------------------------------------------------
  1136. def paintEvent(self, event):
  1137. isBlack = bool(self.fSkinStyle == "calf_black")
  1138. painter = QPainter(self)
  1139. painter.setBrush(Qt.transparent)
  1140. painter.setPen(QPen(QColor(20, 20, 20) if isBlack else QColor(75, 86, 99), 1))
  1141. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1142. painter.setPen(QPen(QColor(45, 45, 45) if isBlack else QColor(86, 99, 114), 1))
  1143. painter.drawLine(0, 0, self.width(), 0)
  1144. AbstractPluginSlot.paintEvent(self, event)
  1145. # ------------------------------------------------------------------------------------------------------------
  1146. class PluginSlot_Classic(AbstractPluginSlot):
  1147. def __init__(self, parent, host, pluginId):
  1148. AbstractPluginSlot.__init__(self, parent, host, pluginId, (0,0,0), "classic")
  1149. self.ui = ui_carla_plugin_classic.Ui_PluginWidget()
  1150. self.ui.setupUi(self)
  1151. # -------------------------------------------------------------
  1152. # Internal stuff
  1153. self.fColorTop = QColor(60, 60, 60)
  1154. self.fColorBottom = QColor(47, 47, 47)
  1155. self.fColorSeprtr = QColor(70, 70, 70)
  1156. # -------------------------------------------------------------
  1157. self.b_enable = self.ui.b_enable
  1158. self.b_gui = self.ui.b_gui
  1159. self.b_edit = self.ui.b_edit
  1160. self.label_name = self.ui.label_name
  1161. self.led_control = self.ui.led_control
  1162. self.led_midi = self.ui.led_midi
  1163. self.led_audio_in = self.ui.led_audio_in
  1164. self.led_audio_out = self.ui.led_audio_out
  1165. self.peak_in = self.ui.peak_in
  1166. self.peak_out = self.ui.peak_out
  1167. self.ready()
  1168. #------------------------------------------------------------------
  1169. def getFixedHeight(self):
  1170. return 36
  1171. #------------------------------------------------------------------
  1172. def paintEvent(self, event):
  1173. painter = QPainter(self)
  1174. painter.save()
  1175. areaX = self.ui.area_right.x()+7
  1176. width = self.width()
  1177. height = self.height()
  1178. painter.setPen(QPen(QColor(17, 17, 17), 1))
  1179. painter.setBrush(QColor(17, 17, 17))
  1180. painter.drawRect(0, 0, width, height)
  1181. painter.setPen(self.fColorSeprtr.lighter(110))
  1182. painter.setBrush(self.fColorBottom)
  1183. painter.setRenderHint(QPainter.Antialiasing, True)
  1184. # name -> leds arc
  1185. path = QPainterPath()
  1186. path.moveTo(areaX-20, height-4)
  1187. path.cubicTo(areaX, height-5, areaX-20, 4.75, areaX, 4.75)
  1188. path.lineTo(areaX, height-5)
  1189. painter.drawPath(path)
  1190. painter.setPen(self.fColorSeprtr)
  1191. painter.setRenderHint(QPainter.Antialiasing, False)
  1192. # separator lines
  1193. painter.drawLine(0, height-5, areaX-20, height-5)
  1194. painter.drawLine(areaX, 4, width, 4)
  1195. painter.setPen(self.fColorBottom)
  1196. painter.setBrush(self.fColorBottom)
  1197. # top, bottom and left lines
  1198. painter.drawLine(0, 0, width, 0)
  1199. painter.drawRect(0, height-4, areaX, 4)
  1200. painter.drawRoundedRect(areaX-20, height-5, areaX, 5, 22, 22)
  1201. painter.drawLine(0, 0, 0, height)
  1202. # fill the rest
  1203. painter.drawRect(areaX-1, 5, width, height)
  1204. # bottom 1px line
  1205. painter.setPen(self.fColorSeprtr)
  1206. painter.drawLine(0, height-1, width, height-1)
  1207. painter.restore()
  1208. AbstractPluginSlot.paintEvent(self, event)
  1209. # ------------------------------------------------------------------------------------------------------------
  1210. class PluginSlot_Compact(AbstractPluginSlot):
  1211. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1212. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1213. self.ui = ui_carla_plugin_compact.Ui_PluginWidget()
  1214. self.ui.setupUi(self)
  1215. self.b_enable = self.ui.b_enable
  1216. self.b_gui = self.ui.b_gui
  1217. self.b_edit = self.ui.b_edit
  1218. self.label_name = self.ui.label_name
  1219. self.led_control = self.ui.led_control
  1220. self.led_midi = self.ui.led_midi
  1221. self.led_audio_in = self.ui.led_audio_in
  1222. self.led_audio_out = self.ui.led_audio_out
  1223. self.peak_in = self.ui.peak_in
  1224. self.peak_out = self.ui.peak_out
  1225. self.ready()
  1226. #------------------------------------------------------------------
  1227. def getFixedHeight(self):
  1228. if self.fSkinStyle == "calf_blue":
  1229. return 36
  1230. return 30
  1231. # ------------------------------------------------------------------------------------------------------------
  1232. class PluginSlot_Default(AbstractPluginSlot):
  1233. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1234. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1235. self.ui = ui_carla_plugin_default.Ui_PluginWidget()
  1236. self.ui.setupUi(self)
  1237. # -------------------------------------------------------------
  1238. self.b_enable = self.ui.b_enable
  1239. self.b_gui = self.ui.b_gui
  1240. self.b_edit = self.ui.b_edit
  1241. self.label_name = self.ui.label_name
  1242. self.led_control = self.ui.led_control
  1243. self.led_midi = self.ui.led_midi
  1244. self.led_audio_in = self.ui.led_audio_in
  1245. self.led_audio_out = self.ui.led_audio_out
  1246. self.peak_in = self.ui.peak_in
  1247. self.peak_out = self.ui.peak_out
  1248. self.w_knobs_left = self.ui.w_knobs_left
  1249. self.w_knobs_right = self.ui.w_knobs_right
  1250. self.ready()
  1251. #------------------------------------------------------------------
  1252. def getFixedHeight(self):
  1253. return 80
  1254. #------------------------------------------------------------------
  1255. def paintEvent(self, event):
  1256. painter = QPainter(self)
  1257. painter.setBrush(Qt.transparent)
  1258. painter.setPen(QPen(QColor(42, 42, 42), 1))
  1259. painter.drawRect(0, 1, self.width()-1, self.getFixedHeight()-3)
  1260. painter.setPen(QPen(QColor(60, 60, 60), 1))
  1261. painter.drawLine(0, 0, self.width(), 0)
  1262. AbstractPluginSlot.paintEvent(self, event)
  1263. # ------------------------------------------------------------------------------------------------------------
  1264. class PluginSlot_Presets(AbstractPluginSlot):
  1265. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1266. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1267. self.ui = ui_carla_plugin_presets.Ui_PluginWidget()
  1268. self.ui.setupUi(self)
  1269. usingMidiPrograms = bool(skinStyle != "presets")
  1270. # -------------------------------------------------------------
  1271. # Set-up programs
  1272. if usingMidiPrograms:
  1273. programCount = self.host.get_midi_program_count(self.fPluginId)
  1274. else:
  1275. programCount = self.host.get_program_count(self.fPluginId)
  1276. if programCount > 0:
  1277. self.ui.cb_presets.setEnabled(True)
  1278. self.ui.label_presets.setEnabled(True)
  1279. for i in range(programCount):
  1280. if usingMidiPrograms:
  1281. progName = self.host.get_midi_program_data(self.fPluginId, i)['name']
  1282. else:
  1283. progName = self.host.get_program_name(self.fPluginId, i)
  1284. self.ui.cb_presets.addItem(progName)
  1285. if usingMidiPrograms:
  1286. curProg = self.host.get_current_midi_program_index(self.fPluginId)
  1287. else:
  1288. curProg = self.host.get_current_program_index(self.fPluginId)
  1289. self.ui.cb_presets.setCurrentIndex(curProg)
  1290. else:
  1291. self.ui.cb_presets.setEnabled(False)
  1292. self.ui.cb_presets.setVisible(False)
  1293. self.ui.label_presets.setEnabled(False)
  1294. self.ui.label_presets.setVisible(False)
  1295. # -------------------------------------------------------------
  1296. self.b_enable = self.ui.b_enable
  1297. self.b_gui = self.ui.b_gui
  1298. self.b_edit = self.ui.b_edit
  1299. self.cb_presets = self.ui.cb_presets
  1300. self.label_name = self.ui.label_name
  1301. self.label_presets = self.ui.label_presets
  1302. self.led_control = self.ui.led_control
  1303. self.led_midi = self.ui.led_midi
  1304. self.led_audio_in = self.ui.led_audio_in
  1305. self.led_audio_out = self.ui.led_audio_out
  1306. self.peak_in = self.ui.peak_in
  1307. self.peak_out = self.ui.peak_out
  1308. if skinStyle == "zynfx":
  1309. self.setupZynFxParams()
  1310. else:
  1311. self.w_knobs_left = self.ui.w_knobs_left
  1312. self.w_knobs_right = self.ui.w_knobs_right
  1313. self.ready()
  1314. if usingMidiPrograms:
  1315. self.ui.cb_presets.currentIndexChanged.connect(self.slot_midiProgramChanged)
  1316. else:
  1317. self.ui.cb_presets.currentIndexChanged.connect(self.slot_programChanged)
  1318. # -------------------------------------------------------------
  1319. def setupZynFxParams(self):
  1320. parameterCount = self.host.get_parameter_count(self.fPluginId)
  1321. index = 0
  1322. for i in range(parameterCount):
  1323. if index >= 8:
  1324. break
  1325. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  1326. paramData = self.host.get_parameter_data(self.fPluginId, i)
  1327. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  1328. if paramData['type'] != PARAMETER_INPUT:
  1329. continue
  1330. if paramData['hints'] & PARAMETER_IS_BOOLEAN:
  1331. continue
  1332. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1333. continue
  1334. paramName = paramInfo['name']
  1335. if paramName.startswith("unused"):
  1336. continue
  1337. # real zyn fx plugins
  1338. if self.fPluginInfo['label'] == "zynalienwah":
  1339. if i == 0: paramName = "Freq"
  1340. elif i == 1: paramName = "Rnd"
  1341. elif i == 2: paramName = "L type" # combobox
  1342. elif i == 3: paramName = "St.df"
  1343. elif i == 5: paramName = "Fb"
  1344. elif i == 7: paramName = "L/R"
  1345. elif self.fPluginInfo['label'] == "zynchorus":
  1346. if i == 0: paramName = "Freq"
  1347. elif i == 1: paramName = "Rnd"
  1348. elif i == 2: paramName = "L type" # combobox
  1349. elif i == 3: paramName = "St.df"
  1350. elif i == 6: paramName = "Fb"
  1351. elif i == 7: paramName = "L/R"
  1352. elif i == 8: paramName = "Flngr" # button
  1353. elif i == 9: paramName = "Subst" # button
  1354. elif self.fPluginInfo['label'] == "zyndistortion":
  1355. if i == 0: paramName = "LRc."
  1356. elif i == 4: paramName = "Neg." # button
  1357. elif i == 5: paramName = "LPF"
  1358. elif i == 6: paramName = "HPF"
  1359. elif i == 7: paramName = "St." # button
  1360. elif i == 8: paramName = "PF" # button
  1361. elif self.fPluginInfo['label'] == "zyndynamicfilter":
  1362. if i == 0: paramName = "Freq"
  1363. elif i == 1: paramName = "Rnd"
  1364. elif i == 2: paramName = "L type" # combobox
  1365. elif i == 3: paramName = "St.df"
  1366. elif i == 4: paramName = "LfoD"
  1367. elif i == 5: paramName = "A.S."
  1368. elif i == 6: paramName = "A.Inv." # button
  1369. elif i == 7: paramName = "A.M."
  1370. elif self.fPluginInfo['label'] == "zynecho":
  1371. if i == 1: paramName = "LRdl."
  1372. elif i == 2: paramName = "LRc."
  1373. elif i == 3: paramName = "Fb."
  1374. elif i == 4: paramName = "Damp"
  1375. elif self.fPluginInfo['label'] == "zynphaser":
  1376. if i == 0: paramName = "Freq"
  1377. elif i == 1: paramName = "Rnd"
  1378. elif i == 2: paramName = "L type" # combobox
  1379. elif i == 3: paramName = "St.df"
  1380. elif i == 5: paramName = "Fb"
  1381. elif i == 7: paramName = "L/R"
  1382. elif i == 8: paramName = "Subst" # button
  1383. elif i == 9: paramName = "Phase"
  1384. elif i == 11: paramName = "Dist"
  1385. elif self.fPluginInfo['label'] == "zynreverb":
  1386. if i == 2: paramName = "I.delfb"
  1387. elif i == 5: paramName = "LPF"
  1388. elif i == 6: paramName = "HPF"
  1389. elif i == 9: paramName = "R.S."
  1390. elif i == 10: paramName = "I.del"
  1391. else:
  1392. paramName = getParameterShortName(paramName)
  1393. widget = PixmapDial(self, i)
  1394. widget.setLabel(paramName)
  1395. widget.setMinimum(paramRanges['min'])
  1396. widget.setMaximum(paramRanges['max'])
  1397. widget.setPixmap(3)
  1398. widget.setCustomPaintColor(QColor(83, 173, 10))
  1399. widget.setCustomPaintMode(PixmapDial.CUSTOM_PAINT_MODE_COLOR)
  1400. widget.forceWhiteLabelGradientText()
  1401. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1402. widget.setEnabled(False)
  1403. self.fParameterList.append([i, widget])
  1404. self.ui.w_knobs_left.layout().addWidget(widget)
  1405. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  1406. widget = PixmapDial(self, PARAMETER_DRYWET)
  1407. widget.setLabel("Wet")
  1408. widget.setMinimum(0.0)
  1409. widget.setMaximum(1.0)
  1410. widget.setPixmap(3)
  1411. widget.setCustomPaintMode(PixmapDial.CUSTOM_PAINT_MODE_CARLA_WET)
  1412. widget.forceWhiteLabelGradientText()
  1413. self.fParameterList.append([PARAMETER_DRYWET, widget])
  1414. self.ui.w_knobs_right.layout().addWidget(widget)
  1415. if self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  1416. widget = PixmapDial(self, PARAMETER_VOLUME)
  1417. widget.setLabel("Volume")
  1418. widget.setMinimum(0.0)
  1419. widget.setMaximum(1.27)
  1420. widget.setPixmap(3)
  1421. widget.setCustomPaintMode(PixmapDial.CUSTOM_PAINT_MODE_CARLA_VOL)
  1422. widget.forceWhiteLabelGradientText()
  1423. self.fParameterList.append([PARAMETER_VOLUME, widget])
  1424. self.ui.w_knobs_right.layout().addWidget(widget)
  1425. #------------------------------------------------------------------
  1426. def getFixedHeight(self):
  1427. return 80
  1428. #------------------------------------------------------------------
  1429. def paintEvent(self, event):
  1430. painter = QPainter(self)
  1431. painter.setBrush(Qt.transparent)
  1432. painter.setPen(QPen(QColor(50, 50, 50), 1))
  1433. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1434. painter.setPen(QPen(QColor(64, 64, 64), 1))
  1435. painter.drawLine(0, 0, self.width(), 0)
  1436. AbstractPluginSlot.paintEvent(self, event)
  1437. # ------------------------------------------------------------------------------------------------------------
  1438. def getColorAndSkinStyle(host, pluginId):
  1439. if False:
  1440. # kdevelop likes this :)
  1441. host = CarlaHostNull()
  1442. progCount = 0
  1443. pluginInfo = PyCarlaPluginInfo
  1444. pluginName = ""
  1445. pluginInfo = host.get_plugin_info(pluginId)
  1446. pluginName = host.get_real_plugin_name(pluginId)
  1447. pluginLabel = pluginInfo['label'].lower()
  1448. pluginMaker = pluginInfo['maker']
  1449. uniqueId = pluginInfo['uniqueId']
  1450. if pluginInfo['type'] == PLUGIN_VST2:
  1451. progCount = host.get_program_count(pluginId)
  1452. else:
  1453. progCount = host.get_midi_program_count(pluginId)
  1454. color = getColorFromCategory(pluginInfo['category'])
  1455. # Samplers
  1456. if pluginInfo['type'] == PLUGIN_SF2:
  1457. return (color, "sf2")
  1458. if pluginInfo['type'] == PLUGIN_SFZ:
  1459. return (color, "sfz")
  1460. # Calf
  1461. if pluginName.split(" ", 1)[0].lower() == "calf":
  1462. return (color, "calf_black" if "mono" in pluginLabel else "calf_blue")
  1463. # OpenAV
  1464. if pluginMaker == "OpenAV Productions":
  1465. return (color, "openav-old")
  1466. if pluginMaker == "OpenAV":
  1467. return (color, "openav")
  1468. # ZynFX
  1469. if pluginInfo['type'] == PLUGIN_INTERNAL:
  1470. if pluginLabel.startswith("zyn") and pluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1471. return (color, "zynfx")
  1472. if pluginInfo['type'] == PLUGIN_LADSPA:
  1473. if pluginLabel.startswith("zyn") and pluginMaker.startswith("Josep Andreu"):
  1474. return (color, "zynfx")
  1475. if pluginInfo['type'] == PLUGIN_LV2:
  1476. if pluginLabel.startswith("http://kxstudio.sf.net/carla/plugins/zyn") and pluginName != "ZynAddSubFX":
  1477. return (color, "zynfx")
  1478. # Presets
  1479. if progCount > 1 and (pluginInfo['hints'] & PLUGIN_USES_MULTI_PROGS) == 0:
  1480. if pluginInfo['type'] == PLUGIN_VST2:
  1481. return (color, "presets")
  1482. return (color, "mpresets")
  1483. # DISTRHO Plugins (needs to be last)
  1484. if pluginMaker.startswith("falkTX, ") or pluginMaker == "DISTRHO" or pluginLabel.startswith("http://distrho.sf.net/plugins/"):
  1485. return (color, pluginLabel.replace("http://distrho.sf.net/plugins/",""))
  1486. return (color, "default")
  1487. def createPluginSlot(parent, host, pluginId, options):
  1488. skinColor, skinStyle = getColorAndSkinStyle(host, pluginId)
  1489. if options['color'] is not None:
  1490. skinColor = options['color']
  1491. if options['skin']:
  1492. skinStyle = options['skin']
  1493. if skinStyle == "classic":
  1494. return PluginSlot_Classic(parent, host, pluginId)
  1495. if "compact" in skinStyle or options['compact']:
  1496. return PluginSlot_Compact(parent, host, pluginId, skinColor, skinStyle)
  1497. if skinStyle.startswith("calf"):
  1498. return PluginSlot_Calf(parent, host, pluginId, skinColor, skinStyle)
  1499. if skinStyle in ("mpresets", "presets", "zynfx"):
  1500. return PluginSlot_Presets(parent, host, pluginId, skinColor, skinStyle)
  1501. return PluginSlot_Default(parent, host, pluginId, skinColor, skinStyle)
  1502. # ------------------------------------------------------------------------------------------------------------
  1503. # Main Testing
  1504. if __name__ == '__main__':
  1505. from carla_app import CarlaApplication
  1506. from carla_host import initHost, loadHostSettings
  1507. import resources_rc
  1508. app = CarlaApplication("Carla-Skins")
  1509. host = initHost("Skins", None, False, False, False)
  1510. loadHostSettings(host)
  1511. host.engine_init("JACK", "Carla-Widgets")
  1512. host.add_plugin(BINARY_NATIVE, PLUGIN_INTERNAL, "", "", "zynreverb", 0, None, 0x0)
  1513. #host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, 0x0)
  1514. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://www.openavproductions.com/sorcer", 0, None, 0x0)
  1515. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://calf.sourceforge.net/plugins/Compressor", 0, None, 0x0)
  1516. host.set_active(0, True)
  1517. #gui = createPluginSlot(None, host, 0, True)
  1518. gui = PluginSlot_Compact(None, host, 0, (0, 0, 0), "default")
  1519. gui.testTimer()
  1520. gui.show()
  1521. app.exec_()