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.

1127 lines
42KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla plugin/slot skin code
  4. # Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt4.QtGui import QFont, QFrame, QPushButton
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Custom)
  22. import ui_carla_plugin_default
  23. import ui_carla_plugin_calf
  24. import ui_carla_plugin_zita
  25. import ui_carla_plugin_zynfx
  26. from carla_widgets import *
  27. from pixmapdial import PixmapDial
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Abstract plugin slot
  30. class AbstractPluginSlot(QFrame):
  31. def __init__(self, parent, pluginId):
  32. QFrame.__init__(self, parent)
  33. # -------------------------------------------------------------
  34. # Get plugin info
  35. self.fPluginId = pluginId
  36. self.fPluginInfo = Carla.host.get_plugin_info(self.fPluginId) if Carla.host is not None else gFakePluginInfo
  37. self.fPluginInfo['filename'] = charPtrToString(self.fPluginInfo['filename'])
  38. self.fPluginInfo['name'] = charPtrToString(self.fPluginInfo['name'])
  39. self.fPluginInfo['label'] = charPtrToString(self.fPluginInfo['label'])
  40. self.fPluginInfo['maker'] = charPtrToString(self.fPluginInfo['maker'])
  41. self.fPluginInfo['copyright'] = charPtrToString(self.fPluginInfo['copyright'])
  42. self.fPluginInfo['iconName'] = charPtrToString(self.fPluginInfo['iconName'])
  43. if not Carla.isLocal:
  44. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_CUSTOM_UI
  45. # -------------------------------------------------------------
  46. # Internal stuff
  47. self.fIsActive = False
  48. self.fLastGreenLedState = False
  49. self.fLastBlueLedState = False
  50. self.fParameterIconTimer = ICON_STATE_NULL
  51. self.fParameterList = [] # index, widget
  52. if Carla.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK or Carla.host is None:
  53. self.fPeaksInputCount = 2
  54. self.fPeaksOutputCount = 2
  55. else:
  56. audioCountInfo = Carla.host.get_audio_port_count_info(self.fPluginId)
  57. self.fPeaksInputCount = int(audioCountInfo['ins'])
  58. self.fPeaksOutputCount = int(audioCountInfo['outs'])
  59. if self.fPeaksInputCount > 2:
  60. self.fPeaksInputCount = 2
  61. if self.fPeaksOutputCount > 2:
  62. self.fPeaksOutputCount = 2
  63. # -------------------------------------------------------------
  64. # Set-up GUI
  65. self.fEditDialog = PluginEdit(self, self.fPluginId)
  66. self.fEditDialog.hide()
  67. # -------------------------------------------------------------
  68. # Set-up common widgets (as none)
  69. self.b_enable = None
  70. self.b_gui = None
  71. self.b_edit = None
  72. self.b_remove = None
  73. self.cb_presets = None
  74. self.label_name = None
  75. self.led_control = None
  76. self.led_midi = None
  77. self.led_audio_in = None
  78. self.led_audio_out = None
  79. self.peak_in = None
  80. self.peak_out = None
  81. #------------------------------------------------------------------
  82. def ready(self):
  83. if self.b_enable is not None:
  84. self.b_enable.clicked.connect(self.slot_enableClicked)
  85. if self.b_gui is not None:
  86. self.b_gui.clicked.connect(self.slot_showCustomUi)
  87. self.b_gui.setEnabled(bool(self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI))
  88. if self.b_edit is None:
  89. # Edit dialog *must* be available
  90. self.b_edit = QPushButton(self)
  91. self.b_edit.setCheckable(True)
  92. self.b_edit.hide()
  93. self.b_edit.clicked.connect(self.slot_showEditDialog)
  94. if self.b_remove is not None:
  95. self.b_remove.clicked.connect(self.slot_removePlugin)
  96. if self.label_name is not None:
  97. self.label_name.setText(self.fPluginInfo['name'])
  98. if self.led_control is not None:
  99. self.led_control.setColor(self.led_control.YELLOW)
  100. self.led_control.setEnabled(False)
  101. if self.led_midi is not None:
  102. self.led_midi.setColor(self.led_midi.RED)
  103. self.led_midi.setEnabled(False)
  104. if self.led_audio_in is not None:
  105. self.led_audio_in.setColor(self.led_audio_in.GREEN)
  106. self.led_audio_in.setEnabled(False)
  107. if self.led_audio_out is not None:
  108. self.led_audio_out.setColor(self.led_audio_out.BLUE)
  109. self.led_audio_out.setEnabled(False)
  110. if self.peak_in is not None:
  111. self.peak_in.setColor(self.peak_in.GREEN)
  112. self.peak_in.setChannels(self.fPeaksInputCount)
  113. self.peak_in.setOrientation(self.peak_in.HORIZONTAL)
  114. if self.peak_out is not None:
  115. self.peak_out.setColor(self.peak_in.BLUE)
  116. self.peak_out.setChannels(self.fPeaksOutputCount)
  117. self.peak_out.setOrientation(self.peak_out.HORIZONTAL)
  118. for paramIndex, paramWidget in self.fParameterList:
  119. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  120. paramWidget.setValue(Carla.host.get_current_parameter_value(self.fPluginId, paramIndex) * 1000)
  121. #------------------------------------------------------------------
  122. def getFixedHeight(self):
  123. return 32
  124. def getHints(self):
  125. return self.fPluginInfo['hints']
  126. #------------------------------------------------------------------
  127. def recheckPluginHints(self, hints):
  128. self.fPluginInfo['hints'] = hints
  129. if self.b_gui is not None:
  130. self.b_gui.setEnabled(bool(hints & PLUGIN_HAS_CUSTOM_UI))
  131. def setId(self, idx):
  132. self.fPluginId = idx
  133. self.fEditDialog.setId(idx)
  134. def setName(self, name):
  135. self.fEditDialog.setName(name)
  136. if self.label_name is not None:
  137. self.label_name.setText(name)
  138. #------------------------------------------------------------------
  139. def setActive(self, active, sendGui=False, sendCallback=True):
  140. self.fIsActive = active
  141. if sendGui: self.activeChanged(active)
  142. if sendCallback: Carla.host.set_active(self.fPluginId, active)
  143. if active:
  144. self.fEditDialog.clearNotes()
  145. self.midiActivityChanged(False)
  146. # called from rack, checks if param is possible first
  147. def setInternalParameter(self, parameterId, value):
  148. if parameterId <= PARAMETER_MAX or parameterId >= PARAMETER_NULL:
  149. return
  150. elif parameterId == PARAMETER_ACTIVE:
  151. return self.setActive(bool(value), True, True)
  152. elif parameterId == PARAMETER_DRYWET:
  153. if (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) == 0: return
  154. Carla.host.set_drywet(self.fPluginId, value)
  155. elif parameterId == PARAMETER_VOLUME:
  156. if (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) == 0: return
  157. Carla.host.set_volume(self.fPluginId, value)
  158. elif parameterId == PARAMETER_BALANCE_LEFT:
  159. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  160. Carla.host.set_balance_left(self.fPluginId, value)
  161. elif parameterId == PARAMETER_BALANCE_RIGHT:
  162. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  163. Carla.host.set_balance_right(self.fPluginId, value)
  164. elif parameterId == PARAMETER_PANNING:
  165. if (self.fPluginInfo['hints'] & PLUGIN_CAN_PANNING) == 0: return
  166. Carla.host.set_panning(self.fPluginId, value)
  167. elif parameterId == PARAMETER_CTRL_CHANNEL:
  168. Carla.host.set_ctrl_channel(self.fPluginId, value)
  169. self.fEditDialog.setParameterValue(parameterId, value)
  170. #------------------------------------------------------------------
  171. def setParameterValue(self, parameterId, value, sendCallback):
  172. self.fParameterIconTimer = ICON_STATE_ON
  173. if parameterId == PARAMETER_ACTIVE:
  174. return self.setActive(bool(value), True, False)
  175. self.fEditDialog.setParameterValue(parameterId, value)
  176. if sendCallback:
  177. self.parameterValueChanged(parameterId, value)
  178. def setParameterDefault(self, parameterId, value):
  179. self.fEditDialog.setParameterDefault(parameterId, value)
  180. def setParameterMidiControl(self, parameterId, control):
  181. self.fEditDialog.setParameterMidiControl(parameterId, control)
  182. def setParameterMidiChannel(self, parameterId, channel):
  183. self.fEditDialog.setParameterMidiChannel(parameterId, channel)
  184. #------------------------------------------------------------------
  185. def setProgram(self, index, sendCallback):
  186. self.fParameterIconTimer = ICON_STATE_ON
  187. self.fEditDialog.setProgram(index)
  188. if sendCallback:
  189. self.programChanged(index)
  190. def setMidiProgram(self, index, sendCallback):
  191. self.fParameterIconTimer = ICON_STATE_ON
  192. self.fEditDialog.setMidiProgram(index)
  193. if sendCallback:
  194. self.midiProgramChanged(index)
  195. #------------------------------------------------------------------
  196. def sendNoteOn(self, channel, note):
  197. if self.fEditDialog.sendNoteOn(channel, note):
  198. self.midiActivityChanged(True)
  199. def sendNoteOff(self, channel, note):
  200. if self.fEditDialog.sendNoteOff(channel, note):
  201. self.midiActivityChanged(False)
  202. #------------------------------------------------------------------
  203. def activeChanged(self, onOff):
  204. self.fIsActive = onOff
  205. if self.b_enable is None:
  206. return
  207. self.b_enable.blockSignals(True)
  208. self.b_enable.setChecked(onOff)
  209. self.b_enable.blockSignals(False)
  210. def editDialogChanged(self, visible):
  211. if self.b_edit is None:
  212. return
  213. self.b_edit.blockSignals(True)
  214. self.b_edit.setChecked(visible)
  215. self.b_edit.blockSignals(False)
  216. def customUiStateChanged(self, state):
  217. if self.b_gui is None:
  218. return
  219. self.b_gui.blockSignals(True)
  220. if state == 0:
  221. self.b_gui.setChecked(False)
  222. self.b_gui.setEnabled(True)
  223. elif state == 1:
  224. self.b_gui.setChecked(True)
  225. self.b_gui.setEnabled(True)
  226. elif state == -1:
  227. self.b_gui.setChecked(False)
  228. self.b_gui.setEnabled(False)
  229. self.b_gui.blockSignals(False)
  230. def parameterActivityChanged(self, onOff):
  231. if self.led_control is None:
  232. return
  233. self.led_control.setChecked(onOff)
  234. def midiActivityChanged(self, onOff):
  235. if self.led_midi is None:
  236. return
  237. self.led_midi.setChecked(onOff)
  238. def parameterValueChanged(self, parameterId, value):
  239. for paramIndex, paramWidget in self.fParameterList:
  240. if paramIndex != parameterId:
  241. continue
  242. paramWidget.blockSignals(True)
  243. paramWidget.setValue(value*1000)
  244. paramWidget.blockSignals(False)
  245. break
  246. def programChanged(self, index):
  247. if self.cb_presets is None:
  248. return
  249. self.cb_presets.blockSignals(True)
  250. self.cb_presets.setCurrentIndex(index)
  251. self.cb_presets.blockSignals(False)
  252. def midiProgramChanged(self, index):
  253. if self.cb_presets is None:
  254. return
  255. self.cb_presets.blockSignals(True)
  256. self.cb_presets.setCurrentIndex(index)
  257. self.cb_presets.blockSignals(False)
  258. def notePressed(self, note):
  259. pass
  260. def noteReleased(self, note):
  261. pass
  262. #------------------------------------------------------------------
  263. def idleFast(self):
  264. # Input peaks
  265. if self.fPeaksInputCount > 0:
  266. if self.fPeaksInputCount > 1:
  267. peak1 = Carla.host.get_input_peak_value(self.fPluginId, True)
  268. peak2 = Carla.host.get_input_peak_value(self.fPluginId, False)
  269. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  270. if self.peak_in is not None:
  271. self.peak_in.displayMeter(1, peak1)
  272. self.peak_in.displayMeter(2, peak2)
  273. else:
  274. peak = Carla.host.get_input_peak_value(self.fPluginId, True)
  275. ledState = bool(peak != 0.0)
  276. if self.peak_in is not None:
  277. self.peak_in.displayMeter(1, peak)
  278. if self.fLastGreenLedState != ledState and self.led_audio_in is not None:
  279. self.fLastGreenLedState = ledState
  280. self.led_audio_in.setChecked(ledState)
  281. # Output peaks
  282. if self.fPeaksOutputCount > 0:
  283. if self.fPeaksOutputCount > 1:
  284. peak1 = Carla.host.get_output_peak_value(self.fPluginId, True)
  285. peak2 = Carla.host.get_output_peak_value(self.fPluginId, False)
  286. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  287. if self.peak_out is not None:
  288. self.peak_out.displayMeter(1, peak1)
  289. self.peak_out.displayMeter(2, peak2)
  290. else:
  291. peak = Carla.host.get_output_peak_value(self.fPluginId, True)
  292. ledState = bool(peak != 0.0)
  293. if self.peak_out is not None:
  294. self.peak_out.displayMeter(1, peak)
  295. if self.fLastBlueLedState != ledState and self.led_audio_out is not None:
  296. self.fLastBlueLedState = ledState
  297. self.led_audio_out.setChecked(ledState)
  298. def idleSlow(self):
  299. if self.fParameterIconTimer == ICON_STATE_ON:
  300. self.fParameterIconTimer = ICON_STATE_WAIT
  301. self.parameterActivityChanged(True)
  302. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  303. self.fParameterIconTimer = ICON_STATE_OFF
  304. elif self.fParameterIconTimer == ICON_STATE_OFF:
  305. self.fParameterIconTimer = ICON_STATE_NULL
  306. self.parameterActivityChanged(False)
  307. self.fEditDialog.idleSlow()
  308. #------------------------------------------------------------------
  309. def showDefaultCustomMenu(self, isEnabled, bEdit = None, bGui = None):
  310. menu = QMenu(self)
  311. actActive = menu.addAction(self.tr("Disable") if isEnabled else self.tr("Enable"))
  312. menu.addSeparator()
  313. if bEdit is not None:
  314. actEdit = menu.addAction(self.tr("Edit"))
  315. actEdit.setCheckable(True)
  316. actEdit.setChecked(bEdit.isChecked())
  317. else:
  318. actEdit = None
  319. if bGui is not None:
  320. actGui = menu.addAction(self.tr("Show Custom UI"))
  321. actGui.setCheckable(True)
  322. actGui.setChecked(bGui.isChecked())
  323. actGui.setEnabled(bGui.isEnabled())
  324. else:
  325. actGui = None
  326. menu.addSeparator()
  327. actClone = menu.addAction(self.tr("Clone"))
  328. actRename = menu.addAction(self.tr("Rename..."))
  329. actRemove = menu.addAction(self.tr("Remove"))
  330. actSel = menu.exec_(QCursor.pos())
  331. if not actSel:
  332. return
  333. if actSel == actActive:
  334. self.setActive(not isEnabled, True, True)
  335. elif actSel == actGui:
  336. bGui.click()
  337. elif actSel == actEdit:
  338. bEdit.click()
  339. elif actSel == actClone:
  340. if Carla.host is not None and not Carla.host.clone_plugin(self.fPluginId):
  341. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  342. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  343. elif actSel == actRename:
  344. oldName = self.fPluginInfo['name']
  345. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  346. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  347. return
  348. newName = newNameTry[0]
  349. if Carla.host is None or Carla.host.rename_plugin(self.fPluginId, newName):
  350. self.setName(newName)
  351. else:
  352. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  353. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  354. elif actSel == actRemove:
  355. if Carla.host is not None and not Carla.host.remove_plugin(self.fPluginId):
  356. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  357. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  358. #------------------------------------------------------------------
  359. @pyqtSlot(bool)
  360. def slot_enableClicked(self, yesNo):
  361. self.setActive(yesNo, False, True)
  362. @pyqtSlot()
  363. def slot_showDefaultCustomMenu(self):
  364. self.showDefaultCustomMenu(self.fIsActive, self.b_edit, self.b_gui)
  365. #------------------------------------------------------------------
  366. @pyqtSlot(bool)
  367. def slot_showCustomUi(self, show):
  368. Carla.host.show_custom_ui(self.fPluginId, show)
  369. @pyqtSlot(bool)
  370. def slot_showEditDialog(self, show):
  371. self.fEditDialog.setVisible(show)
  372. @pyqtSlot()
  373. def slot_removePlugin(self):
  374. Carla.host.remove_plugin(self.fPluginId)
  375. #------------------------------------------------------------------
  376. @pyqtSlot(int)
  377. def slot_parameterValueChanged(self, value):
  378. index = self.sender().getIndex()
  379. value = float(value)/1000.0
  380. Carla.host.set_parameter_value(self.fPluginId, index, value)
  381. self.setParameterValue(index, value, False)
  382. @pyqtSlot(int)
  383. def slot_programChanged(self, index):
  384. Carla.host.set_program(self.fPluginId, index)
  385. self.setProgram(index, False)
  386. @pyqtSlot(int)
  387. def slot_midiProgramChanged(self, index):
  388. Carla.host.set_midi_program(self.fPluginId, index)
  389. self.setMidiProgram(index, False)
  390. # ------------------------------------------------------------------------------------------------------------
  391. class PluginSlot_Default(AbstractPluginSlot):
  392. def __init__(self, parent, pluginId):
  393. AbstractPluginSlot.__init__(self, parent, pluginId)
  394. self.ui = ui_carla_plugin_default.Ui_PluginWidget()
  395. self.ui.setupUi(self)
  396. # -------------------------------------------------------------
  397. # Internal stuff
  398. if self.palette().window().color().lightness() > 100:
  399. # Light background
  400. labelColor = "333"
  401. isLight = True
  402. self.fColorTop = QColor(60, 60, 60)
  403. self.fColorBottom = QColor(47, 47, 47)
  404. self.fColorSeprtr = QColor(70, 70, 70)
  405. else:
  406. # Dark background
  407. labelColor = "BBB"
  408. isLight = False
  409. self.fColorTop = QColor(60, 60, 60)
  410. self.fColorBottom = QColor(47, 47, 47)
  411. self.fColorSeprtr = QColor(70, 70, 70)
  412. # -------------------------------------------------------------
  413. # Set-up GUI
  414. self.setStyleSheet("""
  415. QLabel#label_name {
  416. color: #%s;
  417. }""" % labelColor)
  418. if isLight:
  419. self.ui.b_enable.setPixmaps(":/bitmaps/button_off2.png", ":/bitmaps/button_on2.png", ":/bitmaps/button_off2.png")
  420. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit2.png", ":/bitmaps/button_edit_down2.png", ":/bitmaps/button_edit_hover2.png")
  421. if self.fPluginInfo['iconName'] == "distrho":
  422. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho2.png", ":/bitmaps/button_distrho_down2.png", ":/bitmaps/button_distrho_hover2.png")
  423. elif self.fPluginInfo['iconName'] == "file":
  424. self.ui.b_gui.setPixmaps(":/bitmaps/button_file2.png", ":/bitmaps/button_file_down2.png", ":/bitmaps/button_file_hover2.png")
  425. else:
  426. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui2.png", ":/bitmaps/button_gui_down2.png", ":/bitmaps/button_gui_hover2.png")
  427. else:
  428. self.ui.b_enable.setPixmaps(":/bitmaps/button_off.png", ":/bitmaps/button_on.png", ":/bitmaps/button_off.png")
  429. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit.png", ":/bitmaps/button_edit_down.png", ":/bitmaps/button_edit_hover.png")
  430. if self.fPluginInfo['iconName'] == "distrho":
  431. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho.png", ":/bitmaps/button_distrho_down.png", ":/bitmaps/button_distrho_hover.png")
  432. elif self.fPluginInfo['iconName'] == "file":
  433. self.ui.b_gui.setPixmaps(":/bitmaps/button_file.png", ":/bitmaps/button_file_down.png", ":/bitmaps/button_file_hover.png")
  434. else:
  435. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui.png", ":/bitmaps/button_gui_down.png", ":/bitmaps/button_gui_hover.png")
  436. # -------------------------------------------------------------
  437. self.b_enable = self.ui.b_enable
  438. self.b_gui = self.ui.b_gui
  439. self.b_edit = self.ui.b_edit
  440. self.label_name = self.ui.label_name
  441. self.led_control = self.ui.led_control
  442. self.led_midi = self.ui.led_midi
  443. self.led_audio_in = self.ui.led_audio_in
  444. self.led_audio_out = self.ui.led_audio_out
  445. self.peak_in = self.ui.peak_in
  446. self.peak_out = self.ui.peak_out
  447. self.ready()
  448. self.customContextMenuRequested.connect(self.slot_showDefaultCustomMenu)
  449. #------------------------------------------------------------------
  450. def getFixedHeight(self):
  451. return 48
  452. #------------------------------------------------------------------
  453. def paintEvent(self, event):
  454. painter = QPainter(self)
  455. painter.save()
  456. areaX = self.ui.area_right.x()+7
  457. width = self.width()
  458. height = self.height()
  459. painter.setPen(self.fColorSeprtr.lighter(110))
  460. painter.setBrush(self.fColorBottom)
  461. painter.setRenderHint(QPainter.Antialiasing, True)
  462. # name -> leds arc
  463. path = QPainterPath()
  464. path.moveTo(areaX-20, height-4)
  465. path.cubicTo(areaX, height-5, areaX-20, 4.75, areaX, 4.75)
  466. path.lineTo(areaX, height-5)
  467. painter.drawPath(path)
  468. painter.setPen(self.fColorSeprtr)
  469. painter.setRenderHint(QPainter.Antialiasing, False)
  470. # separator lines
  471. painter.drawLine(0, height-5, areaX-20, height-5)
  472. painter.drawLine(areaX, 4, width, 4)
  473. painter.setPen(self.fColorBottom)
  474. painter.setBrush(self.fColorBottom)
  475. # top, bottom and left lines
  476. painter.drawLine(0, 0, width, 0)
  477. painter.drawRect(0, height-4, areaX, 4)
  478. painter.drawRoundedRect(areaX-20, height-5, areaX, 5, 22, 22)
  479. painter.drawLine(0, 0, 0, height)
  480. # fill the rest
  481. painter.drawRect(areaX-1, 5, width, height)
  482. # bottom 1px line
  483. painter.setPen(self.fColorSeprtr)
  484. painter.drawLine(0, height-1, width, height-1)
  485. painter.restore()
  486. AbstractPluginSlot.paintEvent(self, event)
  487. # ------------------------------------------------------------------------------------------------------------
  488. class PluginSlot_Calf(AbstractPluginSlot):
  489. def __init__(self, parent, pluginId):
  490. AbstractPluginSlot.__init__(self, parent, pluginId)
  491. self.ui = ui_carla_plugin_calf.Ui_PluginWidget()
  492. self.ui.setupUi(self)
  493. # -------------------------------------------------------------
  494. # Internal stuff
  495. self.fButtonFont = QFont()
  496. self.fButtonFont.setBold(False)
  497. self.fButtonFont.setPointSize(9)
  498. self.fButtonColorOn = QColor( 18, 41, 87)
  499. self.fButtonColorOff = QColor(150, 150, 150)
  500. # -------------------------------------------------------------
  501. # Set-up GUI
  502. self.setStyleSheet("""
  503. QLabel#label_name, QLabel#label_audio_in, QLabel#label_audio_out, QLabel#label_midi {
  504. color: black;
  505. }
  506. QFrame#PluginWidget {
  507. background-image: url(:/bitmaps/background_calf.png);
  508. background-repeat: repeat-xy;
  509. }""")
  510. self.ui.b_gui.setPixmaps(":/bitmaps/button_calf2.png", ":/bitmaps/button_calf2_down.png", ":/bitmaps/button_calf2_hover.png")
  511. self.ui.b_edit.setPixmaps(":/bitmaps/button_calf2.png", ":/bitmaps/button_calf2_down.png", ":/bitmaps/button_calf2_hover.png")
  512. self.ui.b_remove.setPixmaps(":/bitmaps/button_calf1.png", ":/bitmaps/button_calf1_down.png", ":/bitmaps/button_calf1_hover.png")
  513. self.ui.b_edit.setTopText(self.tr("Edit"), self.fButtonColorOn, self.fButtonFont)
  514. self.ui.b_remove.setTopText(self.tr("Remove"), self.fButtonColorOn, self.fButtonFont)
  515. if self.fPluginInfo['hints'] & PLUGIN_HAS_CUSTOM_UI:
  516. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  517. else:
  518. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  519. labelFont = self.ui.label_name.font()
  520. labelFont.setBold(True)
  521. labelFont.setPointSize(labelFont.pointSize()+3)
  522. self.ui.label_name.setFont(labelFont)
  523. audioCount = Carla.host.get_audio_port_count_info(self.fPluginId) if Carla.host is not None else {'ins': 2, 'outs': 2 }
  524. midiCount = Carla.host.get_midi_port_count_info(self.fPluginId) if Carla.host is not None else {'ins': 1, 'outs': 0 }
  525. if audioCount['ins'] == 0:
  526. self.ui.label_audio_in.hide()
  527. self.ui.peak_in.hide()
  528. if audioCount['outs'] > 0:
  529. self.ui.peak_out.setMinimumWidth(200)
  530. if audioCount['outs'] == 0:
  531. self.ui.label_audio_out.hide()
  532. self.ui.peak_out.hide()
  533. if midiCount['ins'] == 0:
  534. self.ui.label_midi.hide()
  535. self.ui.led_midi.hide()
  536. # -------------------------------------------------------------
  537. self.b_gui = self.ui.b_gui
  538. self.b_edit = self.ui.b_edit
  539. self.b_remove = self.ui.b_remove
  540. self.label_name = self.ui.label_name
  541. self.led_midi = self.ui.led_midi
  542. self.peak_in = self.ui.peak_in
  543. self.peak_out = self.ui.peak_out
  544. self.ready()
  545. self.ui.led_midi.setColor(self.ui.led_midi.CALF)
  546. self.customContextMenuRequested.connect(self.slot_showDefaultCustomMenu)
  547. #------------------------------------------------------------------
  548. def getFixedHeight(self):
  549. return 75
  550. #------------------------------------------------------------------
  551. def recheckPluginHints(self, hints):
  552. if hints & PLUGIN_HAS_CUSTOM_UI:
  553. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOn, self.fButtonFont)
  554. else:
  555. self.ui.b_gui.setTopText(self.tr("GUI"), self.fButtonColorOff, self.fButtonFont)
  556. AbstractPluginSlot.recheckPluginHints(self, hints)
  557. # ------------------------------------------------------------------------------------------------------------
  558. class PluginSlot_Zita(AbstractPluginSlot):
  559. def __init__(self, parent, pluginId):
  560. AbstractPluginSlot.__init__(self, parent, pluginId)
  561. self.ui = ui_carla_plugin_zita.Ui_PluginWidget()
  562. self.ui.setupUi(self)
  563. # -------------------------------------------------------------
  564. # Internal stuff
  565. audioCount = Carla.host.get_audio_port_count_info(self.fPluginId) if Carla.host is not None else {'ins': 2, 'outs': 2 }
  566. # -------------------------------------------------------------
  567. # Set-up GUI
  568. self.setMinimumWidth(640)
  569. self.setStyleSheet("""
  570. QFrame#PluginWidget {
  571. background-color: #404040;
  572. }
  573. QWidget#w_revsect {
  574. background-image: url(:/bitmaps/zita/revsect.png);
  575. }
  576. QWidget#w_eq1sect {
  577. background-image: url(:/bitmaps/zita/eq1sect.png);
  578. }
  579. QWidget#w_eq2sect {
  580. background-image: url(:/bitmaps/zita/eq2sect.png);
  581. }
  582. QWidget#w_ambmixsect {
  583. background-image: url(:/bitmaps/zita/%s.png);
  584. }
  585. QWidget#w_redzita {
  586. background-image: url(:/bitmaps/zita/redzita.png);
  587. }
  588. """ % ("mixsect" if audioCount['outs'] == 2 else "ambsect"))
  589. # -------------------------------------------------------------
  590. # Set-up Knobs
  591. self.fKnobDelay = PixmapDial(self, 0)
  592. self.fKnobDelay.setPixmap(6)
  593. self.fKnobDelay.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  594. self.fKnobDelay.setMinimum(0.02*1000)
  595. self.fKnobDelay.setMaximum(0.10*1000)
  596. self.fKnobXover = PixmapDial(self, 1)
  597. self.fKnobXover.setPixmap(6)
  598. self.fKnobXover.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  599. self.fKnobXover.setMinimum(50*1000)
  600. self.fKnobXover.setMaximum(1000*1000)
  601. self.fKnobRtLow = PixmapDial(self, 2)
  602. self.fKnobRtLow.setPixmap(6)
  603. self.fKnobRtLow.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  604. self.fKnobRtLow.setMinimum(1*1000)
  605. self.fKnobRtLow.setMaximum(8*1000)
  606. self.fKnobRtMid = PixmapDial(self, 3)
  607. self.fKnobRtMid.setPixmap(6)
  608. self.fKnobRtMid.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  609. self.fKnobRtMid.setMinimum(1*1000)
  610. self.fKnobRtMid.setMaximum(8*1000)
  611. self.fKnobDamping = PixmapDial(self, 4)
  612. self.fKnobDamping.setPixmap(6)
  613. self.fKnobDamping.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  614. self.fKnobDamping.setMinimum(1500*1000)
  615. self.fKnobDamping.setMaximum(24000*1000)
  616. self.fKnobEq1Freq = PixmapDial(self, 5)
  617. self.fKnobEq1Freq.setPixmap(6)
  618. self.fKnobEq1Freq.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  619. self.fKnobEq1Freq.setMinimum(40*1000)
  620. self.fKnobEq1Freq.setMaximum(10000*1000)
  621. self.fKnobEq1Gain = PixmapDial(self, 6)
  622. self.fKnobEq1Gain.setPixmap(6)
  623. self.fKnobEq1Gain.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  624. self.fKnobEq1Gain.setMinimum(-20*1000)
  625. self.fKnobEq1Gain.setMaximum(20*1000)
  626. self.fKnobEq2Freq = PixmapDial(self, 7)
  627. self.fKnobEq2Freq.setPixmap(6)
  628. self.fKnobEq2Freq.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  629. self.fKnobEq2Freq.setMinimum(40*1000)
  630. self.fKnobEq2Freq.setMaximum(10000*1000)
  631. self.fKnobEq2Gain = PixmapDial(self, 8)
  632. self.fKnobEq2Gain.setPixmap(6)
  633. self.fKnobEq2Gain.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  634. self.fKnobEq2Gain.setMinimum(-20*1000)
  635. self.fKnobEq2Gain.setMaximum(20*1000)
  636. self.fKnobMix = PixmapDial(self, 9)
  637. self.fKnobMix.setPixmap(6)
  638. self.fKnobMix.setCustomPaint(PixmapDial.CUSTOM_PAINT_ZITA)
  639. self.fKnobMix.setMinimum(0.0*1000)
  640. self.fKnobMix.setMaximum(1.0*1000)
  641. self.fParameterList.append([0, self.fKnobDelay])
  642. self.fParameterList.append([1, self.fKnobXover])
  643. self.fParameterList.append([2, self.fKnobRtLow])
  644. self.fParameterList.append([3, self.fKnobRtMid])
  645. self.fParameterList.append([4, self.fKnobDamping])
  646. self.fParameterList.append([5, self.fKnobEq1Freq])
  647. self.fParameterList.append([6, self.fKnobEq1Gain])
  648. self.fParameterList.append([7, self.fKnobEq2Freq])
  649. self.fParameterList.append([8, self.fKnobEq2Gain])
  650. self.fParameterList.append([9, self.fKnobMix])
  651. # -------------------------------------------------------------
  652. self.ready()
  653. self.customContextMenuRequested.connect(self.slot_showDefaultCustomMenu)
  654. #------------------------------------------------------------------
  655. def getFixedHeight(self):
  656. return 75
  657. def resizeEvent(self, event):
  658. self.fKnobDelay.move(self.ui.w_revsect.x()+31, 33)
  659. self.fKnobXover.move(self.ui.w_revsect.x()+93, 18)
  660. self.fKnobRtLow.move(self.ui.w_revsect.x()+148, 18)
  661. self.fKnobRtMid.move(self.ui.w_revsect.x()+208, 18)
  662. self.fKnobDamping.move(self.ui.w_revsect.x()+268, 18)
  663. self.fKnobEq1Freq.move(self.ui.w_eq1sect.x()+20, 33)
  664. self.fKnobEq1Gain.move(self.ui.w_eq1sect.x()+69, 18)
  665. self.fKnobEq2Freq.move(self.ui.w_eq2sect.x()+20, 33)
  666. self.fKnobEq2Gain.move(self.ui.w_eq2sect.x()+69, 18)
  667. self.fKnobMix.move(self.ui.w_ambmixsect.x()+24, 33)
  668. AbstractPluginSlot.resizeEvent(self, event)
  669. # ------------------------------------------------------------------------------------------------------------
  670. class PluginSlot_ZynFX(AbstractPluginSlot):
  671. def __init__(self, parent, pluginId):
  672. AbstractPluginSlot.__init__(self, parent, pluginId)
  673. self.ui = ui_carla_plugin_zynfx.Ui_PluginWidget()
  674. self.ui.setupUi(self)
  675. # -------------------------------------------------------------
  676. # Set-up GUI
  677. self.setStyleSheet("""
  678. QFrame#PluginWidget {
  679. background-image: url(:/bitmaps/background_zynfx.png);
  680. background-repeat: repeat-xy;
  681. }""")
  682. self.ui.b_enable.setPixmaps(":/bitmaps/button_off.png", ":/bitmaps/button_on.png", ":/bitmaps/button_off.png")
  683. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit.png", ":/bitmaps/button_edit_down.png", ":/bitmaps/button_edit_hover.png")
  684. # -------------------------------------------------------------
  685. # Set-up parameters
  686. parameterCount = Carla.host.get_parameter_count(self.fPluginId) if Carla.host is not None else 0
  687. index = 0
  688. for i in range(parameterCount):
  689. paramInfo = Carla.host.get_parameter_info(self.fPluginId, i)
  690. paramData = Carla.host.get_parameter_data(self.fPluginId, i)
  691. paramRanges = Carla.host.get_parameter_ranges(self.fPluginId, i)
  692. if paramData['type'] != PARAMETER_INPUT:
  693. continue
  694. paramName = charPtrToString(paramInfo['name'])
  695. paramLow = paramName.lower()
  696. # real zyn fx plugins
  697. if self.fPluginInfo['label'] == "zynAlienWah":
  698. if i == 0: paramName = "Freq"
  699. elif i == 1: paramName = "Rnd"
  700. elif i == 2: paramName = "L type" # combobox
  701. elif i == 3: paramName = "St.df"
  702. elif i == 5: paramName = "Fb"
  703. elif i == 7: paramName = "L/R"
  704. if self.fPluginInfo['label'] == "zynChorus":
  705. if i == 0: paramName = "Freq"
  706. elif i == 1: paramName = "Rnd"
  707. elif i == 2: paramName = "L type" # combobox
  708. elif i == 3: paramName = "St.df"
  709. elif i == 6: paramName = "Fb"
  710. elif i == 7: paramName = "L/R"
  711. elif i == 8: paramName = "Flngr" # button
  712. elif i == 9: paramName = "Subst" # button
  713. elif self.fPluginInfo['label'] == "zynDistortion":
  714. if i == 0: paramName = "LRc."
  715. elif i == 4: paramName = "Neg." # button
  716. elif i == 5: paramName = "LPF"
  717. elif i == 6: paramName = "HPF"
  718. elif i == 7: paramName = "St." # button
  719. elif i == 8: paramName = "PF" # button
  720. elif self.fPluginInfo['label'] == "zynDynamicFilter":
  721. if i == 0: paramName = "Freq"
  722. elif i == 1: paramName = "Rnd"
  723. elif i == 2: paramName = "L type" # combobox
  724. elif i == 3: paramName = "St.df"
  725. elif i == 4: paramName = "LfoD"
  726. elif i == 5: paramName = "A.S."
  727. elif i == 6: paramName = "A.Inv." # button
  728. elif i == 7: paramName = "A.M."
  729. elif self.fPluginInfo['label'] == "zynEcho":
  730. if i == 1: paramName = "LRdl."
  731. elif i == 2: paramName = "LRc."
  732. elif i == 3: paramName = "Fb."
  733. elif i == 4: paramName = "Damp"
  734. elif self.fPluginInfo['label'] == "zynPhaser":
  735. if i == 0: paramName = "Freq"
  736. elif i == 1: paramName = "Rnd"
  737. elif i == 2: paramName = "L type" # combobox
  738. elif i == 3: paramName = "St.df"
  739. elif i == 5: paramName = "Fb"
  740. elif i == 7: paramName = "L/R"
  741. elif i == 8: paramName = "Subst" # button
  742. elif i == 9: paramName = "Phase"
  743. elif i == 11: paramName = "Dist"
  744. elif self.fPluginInfo['label'] == "zynReverb":
  745. if i == 2: paramName = "I.delfb"
  746. elif i == 5: paramName = "LPF"
  747. elif i == 6: paramName = "HPF"
  748. elif i == 9: paramName = "R.S."
  749. elif i == 10: paramName = "I.del"
  750. #elif paramLow.find("damp"):
  751. #paramName = "Damp"
  752. #elif paramLow.find("frequency"):
  753. #paramName = "Freq"
  754. # Cut generic names
  755. #elif paramName == "Depth": paramName = "Dpth"
  756. #elif paramName == "Feedback": paramName = "Fb"
  757. #elif paramName == "L/R Cross": #paramName = "L/R"
  758. #elif paramName == "Random": paramName = "Rnd"
  759. widget = PixmapDial(self, i)
  760. widget.setPixmap(5)
  761. widget.setLabel(paramName)
  762. widget.setCustomPaint(PixmapDial.CUSTOM_PAINT_NO_GRADIENT)
  763. widget.setSingleStep(paramRanges['step']*1000)
  764. widget.setMinimum(paramRanges['min']*1000)
  765. widget.setMaximum(paramRanges['max']*1000)
  766. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  767. widget.setEnabled(False)
  768. self.ui.container.layout().insertWidget(index, widget)
  769. index += 1
  770. self.fParameterList.append([i, widget])
  771. # -------------------------------------------------------------
  772. # Set-up MIDI programs
  773. midiProgramCount = Carla.host.get_midi_program_count(self.fPluginId) if Carla.host is not None else 0
  774. if midiProgramCount > 0:
  775. self.ui.cb_presets.setEnabled(True)
  776. self.ui.label_presets.setEnabled(True)
  777. for i in range(midiProgramCount):
  778. mpData = Carla.host.get_midi_program_data(self.fPluginId, i)
  779. mpName = charPtrToString(mpData['name'])
  780. self.ui.cb_presets.addItem(mpName)
  781. self.fCurrentMidiProgram = Carla.host.get_current_midi_program_index(self.fPluginId)
  782. self.ui.cb_presets.setCurrentIndex(self.fCurrentMidiProgram)
  783. else:
  784. self.fCurrentMidiProgram = -1
  785. self.ui.cb_presets.setEnabled(False)
  786. self.ui.cb_presets.setVisible(False)
  787. self.ui.label_presets.setEnabled(False)
  788. self.ui.label_presets.setVisible(False)
  789. # -------------------------------------------------------------
  790. self.b_enable = self.ui.b_enable
  791. self.b_edit = self.ui.b_edit
  792. self.cb_presets = self.ui.cb_presets
  793. self.label_name = self.ui.label_name
  794. self.peak_in = self.ui.peak_in
  795. self.peak_out = self.ui.peak_out
  796. self.ready()
  797. self.peak_in.setOrientation(self.peak_in.VERTICAL)
  798. self.peak_out.setOrientation(self.peak_out.VERTICAL)
  799. self.customContextMenuRequested.connect(self.slot_showDefaultCustomMenu)
  800. self.ui.cb_presets.currentIndexChanged.connect(self.slot_midiProgramChanged)
  801. #------------------------------------------------------------------
  802. def getFixedHeight(self):
  803. return 70
  804. # ------------------------------------------------------------------------------------------------------------
  805. def createPluginSlot(parent, pluginId):
  806. pluginInfo = Carla.host.get_plugin_info(pluginId)
  807. pluginName = Carla.host.get_real_plugin_name(pluginId)
  808. pluginLabel = charPtrToString(pluginInfo['label'])
  809. uniqueId = int(pluginInfo['uniqueId'])
  810. #pluginMaker = charPtrToString(pluginInfo['maker'])
  811. #pluginIcon = charPtrToString(pluginInfo['iconName'])
  812. if pluginInfo['type'] == PLUGIN_INTERNAL:
  813. if pluginLabel.startswith("zyn") and pluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  814. return PluginSlot_ZynFX(parent, pluginId)
  815. if pluginInfo['type'] == PLUGIN_LADSPA:
  816. if (pluginLabel == "zita-reverb" and uniqueId == 3701) or (pluginLabel == "zita-reverb-amb" and uniqueId == 3702):
  817. return PluginSlot_Zita(parent, pluginId)
  818. if pluginName.split(" ", 1)[0].lower() == "calf":
  819. return PluginSlot_Calf(parent, pluginId)
  820. #return PluginSlot_Pixmap(parent, pluginId)
  821. return PluginSlot_Default(parent, pluginId)
  822. # ------------------------------------------------------------------------------------------------------------
  823. # Main Testing
  824. if __name__ == '__main__':
  825. from carla_style import CarlaApplication
  826. import resources_rc
  827. app = CarlaApplication("Carla-Skins")
  828. gui = PluginSlot_Pixmap(None, 0)
  829. #gui = PluginSlot_Calf(None, 0)
  830. #gui = PluginSlot_ZynFX(None, 0)
  831. gui.show()
  832. app.exec_()
  833. #if (self.pinfo['category'] == PLUGIN_CATEGORY_SYNTH):
  834. #self.set_plugin_widget_color(PALETTE_COLOR_WHITE)
  835. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_DELAY):
  836. #self.set_plugin_widget_color(PALETTE_COLOR_ORANGE)
  837. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_EQ):
  838. #self.set_plugin_widget_color(PALETTE_COLOR_GREEN)
  839. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_FILTER):
  840. #self.set_plugin_widget_color(PALETTE_COLOR_BLUE)
  841. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_DYNAMICS):
  842. #self.set_plugin_widget_color(PALETTE_COLOR_PINK)
  843. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_MODULATOR):
  844. #self.set_plugin_widget_color(PALETTE_COLOR_RED)
  845. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_UTILITY):
  846. #self.set_plugin_widget_color(PALETTE_COLOR_YELLOW)
  847. #elif (self.pinfo['category'] == PLUGIN_CATEGORY_OUTRO):
  848. #self.set_plugin_widget_color(PALETTE_COLOR_BROWN)
  849. #else:
  850. #self.set_plugin_widget_color(PALETTE_COLOR_NONE)