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.

1976 lines
72KB

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