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.

2032 lines
75KB

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