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.

2313 lines
89KB

  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. if (self.fPluginInfo['hints'] & PLUGIN_CAN_FORTH) != 0:
  651. if widget.getTweak('ShowForth', 0):
  652. widget = ScalableDial(self, PARAMETER_FORTH, 100, 0.0, -1.0, 1.0, "Forth", skinNum * 16 + ScalableDial.CUSTOM_PAINT_MODE_CARLA_FORTH, -1, "%", self.fSkinStyle, whiteLabels, self.fTweaks)
  653. self.fParameterList.append([PARAMETER_FORTH, widget])
  654. self.w_knobs_right.layout().addWidget(widget)
  655. for paramIndex, paramWidget in self.fParameterList:
  656. if not paramWidget.fIsOutput:
  657. paramWidget.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  658. paramWidget.dragStateChanged.connect(self.slot_parameterDragStateChanged)
  659. paramWidget.realValueChanged.connect(self.slot_parameterValueChanged)
  660. paramWidget.blockSignals(True)
  661. paramWidget.setValue(self.host.get_internal_parameter_value(self.fPluginId, paramIndex))
  662. paramWidget.blockSignals(False)
  663. # -------------------------------------------------------------
  664. self.setWindowTitle(self.fPluginInfo['name'])
  665. if not self.fAdjustViewableKnobCountScheduled:
  666. self.fAdjustViewableKnobCountScheduled = True
  667. QTimer.singleShot(5, self.adjustViewableKnobCount)
  668. # -----------------------------------------------------------------
  669. def getFixedHeight(self):
  670. return 32
  671. def getHints(self):
  672. return self.fPluginInfo['hints']
  673. def getPluginId(self):
  674. return self.fPluginId
  675. # -----------------------------------------------------------------
  676. def setPluginId(self, idx):
  677. self.fPluginId = idx
  678. self.fEditDialog.setPluginId(idx)
  679. def setName(self, name):
  680. self.fPluginInfo['name'] = name
  681. self.fEditDialog.setName(name)
  682. if self.label_name is not None:
  683. self.label_name.setText(name)
  684. def setSelected(self, yesNo):
  685. if self.fIsSelected == yesNo:
  686. return
  687. self.fIsSelected = yesNo
  688. self.update()
  689. # -----------------------------------------------------------------
  690. def setActive(self, active, sendCallback=False, sendHost=True):
  691. self.fIsActive = active
  692. if sendCallback:
  693. self.fParameterIconTimer = ICON_STATE_ON
  694. self.activeChanged(active)
  695. if sendHost:
  696. self.host.set_active(self.fPluginId, active)
  697. if active:
  698. self.fEditDialog.clearNotes()
  699. self.midiActivityChanged(False)
  700. if self.label_name is not None:
  701. self.label_name.setEnabled(self.fIsActive)
  702. # called from rack, checks if param is possible first
  703. def setInternalParameter(self, parameterId, value):
  704. if parameterId <= PARAMETER_MAX or parameterId >= PARAMETER_NULL:
  705. return
  706. elif parameterId == PARAMETER_ACTIVE:
  707. return self.setActive(bool(value), True, True)
  708. elif parameterId == PARAMETER_DRYWET:
  709. if (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) == 0: return
  710. self.host.set_drywet(self.fPluginId, value)
  711. elif parameterId == PARAMETER_VOLUME:
  712. if (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) == 0: return
  713. self.host.set_volume(self.fPluginId, value)
  714. elif parameterId == PARAMETER_BALANCE_LEFT:
  715. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  716. self.host.set_balance_left(self.fPluginId, value)
  717. elif parameterId == PARAMETER_BALANCE_RIGHT:
  718. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  719. self.host.set_balance_right(self.fPluginId, value)
  720. elif parameterId == PARAMETER_PANNING:
  721. if (self.fPluginInfo['hints'] & PLUGIN_CAN_PANNING) == 0: return
  722. self.host.set_panning(self.fPluginId, value)
  723. elif parameterId == PARAMETER_FORTH:
  724. if (self.fPluginInfo['hints'] & PLUGIN_CAN_FORTH) == 0: return
  725. self.host.set_forth(self.fPluginId, value)
  726. elif parameterId == PARAMETER_CTRL_CHANNEL:
  727. self.host.set_ctrl_channel(self.fPluginId, value)
  728. self.setParameterValue(parameterId, value, True)
  729. self.fEditDialog.setParameterValue(parameterId, value)
  730. # -----------------------------------------------------------------
  731. def setParameterValue(self, parameterId, value, sendCallback):
  732. if parameterId == PARAMETER_ACTIVE:
  733. return self.setActive(bool(value), True, False)
  734. self.fEditDialog.setParameterValue(parameterId, value)
  735. if sendCallback:
  736. self.fParameterIconTimer = ICON_STATE_ON
  737. self.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  738. def setParameterDefault(self, parameterId, value):
  739. self.fEditDialog.setParameterDefault(parameterId, value)
  740. def setParameterMappedControlIndex(self, parameterId, control):
  741. self.fEditDialog.setParameterMappedControlIndex(parameterId, control)
  742. def setParameterMappedRange(self, parameterId, minimum, maximum):
  743. self.fEditDialog.setParameterMappedRange(parameterId, minimum, maximum)
  744. def setParameterMidiChannel(self, parameterId, channel):
  745. self.fEditDialog.setParameterMidiChannel(parameterId, channel)
  746. # -----------------------------------------------------------------
  747. def setProgram(self, index, sendCallback):
  748. self.fEditDialog.setProgram(index)
  749. if sendCallback:
  750. self.fParameterIconTimer = ICON_STATE_ON
  751. self.editDialogProgramChanged(self.fPluginId, index)
  752. self.updateParameterValues()
  753. def setMidiProgram(self, index, sendCallback):
  754. self.fEditDialog.setMidiProgram(index)
  755. if sendCallback:
  756. self.fParameterIconTimer = ICON_STATE_ON
  757. self.editDialogMidiProgramChanged(self.fPluginId, index)
  758. self.updateParameterValues()
  759. # -----------------------------------------------------------------
  760. def setOption(self, option, yesNo):
  761. self.fEditDialog.setOption(option, yesNo)
  762. # -----------------------------------------------------------------
  763. def showCustomUI(self):
  764. self.host.show_custom_ui(self.fPluginId, True)
  765. if self.b_gui is not None:
  766. self.b_gui.setChecked(True)
  767. def hideCustomUI(self):
  768. self.host.show_custom_ui(self.fPluginId, False)
  769. if self.b_gui is not None:
  770. self.b_gui.setChecked(False)
  771. def showEditDialog(self):
  772. self.fEditDialog.show()
  773. self.fEditDialog.activateWindow()
  774. if self.b_edit is not None:
  775. self.b_edit.setChecked(True)
  776. def showRenameDialog(self):
  777. oldName = self.fPluginInfo['name']
  778. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  779. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  780. return
  781. newName = newNameTry[0]
  782. if not self.host.rename_plugin(self.fPluginId, newName):
  783. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  784. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  785. return
  786. def showReplaceDialog(self):
  787. data = gCarla.gui.showAddPluginDialog()
  788. if data is None:
  789. return
  790. btype, ptype, filename, label, uniqueId, extraPtr = data
  791. if not self.host.replace_plugin(self.fPluginId):
  792. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  793. return
  794. ok = self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, PLUGIN_OPTIONS_NULL)
  795. self.host.replace_plugin(self.host.get_max_plugin_number())
  796. if not ok:
  797. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  798. # -----------------------------------------------------------------
  799. def activeChanged(self, onOff):
  800. self.fIsActive = onOff
  801. if self.b_enable is None:
  802. return
  803. self.b_enable.blockSignals(True)
  804. self.b_enable.setChecked(onOff)
  805. self.b_enable.blockSignals(False)
  806. def customUiStateChanged(self, state):
  807. if self.b_gui is None:
  808. return
  809. self.b_gui.blockSignals(True)
  810. if state == 0:
  811. self.b_gui.setChecked(False)
  812. self.b_gui.setEnabled(True)
  813. elif state == 1:
  814. self.b_gui.setChecked(True)
  815. self.b_gui.setEnabled(True)
  816. elif state == -1:
  817. self.b_gui.setChecked(False)
  818. self.b_gui.setEnabled(False)
  819. self.b_gui.blockSignals(False)
  820. def parameterActivityChanged(self, onOff):
  821. if self.led_control is None:
  822. return
  823. self.led_control.setChecked(onOff)
  824. def midiActivityChanged(self, onOff):
  825. if self.led_midi is None:
  826. return
  827. self.led_midi.setChecked(onOff)
  828. def optionChanged(self, option, yesNo):
  829. pass
  830. # -----------------------------------------------------------------
  831. # PluginEdit callbacks
  832. def editDialogVisibilityChanged(self, pluginId, visible):
  833. if self.b_edit is None:
  834. return
  835. self.b_edit.blockSignals(True)
  836. self.b_edit.setChecked(visible)
  837. self.b_edit.blockSignals(False)
  838. def editDialogPluginHintsChanged(self, pluginId, hints):
  839. self.fPluginInfo['hints'] = hints
  840. for paramIndex, paramWidget in self.fParameterList:
  841. if paramIndex == PARAMETER_DRYWET:
  842. paramWidget.setVisible(hints & PLUGIN_CAN_DRYWET)
  843. elif paramIndex == PARAMETER_VOLUME:
  844. paramWidget.setVisible(hints & PLUGIN_CAN_VOLUME)
  845. # jpka: FIXME i add it, but can't trigger it for test, so disable to prevent possible crashes. Maybe it don't needed.
  846. # self.dial0.setVisible(hints & PLUGIN_CAN_DRYWET)
  847. # self.dial1.setVisible(hints & PLUGIN_CAN_VOLUME)
  848. # print("self.dial0.setVisible(hints & PLUGIN_CAN_DRYWET)")
  849. if self.b_gui is not None:
  850. self.b_gui.setEnabled(bool(hints & PLUGIN_HAS_CUSTOM_UI))
  851. # NOTE: self.fParameterList is empty when compacted.
  852. def editDialogParameterValueChanged(self, pluginId, parameterId, value):
  853. for paramIndex, paramWidget in self.fParameterList:
  854. if (paramIndex != parameterId) or paramWidget.fIsOutput:
  855. continue
  856. paramWidget.blockSignals(True)
  857. paramWidget.setValue(value)
  858. paramWidget.blockSignals(False)
  859. break
  860. if isinstance(self, PluginSlot_Compact):
  861. if (parameterId == PARAMETER_DRYWET) and (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET):
  862. self.dial0.blockSignals(True)
  863. self.dial0.setValue(value)
  864. self.dial0.blockSignals(False)
  865. if (parameterId == PARAMETER_VOLUME) and (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME):
  866. self.dial1.blockSignals(True)
  867. self.dial1.setValue(value)
  868. self.dial1.blockSignals(False)
  869. def editDialogProgramChanged(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 editDialogMidiProgramChanged(self, pluginId, index):
  878. if self.cb_presets is None:
  879. return
  880. self.cb_presets.blockSignals(True)
  881. self.cb_presets.setCurrentIndex(index)
  882. self.cb_presets.blockSignals(False)
  883. # FIXME
  884. self.updateParameterValues()
  885. def editDialogNotePressed(self, pluginId, note):
  886. pass
  887. def editDialogNoteReleased(self, pluginId, note):
  888. pass
  889. def editDialogMidiActivityChanged(self, pluginId, onOff):
  890. self.midiActivityChanged(onOff)
  891. # -----------------------------------------------------------------
  892. def idleFast(self):
  893. # Input peaks
  894. if self.fPeaksInputCount > 0:
  895. if self.fPeaksInputCount > 1:
  896. peak1 = self.host.get_input_peak_value(self.fPluginId, True)
  897. peak2 = self.host.get_input_peak_value(self.fPluginId, False)
  898. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  899. if self.peak_in is not None:
  900. self.peak_in.displayMeter(1, peak1)
  901. self.peak_in.displayMeter(2, peak2)
  902. else:
  903. peak = self.host.get_input_peak_value(self.fPluginId, True)
  904. ledState = bool(peak != 0.0)
  905. if self.peak_in is not None:
  906. self.peak_in.displayMeter(1, peak)
  907. if self.fLastGreenLedState != ledState and self.led_audio_in is not None:
  908. self.fLastGreenLedState = ledState
  909. self.led_audio_in.setChecked(ledState)
  910. # Output peaks
  911. if self.fPeaksOutputCount > 0:
  912. if self.fPeaksOutputCount > 1:
  913. peak1 = self.host.get_output_peak_value(self.fPluginId, True)
  914. peak2 = self.host.get_output_peak_value(self.fPluginId, False)
  915. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  916. if self.peak_out is not None:
  917. self.peak_out.displayMeter(1, peak1)
  918. self.peak_out.displayMeter(2, peak2)
  919. else:
  920. peak = self.host.get_output_peak_value(self.fPluginId, True)
  921. ledState = bool(peak != 0.0)
  922. if self.peak_out is not None:
  923. self.peak_out.displayMeter(1, peak)
  924. if self.fLastBlueLedState != ledState and self.led_audio_out is not None:
  925. self.fLastBlueLedState = ledState
  926. self.led_audio_out.setChecked(ledState)
  927. def idleSlow(self):
  928. if self.fParameterIconTimer == ICON_STATE_ON:
  929. self.parameterActivityChanged(True)
  930. self.fParameterIconTimer = ICON_STATE_WAIT
  931. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  932. self.fParameterIconTimer = ICON_STATE_OFF
  933. elif self.fParameterIconTimer == ICON_STATE_OFF:
  934. self.parameterActivityChanged(False)
  935. self.fParameterIconTimer = ICON_STATE_NULL
  936. self.fEditDialog.idleSlow()
  937. # 7-seg displays are pretty effective, but added frame skip will make it even better.
  938. self.slowTimer = (self.slowTimer + 1) % 2 # Half the FPS, win some CPU.
  939. # NOTE: self.fParameterList is empty when compacted.
  940. for paramIndex, paramWidget in self.fParameterList:
  941. if not paramWidget.fIsOutput:
  942. continue
  943. # VU displays are CPU effective, make it run faster than 7-seg displays.
  944. # if (self.slowTimer > 0) and (not paramWidget.fIsVuOutput):
  945. if (self.slowTimer > 0):
  946. continue
  947. paramWidget.blockSignals(True) # TODO Is it required for output?
  948. value = self.host.get_current_parameter_value(self.fPluginId, paramIndex)
  949. paramWidget.setValue(value, False)
  950. paramWidget.blockSignals(False)
  951. # -----------------------------------------------------------------
  952. def drawOutline(self, painter):
  953. painter.save()
  954. painter.setBrush(Qt.transparent)
  955. w = float(self.width())
  956. h = float(self.height())
  957. painter.setPen(self.shadow_pen)
  958. painter.drawLine(QLineF(0.5, h-1, w-1, h-1))
  959. if self.fIsSelected:
  960. painter.setCompositionMode(QPainter.CompositionMode_Plus)
  961. painter.setPen(self.sel_pen)
  962. painter.drawRect(QRectF(0.5, 0.5, w-1, h-1))
  963. sidelines = [QLineF(1, 1, 1, h-1), QLineF(w-1, 1, w-1, h-1)]
  964. painter.setPen(self.sel_side_pen)
  965. painter.drawLines(sidelines)
  966. painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
  967. painter.restore()
  968. def updateParameterValues(self):
  969. for paramIndex, paramWidget in self.fParameterList:
  970. if paramIndex < 0: # DryWet and Volume
  971. continue
  972. if paramWidget.fIsOutput:
  973. continue
  974. paramWidget.blockSignals(True)
  975. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramIndex))
  976. paramWidget.blockSignals(False)
  977. # -----------------------------------------------------------------
  978. @pyqtSlot(bool)
  979. def slot_enableClicked(self, yesNo):
  980. self.setActive(yesNo, False, True)
  981. @pyqtSlot()
  982. def slot_showCustomMenu(self):
  983. menu = QMenu(self)
  984. # -------------------------------------------------------------
  985. # Expand/Minimize and Tweaks
  986. actCompact = menu.addAction(self.tr("Expand") if isinstance(self, PluginSlot_Compact) else self.tr("Minimize"))
  987. actColor = menu.addAction(self.tr("Change Color..."))
  988. actColorRandom = menu.addAction(self.tr("Random Color"))
  989. actSkin = menu.addAction(self.tr("Change Skin..."))
  990. menu.addSeparator()
  991. # -------------------------------------------------------------
  992. # Find in patchbay, if possible
  993. if self.host.processMode in (ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,
  994. ENGINE_PROCESS_MODE_PATCHBAY):
  995. actFindInPatchbay = menu.addAction(self.tr("Find plugin in patchbay"))
  996. menu.addSeparator()
  997. else:
  998. actFindInPatchbay = None
  999. # -------------------------------------------------------------
  1000. # Move up and down
  1001. actMoveUp = menu.addAction(self.tr("Move Up"))
  1002. actMoveDown = menu.addAction(self.tr("Move Down"))
  1003. if self.fPluginId == 0:
  1004. actMoveUp.setEnabled(False)
  1005. if self.fPluginId >= self.fParent.getPluginCount():
  1006. actMoveDown.setEnabled(False)
  1007. # -------------------------------------------------------------
  1008. # Bypass and Enable/Disable
  1009. actBypass = menu.addAction(self.tr("Bypass"))
  1010. actEnable = menu.addAction(self.tr("Disable") if self.fIsActive else self.tr("Enable"))
  1011. menu.addSeparator()
  1012. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  1013. actBypass.setCheckable(True)
  1014. actBypass.setChecked(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_DRYWET) == 0.0)
  1015. else:
  1016. actBypass.setVisible(False)
  1017. # -------------------------------------------------------------
  1018. # Reset and Randomize parameters
  1019. actReset = menu.addAction(self.tr("Reset parameters"))
  1020. actRandom = menu.addAction(self.tr("Randomize parameters"))
  1021. menu.addSeparator()
  1022. # -------------------------------------------------------------
  1023. # Edit and Show Custom UI
  1024. actEdit = menu.addAction(self.tr("Edit"))
  1025. actGui = menu.addAction(self.tr("Show Custom UI"))
  1026. menu.addSeparator()
  1027. if self.b_edit is not None:
  1028. actEdit.setCheckable(True)
  1029. actEdit.setChecked(self.b_edit.isChecked())
  1030. else:
  1031. actEdit.setVisible(False)
  1032. if self.b_gui is not None:
  1033. actGui.setCheckable(True)
  1034. actGui.setChecked(self.b_gui.isChecked())
  1035. actGui.setEnabled(self.b_gui.isEnabled())
  1036. else:
  1037. actGui.setVisible(False)
  1038. # -------------------------------------------------------------
  1039. # Other stuff
  1040. actClone = menu.addAction(self.tr("Clone"))
  1041. actRename = menu.addAction(self.tr("Rename..."))
  1042. actReplace = menu.addAction(self.tr("Replace..."))
  1043. actRemove = menu.addAction(self.tr("Remove"))
  1044. if self.fIdleTimerId != 0:
  1045. actRemove.setVisible(False)
  1046. if self.host.exportLV2:
  1047. menu.addSeparator()
  1048. actExportLV2 = menu.addAction(self.tr("Export LV2..."))
  1049. else:
  1050. actExportLV2 = None
  1051. # -------------------------------------------------------------
  1052. # exec
  1053. actSel = menu.exec_(QCursor.pos())
  1054. if not actSel:
  1055. return
  1056. # -------------------------------------------------------------
  1057. # Expand/Minimize
  1058. elif actSel == actCompact:
  1059. # FIXME
  1060. gCarla.gui.compactPlugin(self.fPluginId)
  1061. # -------------------------------------------------------------
  1062. # Tweaks
  1063. elif actSel == actColor:
  1064. initial = QColor(self.fSkinColor[0], self.fSkinColor[1], self.fSkinColor[2])
  1065. color = QColorDialog.getColor(initial, self, self.tr("Change Color"), QColorDialog.DontUseNativeDialog)
  1066. if not color.isValid():
  1067. return
  1068. color = color.getRgb()[0:3]
  1069. colorStr = "%i;%i;%i" % color
  1070. gCarla.gui.changePluginColor(self.fPluginId, color, colorStr)
  1071. elif actSel == actColorRandom:
  1072. hue = QColor(self.fSkinColor[0], self.fSkinColor[1], self.fSkinColor[2]).hueF()
  1073. color = QColor.fromHslF((hue + random.random()*0.5 + 0.25) % 1.0, 0.25, 0.125, 1).getRgb()[0:3]
  1074. colorStr = "%i;%i;%i" % color
  1075. gCarla.gui.changePluginColor(self.fPluginId, color, colorStr)
  1076. elif actSel == actSkin:
  1077. skin = QInputDialog.getItem(self, self.tr("Change Skin"),
  1078. self.tr("Change Skin to:"),
  1079. skinList, arrayIndex(skinList, self.fSkinStyle), False)
  1080. if not all(skin):
  1081. return
  1082. gCarla.gui.changePluginSkin(self.fPluginId, skin[0])
  1083. # -------------------------------------------------------------
  1084. # Find in patchbay
  1085. elif actSel == actFindInPatchbay:
  1086. gCarla.gui.findPluginInPatchbay(self.fPluginId)
  1087. # -------------------------------------------------------------
  1088. # Move up and down
  1089. elif actSel == actMoveUp:
  1090. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId-1)
  1091. elif actSel == actMoveDown:
  1092. gCarla.gui.switchPlugins(self.fPluginId, self.fPluginId+1)
  1093. # -------------------------------------------------------------
  1094. # Bypass and Enable/Disable
  1095. elif actSel == actBypass:
  1096. value = 0.0 if actBypass.isChecked() else 1.0
  1097. self.host.set_drywet(self.fPluginId, value)
  1098. self.setParameterValue(PARAMETER_DRYWET, value, True)
  1099. elif actSel == actEnable:
  1100. self.setActive(not self.fIsActive, True, True)
  1101. # -------------------------------------------------------------
  1102. # Reset and Randomize parameters
  1103. elif actSel == actReset:
  1104. self.host.reset_parameters(self.fPluginId)
  1105. elif actSel == actRandom:
  1106. self.host.randomize_parameters(self.fPluginId)
  1107. # -------------------------------------------------------------
  1108. # Edit and Show Custom UI
  1109. elif actSel == actEdit:
  1110. self.b_edit.click()
  1111. elif actSel == actGui:
  1112. self.b_gui.click()
  1113. # -------------------------------------------------------------
  1114. # Clone
  1115. elif actSel == actClone:
  1116. if not self.host.clone_plugin(self.fPluginId):
  1117. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1118. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1119. # -------------------------------------------------------------
  1120. # Rename
  1121. elif actSel == actRename:
  1122. self.showRenameDialog()
  1123. # -------------------------------------------------------------
  1124. # Replace
  1125. elif actSel == actReplace:
  1126. self.showReplaceDialog()
  1127. # -------------------------------------------------------------
  1128. # Remove
  1129. elif actSel == actRemove:
  1130. if not self.host.remove_plugin(self.fPluginId):
  1131. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1132. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1133. # -------------------------------------------------------------
  1134. # Export LV2
  1135. elif actSel == actExportLV2:
  1136. filepath = QInputDialog.getItem(self, self.tr("Export LV2 Plugin"),
  1137. self.tr("Select LV2 Path where plugin will be exported to:"),
  1138. CARLA_DEFAULT_LV2_PATH, editable=False)
  1139. if not all(filepath):
  1140. return
  1141. plugname = self.fPluginInfo['name']
  1142. filepath = os.path.join(filepath[0], plugname.replace(" ","_"))
  1143. if not filepath.endswith(".lv2"):
  1144. filepath += ".lv2"
  1145. if os.path.exists(filepath):
  1146. if QMessageBox.question(self, self.tr("Export to LV2"),
  1147. self.tr("Plugin bundle already exists, overwrite?")) == QMessageBox.Ok:
  1148. return
  1149. if not self.host.export_plugin_lv2(self.fPluginId, filepath):
  1150. return CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1151. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1152. QMessageBox.information(self, self.tr("Plugin exported"),
  1153. self.tr("Plugin exported successfully, saved in folder:\n%s" % filepath))
  1154. # -------------------------------------------------------------
  1155. @pyqtSlot()
  1156. def slot_knobCustomMenu(self):
  1157. PluginEdit.slot_knobCustomMenu(self)
  1158. # -----------------------------------------------------------------
  1159. @pyqtSlot(bool)
  1160. def slot_showCustomUi(self, show):
  1161. self.host.show_custom_ui(self.fPluginId, show)
  1162. @pyqtSlot(bool)
  1163. def slot_showEditDialog(self, show):
  1164. self.fEditDialog.setVisible(show)
  1165. @pyqtSlot()
  1166. def slot_removePlugin(self):
  1167. if not self.host.remove_plugin(self.fPluginId):
  1168. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1169. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1170. # -----------------------------------------------------------------
  1171. @pyqtSlot(bool)
  1172. def slot_parameterDragStateChanged(self, touch):
  1173. index = self.sender().getIndex()
  1174. if index >= 0:
  1175. self.host.set_parameter_touch(self.fPluginId, index, touch)
  1176. @pyqtSlot(float)
  1177. def slot_parameterValueChanged(self, value):
  1178. index = self.sender().getIndex()
  1179. if index < 0:
  1180. self.setInternalParameter(index, value)
  1181. else:
  1182. self.host.set_parameter_value(self.fPluginId, index, value)
  1183. self.setParameterValue(index, value, False)
  1184. @pyqtSlot(int)
  1185. def slot_programChanged(self, index):
  1186. self.host.set_program(self.fPluginId, index)
  1187. self.setProgram(index, False)
  1188. @pyqtSlot(int)
  1189. def slot_midiProgramChanged(self, index):
  1190. self.host.set_midi_program(self.fPluginId, index)
  1191. self.setMidiProgram(index, False)
  1192. # -----------------------------------------------------------------
  1193. def adjustViewableKnobCount(self):
  1194. if self.w_knobs_left is None or self.spacer_knobs is None:
  1195. return
  1196. curWidth = 2
  1197. maxWidth = self.w_knobs_left.width() + self.spacer_knobs.geometry().width() + 2
  1198. plen = len(self.fParameterList)
  1199. for i in range(plen):
  1200. index, widget = self.fParameterList[i]
  1201. if index < 0:
  1202. break
  1203. if not widget.getIsVisible():
  1204. continue
  1205. curWidth += widget.width() + RACK_KNOB_GAP
  1206. if self.fTweaks.get('MoreSpace', 0):
  1207. if self.w_knobs_right is None: # calf
  1208. limit = curWidth
  1209. else:
  1210. if QT_VERSION < 0x60000:
  1211. limit = curWidth + self.w_knobs_right.getContentsMargins()[0] + 8
  1212. else:
  1213. limit = curWidth + 4 + 8
  1214. else:
  1215. limit = curWidth + 56 + 8
  1216. if limit < maxWidth:
  1217. #if not widget.isVisible():
  1218. widget.show()
  1219. continue
  1220. for i2 in range(i, plen):
  1221. index2, widget2 = self.fParameterList[i2]
  1222. if index2 < 0:
  1223. break
  1224. #if widget2.isVisible():
  1225. widget2.hide()
  1226. break
  1227. self.fAdjustViewableKnobCountScheduled = False
  1228. def testTimer(self):
  1229. self.fIdleTimerId = self.startTimer(25)
  1230. # -----------------------------------------------------------------
  1231. def mouseDoubleClickEvent(self, event):
  1232. QFrame.mouseDoubleClickEvent(self, event)
  1233. # FIXME
  1234. gCarla.gui.compactPlugin(self.fPluginId)
  1235. def closeEvent(self, event):
  1236. if self.fIdleTimerId != 0:
  1237. self.killTimer(self.fIdleTimerId)
  1238. self.fIdleTimerId = 0
  1239. self.host.engine_close()
  1240. QFrame.closeEvent(self, event)
  1241. def resizeEvent(self, event):
  1242. if not self.fAdjustViewableKnobCountScheduled:
  1243. self.fAdjustViewableKnobCountScheduled = True
  1244. QTimer.singleShot(100, self.adjustViewableKnobCount)
  1245. QFrame.resizeEvent(self, event)
  1246. def timerEvent(self, event):
  1247. if event.timerId() == self.fIdleTimerId:
  1248. self.host.engine_idle()
  1249. self.idleFast()
  1250. self.idleSlow()
  1251. QFrame.timerEvent(self, event)
  1252. def paintEvent(self, event):
  1253. painter = QPainter(self)
  1254. # Colorization
  1255. if self.fSkinColor != (0,0,0):
  1256. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  1257. r,g,b = self.fSkinColor
  1258. painter.setBrush(QColor(r,g,b))
  1259. painter.setPen(Qt.NoPen)
  1260. painter.drawRect(QRectF(0,0,self.width(),self.height()))
  1261. painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
  1262. self.drawOutline(painter)
  1263. QFrame.paintEvent(self, event)
  1264. # ------------------------------------------------------------------------------------------------------------
  1265. class PluginSlot_Calf(AbstractPluginSlot):
  1266. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1267. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1268. self.ui = ui_carla_plugin_calf.Ui_PluginWidget()
  1269. self.ui.setupUi(self)
  1270. audioCount = self.host.get_audio_port_count_info(self.fPluginId)
  1271. midiCount = self.host.get_midi_port_count_info(self.fPluginId)
  1272. # -------------------------------------------------------------
  1273. # Internal stuff
  1274. self.fButtonFont = self.ui.b_gui.font()
  1275. self.fButtonFont.setBold(False)
  1276. self.fButtonFont.setPixelSize(10)
  1277. self.fButtonColorOn = QColor( 18, 41, 87)
  1278. self.fButtonColorOff = QColor(150, 150, 150)
  1279. # -------------------------------------------------------------
  1280. # Set-up GUI
  1281. self.ui.label_active.setFont(self.fButtonFont)
  1282. self.ui.b_remove.setPixmaps(":/bitmaps/button_calf1.png",
  1283. ":/bitmaps/button_calf1_down.png",
  1284. ":/bitmaps/button_calf1_hover.png")
  1285. self.ui.b_edit.setTopText(self.tr("Edit"), self.fButtonColorOn, self.fButtonFont)
  1286. self.ui.b_remove.setTopText(self.tr("Remove"), self.fButtonColorOn, self.fButtonFont)
  1287. if self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI:
  1288. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1289. else:
  1290. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1291. if audioCount['ins'] == 0:
  1292. self.ui.label_audio_in.hide()
  1293. if audioCount['outs'] == 0:
  1294. self.ui.label_audio_out.hide()
  1295. if midiCount['ins'] == 0:
  1296. self.ui.label_midi.hide()
  1297. self.ui.led_midi.hide()
  1298. if self.fIdleTimerId != 0:
  1299. self.ui.b_remove.setEnabled(False)
  1300. self.ui.b_remove.setVisible(False)
  1301. # -------------------------------------------------------------
  1302. self.b_enable = self.ui.b_enable
  1303. self.b_gui = self.ui.b_gui
  1304. self.b_edit = self.ui.b_edit
  1305. self.b_remove = self.ui.b_remove
  1306. self.label_name = self.ui.label_name
  1307. self.led_midi = self.ui.led_midi
  1308. self.peak_in = self.ui.peak_in
  1309. self.peak_out = self.ui.peak_out
  1310. self.w_knobs_left = self.ui.w_knobs
  1311. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1312. self.ready()
  1313. self.ui.led_midi.setColor(self.ui.led_midi.CALF)
  1314. # -----------------------------------------------------------------
  1315. def getFixedHeight(self):
  1316. return 94 if max(self.peak_in.channelCount(), self.peak_out.channelCount()) < 2 else 106
  1317. # -----------------------------------------------------------------
  1318. def editDialogPluginHintsChanged(self, pluginId, hints):
  1319. if hints & PLUGIN_HAS_CUSTOM_UI:
  1320. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  1321. else:
  1322. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  1323. AbstractPluginSlot.editDialogPluginHintsChanged(self, pluginId, hints)
  1324. # -----------------------------------------------------------------
  1325. def paintEvent(self, event):
  1326. isBlack = bool(self.fSkinStyle == "calf_black")
  1327. painter = QPainter(self)
  1328. painter.setBrush(Qt.transparent)
  1329. painter.setPen(QPen(QColor(20, 20, 20) if isBlack else QColor(75, 86, 99), 1))
  1330. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1331. painter.setPen(QPen(QColor(45, 45, 45) if isBlack else QColor(86, 99, 114), 1))
  1332. painter.drawLine(0, 0, self.width(), 0)
  1333. AbstractPluginSlot.paintEvent(self, event)
  1334. # ------------------------------------------------------------------------------------------------------------
  1335. class PluginSlot_Classic(AbstractPluginSlot):
  1336. def __init__(self, parent, host, pluginId):
  1337. AbstractPluginSlot.__init__(self, parent, host, pluginId, (0,0,0), "classic")
  1338. self.ui = ui_carla_plugin_classic.Ui_PluginWidget()
  1339. self.ui.setupUi(self)
  1340. # -------------------------------------------------------------
  1341. # Internal stuff
  1342. self.fColorTop = QColor(60, 60, 60)
  1343. self.fColorBottom = QColor(47, 47, 47)
  1344. self.fColorSeprtr = QColor(70, 70, 70)
  1345. # -------------------------------------------------------------
  1346. self.b_enable = self.ui.b_enable
  1347. self.b_gui = self.ui.b_gui
  1348. self.b_edit = self.ui.b_edit
  1349. self.label_name = self.ui.label_name
  1350. self.led_control = self.ui.led_control
  1351. self.led_midi = self.ui.led_midi
  1352. self.led_audio_in = self.ui.led_audio_in
  1353. self.led_audio_out = self.ui.led_audio_out
  1354. self.peak_in = self.ui.peak_in
  1355. self.peak_out = self.ui.peak_out
  1356. self.ready()
  1357. # -----------------------------------------------------------------
  1358. def getFixedHeight(self):
  1359. return 36
  1360. # -----------------------------------------------------------------
  1361. def paintEvent(self, event):
  1362. painter = QPainter(self)
  1363. painter.save()
  1364. areaX = self.ui.area_right.x()+7
  1365. width = self.width()
  1366. height = self.height()
  1367. painter.setPen(QPen(QColor(17, 17, 17), 1))
  1368. painter.setBrush(QColor(17, 17, 17))
  1369. painter.drawRect(0, 0, width, height)
  1370. painter.setPen(self.fColorSeprtr.lighter(110))
  1371. painter.setBrush(self.fColorBottom)
  1372. painter.setRenderHint(QPainter.Antialiasing, True)
  1373. # name -> leds arc
  1374. path = QPainterPath()
  1375. path.moveTo(areaX-20, height-4)
  1376. path.cubicTo(areaX, height-5, areaX-20, 4.75, areaX, 4.75)
  1377. path.lineTo(areaX, height-5)
  1378. painter.drawPath(path)
  1379. painter.setPen(self.fColorSeprtr)
  1380. painter.setRenderHint(QPainter.Antialiasing, False)
  1381. # separator lines
  1382. painter.drawLine(0, height-5, areaX-20, height-5)
  1383. painter.drawLine(areaX, 4, width, 4)
  1384. painter.setPen(self.fColorBottom)
  1385. painter.setBrush(self.fColorBottom)
  1386. # top, bottom and left lines
  1387. painter.drawLine(0, 0, width, 0)
  1388. painter.drawRect(0, height-4, areaX, 4)
  1389. painter.drawRoundedRect(areaX-20, height-5, areaX, 5, 22, 22)
  1390. painter.drawLine(0, 0, 0, height)
  1391. # fill the rest
  1392. painter.drawRect(areaX-1, 5, width, height)
  1393. # bottom 1px line
  1394. painter.setPen(self.fColorSeprtr)
  1395. painter.drawLine(0, height-1, width, height-1)
  1396. painter.restore()
  1397. AbstractPluginSlot.paintEvent(self, event)
  1398. # ------------------------------------------------------------------------------------------------------------
  1399. class PluginSlot_Compact(AbstractPluginSlot):
  1400. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1401. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1402. self.ui = ui_carla_plugin_compact.Ui_PluginWidget()
  1403. self.ui.setupUi(self)
  1404. self.b_enable = self.ui.b_enable
  1405. self.b_gui = self.ui.b_gui
  1406. self.b_edit = self.ui.b_edit
  1407. self.label_name = self.ui.label_name
  1408. self.led_control = self.ui.led_control
  1409. self.led_midi = self.ui.led_midi
  1410. self.led_audio_in = self.ui.led_audio_in
  1411. self.led_audio_out = self.ui.led_audio_out
  1412. self.peak_in = self.ui.peak_in
  1413. self.peak_out = self.ui.peak_out
  1414. if self.fTweaks.get('ShowProgramsOnCompact', 0):
  1415. insertProgramList(self, self.ui.layout_peaks, 0)
  1416. if self.fTweaks.get('ShowMidiProgramsOnCompact', 0):
  1417. insertMidiProgramList(self, self.ui.layout_peaks, 0)
  1418. self.ready()
  1419. # -----------------------------------------------------------------
  1420. def getFixedHeight(self):
  1421. if self.fSkinStyle == "calf_blue":
  1422. return 36
  1423. return 30
  1424. # ------------------------------------------------------------------------------------------------------------
  1425. class PluginSlot_Default(AbstractPluginSlot):
  1426. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1427. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1428. self.ui = ui_carla_plugin_default.Ui_PluginWidget()
  1429. self.ui.setupUi(self)
  1430. # -------------------------------------------------------------
  1431. self.b_enable = self.ui.b_enable
  1432. self.b_gui = self.ui.b_gui
  1433. self.b_edit = self.ui.b_edit
  1434. self.label_name = self.ui.label_name
  1435. self.led_control = self.ui.led_control
  1436. self.led_midi = self.ui.led_midi
  1437. self.led_audio_in = self.ui.led_audio_in
  1438. self.led_audio_out = self.ui.led_audio_out
  1439. self.peak_in = self.ui.peak_in
  1440. self.peak_out = self.ui.peak_out
  1441. self.w_knobs_left = self.ui.w_knobs_left
  1442. self.w_knobs_right = self.ui.w_knobs_right
  1443. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1444. if self.fTweaks.get('MoreSpace', 0):
  1445. self.ui.layout_bottom.setContentsMargins(0, 4, 0, 0)
  1446. if self.fTweaks.get('ShowPrograms', 0):
  1447. # insertProgramList(self, self.ui.layout_top, 6)
  1448. insertProgramList(self, self.ui.layout_peaks, 0)
  1449. if self.fTweaks.get('ShowMidiPrograms', 0):
  1450. # insertMidiProgramList(self, self.ui.layout_top, 6)
  1451. insertMidiProgramList(self, self.ui.layout_peaks, 0)
  1452. self.ready()
  1453. # -----------------------------------------------------------------
  1454. def getFixedHeight(self):
  1455. if self.fSkinStyle == "tube":
  1456. return 98
  1457. return 80
  1458. # -----------------------------------------------------------------
  1459. def paintEvent(self, event):
  1460. painter = QPainter(self)
  1461. painter.setBrush(Qt.transparent)
  1462. painter.setPen(QPen(QColor(42, 42, 42), 1))
  1463. painter.drawRect(0, 1, self.width()-1, self.getFixedHeight()-3)
  1464. painter.setPen(QPen(QColor(60, 60, 60), 1))
  1465. painter.drawLine(0, 0, self.width(), 0)
  1466. AbstractPluginSlot.paintEvent(self, event)
  1467. # ------------------------------------------------------------------------------------------------------------
  1468. class PluginSlot_Presets(AbstractPluginSlot):
  1469. def __init__(self, parent, host, pluginId, skinColor, skinStyle):
  1470. AbstractPluginSlot.__init__(self, parent, host, pluginId, skinColor, skinStyle)
  1471. self.ui = ui_carla_plugin_presets.Ui_PluginWidget()
  1472. self.ui.setupUi(self)
  1473. usingMidiPrograms = bool(skinStyle != "presets")
  1474. # -------------------------------------------------------------
  1475. # Set-up programs
  1476. if usingMidiPrograms:
  1477. programCount = self.host.get_midi_program_count(self.fPluginId)
  1478. else:
  1479. programCount = self.host.get_program_count(self.fPluginId)
  1480. if programCount > 0:
  1481. self.ui.cb_presets.setEnabled(True)
  1482. self.ui.label_presets.setEnabled(True)
  1483. for i in range(programCount):
  1484. if usingMidiPrograms:
  1485. progName = self.host.get_midi_program_data(self.fPluginId, i)['name']
  1486. else:
  1487. progName = self.host.get_program_name(self.fPluginId, i)
  1488. self.ui.cb_presets.addItem(progName)
  1489. if usingMidiPrograms:
  1490. curProg = self.host.get_current_midi_program_index(self.fPluginId)
  1491. else:
  1492. curProg = self.host.get_current_program_index(self.fPluginId)
  1493. self.ui.cb_presets.setCurrentIndex(curProg)
  1494. else:
  1495. self.ui.cb_presets.setEnabled(False)
  1496. self.ui.cb_presets.setVisible(False)
  1497. self.ui.label_presets.setEnabled(False)
  1498. self.ui.label_presets.setVisible(False)
  1499. # -------------------------------------------------------------
  1500. self.b_enable = self.ui.b_enable
  1501. self.b_gui = self.ui.b_gui
  1502. self.b_edit = self.ui.b_edit
  1503. self.cb_presets = self.ui.cb_presets
  1504. self.label_name = self.ui.label_name
  1505. self.label_presets = self.ui.label_presets
  1506. self.led_control = self.ui.led_control
  1507. self.led_midi = self.ui.led_midi
  1508. self.led_audio_in = self.ui.led_audio_in
  1509. self.led_audio_out = self.ui.led_audio_out
  1510. self.peak_in = self.ui.peak_in
  1511. self.peak_out = self.ui.peak_out
  1512. # if skinStyle == "zynfx": # TODO jpka: TEST ing zynfx as normal tweakable skin
  1513. if False:
  1514. self.setupZynFxParams()
  1515. else:
  1516. self.w_knobs_left = self.ui.w_knobs_left
  1517. self.w_knobs_right = self.ui.w_knobs_right
  1518. self.spacer_knobs = self.ui.layout_bottom.itemAt(1).spacerItem()
  1519. if self.fTweaks.get('MoreSpace', 0):
  1520. self.ui.layout_bottom.setContentsMargins(0, 4, 0, 0)
  1521. self.ready()
  1522. if usingMidiPrograms:
  1523. self.ui.cb_presets.currentIndexChanged.connect(self.slot_midiProgramChanged)
  1524. else:
  1525. self.ui.cb_presets.currentIndexChanged.connect(self.slot_programChanged)
  1526. # -------------------------------------------------------------
  1527. # it works only for internal zyn builds, which are disabled by default
  1528. # (?) not for just manual "zynfx" skin selection
  1529. def setupZynFxParams(self):
  1530. parameterCount = min(self.host.get_parameter_count(self.fPluginId), 8)
  1531. for i in range(parameterCount):
  1532. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  1533. paramData = self.host.get_parameter_data(self.fPluginId, i)
  1534. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  1535. if paramData['type'] != PARAMETER_INPUT:
  1536. continue
  1537. if paramData['hints'] & PARAMETER_IS_BOOLEAN:
  1538. continue
  1539. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1540. continue
  1541. paramName = paramInfo['name']
  1542. if paramName.startswith("unused"):
  1543. continue
  1544. # real zyn fx plugins
  1545. if self.fPluginInfo['label'] == "zynalienwah":
  1546. if i == 0: paramName = "Freq"
  1547. elif i == 1: paramName = "Rnd"
  1548. elif i == 2: paramName = "L type" # combobox
  1549. elif i == 3: paramName = "St.df"
  1550. elif i == 5: paramName = "Fb"
  1551. elif i == 7: paramName = "L/R"
  1552. elif self.fPluginInfo['label'] == "zynchorus":
  1553. if i == 0: paramName = "Freq"
  1554. elif i == 1: paramName = "Rnd"
  1555. elif i == 2: paramName = "L type" # combobox
  1556. elif i == 3: paramName = "St.df"
  1557. elif i == 6: paramName = "Fb"
  1558. elif i == 7: paramName = "L/R"
  1559. elif i == 8: paramName = "Flngr" # button
  1560. elif i == 9: paramName = "Subst" # button
  1561. elif self.fPluginInfo['label'] == "zyndistortion":
  1562. if i == 0: paramName = "LRc."
  1563. elif i == 4: paramName = "Neg." # button
  1564. elif i == 5: paramName = "LPF"
  1565. elif i == 6: paramName = "HPF"
  1566. elif i == 7: paramName = "St." # button
  1567. elif i == 8: paramName = "PF" # button
  1568. elif self.fPluginInfo['label'] == "zyndynamicfilter":
  1569. if i == 0: paramName = "Freq"
  1570. elif i == 1: paramName = "Rnd"
  1571. elif i == 2: paramName = "L type" # combobox
  1572. elif i == 3: paramName = "St.df"
  1573. elif i == 4: paramName = "LfoD"
  1574. elif i == 5: paramName = "A.S."
  1575. elif i == 6: paramName = "A.Inv." # button
  1576. elif i == 7: paramName = "A.M."
  1577. elif self.fPluginInfo['label'] == "zynecho":
  1578. if i == 1: paramName = "LRdl."
  1579. elif i == 2: paramName = "LRc."
  1580. elif i == 3: paramName = "Fb."
  1581. elif i == 4: paramName = "Damp"
  1582. elif self.fPluginInfo['label'] == "zynphaser":
  1583. if i == 0: paramName = "Freq"
  1584. elif i == 1: paramName = "Rnd"
  1585. elif i == 2: paramName = "L type" # combobox
  1586. elif i == 3: paramName = "St.df"
  1587. elif i == 5: paramName = "Fb"
  1588. elif i == 7: paramName = "L/R"
  1589. elif i == 8: paramName = "Subst" # button
  1590. elif i == 9: paramName = "Phase"
  1591. elif i == 11: paramName = "Dist"
  1592. elif self.fPluginInfo['label'] == "zynreverb":
  1593. if i == 2: paramName = "I.delfb"
  1594. elif i == 5: paramName = "LPF"
  1595. elif i == 6: paramName = "HPF"
  1596. elif i == 9: paramName = "R.S."
  1597. elif i == 10: paramName = "I.del"
  1598. else:
  1599. paramName = getParameterShortName(paramName)
  1600. widget = ScalableDial(self, i)
  1601. widget.setLabel(paramName)
  1602. widget.setMinimum(paramRanges['min'])
  1603. widget.setMaximum(paramRanges['max'])
  1604. widget.setImage(3)
  1605. widget.setCustomPaintColor(QColor(83, 173, 10))
  1606. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_COLOR)
  1607. widget.forceWhiteLabelGradientText()
  1608. widget.hide()
  1609. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  1610. widget.setEnabled(False)
  1611. self.fParameterList.append([i, widget])
  1612. self.ui.w_knobs_left.layout().addWidget(widget)
  1613. if self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET:
  1614. widget = ScalableDial(self, PARAMETER_DRYWET)
  1615. widget.setLabel("Wet")
  1616. widget.setMinimum(0.0)
  1617. widget.setMaximum(1.0)
  1618. widget.setImage(3)
  1619. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_CARLA_WET)
  1620. widget.forceWhiteLabelGradientText()
  1621. self.fParameterList.append([PARAMETER_DRYWET, widget])
  1622. self.ui.w_knobs_right.layout().addWidget(widget)
  1623. if self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME:
  1624. widget = ScalableDial(self, PARAMETER_VOLUME)
  1625. widget.setLabel("Volume")
  1626. widget.setMinimum(0.0)
  1627. widget.setMaximum(1.27)
  1628. widget.setImage(3)
  1629. widget.setCustomPaintMode(ScalableDial.CUSTOM_PAINT_MODE_CARLA_VOL)
  1630. widget.forceWhiteLabelGradientText()
  1631. self.fParameterList.append([PARAMETER_VOLUME, widget])
  1632. self.ui.w_knobs_right.layout().addWidget(widget)
  1633. # -----------------------------------------------------------------
  1634. def getFixedHeight(self):
  1635. return 80
  1636. # -----------------------------------------------------------------
  1637. def paintEvent(self, event):
  1638. painter = QPainter(self)
  1639. painter.setBrush(Qt.transparent)
  1640. painter.setPen(QPen(QColor(50, 50, 50), 1))
  1641. painter.drawRect(0, 1, self.width()-1, self.height()-3)
  1642. painter.setPen(QPen(QColor(64, 64, 64), 1))
  1643. painter.drawLine(0, 0, self.width(), 0)
  1644. AbstractPluginSlot.paintEvent(self, event)
  1645. # ------------------------------------------------------------------------------------------------------------
  1646. def insertProgramList(self, layout, index):
  1647. count = self.host.get_program_count(self.fPluginId)
  1648. if count:
  1649. cb = QComboBox(None)
  1650. cb.setObjectName("cb_presets0") # use this stylesheet
  1651. for i in range(count):
  1652. string = self.host.get_program_name(self.fPluginId, i)
  1653. if len(string) == 0:
  1654. print("Carla: WARNING: Program List have zero length item.")
  1655. return
  1656. cb.addItem(string)
  1657. layout.insertWidget(index, cb)
  1658. cb.setCurrentIndex(self.host.get_current_program_index(self.fPluginId))
  1659. cb.currentIndexChanged.connect(self.slot_programChanged)
  1660. def insertMidiProgramList(self, layout, index):
  1661. count = self.host.get_midi_program_count(self.fPluginId)
  1662. if count:
  1663. cb = QComboBox(None)
  1664. cb.setObjectName("cb_presets1") # use this stylesheet
  1665. for i in range(count):
  1666. string = self.host.get_midi_program_data(self.fPluginId, i)['name']
  1667. if len(string) == 0:
  1668. print("Carla: WARNING: MIDI Program List have zero length item.")
  1669. return
  1670. cb.addItem(string)
  1671. layout.insertWidget(index, cb)
  1672. cb.setCurrentIndex(self.host.get_current_midi_program_index(self.fPluginId))
  1673. cb.currentIndexChanged.connect(self.slot_midiProgramChanged)
  1674. # ------------------------------------------------------------------------------------------------------------
  1675. def getColorAndSkinStyle(host, pluginId):
  1676. pluginInfo = host.get_plugin_info(pluginId)
  1677. pluginName = host.get_real_plugin_name(pluginId)
  1678. pluginLabel = pluginInfo['label'].lower()
  1679. pluginMaker = pluginInfo['maker']
  1680. uniqueId = pluginInfo['uniqueId']
  1681. if pluginInfo['type'] in (PLUGIN_VST2, PLUGIN_VST3, PLUGIN_AU):
  1682. progCount = host.get_program_count(pluginId)
  1683. else:
  1684. progCount = host.get_midi_program_count(pluginId)
  1685. colorCategory = getColorFromCategory(pluginInfo['category'])
  1686. colorNone = (0,0,0)
  1687. # Samplers
  1688. if pluginInfo['type'] == PLUGIN_SF2:
  1689. return (colorCategory, "mpresets")
  1690. if pluginInfo['type'] == PLUGIN_SFZ:
  1691. return (colorCategory, "mpresets")
  1692. # Calf
  1693. if pluginName.split(" ", 1)[0].lower() == "calf":
  1694. return (colorNone, "calf_black" if "mono" in pluginLabel else "calf_blue")
  1695. # OpenAV
  1696. if pluginMaker == "OpenAV Productions":
  1697. return (colorNone, "openav-old")
  1698. if pluginMaker == "OpenAV":
  1699. return (colorNone, "openav")
  1700. # Tube
  1701. if "tube" in pluginLabel:
  1702. return (colorCategory, "tube")
  1703. # ZynFX
  1704. if pluginInfo['type'] == PLUGIN_INTERNAL:
  1705. if pluginLabel.startswith("zyn") and pluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1706. return (colorNone, "zynfx")
  1707. if pluginInfo['type'] == PLUGIN_LADSPA:
  1708. if pluginLabel.startswith("zyn") and pluginMaker.startswith("Josep Andreu"):
  1709. return (colorNone, "zynfx")
  1710. if pluginInfo['type'] == PLUGIN_LV2:
  1711. # if pluginLabel.startswith("http://kxstudio.sf.net/carla/plugins/zyn") and pluginName != "ZynAddSubFX":
  1712. 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
  1713. return (colorNone, "zynfx")
  1714. # Presets
  1715. if progCount > 1 and (pluginInfo['hints'] & PLUGIN_USES_MULTI_PROGS) == 0:
  1716. if pluginInfo['type'] in (PLUGIN_VST2, PLUGIN_VST3, PLUGIN_AU):
  1717. return (colorCategory, "presets")
  1718. return (colorCategory, "mpresets")
  1719. # DISTRHO Plugins (needs to be last)
  1720. if pluginMaker.startswith("falkTX, ") or pluginMaker == "DISTRHO" or pluginLabel.startswith("http://distrho.sf.net/plugins/"):
  1721. skinStyle = pluginLabel.replace("http://distrho.sf.net/plugins/","")
  1722. if skinStyle in ("3bandeq", "nekobi"):
  1723. return (colorNone, skinStyle)
  1724. return (colorCategory, "default")
  1725. def createPluginSlot(parent, host, pluginId, options):
  1726. skinColor, skinStyle = getColorAndSkinStyle(host, pluginId)
  1727. if options['color'] is not None:
  1728. skinColor = options['color']
  1729. if options['skin']:
  1730. skinStyle = options['skin']
  1731. if skinStyle == "classic":
  1732. return PluginSlot_Classic(parent, host, pluginId)
  1733. if "compact" in skinStyle or options['compact']:
  1734. return PluginSlot_Compact(parent, host, pluginId, skinColor, skinStyle)
  1735. if skinStyle.startswith("calf"):
  1736. return PluginSlot_Calf(parent, host, pluginId, skinColor, skinStyle)
  1737. if skinStyle in ("mpresets", "presets", "zynfx"):
  1738. return PluginSlot_Presets(parent, host, pluginId, skinColor, skinStyle)
  1739. return PluginSlot_Default(parent, host, pluginId, skinColor, skinStyle)
  1740. # ------------------------------------------------------------------------------------------------------------
  1741. # Main Testing
  1742. if __name__ == '__main__':
  1743. from carla_app import CarlaApplication
  1744. from carla_host import initHost, loadHostSettings
  1745. import resources_rc
  1746. app = CarlaApplication("Carla-Skins")
  1747. host = initHost("Skins", None, False, False, False)
  1748. loadHostSettings(host)
  1749. host.engine_init("JACK", "Carla-Widgets")
  1750. host.add_plugin(BINARY_NATIVE, PLUGIN_INTERNAL, "", "", "zynreverb", 0, None, PLUGIN_OPTIONS_NULL)
  1751. #host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, PLUGIN_OPTIONS_NULL)
  1752. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://www.openavproductions.com/sorcer", 0, None, PLUGIN_OPTIONS_NULL)
  1753. #host.add_plugin(BINARY_NATIVE, PLUGIN_LV2, "", "", "http://calf.sourceforge.net/plugins/Compressor", 0, None, PLUGIN_OPTIONS_NULL)
  1754. host.set_active(0, True)
  1755. #gui = createPluginSlot(None, host, 0, True)
  1756. gui = PluginSlot_Compact(None, host, 0, (0, 0, 0), "default")
  1757. gui.testTimer()
  1758. gui.show()
  1759. app.exec_()