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.

2022 lines
75KB

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