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.

2110 lines
78KB

  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 and Tweaks
  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. # Find in patchbay, if possible
  809. if self.host.processMode in (ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,
  810. ENGINE_PROCESS_MODE_PATCHBAY):
  811. actFindInPatchbay = menu.addAction(self.tr("Find plugin in patchbay"))
  812. menu.addSeparator()
  813. else:
  814. actFindInPatchbay = None
  815. # -------------------------------------------------------------
  816. # Move up and down
  817. actMoveUp = menu.addAction(self.tr("Move Up"))
  818. actMoveDown = menu.addAction(self.tr("Move Down"))
  819. if self.fPluginId == 0:
  820. actMoveUp.setEnabled(False)
  821. if self.fPluginId >= self.fParent.getPluginCount():
  822. actMoveDown.setEnabled(False)
  823. # -------------------------------------------------------------
  824. # Bypass and Enable/Disable
  825. actBypass = menu.addAction(self.tr("Bypass"))
  826. actEnable = menu.addAction(self.tr("Disable") if self.fIsActive else self.tr("Enable"))
  827. menu.addSeparator()
  828. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  829. actBypass.setCheckable(True)
  830. actBypass.setChecked(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_DRYWET) == 0.0)
  831. else:
  832. actBypass.setVisible(False)
  833. # -------------------------------------------------------------
  834. # Reset and Randomize parameters
  835. actReset = menu.addAction(self.tr("Reset parameters"))
  836. actRandom = menu.addAction(self.tr("Randomize parameters"))
  837. menu.addSeparator()
  838. # -------------------------------------------------------------
  839. # Edit and Show Custom UI
  840. actEdit = menu.addAction(self.tr("Edit"))
  841. actGui = menu.addAction(self.tr("Show Custom UI"))
  842. menu.addSeparator()
  843. if self.b_edit is not None:
  844. actEdit.setCheckable(True)
  845. actEdit.setChecked(self.b_edit.isChecked())
  846. else:
  847. actEdit.setVisible(False)
  848. if self.b_gui is not None:
  849. actGui.setCheckable(True)
  850. actGui.setChecked(self.b_gui.isChecked())
  851. actGui.setEnabled(self.b_gui.isEnabled())
  852. else:
  853. actGui.setVisible(False)
  854. # -------------------------------------------------------------
  855. # Other stuff
  856. actClone = menu.addAction(self.tr("Clone"))
  857. actRename = menu.addAction(self.tr("Rename..."))
  858. actReplace = menu.addAction(self.tr("Replace..."))
  859. actRemove = menu.addAction(self.tr("Remove"))
  860. if self.fIdleTimerId != 0:
  861. actRemove.setVisible(False)
  862. if self.host.exportLV2:
  863. menu.addSeparator()
  864. actExportLV2 = menu.addAction(self.tr("Export LV2..."))
  865. else:
  866. actExportLV2 = None
  867. # -------------------------------------------------------------
  868. # exec
  869. actSel = menu.exec_(QCursor.pos())
  870. if not actSel:
  871. return
  872. # -------------------------------------------------------------
  873. # Expand/Minimize
  874. elif actSel == actCompact:
  875. # FIXME
  876. gCarla.gui.compactPlugin(self.fPluginId)
  877. # -------------------------------------------------------------
  878. # Tweaks
  879. elif actSel == actColor:
  880. initial = QColor(self.fSkinColor[0], self.fSkinColor[1], self.fSkinColor[2])
  881. color = QColorDialog.getColor(initial, self, self.tr("Change Color"), QColorDialog.DontUseNativeDialog)
  882. if not color.isValid():
  883. return
  884. color = color.getRgb()[0:3]
  885. colorStr = "%i;%i;%i" % color
  886. gCarla.gui.changePluginColor(self.fPluginId, color, colorStr)
  887. elif actSel == actSkin:
  888. skinList = [
  889. "default",
  890. "3bandeq",
  891. "rncbc",
  892. "calf_black",
  893. "calf_blue",
  894. "classic",
  895. "openav-old",
  896. "openav",
  897. "zynfx",
  898. "presets",
  899. "mpresets",
  900. ]
  901. try:
  902. index = skinList.index(self.fSkinStyle)
  903. except:
  904. index = 0
  905. skin = QInputDialog.getItem(self, self.tr("Change Skin"),
  906. self.tr("Change Skin to:"),
  907. skinList, index, False)
  908. if not all(skin):
  909. return
  910. gCarla.gui.changePluginSkin(self.fPluginId, skin[0])
  911. # -------------------------------------------------------------
  912. # Find in patchbay
  913. elif actSel == actFindInPatchbay:
  914. gCarla.gui.findPluginInPatchbay(self.fPluginId)
  915. # -------------------------------------------------------------
  916. # Move up and down
  917. elif actSel == actMoveUp:
  918. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId-1)
  919. elif actSel == actMoveDown:
  920. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId+1)
  921. # -------------------------------------------------------------
  922. # Bypass and Enable/Disable
  923. elif actSel == actBypass:
  924. value = 0.0 if actBypass.isChecked() else 1.0
  925. self.host.set_drywet(self.fPluginId, value)
  926. self.setParameterValue(PARAMETER_DRYWET, value, True)
  927. elif actSel == actEnable:
  928. self.setActive(not self.fIsActive, True, True)
  929. # -------------------------------------------------------------
  930. # Reset and Randomize parameters
  931. elif actSel == actReset:
  932. self.host.reset_parameters(self.fPluginId)
  933. elif actSel == actRandom:
  934. self.host.randomize_parameters(self.fPluginId)
  935. # -------------------------------------------------------------
  936. # Edit and Show Custom UI
  937. elif actSel == actEdit:
  938. self.b_edit.click()
  939. elif actSel == actGui:
  940. self.b_gui.click()
  941. # -------------------------------------------------------------
  942. # Clone
  943. elif actSel == actClone:
  944. if not self.host.clone_plugin(self.fPluginId):
  945. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  946. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  947. # -------------------------------------------------------------
  948. # Rename
  949. elif actSel == actRename:
  950. self.showRenameDialog()
  951. # -------------------------------------------------------------
  952. # Replace
  953. elif actSel == actReplace:
  954. self.showReplaceDialog()
  955. # -------------------------------------------------------------
  956. # Remove
  957. elif actSel == actRemove:
  958. if not self.host.remove_plugin(self.fPluginId):
  959. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  960. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  961. # -------------------------------------------------------------
  962. # Export LV2
  963. elif actSel == actExportLV2:
  964. filepath = QInputDialog.getItem(self, self.tr("Export LV2 Plugin"),
  965. self.tr("Select LV2 Path where plugin will be exported to:"),
  966. CARLA_DEFAULT_LV2_PATH, editable=False)
  967. if not all(filepath):
  968. return
  969. plugname = self.fPluginInfo['name']
  970. filepath = os.path.join(filepath[0], plugname.replace(" ","_"))
  971. if not filepath.endswith(".lv2"):
  972. filepath += ".lv2"
  973. if os.path.exists(filepath):
  974. if QMessageBox.question(self, self.tr("Export to LV2"),
  975. self.tr("Plugin bundle already exists, overwrite?")) == QMessageBox.Ok:
  976. return
  977. if not self.host.export_plugin_lv2(self.fPluginId, filepath):
  978. return CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  979. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  980. QMessageBox.information(self, self.tr("Plugin exported"),
  981. self.tr("Plugin exported successfully, saved in folder:\n%s" % filepath))
  982. # -------------------------------------------------------------
  983. @pyqtSlot()
  984. def slot_knobCustomMenu(self):
  985. sender = self.sender()
  986. index = sender.fIndex
  987. minimum = sender.fMinimum
  988. maximum = sender.fMaximum
  989. current = sender.fRealValue
  990. label = sender.fLabel
  991. if index in (PARAMETER_NULL, PARAMETER_CTRL_CHANNEL) or index <= PARAMETER_MAX:
  992. return
  993. elif index in (PARAMETER_DRYWET, PARAMETER_VOLUME):
  994. default = 1.0
  995. elif index == PARAMETER_BALANCE_LEFT:
  996. default = -1.0
  997. elif index == PARAMETER_BALANCE_RIGHT:
  998. default = 1.0
  999. elif index == PARAMETER_PANNING:
  1000. default = 0.0
  1001. else:
  1002. default = self.host.get_default_parameter_value(self.fPluginId, index)
  1003. if index < PARAMETER_NULL:
  1004. # show in integer percentage
  1005. textReset = self.tr("Reset (%i%%)" % round(default*100.0))
  1006. textMinim = self.tr("Set to Minimum (%i%%)" % round(minimum*100.0))
  1007. textMaxim = self.tr("Set to Maximum (%i%%)" % round(maximum*100.0))
  1008. else:
  1009. # show in full float value
  1010. textReset = self.tr("Reset (%f)" % default)
  1011. textMinim = self.tr("Set to Minimum (%f)" % minimum)
  1012. textMaxim = self.tr("Set to Maximum (%f)" % maximum)
  1013. menu = QMenu(self)
  1014. actReset = menu.addAction(textReset)
  1015. menu.addSeparator()
  1016. actMinimum = menu.addAction(textMinim)
  1017. actCenter = menu.addAction(self.tr("Set to Center"))
  1018. actMaximum = menu.addAction(textMaxim)
  1019. menu.addSeparator()
  1020. actSet = menu.addAction(self.tr("Set value..."))
  1021. if index > PARAMETER_NULL or index not in (PARAMETER_BALANCE_LEFT, PARAMETER_BALANCE_RIGHT, PARAMETER_PANNING):
  1022. menu.removeAction(actCenter)
  1023. actSelected = menu.exec_(QCursor.pos())
  1024. if actSelected == actSet:
  1025. if index < PARAMETER_NULL:
  1026. value, ok = QInputDialog.getInt(self, self.tr("Set value"), label, round(current*100), round(minimum*100), round(maximum*100), 1)
  1027. if not ok:
  1028. return
  1029. value = float(value)/100.0
  1030. else:
  1031. paramInfo = self.host.get_parameter_info(self.fPluginId, index)
  1032. paramRanges = self.host.get_parameter_ranges(self.fPluginId, index)
  1033. scalePoints = []
  1034. for i in range(paramInfo['scalePointCount']):
  1035. scalePoints.append(self.host.get_parameter_scalepoint_info(self.fPluginId, index, i))
  1036. prefix = ""
  1037. suffix = paramInfo['unit'].strip()
  1038. if suffix == "(coef)":
  1039. prefix = "* "
  1040. suffix = ""
  1041. else:
  1042. suffix = " " + suffix
  1043. dialog = CustomInputDialog(self, label, current, minimum, maximum,
  1044. paramRanges['step'], paramRanges['stepSmall'], scalePoints, prefix, suffix)
  1045. if not dialog.exec_():
  1046. return
  1047. value = dialog.returnValue()
  1048. elif actSelected == actMinimum:
  1049. value = minimum
  1050. elif actSelected == actMaximum:
  1051. value = maximum
  1052. elif actSelected == actReset:
  1053. value = default
  1054. elif actSelected == actCenter:
  1055. value = 0.0
  1056. else:
  1057. return
  1058. sender.setValue(value, True)
  1059. #------------------------------------------------------------------
  1060. @pyqtSlot(bool)
  1061. def slot_showCustomUi(self, show):
  1062. self.host.show_custom_ui(self.fPluginId, show)
  1063. @pyqtSlot(bool)
  1064. def slot_showEditDialog(self, show):
  1065. self.fEditDialog.setVisible(show)
  1066. @pyqtSlot()
  1067. def slot_removePlugin(self):
  1068. if not self.host.remove_plugin(self.fPluginId):
  1069. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1070. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1071. #------------------------------------------------------------------
  1072. @pyqtSlot(bool)
  1073. def slot_parameterDragStateChanged(self, touch):
  1074. index = self.sender().getIndex()
  1075. if index >= 0:
  1076. self.host.set_parameter_touch(self.fPluginId, index, touch)
  1077. @pyqtSlot(float)
  1078. def slot_parameterValueChanged(self, value):
  1079. index = self.sender().getIndex()
  1080. if index < 0:
  1081. self.setInternalParameter(index, value)
  1082. else:
  1083. self.host.set_parameter_value(self.fPluginId, index, value)
  1084. self.setParameterValue(index, value, False)
  1085. @pyqtSlot(int)
  1086. def slot_programChanged(self, index):
  1087. self.host.set_program(self.fPluginId, index)
  1088. self.setProgram(index, False)
  1089. @pyqtSlot(int)
  1090. def slot_midiProgramChanged(self, index):
  1091. self.host.set_midi_program(self.fPluginId, index)
  1092. self.setMidiProgram(index, False)
  1093. #------------------------------------------------------------------
  1094. def adjustViewableKnobCount(self):
  1095. if self.w_knobs_left is None or self.spacer_knobs is None:
  1096. return
  1097. curWidth = 2
  1098. maxWidth = self.w_knobs_left.width() + self.spacer_knobs.geometry().width() + 2
  1099. plen = len(self.fParameterList)
  1100. for i in range(plen):
  1101. index, widget = self.fParameterList[i]
  1102. if index < 0:
  1103. break
  1104. curWidth += widget.width() + 4
  1105. if curWidth + widget.width() * 2 + 8 < maxWidth:
  1106. #if not widget.isVisible():
  1107. widget.show()
  1108. continue
  1109. for i2 in range(i, plen):
  1110. index2, widget2 = self.fParameterList[i2]
  1111. if index2 < 0:
  1112. break
  1113. #if widget2.isVisible():
  1114. widget2.hide()
  1115. break
  1116. self.fAdjustViewableKnobCountScheduled = False
  1117. def testTimer(self):
  1118. self.fIdleTimerId = self.startTimer(25)
  1119. #------------------------------------------------------------------
  1120. def mouseDoubleClickEvent(self, event):
  1121. QFrame.mouseDoubleClickEvent(self, event)
  1122. # FIXME
  1123. gCarla.gui.compactPlugin(self.fPluginId)
  1124. def closeEvent(self, event):
  1125. if self.fIdleTimerId != 0:
  1126. self.killTimer(self.fIdleTimerId)
  1127. self.fIdleTimerId = 0
  1128. self.host.engine_close()
  1129. QFrame.closeEvent(self, event)
  1130. def resizeEvent(self, event):
  1131. if not self.fAdjustViewableKnobCountScheduled:
  1132. self.fAdjustViewableKnobCountScheduled = True
  1133. QTimer.singleShot(100, self.adjustViewableKnobCount)
  1134. QFrame.resizeEvent(self, event)
  1135. def timerEvent(self, event):
  1136. if event.timerId() == self.fIdleTimerId:
  1137. self.host.engine_idle()
  1138. self.idleFast()
  1139. self.idleSlow()
  1140. QFrame.timerEvent(self, event)
  1141. def paintEvent(self, event):
  1142. painter = QPainter(self)
  1143. # Colorization
  1144. if self.fSkinColor != (0,0,0):
  1145. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  1146. r,g,b = self.fSkinColor
  1147. painter.setBrush(QColor(r,g,b))
  1148. painter.setPen(Qt.NoPen)
  1149. painter.drawRect(QRectF(0,0,self.width(),self.height()))
  1150. painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
  1151. self.drawOutline(painter)
  1152. QFrame.paintEvent(self, event)
  1153. # ------------------------------------------------------------------------------------------------------------
  1154. class PluginSlot_Calf(AbstractPluginSlot):
  1155. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1156. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1157. self.ui = ui_carla_plugin_calf.Ui_PluginWidget()
  1158. self.ui.setupUi(self)
  1159. audioCount = self.host.get_audio_port_count_info(self.fPluginId)
  1160. midiCount = self.host.get_midi_port_count_info(self.fPluginId)
  1161. # -------------------------------------------------------------
  1162. # Internal stuff
  1163. self.fButtonFont = self.ui.b_gui.font()
  1164. self.fButtonFont.setBold(False)
  1165. self.fButtonFont.setPixelSize(10)
  1166. self.fButtonColorOn = QColor( 18, 41, 87)
  1167. self.fButtonColorOff = QColor(150, 150, 150)
  1168. # -------------------------------------------------------------
  1169. # Set-up GUI
  1170. self.ui.label_active.setFont(self.fButtonFont)
  1171. self.ui.b_remove.setPixmaps(":/bitmaps/button_calf1.png", ":/bitmaps/button_calf1_down.png", ":/bitmaps/button_calf1_hover.png")
  1172. self.ui.b_edit.setTopText(self.tr("Edit"), self.fButtonColorOn, self.fButtonFont)
  1173. self.ui.b_remove.setTopText(self.tr("Remove"), self.fButtonColorOn, self.fButtonFont)
  1174. if self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI:
  1175. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1176. else:
  1177. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1178. if audioCount['ins'] == 0:
  1179. self.ui.label_audio_in.hide()
  1180. if audioCount['outs'] == 0:
  1181. self.ui.label_audio_out.hide()
  1182. if midiCount['ins'] == 0:
  1183. self.ui.label_midi.hide()
  1184. self.ui.led_midi.hide()
  1185. if self.fIdleTimerId != 0:
  1186. self.ui.b_remove.setEnabled(False)
  1187. self.ui.b_remove.setVisible(False)
  1188. # -------------------------------------------------------------
  1189. self.b_enable = self.ui.b_enable
  1190. self.b_gui = self.ui.b_gui
  1191. self.b_edit = self.ui.b_edit
  1192. self.b_remove = self.ui.b_remove
  1193. self.label_name = self.ui.label_name
  1194. self.led_midi = self.ui.led_midi
  1195. self.peak_in = self.ui.peak_in
  1196. self.peak_out = self.ui.peak_out
  1197. self.w_knobs_left = self.ui.w_knobs
  1198. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1199. self.ready()
  1200. self.ui.led_midi.setColor(self.ui.led_midi.CALF)
  1201. #------------------------------------------------------------------
  1202. def getFixedHeight(self):
  1203. return 94 if max(self.peak_in.channelCount(), self.peak_out.channelCount()) < 2 else 106
  1204. #------------------------------------------------------------------
  1205. def editDialogPluginHintsChanged(self, pluginId, hints):
  1206. if hints & PLUGIN_HAS_CUSTOM_UI:
  1207. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1208. else:
  1209. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1210. AbstractPluginSlot.editDialogPluginHintsChanged(self, pluginId, hints)
  1211. #------------------------------------------------------------------
  1212. def paintEvent(self, event):
  1213. isBlack = bool(self.fSkinStyle == "calf_black")
  1214. painter = QPainter(self)
  1215. painter.setBrush(Qt.transparent)
  1216. painter.setPen(QPen(QColor(20, 20, 20) if isBlack else QColor(75, 86, 99), 1))
  1217. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1218. painter.setPen(QPen(QColor(45, 45, 45) if isBlack else QColor(86, 99, 114), 1))
  1219. painter.drawLine(0, 0, self.width(), 0)
  1220. AbstractPluginSlot.paintEvent(self, event)
  1221. # ------------------------------------------------------------------------------------------------------------
  1222. class PluginSlot_Classic(AbstractPluginSlot):
  1223. def __init__(self, parent, host, pluginId):
  1224. AbstractPluginSlot.__init__(self, parent, host, pluginId, (0,0,0), "classic")
  1225. self.ui = ui_carla_plugin_classic.Ui_PluginWidget()
  1226. self.ui.setupUi(self)
  1227. # -------------------------------------------------------------
  1228. # Internal stuff
  1229. self.fColorTop = QColor(60, 60, 60)
  1230. self.fColorBottom = QColor(47, 47, 47)
  1231. self.fColorSeprtr = QColor(70, 70, 70)
  1232. # -------------------------------------------------------------
  1233. self.b_enable = self.ui.b_enable
  1234. self.b_gui = self.ui.b_gui
  1235. self.b_edit = self.ui.b_edit
  1236. self.label_name = self.ui.label_name
  1237. self.led_control = self.ui.led_control
  1238. self.led_midi = self.ui.led_midi
  1239. self.led_audio_in = self.ui.led_audio_in
  1240. self.led_audio_out = self.ui.led_audio_out
  1241. self.peak_in = self.ui.peak_in
  1242. self.peak_out = self.ui.peak_out
  1243. self.ready()
  1244. #------------------------------------------------------------------
  1245. def getFixedHeight(self):
  1246. return 36
  1247. #------------------------------------------------------------------
  1248. def paintEvent(self, event):
  1249. painter = QPainter(self)
  1250. painter.save()
  1251. areaX = self.ui.area_right.x()+7
  1252. width = self.width()
  1253. height = self.height()
  1254. painter.setPen(QPen(QColor(17, 17, 17), 1))
  1255. painter.setBrush(QColor(17, 17, 17))
  1256. painter.drawRect(0, 0, width, height)
  1257. painter.setPen(self.fColorSeprtr.lighter(110))
  1258. painter.setBrush(self.fColorBottom)
  1259. painter.setRenderHint(QPainter.Antialiasing, True)
  1260. # name -> leds arc
  1261. path = QPainterPath()
  1262. path.moveTo(areaX-20, height-4)
  1263. path.cubicTo(areaX, height-5, areaX-20, 4.75, areaX, 4.75)
  1264. path.lineTo(areaX, height-5)
  1265. painter.drawPath(path)
  1266. painter.setPen(self.fColorSeprtr)
  1267. painter.setRenderHint(QPainter.Antialiasing, False)
  1268. # separator lines
  1269. painter.drawLine(0, height-5, areaX-20, height-5)
  1270. painter.drawLine(areaX, 4, width, 4)
  1271. painter.setPen(self.fColorBottom)
  1272. painter.setBrush(self.fColorBottom)
  1273. # top, bottom and left lines
  1274. painter.drawLine(0, 0, width, 0)
  1275. painter.drawRect(0, height-4, areaX, 4)
  1276. painter.drawRoundedRect(areaX-20, height-5, areaX, 5, 22, 22)
  1277. painter.drawLine(0, 0, 0, height)
  1278. # fill the rest
  1279. painter.drawRect(areaX-1, 5, width, height)
  1280. # bottom 1px line
  1281. painter.setPen(self.fColorSeprtr)
  1282. painter.drawLine(0, height-1, width, height-1)
  1283. painter.restore()
  1284. AbstractPluginSlot.paintEvent(self, event)
  1285. # ------------------------------------------------------------------------------------------------------------
  1286. class PluginSlot_Compact(AbstractPluginSlot):
  1287. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1288. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1289. self.ui = ui_carla_plugin_compact.Ui_PluginWidget()
  1290. self.ui.setupUi(self)
  1291. self.b_enable = self.ui.b_enable
  1292. self.b_gui = self.ui.b_gui
  1293. self.b_edit = self.ui.b_edit
  1294. self.label_name = self.ui.label_name
  1295. self.led_control = self.ui.led_control
  1296. self.led_midi = self.ui.led_midi
  1297. self.led_audio_in = self.ui.led_audio_in
  1298. self.led_audio_out = self.ui.led_audio_out
  1299. self.peak_in = self.ui.peak_in
  1300. self.peak_out = self.ui.peak_out
  1301. self.ready()
  1302. #------------------------------------------------------------------
  1303. def getFixedHeight(self):
  1304. if self.fSkinStyle == "calf_blue":
  1305. return 36
  1306. return 30
  1307. # ------------------------------------------------------------------------------------------------------------
  1308. class PluginSlot_Default(AbstractPluginSlot):
  1309. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1310. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1311. self.ui = ui_carla_plugin_default.Ui_PluginWidget()
  1312. self.ui.setupUi(self)
  1313. # -------------------------------------------------------------
  1314. self.b_enable = self.ui.b_enable
  1315. self.b_gui = self.ui.b_gui
  1316. self.b_edit = self.ui.b_edit
  1317. self.label_name = self.ui.label_name
  1318. self.led_control = self.ui.led_control
  1319. self.led_midi = self.ui.led_midi
  1320. self.led_audio_in = self.ui.led_audio_in
  1321. self.led_audio_out = self.ui.led_audio_out
  1322. self.peak_in = self.ui.peak_in
  1323. self.peak_out = self.ui.peak_out
  1324. self.w_knobs_left = self.ui.w_knobs_left
  1325. self.w_knobs_right = self.ui.w_knobs_right
  1326. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1327. self.ready()
  1328. #------------------------------------------------------------------
  1329. def getFixedHeight(self):
  1330. return 80
  1331. #------------------------------------------------------------------
  1332. def paintEvent(self, event):
  1333. painter = QPainter(self)
  1334. painter.setBrush(Qt.transparent)
  1335. painter.setPen(QPen(QColor(42, 42, 42), 1))
  1336. painter.drawRect(0, 1, self.width()-1, self.getFixedHeight()-3)
  1337. painter.setPen(QPen(QColor(60, 60, 60), 1))
  1338. painter.drawLine(0, 0, self.width(), 0)
  1339. AbstractPluginSlot.paintEvent(self, event)
  1340. # ------------------------------------------------------------------------------------------------------------
  1341. class PluginSlot_Presets(AbstractPluginSlot):
  1342. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1343. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1344. self.ui = ui_carla_plugin_presets.Ui_PluginWidget()
  1345. self.ui.setupUi(self)
  1346. usingMidiPrograms = bool(skinStyle != "presets")
  1347. # -------------------------------------------------------------
  1348. # Set-up programs
  1349. if usingMidiPrograms:
  1350. programCount = self.host.get_midi_program_count(self.fPluginId)
  1351. else:
  1352. programCount = self.host.get_program_count(self.fPluginId)
  1353. if programCount > 0:
  1354. self.ui.cb_presets.setEnabled(True)
  1355. self.ui.label_presets.setEnabled(True)
  1356. for i in range(programCount):
  1357. if usingMidiPrograms:
  1358. progName = self.host.get_midi_program_data(self.fPluginId, i)['name']
  1359. else:
  1360. progName = self.host.get_program_name(self.fPluginId, i)
  1361. self.ui.cb_presets.addItem(progName)
  1362. if usingMidiPrograms:
  1363. curProg = self.host.get_current_midi_program_index(self.fPluginId)
  1364. else:
  1365. curProg = self.host.get_current_program_index(self.fPluginId)
  1366. self.ui.cb_presets.setCurrentIndex(curProg)
  1367. else:
  1368. self.ui.cb_presets.setEnabled(False)
  1369. self.ui.cb_presets.setVisible(False)
  1370. self.ui.label_presets.setEnabled(False)
  1371. self.ui.label_presets.setVisible(False)
  1372. # -------------------------------------------------------------
  1373. self.b_enable = self.ui.b_enable
  1374. self.b_gui = self.ui.b_gui
  1375. self.b_edit = self.ui.b_edit
  1376. self.cb_presets = self.ui.cb_presets
  1377. self.label_name = self.ui.label_name
  1378. self.label_presets = self.ui.label_presets
  1379. self.led_control = self.ui.led_control
  1380. self.led_midi = self.ui.led_midi
  1381. self.led_audio_in = self.ui.led_audio_in
  1382. self.led_audio_out = self.ui.led_audio_out
  1383. self.peak_in = self.ui.peak_in
  1384. self.peak_out = self.ui.peak_out
  1385. if skinStyle == "zynfx":
  1386. self.setupZynFxParams()
  1387. else:
  1388. self.w_knobs_left = self.ui.w_knobs_left
  1389. self.w_knobs_right = self.ui.w_knobs_right
  1390. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1391. self.ready()
  1392. if usingMidiPrograms:
  1393. self.ui.cb_presets.currentIndexChanged.connect(self.slot_midiProgramChanged)
  1394. else:
  1395. self.ui.cb_presets.currentIndexChanged.connect(self.slot_programChanged)
  1396. # -------------------------------------------------------------
  1397. def setupZynFxParams(self):
  1398. parameterCount = min(self.host.get_parameter_count(self.fPluginId), 8)
  1399. for i in range(parameterCount):
  1400. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  1401. paramData = self.host.get_parameter_data(self.fPluginId, i)
  1402. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  1403. if paramData['type'] != PARAMETER_INPUT:
  1404. continue
  1405. if paramData['hints'] & PARAMETER_IS_BOOLEAN:
  1406. continue
  1407. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1408. continue
  1409. paramName = paramInfo['name']
  1410. if paramName.startswith("unused"):
  1411. continue
  1412. # real zyn fx plugins
  1413. if self.fPluginInfo['label'] == "zynalienwah":
  1414. if i == 0: paramName = "Freq"
  1415. elif i == 1: paramName = "Rnd"
  1416. elif i == 2: paramName = "L type" # combobox
  1417. elif i == 3: paramName = "St.df"
  1418. elif i == 5: paramName = "Fb"
  1419. elif i == 7: paramName = "L/R"
  1420. elif self.fPluginInfo['label'] == "zynchorus":
  1421. if i == 0: paramName = "Freq"
  1422. elif i == 1: paramName = "Rnd"
  1423. elif i == 2: paramName = "L type" # combobox
  1424. elif i == 3: paramName = "St.df"
  1425. elif i == 6: paramName = "Fb"
  1426. elif i == 7: paramName = "L/R"
  1427. elif i == 8: paramName = "Flngr" # button
  1428. elif i == 9: paramName = "Subst" # button
  1429. elif self.fPluginInfo['label'] == "zyndistortion":
  1430. if i == 0: paramName = "LRc."
  1431. elif i == 4: paramName = "Neg." # button
  1432. elif i == 5: paramName = "LPF"
  1433. elif i == 6: paramName = "HPF"
  1434. elif i == 7: paramName = "St." # button
  1435. elif i == 8: paramName = "PF" # button
  1436. elif self.fPluginInfo['label'] == "zyndynamicfilter":
  1437. if i == 0: paramName = "Freq"
  1438. elif i == 1: paramName = "Rnd"
  1439. elif i == 2: paramName = "L type" # combobox
  1440. elif i == 3: paramName = "St.df"
  1441. elif i == 4: paramName = "LfoD"
  1442. elif i == 5: paramName = "A.S."
  1443. elif i == 6: paramName = "A.Inv." # button
  1444. elif i == 7: paramName = "A.M."
  1445. elif self.fPluginInfo['label'] == "zynecho":
  1446. if i == 1: paramName = "LRdl."
  1447. elif i == 2: paramName = "LRc."
  1448. elif i == 3: paramName = "Fb."
  1449. elif i == 4: paramName = "Damp"
  1450. elif self.fPluginInfo['label'] == "zynphaser":
  1451. if i == 0: paramName = "Freq"
  1452. elif i == 1: paramName = "Rnd"
  1453. elif i == 2: paramName = "L type" # combobox
  1454. elif i == 3: paramName = "St.df"
  1455. elif i == 5: paramName = "Fb"
  1456. elif i == 7: paramName = "L/R"
  1457. elif i == 8: paramName = "Subst" # button
  1458. elif i == 9: paramName = "Phase"
  1459. elif i == 11: paramName = "Dist"
  1460. elif self.fPluginInfo['label'] == "zynreverb":
  1461. if i == 2: paramName = "I.delfb"
  1462. elif i == 5: paramName = "LPF"
  1463. elif i == 6: paramName = "HPF"
  1464. elif i == 9: paramName = "R.S."
  1465. elif i == 10: paramName = "I.del"
  1466. else:
  1467. paramName = getParameterShortName(paramName)
  1468. widget = PixmapDial(self, i)
  1469. widget.setLabel(paramName)
  1470. widget.setMinimum(paramRanges['min'])
  1471. widget.setMaximum(paramRanges['max'])
  1472. widget.setPixmap(3)
  1473. widget.setCustomPaintColor(QColor(83, 173, 10))
  1474. widget.setCustomPaintMode(PixmapDial.CUSTOM_PAINT_MODE_COLOR)
  1475. widget.forceWhiteLabelGradientText()
  1476. widget.hide()
  1477. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1478. widget.setEnabled(False)
  1479. self.fParameterList.append([i, widget])
  1480. self.ui.w_knobs_left.layout().addWidget(widget)
  1481. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  1482. widget = PixmapDial(self, PARAMETER_DRYWET)
  1483. widget.setLabel("Wet")
  1484. widget.setMinimum(0.0)
  1485. widget.setMaximum(1.0)
  1486. widget.setPixmap(3)
  1487. widget.setCustomPaintMode(PixmapDial.CUSTOM_PAINT_MODE_CARLA_WET)
  1488. widget.forceWhiteLabelGradientText()
  1489. self.fParameterList.append([PARAMETER_DRYWET, widget])
  1490. self.ui.w_knobs_right.layout().addWidget(widget)
  1491. if self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  1492. widget = PixmapDial(self, PARAMETER_VOLUME)
  1493. widget.setLabel("Volume")
  1494. widget.setMinimum(0.0)
  1495. widget.setMaximum(1.27)
  1496. widget.setPixmap(3)
  1497. widget.setCustomPaintMode(PixmapDial.CUSTOM_PAINT_MODE_CARLA_VOL)
  1498. widget.forceWhiteLabelGradientText()
  1499. self.fParameterList.append([PARAMETER_VOLUME, widget])
  1500. self.ui.w_knobs_right.layout().addWidget(widget)
  1501. #------------------------------------------------------------------
  1502. def getFixedHeight(self):
  1503. return 80
  1504. #------------------------------------------------------------------
  1505. def paintEvent(self, event):
  1506. painter = QPainter(self)
  1507. painter.setBrush(Qt.transparent)
  1508. painter.setPen(QPen(QColor(50, 50, 50), 1))
  1509. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1510. painter.setPen(QPen(QColor(64, 64, 64), 1))
  1511. painter.drawLine(0, 0, self.width(), 0)
  1512. AbstractPluginSlot.paintEvent(self, event)
  1513. # ------------------------------------------------------------------------------------------------------------
  1514. def getColorAndSkinStyle(host, pluginId):
  1515. if False:
  1516. # kdevelop likes this :)
  1517. host = CarlaHostNull()
  1518. progCount = 0
  1519. pluginInfo = PyCarlaPluginInfo
  1520. pluginName = ""
  1521. pluginInfo = host.get_plugin_info(pluginId)
  1522. pluginName = host.get_real_plugin_name(pluginId)
  1523. pluginLabel = pluginInfo['label'].lower()
  1524. pluginMaker = pluginInfo['maker']
  1525. uniqueId = pluginInfo['uniqueId']
  1526. if pluginInfo['type'] in (PLUGIN_VST2, PLUGIN_VST3, PLUGIN_AU):
  1527. progCount = host.get_program_count(pluginId)
  1528. else:
  1529. progCount = host.get_midi_program_count(pluginId)
  1530. colorCategory = getColorFromCategory(pluginInfo['category'])
  1531. colorNone = (0,0,0)
  1532. # Samplers
  1533. if pluginInfo['type'] == PLUGIN_SF2:
  1534. return (colorCategory, "sf2")
  1535. if pluginInfo['type'] == PLUGIN_SFZ:
  1536. return (colorCategory, "sfz")
  1537. # Calf
  1538. if pluginName.split(" ", 1)[0].lower() == "calf":
  1539. return (colorNone, "calf_black" if "mono" in pluginLabel else "calf_blue")
  1540. # OpenAV
  1541. if pluginMaker == "OpenAV Productions":
  1542. return (colorNone, "openav-old")
  1543. if pluginMaker == "OpenAV":
  1544. return (colorNone, "openav")
  1545. # ZynFX
  1546. if pluginInfo['type'] == PLUGIN_INTERNAL:
  1547. if pluginLabel.startswith("zyn") and pluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1548. return (colorNone, "zynfx")
  1549. if pluginInfo['type'] == PLUGIN_LADSPA:
  1550. if pluginLabel.startswith("zyn") and pluginMaker.startswith("Josep Andreu"):
  1551. return (colorNone, "zynfx")
  1552. if pluginInfo['type'] == PLUGIN_LV2:
  1553. if pluginLabel.startswith("http://kxstudio.sf.net/carla/plugins/zyn") and pluginName != "ZynAddSubFX":
  1554. return (colorNone, "zynfx")
  1555. # Presets
  1556. if progCount > 1 and (pluginInfo['hints'] & PLUGIN_USES_MULTI_PROGS) == 0:
  1557. if pluginInfo['type'] in (PLUGIN_VST2, PLUGIN_VST3, PLUGIN_AU):
  1558. return (colorCategory, "presets")
  1559. return (colorCategory, "mpresets")
  1560. # DISTRHO Plugins (needs to be last)
  1561. if pluginMaker.startswith("falkTX, ") or pluginMaker == "DISTRHO" or pluginLabel.startswith("http://distrho.sf.net/plugins/"):
  1562. return (colorNone, pluginLabel.replace("http://distrho.sf.net/plugins/",""))
  1563. return (colorCategory, "default")
  1564. def createPluginSlot(parent, host, pluginId, options):
  1565. skinColor, skinStyle = getColorAndSkinStyle(host, pluginId)
  1566. if options['color'] is not None:
  1567. skinColor = options['color']
  1568. if options['skin']:
  1569. skinStyle = options['skin']
  1570. if skinStyle == "classic":
  1571. return PluginSlot_Classic(parent, host, pluginId)
  1572. if "compact" in skinStyle or options['compact']:
  1573. return PluginSlot_Compact(parent, host, pluginId, skinColor, skinStyle)
  1574. if skinStyle.startswith("calf"):
  1575. return PluginSlot_Calf(parent, host, pluginId, skinColor, skinStyle)
  1576. if skinStyle in ("mpresets", "presets", "zynfx"):
  1577. return PluginSlot_Presets(parent, host, pluginId, skinColor, skinStyle)
  1578. return PluginSlot_Default(parent, host, pluginId, skinColor, skinStyle)
  1579. # ------------------------------------------------------------------------------------------------------------
  1580. # Main Testing
  1581. if __name__ == '__main__':
  1582. from carla_app import CarlaApplication
  1583. from carla_host import initHost, loadHostSettings
  1584. import resources_rc
  1585. app = CarlaApplication("Carla-Skins")
  1586. host = initHost("Skins", None, False, False, False)
  1587. loadHostSettings(host)
  1588. host.engine_init("JACK", "Carla-Widgets")
  1589. host.add_plugin(BINARY_NATIVE, PLUGIN_INTERNAL, "", "", "zynreverb", 0, None, PLUGIN_OPTIONS_NULL)
  1590. #host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, PLUGIN_OPTIONS_NULL)
  1591. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://www.openavproductions.com/sorcer", 0, None, PLUGIN_OPTIONS_NULL)
  1592. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://calf.sourceforge.net/plugins/Compressor", 0, None, PLUGIN_OPTIONS_NULL)
  1593. host.set_active(0, True)
  1594. #gui = createPluginSlot(None, host, 0, True)
  1595. gui = PluginSlot_Compact(None, host, 0, (0, 0, 0), "default")
  1596. gui.testTimer()
  1597. gui.show()
  1598. app.exec_()