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.

2011 lines
74KB

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