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.

2068 lines
76KB

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