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.

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