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.

2301 lines
88KB

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