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.

2084 lines
77KB

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