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.

1607 lines
64KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla widgets code
  4. # Copyright (C) 2011-2013 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. try:
  20. from PyQt5.QtCore import QByteArray
  21. from PyQt5.QtGui import QColor, QCursor, QFontMetrics, QPainter, QPainterPath
  22. from PyQt5.QtWidgets import QDialog, QFrame, QInputDialog, QLineEdit, QMenu, QVBoxLayout, QWidget
  23. except:
  24. from PyQt4.QtCore import QByteArray
  25. from PyQt4.QtGui import QColor, QCursor, QFontMetrics, QPainter, QPainterPath
  26. from PyQt4.QtGui import QDialog, QFrame, QInputDialog, QLineEdit, QMenu, QVBoxLayout, QWidget
  27. # ------------------------------------------------------------------------------------------------------------
  28. # Imports (Custom)
  29. import ui_carla_about
  30. import ui_carla_edit
  31. import ui_carla_parameter
  32. import ui_carla_plugin
  33. from carla_shared import *
  34. # ------------------------------------------------------------------------------------------------------------
  35. # Carla GUI defines
  36. ICON_STATE_NULL = 0
  37. ICON_STATE_OFF = 1
  38. ICON_STATE_WAIT = 2
  39. ICON_STATE_ON = 3
  40. # ------------------------------------------------------------------------------------------------------------
  41. # Carla About dialog
  42. class CarlaAboutW(QDialog):
  43. def __init__(self, parent):
  44. QDialog.__init__(self, parent)
  45. self.ui = ui_carla_about.Ui_CarlaAboutW()
  46. self.ui.setupUi(self)
  47. if Carla.isControl:
  48. extraInfo = " - <b>%s</b>" % self.tr("OSC Bridge Version")
  49. else:
  50. extraInfo = ""
  51. self.ui.l_about.setText(self.tr(""
  52. "<br>Version %s"
  53. "<br>Carla is a Multi-Plugin Host for JACK%s.<br>"
  54. "<br>Copyright (C) 2011-2013 falkTX<br>"
  55. "" % (VERSION, extraInfo)))
  56. if Carla.isControl:
  57. self.ui.l_extended.hide()
  58. self.ui.tabWidget.removeTab(1)
  59. self.ui.tabWidget.removeTab(1)
  60. self.adjustSize()
  61. else:
  62. self.ui.l_extended.setText(cString(Carla.host.get_extended_license_text()))
  63. if Carla.host.is_engine_running():
  64. self.ui.le_osc_url_tcp.setText(cString(Carla.host.get_host_osc_url_tcp()))
  65. self.ui.le_osc_url_udp.setText(cString(Carla.host.get_host_osc_url_udp()))
  66. else:
  67. self.ui.le_osc_url_tcp.setText(self.tr("(Engine not running)"))
  68. self.ui.le_osc_url_udp.setText(self.tr("(Engine not running)"))
  69. self.ui.l_osc_cmds.setText(""
  70. " /set_active <i-value>\n"
  71. " /set_drywet <f-value>\n"
  72. " /set_volume <f-value>\n"
  73. " /set_balance_left <f-value>\n"
  74. " /set_balance_right <f-value>\n"
  75. " /set_panning <f-value>\n"
  76. " /set_parameter_value <i-index> <f-value>\n"
  77. " /set_parameter_midi_cc <i-index> <i-cc>\n"
  78. " /set_parameter_midi_channel <i-index> <i-channel>\n"
  79. " /set_program <i-index>\n"
  80. " /set_midi_program <i-index>\n"
  81. " /note_on <i-note> <i-velo>\n"
  82. " /note_off <i-note>\n"
  83. )
  84. self.ui.l_example.setText("/Carla/2/set_parameter_value 5 1.0")
  85. self.ui.l_example_help.setText("<i>(as in this example, \"2\" is the plugin number and \"5\" the parameter)</i>")
  86. self.ui.l_ladspa.setText(self.tr("Everything! (Including LRDF)"))
  87. self.ui.l_dssi.setText(self.tr("Everything! (Including CustomData/Chunks)"))
  88. self.ui.l_lv2.setText(self.tr("About 80&#37; complete (using custom extensions)<br/>"
  89. "Implemented Feature/Extensions:"
  90. "<ul>"
  91. "<li>http://lv2plug.in/ns/ext/atom</li>"
  92. "<li>http://lv2plug.in/ns/ext/buf-size</li>"
  93. "<li>http://lv2plug.in/ns/ext/data-access</li>"
  94. #"<li>http://lv2plug.in/ns/ext/dynmanifest</li>"
  95. "<li>http://lv2plug.in/ns/ext/event</li>"
  96. "<li>http://lv2plug.in/ns/ext/instance-access</li>"
  97. "<li>http://lv2plug.in/ns/ext/log</li>"
  98. "<li>http://lv2plug.in/ns/ext/midi</li>"
  99. #"<li>http://lv2plug.in/ns/ext/morph</li>"
  100. "<li>http://lv2plug.in/ns/ext/options</li>"
  101. "<li>http://lv2plug.in/ns/ext/parameters</li>"
  102. #"<li>http://lv2plug.in/ns/ext/patch</li>"
  103. #"<li>http://lv2plug.in/ns/ext/port-groups</li>"
  104. #"<li>http://lv2plug.in/ns/ext/port-props</li>"
  105. "<li>http://lv2plug.in/ns/ext/presets</li>"
  106. #"<li>http://lv2plug.in/ns/ext/resize-port</li>"
  107. "<li>http://lv2plug.in/ns/ext/state</li>"
  108. "<li>http://lv2plug.in/ns/ext/time</li>"
  109. "<li>http://lv2plug.in/ns/ext/uri-map</li>"
  110. "<li>http://lv2plug.in/ns/ext/urid</li>"
  111. #"<li>http://lv2plug.in/ns/ext/worker</li>"
  112. "<li>http://lv2plug.in/ns/extensions/ui</li>"
  113. "<li>http://lv2plug.in/ns/extensions/units</li>"
  114. "<li>http://kxstudio.sf.net/ns/lv2ext/external-ui</li>"
  115. "<li>http://kxstudio.sf.net/ns/lv2ext/programs</li>"
  116. "<li>http://kxstudio.sf.net/ns/lv2ext/rtmempool</li>"
  117. "<li>http://ll-plugins.nongnu.org/lv2/ext/midimap</li>"
  118. "<li>http://ll-plugins.nongnu.org/lv2/ext/miditype</li>"
  119. "</ul>"))
  120. self.ui.l_vst.setText(self.tr("<p>About 85&#37; complete (missing vst bank/presets and some minor stuff)</p>"))
  121. def done(self, r):
  122. QDialog.done(self, r)
  123. self.close()
  124. # ------------------------------------------------------------------------------------------------------------
  125. # Plugin Parameter
  126. class PluginParameter(QWidget):
  127. midiControlChanged = pyqtSignal(int, int)
  128. midiChannelChanged = pyqtSignal(int, int)
  129. valueChanged = pyqtSignal(int, float)
  130. def __init__(self, parent, pInfo, pluginId, tabIndex):
  131. QWidget.__init__(self, parent)
  132. self.ui = ui_carla_parameter.Ui_PluginParameter()
  133. self.ui.setupUi(self)
  134. # -------------------------------------------------------------
  135. # Internal stuff
  136. self.fMidiControl = -1
  137. self.fMidiChannel = 1
  138. self.fParameterId = pInfo['index']
  139. self.fPluginId = pluginId
  140. self.fTabIndex = tabIndex
  141. # -------------------------------------------------------------
  142. # Set-up GUI
  143. pType = pInfo['type']
  144. pHints = pInfo['hints']
  145. self.ui.label.setText(pInfo['name'])
  146. self.ui.widget.setName(pInfo['name'])
  147. if pType == PARAMETER_INPUT:
  148. self.ui.widget.setMinimum(pInfo['minimum'])
  149. self.ui.widget.setMaximum(pInfo['maximum'])
  150. self.ui.widget.setDefault(pInfo['default'])
  151. self.ui.widget.setValue(pInfo['current'], False)
  152. self.ui.widget.setLabel(pInfo['unit'])
  153. self.ui.widget.setStep(pInfo['step'])
  154. self.ui.widget.setStepSmall(pInfo['stepSmall'])
  155. self.ui.widget.setStepLarge(pInfo['stepLarge'])
  156. self.ui.widget.setScalePoints(pInfo['scalePoints'], bool(pHints & PARAMETER_USES_SCALEPOINTS))
  157. if not pHints & PARAMETER_IS_ENABLED:
  158. self.ui.label.setEnabled(False)
  159. self.ui.widget.setEnabled(False)
  160. self.ui.widget.setReadOnly(True)
  161. self.ui.sb_control.setEnabled(False)
  162. self.ui.sb_channel.setEnabled(False)
  163. elif not pHints & PARAMETER_IS_AUTOMABLE:
  164. self.ui.sb_control.setEnabled(False)
  165. self.ui.sb_channel.setEnabled(False)
  166. if pHints & PARAMETER_IS_READ_ONLY:
  167. self.ui.widget.setReadOnly(True)
  168. elif pType == PARAMETER_OUTPUT:
  169. self.ui.widget.setMinimum(pInfo['minimum'])
  170. self.ui.widget.setMaximum(pInfo['maximum'])
  171. self.ui.widget.setValue(pInfo['current'], False)
  172. self.ui.widget.setLabel(pInfo['unit'])
  173. self.ui.widget.setReadOnly(True)
  174. if not pHints & PARAMETER_IS_AUTOMABLE:
  175. self.ui.sb_control.setEnabled(False)
  176. self.ui.sb_channel.setEnabled(False)
  177. else:
  178. self.ui.widget.setVisible(False)
  179. self.ui.sb_control.setVisible(False)
  180. self.ui.sb_channel.setVisible(False)
  181. if pHints & PARAMETER_USES_CUSTOM_TEXT:
  182. self.ui.widget.setTextCallback(self._textCallBack)
  183. self.ui.widget.updateAll()
  184. self.setMidiControl(pInfo['midiCC'])
  185. self.setMidiChannel(pInfo['midiChannel'])
  186. # -------------------------------------------------------------
  187. # Set-up connections
  188. self.ui.sb_control.customContextMenuRequested.connect(self.slot_controlSpinboxCustomMenu)
  189. self.ui.sb_channel.customContextMenuRequested.connect(self.slot_channelSpinboxCustomMenu)
  190. self.ui.sb_control.valueChanged.connect(self.slot_controlSpinboxChanged)
  191. self.ui.sb_channel.valueChanged.connect(self.slot_channelSpinboxChanged)
  192. self.ui.widget.valueChanged.connect(self.slot_widgetValueChanged)
  193. # -------------------------------------------------------------
  194. def pluginId(self):
  195. return self.fPluginId
  196. def tabIndex(self):
  197. return self.fTabIndex
  198. def setDefault(self, value):
  199. self.ui.widget.setDefault(value)
  200. def setValue(self, value, send=True):
  201. self.ui.widget.setValue(value, send)
  202. def setMidiControl(self, control):
  203. self.fMidiControl = control
  204. self.ui.sb_control.blockSignals(True)
  205. self.ui.sb_control.setValue(control)
  206. self.ui.sb_control.blockSignals(False)
  207. def setMidiChannel(self, channel):
  208. self.fMidiChannel = channel
  209. self.ui.sb_channel.blockSignals(True)
  210. self.ui.sb_channel.setValue(channel)
  211. self.ui.sb_channel.blockSignals(False)
  212. def setLabelWidth(self, width):
  213. self.ui.label.setMinimumWidth(width)
  214. self.ui.label.setMaximumWidth(width)
  215. @pyqtSlot()
  216. def slot_controlSpinboxCustomMenu(self):
  217. menu = QMenu(self)
  218. actNone = menu.addAction(self.tr("None"))
  219. if self.fMidiControl == -1:
  220. actNone.setCheckable(True)
  221. actNone.setChecked(True)
  222. for cc in MIDI_CC_LIST:
  223. action = menu.addAction(cc)
  224. if self.fMidiControl != -1 and int(cc.split(" ")[0], 16) == self.fMidiControl:
  225. action.setCheckable(True)
  226. action.setChecked(True)
  227. actSel = menu.exec_(QCursor.pos())
  228. if not actSel:
  229. pass
  230. elif actSel == actNone:
  231. self.ui.sb_control.setValue(-1)
  232. else:
  233. selControlStr = actSel.text()
  234. selControl = int(selControlStr.split(" ")[0], 16)
  235. self.ui.sb_control.setValue(selControl)
  236. @pyqtSlot()
  237. def slot_channelSpinboxCustomMenu(self):
  238. menu = QMenu(self)
  239. for i in range(1, 16+1):
  240. action = menu.addAction("%i" % i)
  241. if self.fMidiChannel == i:
  242. action.setCheckable(True)
  243. action.setChecked(True)
  244. actSel = menu.exec_(QCursor.pos())
  245. if actSel:
  246. selChannel = int(actSel.text())
  247. self.ui.sb_channel.setValue(selChannel)
  248. @pyqtSlot(int)
  249. def slot_controlSpinboxChanged(self, control):
  250. if self.fMidiControl != control:
  251. self.midiControlChanged.emit(self.fParameterId, control)
  252. self.fMidiControl = control
  253. @pyqtSlot(int)
  254. def slot_channelSpinboxChanged(self, channel):
  255. if self.fMidiChannel != channel:
  256. self.midiChannelChanged.emit(self.fParameterId, channel)
  257. self.fMidiChannel = channel
  258. @pyqtSlot(float)
  259. def slot_widgetValueChanged(self, value):
  260. self.valueChanged.emit(self.fParameterId, value)
  261. def _textCallBack(self):
  262. return cString(Carla.host.get_parameter_text(self.fPluginId, self.fParameterId))
  263. # ------------------------------------------------------------------------------------------------------------
  264. # Plugin Editor (Built-in)
  265. class PluginEdit(QDialog):
  266. def __init__(self, parent, pluginId):
  267. QDialog.__init__(self, Carla.gui)
  268. self.ui = ui_carla_edit.Ui_PluginEdit()
  269. self.ui.setupUi(self)
  270. # -------------------------------------------------------------
  271. # Internal stuff
  272. self.fGeometry = QByteArray()
  273. self.fPluginId = pluginId
  274. self.fPuginInfo = None
  275. self.fRealParent = parent
  276. self.fCurrentProgram = -1
  277. self.fCurrentMidiProgram = -1
  278. self.fCurrentStateFilename = None
  279. self.fControlChannel = 0
  280. self.fScrollAreaSetup = False
  281. self.fParameterCount = 0
  282. self.fParameterList = [] # (type, id, widget)
  283. self.fParametersToUpdate = [] # (id, value)
  284. self.fPlayingNotes = [] # (channel, note)
  285. self.fTabIconOff = QIcon(":/bitmaps/led_off.png")
  286. self.fTabIconOn = QIcon(":/bitmaps/led_yellow.png")
  287. self.fTabIconCount = 0
  288. self.fTabIconTimers = []
  289. # -------------------------------------------------------------
  290. # Set-up GUI
  291. self.ui.dial_drywet.setCustomPaint(self.ui.dial_drywet.CUSTOM_PAINT_CARLA_WET)
  292. self.ui.dial_drywet.setPixmap(3)
  293. self.ui.dial_drywet.setLabel("Dry/Wet")
  294. self.ui.dial_vol.setCustomPaint(self.ui.dial_vol.CUSTOM_PAINT_CARLA_VOL)
  295. self.ui.dial_vol.setPixmap(3)
  296. self.ui.dial_vol.setLabel("Volume")
  297. self.ui.dial_b_left.setCustomPaint(self.ui.dial_b_left.CUSTOM_PAINT_CARLA_L)
  298. self.ui.dial_b_left.setPixmap(4)
  299. self.ui.dial_b_left.setLabel("L")
  300. self.ui.dial_b_right.setCustomPaint(self.ui.dial_b_right.CUSTOM_PAINT_CARLA_R)
  301. self.ui.dial_b_right.setPixmap(4)
  302. self.ui.dial_b_right.setLabel("R")
  303. self.ui.keyboard.setMode(self.ui.keyboard.HORIZONTAL)
  304. self.ui.keyboard.setOctaves(10)
  305. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  306. self.ui.scrollArea.ensureVisible(self.ui.keyboard.width() / 3, 0)
  307. self.ui.scrollArea.setEnabled(False)
  308. self.ui.scrollArea.setVisible(False)
  309. #self.reloadAll()
  310. # -------------------------------------------------------------
  311. # Set-up connections
  312. self.finished.connect(self.slot_finished)
  313. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  314. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  315. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  316. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  317. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  318. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  319. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  320. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  321. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  322. self.ui.dial_drywet.valueChanged.connect(self.slot_dryWetChanged)
  323. self.ui.dial_vol.valueChanged.connect(self.slot_volumeChanged)
  324. self.ui.dial_b_left.valueChanged.connect(self.slot_balanceLeftChanged)
  325. self.ui.dial_b_right.valueChanged.connect(self.slot_balanceRightChanged)
  326. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  327. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  328. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  329. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  330. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  331. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  332. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  333. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  334. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  335. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  336. if Carla.isLocal:
  337. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  338. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  339. else:
  340. self.ui.b_load_state.setEnabled(False)
  341. self.ui.b_save_state.setEnabled(False)
  342. # -------------------------------------------------------------
  343. def reloadAll(self):
  344. self.fPluginInfo = Carla.host.get_plugin_info(self.fPluginId)
  345. self.fPluginInfo['binary'] = cString(self.fPluginInfo['binary'])
  346. self.fPluginInfo['name'] = cString(self.fPluginInfo['name'])
  347. self.fPluginInfo['label'] = cString(self.fPluginInfo['label'])
  348. self.fPluginInfo['maker'] = cString(self.fPluginInfo['maker'])
  349. self.fPluginInfo['copyright'] = cString(self.fPluginInfo['copyright'])
  350. self.fPluginInfo['iconName'] = cString(self.fPluginInfo['iconName'])
  351. if not Carla.isLocal:
  352. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_GUI
  353. self.reloadInfo()
  354. self.reloadParameters()
  355. self.reloadPrograms()
  356. if self.fPluginInfo['type'] == PLUGIN_LV2:
  357. self.ui.b_save_state.setEnabled(False)
  358. if not self.ui.scrollArea.isEnabled():
  359. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  360. def reloadInfo(self):
  361. pluginName = cString(Carla.host.get_real_plugin_name(self.fPluginId))
  362. pluginType = self.fPluginInfo['type']
  363. pluginHints = self.fPluginInfo['hints']
  364. audioCountInfo = Carla.host.get_audio_port_count_info(self.fPluginId)
  365. midiCountInfo = Carla.host.get_midi_port_count_info(self.fPluginId)
  366. paramCountInfo = Carla.host.get_parameter_count_info(self.fPluginId)
  367. if pluginType == PLUGIN_INTERNAL:
  368. self.ui.le_type.setText(self.tr("Internal"))
  369. elif pluginType == PLUGIN_LADSPA:
  370. self.ui.le_type.setText("LADSPA")
  371. elif pluginType == PLUGIN_DSSI:
  372. self.ui.le_type.setText("DSSI")
  373. elif pluginType == PLUGIN_LV2:
  374. self.ui.le_type.setText("LV2")
  375. elif pluginType == PLUGIN_VST:
  376. self.ui.le_type.setText("VST")
  377. elif pluginType == PLUGIN_AU:
  378. self.ui.le_type.setText("AU")
  379. elif pluginType == PLUGIN_CSOUND:
  380. self.ui.le_type.setText("CSOUND")
  381. elif pluginType == PLUGIN_GIG:
  382. self.ui.le_type.setText("GIG")
  383. elif pluginType == PLUGIN_SF2:
  384. self.ui.le_type.setText("SF2")
  385. elif pluginType == PLUGIN_SFZ:
  386. self.ui.le_type.setText("SFZ")
  387. else:
  388. self.ui.le_type.setText(self.tr("Unknown"))
  389. self.ui.le_name.setText(pluginName)
  390. self.ui.le_name.setToolTip(pluginName)
  391. self.ui.le_label.setText(self.fPluginInfo['label'])
  392. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  393. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  394. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  395. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  396. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  397. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  398. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  399. self.ui.le_ains.setText(str(audioCountInfo['ins']))
  400. self.ui.le_aouts.setText(str(audioCountInfo['outs']))
  401. self.ui.le_params.setText(str(paramCountInfo['ins']))
  402. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  403. self.setWindowTitle(self.fPluginInfo['name'])
  404. if self.fPluginInfo['latency'] > 0:
  405. self.ui.le_latency.setText("%i samples" % self.fPluginInfo['latency'])
  406. else:
  407. self.ui.le_latency.setText(self.tr("None"))
  408. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  409. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  410. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  411. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  412. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFER)
  413. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFER)
  414. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  415. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  416. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  417. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  418. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  419. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  420. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  421. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  422. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  423. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  424. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  425. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  426. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  427. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  428. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  429. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  430. if self.fPluginInfo['type'] != PLUGIN_VST:
  431. self.ui.tab_programs.setCurrentIndex(1)
  432. # Show/hide keyboard
  433. showKeyboard = (pluginHints & PLUGIN_IS_SYNTH) != 0 or (midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  434. self.ui.scrollArea.setEnabled(showKeyboard)
  435. self.ui.scrollArea.setVisible(showKeyboard)
  436. # Force-Update parent for new hints
  437. if self.fRealParent:
  438. self.fRealParent.recheckPluginHints(pluginHints)
  439. def reloadParameters(self):
  440. parameterCount = Carla.host.get_parameter_count(self.fPluginId)
  441. # Reset
  442. self.fParameterCount = 0
  443. self.fParameterList = []
  444. self.fParametersToUpdate = []
  445. self.fTabIconCount = 0
  446. self.fTabIconTimers = []
  447. # Remove all previous parameters
  448. for x in range(self.ui.tabWidget.count()-1):
  449. self.ui.tabWidget.widget(1).deleteLater()
  450. self.ui.tabWidget.removeTab(1)
  451. if parameterCount <= 0:
  452. pass
  453. elif parameterCount <= Carla.maxParameters:
  454. paramInputListFull = []
  455. paramOutputListFull = []
  456. paramInputList = [] # ([params], width)
  457. paramInputWidth = 0
  458. paramOutputList = [] # ([params], width)
  459. paramOutputWidth = 0
  460. for i in range(parameterCount):
  461. paramInfo = Carla.host.get_parameter_info(self.fPluginId, i)
  462. paramData = Carla.host.get_parameter_data(self.fPluginId, i)
  463. paramRanges = Carla.host.get_parameter_ranges(self.fPluginId, i)
  464. paramValue = Carla.host.get_current_parameter_value(self.fPluginId, i)
  465. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  466. continue
  467. parameter = {
  468. 'type': paramData['type'],
  469. 'hints': paramData['hints'],
  470. 'name': cString(paramInfo['name']),
  471. 'unit': cString(paramInfo['unit']),
  472. 'scalePoints': [],
  473. 'index': paramData['index'],
  474. 'default': paramRanges['def'],
  475. 'minimum': paramRanges['min'],
  476. 'maximum': paramRanges['max'],
  477. 'step': paramRanges['step'],
  478. 'stepSmall': paramRanges['stepSmall'],
  479. 'stepLarge': paramRanges['stepLarge'],
  480. 'midiCC': paramData['midiCC'],
  481. 'midiChannel': paramData['midiChannel']+1,
  482. 'current': paramValue
  483. }
  484. for j in range(paramInfo['scalePointCount']):
  485. scalePointInfo = Carla.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  486. parameter['scalePoints'].append({
  487. 'value': scalePointInfo['value'],
  488. 'label': cString(scalePointInfo['label'])
  489. })
  490. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  491. # -----------------------------------------------------------------
  492. # Get width values, in packs of 10
  493. if parameter['type'] == PARAMETER_INPUT:
  494. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  495. if paramInputWidthTMP > paramInputWidth:
  496. paramInputWidth = paramInputWidthTMP
  497. paramInputList.append(parameter)
  498. if len(paramInputList) == 10:
  499. paramInputListFull.append((paramInputList, paramInputWidth))
  500. paramInputList = []
  501. paramInputWidth = 0
  502. else:
  503. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  504. if paramOutputWidthTMP > paramOutputWidth:
  505. paramOutputWidth = paramOutputWidthTMP
  506. paramOutputList.append(parameter)
  507. if len(paramOutputList) == 10:
  508. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  509. paramOutputList = []
  510. paramOutputWidth = 0
  511. # for i in range(parameterCount)
  512. else:
  513. # Final page width values
  514. if 0 < len(paramInputList) < 10:
  515. paramInputListFull.append((paramInputList, paramInputWidth))
  516. if 0 < len(paramOutputList) < 10:
  517. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  518. # -----------------------------------------------------------------
  519. # Create parameter tabs + widgets
  520. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  521. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  522. else: # > Carla.maxParameters
  523. fakeName = self.tr("This plugin has too many parameters to display here!")
  524. paramFakeListFull = []
  525. paramFakeList = []
  526. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  527. parameter = {
  528. 'type': PARAMETER_UNKNOWN,
  529. 'hints': 0,
  530. 'name': fakeName,
  531. 'unit': "",
  532. 'scalePoints': [],
  533. 'index': 0,
  534. 'default': 0.0,
  535. 'minimum': 0.0,
  536. 'maximum': 0.0,
  537. 'step': 0.0,
  538. 'stepSmall': 0.0,
  539. 'stepLarge': 0.0,
  540. 'midiCC': -1,
  541. 'midiChannel': 1,
  542. 'current': 0.0
  543. }
  544. paramFakeList.append(parameter)
  545. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  546. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  547. def reloadPrograms(self):
  548. # Programs
  549. self.ui.cb_programs.blockSignals(True)
  550. self.ui.cb_programs.clear()
  551. programCount = Carla.host.get_program_count(self.fPluginId)
  552. if programCount > 0:
  553. self.ui.cb_programs.setEnabled(True)
  554. self.ui.label_programs.setEnabled(True)
  555. for i in range(programCount):
  556. pName = cString(Carla.host.get_program_name(self.fPluginId, i))
  557. #pName = pName[:40] + (pName[40:] and "...")
  558. self.ui.cb_programs.addItem(pName)
  559. self.fCurrentProgram = Carla.host.get_current_program_index(self.fPluginId)
  560. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  561. else:
  562. self.fCurrentProgram = -1
  563. self.ui.cb_programs.setEnabled(False)
  564. self.ui.label_programs.setEnabled(False)
  565. self.ui.cb_programs.blockSignals(False)
  566. # MIDI Programs
  567. self.ui.cb_midi_programs.blockSignals(True)
  568. self.ui.cb_midi_programs.clear()
  569. midiProgramCount = Carla.host.get_midi_program_count(self.fPluginId)
  570. if midiProgramCount > 0:
  571. self.ui.cb_midi_programs.setEnabled(True)
  572. self.ui.label_midi_programs.setEnabled(True)
  573. for i in range(midiProgramCount):
  574. mpData = Carla.host.get_midi_program_data(self.fPluginId, i)
  575. mpBank = int(mpData['bank'])
  576. mpProg = int(mpData['program'])
  577. mpName = cString(mpData['name'])
  578. #mpName = mpName[:40] + (mpName[40:] and "...")
  579. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  580. self.fCurrentMidiProgram = Carla.host.get_current_midi_program_index(self.fPluginId)
  581. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  582. else:
  583. self.fCurrentMidiProgram = -1
  584. self.ui.cb_midi_programs.setEnabled(False)
  585. self.ui.label_midi_programs.setEnabled(False)
  586. self.ui.cb_midi_programs.blockSignals(False)
  587. if self.fPluginInfo['type'] == PLUGIN_LV2:
  588. self.ui.b_load_state.setEnabled(programCount > 0)
  589. def updateInfo(self):
  590. # Update current program text
  591. if self.ui.cb_programs.count() > 0:
  592. pIndex = self.ui.cb_programs.currentIndex()
  593. pName = cString(Carla.host.get_program_name(self.fPluginId, pIndex))
  594. #pName = pName[:40] + (pName[40:] and "...")
  595. self.ui.cb_programs.setItemText(pIndex, pName)
  596. # Update current midi program text
  597. if self.ui.cb_midi_programs.count() > 0:
  598. mpIndex = self.ui.cb_midi_programs.currentIndex()
  599. mpData = Carla.host.get_midi_program_data(self.fPluginId, mpIndex)
  600. mpBank = int(mpData['bank'])
  601. mpProg = int(mpData['program'])
  602. mpName = cString(mpData['name'])
  603. #mpName = mpName[:40] + (mpName[40:] and "...")
  604. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  605. # Update all parameter values
  606. for paramType, paramId, paramWidget in self.fParameterList:
  607. paramWidget.setValue(Carla.host.get_current_parameter_value(self.fPluginId, paramId), False)
  608. paramWidget.update()
  609. self.fParametersToUpdate = []
  610. def clearNotes(self):
  611. self.fPlayingNotes = []
  612. self.ui.keyboard.allNotesOff()
  613. def setParameterValue(self, parameterId, value):
  614. for paramItem in self.fParametersToUpdate:
  615. if paramItem[0] == parameterId:
  616. paramItem[1] = value
  617. break
  618. else:
  619. self.fParametersToUpdate.append([parameterId, value])
  620. def setParameterDefault(self, parameterId, value):
  621. for paramType, paramId, paramWidget in self.fParameterList:
  622. if paramId == parameterId:
  623. paramWidget.setDefault(value)
  624. break
  625. def setParameterMidiControl(self, parameterId, control):
  626. for paramType, paramId, paramWidget in self.fParameterList:
  627. if paramId == parameterId:
  628. paramWidget.setMidiControl(control)
  629. break
  630. def setParameterMidiChannel(self, parameterId, channel):
  631. for paramType, paramId, paramWidget in self.fParameterList:
  632. if paramId == parameterId:
  633. paramWidget.setMidiChannel(channel+1)
  634. break
  635. def setProgram(self, index):
  636. self.ui.cb_programs.blockSignals(True)
  637. self.ui.cb_programs.setCurrentIndex(index)
  638. self.ui.cb_programs.blockSignals(False)
  639. def setMidiProgram(self, index):
  640. self.ui.cb_midi_programs.blockSignals(True)
  641. self.ui.cb_midi_programs.setCurrentIndex(index)
  642. self.ui.cb_midi_programs.blockSignals(False)
  643. def sendNoteOn(self, channel, note):
  644. if self.fControlChannel == channel:
  645. self.ui.keyboard.sendNoteOn(note, False)
  646. if len(self.fPlayingNotes) == 0 and self.fRealParent:
  647. self.fRealParent.ui.led_midi.setChecked(True)
  648. playItem = (channel, note)
  649. if playItem not in self.fPlayingNotes:
  650. self.fPlayingNotes.append(playItem)
  651. def sendNoteOff(self, channel, note):
  652. if self.fControlChannel == channel:
  653. self.ui.keyboard.sendNoteOff(note, False)
  654. if len(self.fPlayingNotes) == 1 and self.fRealParent:
  655. self.fRealParent.ui.led_midi.setChecked(False)
  656. playItem = (channel, note)
  657. if playItem in self.fPlayingNotes:
  658. self.fPlayingNotes.remove(playItem)
  659. def setVisible(self, yesNo):
  660. if yesNo:
  661. if not self.fGeometry.isNull():
  662. self.restoreGeometry(self.fGeometry)
  663. else:
  664. self.fGeometry = self.saveGeometry()
  665. QDialog.setVisible(self, yesNo)
  666. def idleSlow(self):
  667. # Check Tab icons
  668. for i in range(len(self.fTabIconTimers)):
  669. if self.fTabIconTimers[i] == ICON_STATE_ON:
  670. self.fTabIconTimers[i] = ICON_STATE_WAIT
  671. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  672. self.fTabIconTimers[i] = ICON_STATE_OFF
  673. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  674. self.fTabIconTimers[i] = ICON_STATE_NULL
  675. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  676. # Check parameters needing update
  677. for index, value in self.fParametersToUpdate:
  678. if index == PARAMETER_DRYWET:
  679. self.ui.dial_drywet.blockSignals(True)
  680. self.ui.dial_drywet.setValue(value * 1000)
  681. self.ui.dial_drywet.blockSignals(False)
  682. elif index == PARAMETER_VOLUME:
  683. self.ui.dial_vol.blockSignals(True)
  684. self.ui.dial_vol.setValue(value * 1000)
  685. self.ui.dial_vol.blockSignals(False)
  686. elif index == PARAMETER_BALANCE_LEFT:
  687. self.ui.dial_b_left.blockSignals(True)
  688. self.ui.dial_b_left.setValue(value * 1000)
  689. self.ui.dial_b_left.blockSignals(False)
  690. elif index == PARAMETER_BALANCE_RIGHT:
  691. self.ui.dial_b_right.blockSignals(True)
  692. self.ui.dial_b_right.setValue(value * 1000)
  693. self.ui.dial_b_right.blockSignals(False)
  694. #elif index == PARAMETER_PANNING:
  695. #self.ui.dial_pan.blockSignals(True)
  696. #self.ui.dial_pan.setValue(value * 1000, True, False)
  697. #self.ui.dial_pan.blockSignals(False)
  698. elif index == PARAMETER_CTRL_CHANNEL:
  699. self.fControlChannel = int(value)
  700. self.ui.sb_ctrl_channel.blockSignals(True)
  701. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  702. self.ui.sb_ctrl_channel.blockSignals(False)
  703. self.ui.keyboard.allNotesOff()
  704. self._updateCtrlMidiProgram()
  705. elif index >= 0:
  706. for paramType, paramId, paramWidget in self.fParameterList:
  707. if paramId != index:
  708. continue
  709. paramWidget.setValue(value, False)
  710. if paramType == PARAMETER_INPUT:
  711. tabIndex = paramWidget.tabIndex()
  712. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  713. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  714. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  715. break
  716. # Clear all parameters
  717. self.fParametersToUpdate = []
  718. # Update parameter outputs
  719. for paramType, paramId, paramWidget in self.fParameterList:
  720. if paramType == PARAMETER_OUTPUT:
  721. value = Carla.host.get_current_parameter_value(self.fPluginId, paramId)
  722. paramWidget.setValue(value, False)
  723. @pyqtSlot()
  724. def slot_stateSave(self):
  725. if self.fPluginInfo['type'] == PLUGIN_LV2:
  726. # TODO
  727. return
  728. if self.fCurrentStateFilename:
  729. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  730. if askTry == QMessageBox.Ok:
  731. Carla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  732. return
  733. self.fCurrentStateFilename = None
  734. fileFilter = self.tr("Carla State File (*.carxs)")
  735. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  736. if filenameTry:
  737. if not filenameTry.lower().endswith(".carxs"):
  738. filenameTry += ".carxs"
  739. self.fCurrentStateFilename = filenameTry
  740. Carla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  741. @pyqtSlot()
  742. def slot_stateLoad(self):
  743. if self.fPluginInfo['type'] == PLUGIN_LV2:
  744. presetList = []
  745. for i in range(Carla.host.get_program_count(self.fPluginId)):
  746. presetList.append("%03i - %s" % (i+1, cString(Carla.host.get_program_name(self.fPluginId, i))))
  747. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  748. if ret[1]:
  749. index = int(ret[0].split(" - ", 1)[0])-1
  750. Carla.host.set_midi_program(self.fPluginId, -1)
  751. Carla.host.set_program(self.fPluginId, index)
  752. self.setMidiProgram(-1)
  753. return
  754. fileFilter = self.tr("Carla State File (*.carxs)")
  755. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  756. if filenameTry:
  757. self.fCurrentStateFilename = filenameTry
  758. Carla.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  759. @pyqtSlot(bool)
  760. def slot_optionChanged(self, clicked):
  761. sender = self.sender()
  762. if sender == self.ui.ch_fixed_buffer:
  763. option = PLUGIN_OPTION_FIXED_BUFFER
  764. elif sender == self.ui.ch_force_stereo:
  765. option = PLUGIN_OPTION_FORCE_STEREO
  766. elif sender == self.ui.ch_map_program_changes:
  767. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  768. elif sender == self.ui.ch_use_chunks:
  769. option = PLUGIN_OPTION_USE_CHUNKS
  770. elif sender == self.ui.ch_send_control_changes:
  771. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  772. elif sender == self.ui.ch_send_channel_pressure:
  773. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  774. elif sender == self.ui.ch_send_note_aftertouch:
  775. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  776. elif sender == self.ui.ch_send_pitchbend:
  777. option = PLUGIN_OPTION_SEND_PITCHBEND
  778. elif sender == self.ui.ch_send_all_sound_off:
  779. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  780. else:
  781. return
  782. Carla.host.set_option(self.fPluginId, option, clicked)
  783. @pyqtSlot(int)
  784. def slot_dryWetChanged(self, value):
  785. Carla.host.set_drywet(self.fPluginId, float(value)/1000)
  786. @pyqtSlot(int)
  787. def slot_volumeChanged(self, value):
  788. Carla.host.set_volume(self.fPluginId, float(value)/1000)
  789. @pyqtSlot(int)
  790. def slot_balanceLeftChanged(self, value):
  791. Carla.host.set_balance_left(self.fPluginId, float(value)/1000)
  792. @pyqtSlot(int)
  793. def slot_balanceRightChanged(self, value):
  794. Carla.host.set_balance_right(self.fPluginId, float(value)/1000)
  795. @pyqtSlot(int)
  796. def slot_panningChanged(self, value):
  797. Carla.host.set_panning(self.fPluginId, float(value)/1000)
  798. @pyqtSlot(int)
  799. def slot_ctrlChannelChanged(self, value):
  800. self.fControlChannel = value-1
  801. Carla.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  802. self.ui.keyboard.allNotesOff()
  803. self._updateCtrlMidiProgram()
  804. @pyqtSlot(int, float)
  805. def slot_parameterValueChanged(self, parameterId, value):
  806. Carla.host.set_parameter_value(self.fPluginId, parameterId, value)
  807. @pyqtSlot(int, int)
  808. def slot_parameterMidiControlChanged(self, parameterId, control):
  809. Carla.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  810. @pyqtSlot(int, int)
  811. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  812. Carla.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  813. @pyqtSlot(int)
  814. def slot_programIndexChanged(self, index):
  815. self.fCurrentProgram = index
  816. Carla.host.set_program(self.fPluginId, index)
  817. @pyqtSlot(int)
  818. def slot_midiProgramIndexChanged(self, index):
  819. self.fCurrentMidiProgram = index
  820. Carla.host.set_midi_program(self.fPluginId, index)
  821. @pyqtSlot(int)
  822. def slot_noteOn(self, note):
  823. if self.fControlChannel >= 0:
  824. Carla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  825. @pyqtSlot(int)
  826. def slot_noteOff(self, note):
  827. if self.fControlChannel >= 0:
  828. Carla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  829. @pyqtSlot()
  830. def slot_finished(self):
  831. if self.fRealParent:
  832. self.fRealParent.editClosed()
  833. @pyqtSlot()
  834. def slot_knobCustomMenu(self):
  835. dialName = self.sender().objectName()
  836. if dialName == "dial_drywet":
  837. minimum = 0
  838. maximum = 100
  839. default = 100
  840. label = "Dry/Wet"
  841. elif dialName == "dial_vol":
  842. minimum = 0
  843. maximum = 127
  844. default = 100
  845. label = "Volume"
  846. elif dialName == "dial_b_left":
  847. minimum = -100
  848. maximum = 100
  849. default = -100
  850. label = "Balance-Left"
  851. elif dialName == "dial_b_right":
  852. minimum = -100
  853. maximum = 100
  854. default = 100
  855. label = "Balance-Right"
  856. elif dialName == "dial_panning":
  857. minimum = -100
  858. maximum = 100
  859. default = 0
  860. label = "Panning"
  861. else:
  862. minimum = 0
  863. maximum = 100
  864. default = 100
  865. label = "Unknown"
  866. current = self.sender().value() / 10
  867. menu = QMenu(self)
  868. actReset = menu.addAction(self.tr("Reset (%i%%)" % default))
  869. menu.addSeparator()
  870. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % minimum))
  871. actCenter = menu.addAction(self.tr("Set to Center"))
  872. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % maximum))
  873. menu.addSeparator()
  874. actSet = menu.addAction(self.tr("Set value..."))
  875. if label not in ("Balance-Left", "Balance-Right"):
  876. menu.removeAction(actCenter)
  877. actSelected = menu.exec_(QCursor.pos())
  878. if actSelected == actSet:
  879. valueTry = QInputDialog.getInteger(self, self.tr("Set value"), label, current, minimum, maximum, 1)
  880. if valueTry[1]:
  881. value = valueTry[0] * 10
  882. else:
  883. return
  884. elif actSelected == actMinimum:
  885. value = minimum * 10
  886. elif actSelected == actMaximum:
  887. value = maximum * 10
  888. elif actSelected == actReset:
  889. value = default * 10
  890. elif actSelected == actCenter:
  891. value = 0
  892. else:
  893. return
  894. if label == "Dry/Wet":
  895. self.ui.dial_drywet.setValue(value)
  896. elif label == "Volume":
  897. self.ui.dial_vol.setValue(value)
  898. elif label == "Balance-Left":
  899. self.ui.dial_b_left.setValue(value)
  900. elif label == "Balance-Right":
  901. self.ui.dial_b_right.setValue(value)
  902. #elif label == "Panning":
  903. #self.ui.dial_panning.setValue(value)
  904. @pyqtSlot()
  905. def slot_channelCustomMenu(self):
  906. menu = QMenu(self)
  907. actNone = menu.addAction(self.tr("None"))
  908. if self.fControlChannel+1 == 0:
  909. actNone.setCheckable(True)
  910. actNone.setChecked(True)
  911. for i in range(1, 16+1):
  912. action = menu.addAction("%i" % i)
  913. if self.fControlChannel+1 == i:
  914. action.setCheckable(True)
  915. action.setChecked(True)
  916. actSel = menu.exec_(QCursor.pos())
  917. if not actSel:
  918. pass
  919. elif actSel == actNone:
  920. self.ui.sb_ctrl_channel.setValue(0)
  921. elif actSel:
  922. selChannel = int(actSel.text())
  923. self.ui.sb_ctrl_channel.setValue(selChannel)
  924. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  925. i = 1
  926. for paramList, width in paramListFull:
  927. if len(paramList) == 0:
  928. break
  929. tabIndex = self.ui.tabWidget.count()
  930. tabPageContainer = QWidget(self.ui.tabWidget)
  931. tabPageLayout = QVBoxLayout(tabPageContainer)
  932. tabPageContainer.setLayout(tabPageLayout)
  933. for paramInfo in paramList:
  934. paramWidget = PluginParameter(tabPageContainer, paramInfo, self.fPluginId, tabIndex)
  935. paramWidget.setLabelWidth(width)
  936. tabPageLayout.addWidget(paramWidget)
  937. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  938. if paramType == PARAMETER_INPUT:
  939. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  940. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  941. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  942. tabPageLayout.addStretch()
  943. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  944. i += 1
  945. if paramType == PARAMETER_INPUT:
  946. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  947. self.fTabIconTimers.append(ICON_STATE_NULL)
  948. def _updateCtrlMidiProgram(self):
  949. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2):
  950. return
  951. elif not self.fPluginInfo['hints'] & PLUGIN_IS_SYNTH:
  952. return
  953. if self.fControlChannel < 0:
  954. self.ui.cb_midi_programs.setEnabled(False)
  955. return
  956. self.ui.cb_midi_programs.setEnabled(True)
  957. mpIndex = Carla.host.get_current_midi_program_index(self.fPluginId)
  958. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  959. self.setMidiProgram(mpIndex)
  960. def showEvent(self, event):
  961. if not self.fScrollAreaSetup:
  962. self.fScrollAreaSetup = True
  963. minHeight = self.ui.scrollArea.height()+2
  964. self.ui.scrollArea.setMinimumHeight(minHeight)
  965. self.ui.scrollArea.setMaximumHeight(minHeight)
  966. QDialog.showEvent(self, event)
  967. def done(self, r):
  968. QDialog.done(self, r)
  969. self.close()
  970. # ------------------------------------------------------------------------------------------------------------
  971. # Plugin Widget
  972. class PluginWidget(QFrame):
  973. def __init__(self, parent, pluginId):
  974. QFrame.__init__(self, parent)
  975. self.ui = ui_carla_plugin.Ui_PluginWidget()
  976. self.ui.setupUi(self)
  977. # -------------------------------------------------------------
  978. # Internal stuff
  979. self.fPluginId = pluginId
  980. self.fPluginInfo = Carla.host.get_plugin_info(self.fPluginId)
  981. self.fPluginInfo['binary'] = cString(self.fPluginInfo['binary'])
  982. self.fPluginInfo['name'] = cString(self.fPluginInfo['name'])
  983. self.fPluginInfo['label'] = cString(self.fPluginInfo['label'])
  984. self.fPluginInfo['maker'] = cString(self.fPluginInfo['maker'])
  985. self.fPluginInfo['copyright'] = cString(self.fPluginInfo['copyright'])
  986. self.fPluginInfo['iconName'] = cString(self.fPluginInfo['iconName'])
  987. if not Carla.isLocal:
  988. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_GUI
  989. self.fLastGreenLedState = False
  990. self.fLastBlueLedState = False
  991. self.fParameterIconTimer = ICON_STATE_NULL
  992. if Carla.processMode == PROCESS_MODE_CONTINUOUS_RACK:
  993. self.fPeaksInputCount = 2
  994. self.fPeaksOutputCount = 2
  995. else:
  996. audioCountInfo = Carla.host.get_audio_port_count_info(self.fPluginId)
  997. self.fPeaksInputCount = int(audioCountInfo['ins'])
  998. self.fPeaksOutputCount = int(audioCountInfo['outs'])
  999. if self.fPeaksInputCount > 2:
  1000. self.fPeaksInputCount = 2
  1001. if self.fPeaksOutputCount > 2:
  1002. self.fPeaksOutputCount = 2
  1003. if self.palette().window().color().lightness() > 100:
  1004. # Light background
  1005. labelColor = "333"
  1006. isLight = True
  1007. self.fColorTop = QColor(60, 60, 60)
  1008. self.fColorBottom = QColor(47, 47, 47)
  1009. self.fColorSeprtr = QColor(70, 70, 70)
  1010. else:
  1011. # Dark background
  1012. labelColor = "BBB"
  1013. isLight = False
  1014. self.fColorTop = QColor(60, 60, 60)
  1015. self.fColorBottom = QColor(47, 47, 47)
  1016. self.fColorSeprtr = QColor(70, 70, 70)
  1017. # -------------------------------------------------------------
  1018. # Set-up GUI
  1019. self.setStyleSheet("""
  1020. QLabel#label_name {
  1021. color: #%s;
  1022. }""" % labelColor)
  1023. if isLight:
  1024. self.ui.b_enable.setPixmaps(":/bitmaps/button_off2.png", ":/bitmaps/button_on2.png", ":/bitmaps/button_off2.png")
  1025. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit2.png", ":/bitmaps/button_edit_down2.png", ":/bitmaps/button_edit_hover2.png")
  1026. if self.fPluginInfo['iconName'] == "distrho":
  1027. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho2.png", ":/bitmaps/button_distrho_down2.png", ":/bitmaps/button_distrho_hover2.png")
  1028. elif self.fPluginInfo['iconName'] == "file":
  1029. self.ui.b_gui.setPixmaps(":/bitmaps/button_file2.png", ":/bitmaps/button_file_down2.png", ":/bitmaps/button_file_hover2.png")
  1030. else:
  1031. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui2.png", ":/bitmaps/button_gui_down2.png", ":/bitmaps/button_gui_hover2.png")
  1032. else:
  1033. self.ui.b_enable.setPixmaps(":/bitmaps/button_off.png", ":/bitmaps/button_on.png", ":/bitmaps/button_off.png")
  1034. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit.png", ":/bitmaps/button_edit_down.png", ":/bitmaps/button_edit_hover.png")
  1035. if self.fPluginInfo['iconName'] == "distrho":
  1036. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho.png", ":/bitmaps/button_distrho_down.png", ":/bitmaps/button_distrho_hover.png")
  1037. elif self.fPluginInfo['iconName'] == "file":
  1038. self.ui.b_gui.setPixmaps(":/bitmaps/button_file.png", ":/bitmaps/button_file_down.png", ":/bitmaps/button_file_hover.png")
  1039. else:
  1040. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui.png", ":/bitmaps/button_gui_down.png", ":/bitmaps/button_gui_hover.png")
  1041. self.ui.led_control.setColor(self.ui.led_control.YELLOW)
  1042. self.ui.led_control.setEnabled(False)
  1043. self.ui.led_midi.setColor(self.ui.led_midi.RED)
  1044. self.ui.led_midi.setEnabled(False)
  1045. self.ui.led_audio_in.setColor(self.ui.led_audio_in.GREEN)
  1046. self.ui.led_audio_in.setEnabled(False)
  1047. self.ui.led_audio_out.setColor(self.ui.led_audio_out.BLUE)
  1048. self.ui.led_audio_out.setEnabled(False)
  1049. self.ui.peak_in.setColor(self.ui.peak_in.GREEN)
  1050. self.ui.peak_in.setChannels(self.fPeaksInputCount)
  1051. self.ui.peak_in.setOrientation(self.ui.peak_in.HORIZONTAL)
  1052. self.ui.peak_out.setColor(self.ui.peak_in.BLUE)
  1053. self.ui.peak_out.setChannels(self.fPeaksOutputCount)
  1054. self.ui.peak_out.setOrientation(self.ui.peak_out.HORIZONTAL)
  1055. self.ui.label_name.setText(self.fPluginInfo['name'])
  1056. self.ui.edit_dialog = PluginEdit(self, self.fPluginId)
  1057. self.ui.edit_dialog.hide()
  1058. self.setMinimumHeight(32)
  1059. self.setMaximumHeight(32)
  1060. # -------------------------------------------------------------
  1061. # Set-up connections
  1062. self.customContextMenuRequested.connect(self.slot_showCustomMenu)
  1063. self.ui.b_enable.clicked.connect(self.slot_enableClicked)
  1064. self.ui.b_gui.clicked.connect(self.slot_guiClicked)
  1065. self.ui.b_edit.clicked.connect(self.slot_editClicked)
  1066. # -------------------------------------------------------------
  1067. def idleFast(self):
  1068. # Input peaks
  1069. if self.fPeaksInputCount > 0:
  1070. if self.fPeaksInputCount > 1:
  1071. peak1 = Carla.host.get_input_peak_value(self.fPluginId, 1)
  1072. peak2 = Carla.host.get_input_peak_value(self.fPluginId, 2)
  1073. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  1074. self.ui.peak_in.displayMeter(1, peak1)
  1075. self.ui.peak_in.displayMeter(2, peak2)
  1076. else:
  1077. peak = Carla.host.get_input_peak_value(self.fPluginId, 1)
  1078. ledState = bool(peak != 0.0)
  1079. self.ui.peak_in.displayMeter(1, peak)
  1080. if self.fLastGreenLedState != ledState:
  1081. self.fLastGreenLedState = ledState
  1082. self.ui.led_audio_in.setChecked(ledState)
  1083. # Output peaks
  1084. if self.fPeaksOutputCount > 0:
  1085. if self.fPeaksOutputCount > 1:
  1086. peak1 = Carla.host.get_output_peak_value(self.fPluginId, 1)
  1087. peak2 = Carla.host.get_output_peak_value(self.fPluginId, 2)
  1088. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  1089. self.ui.peak_out.displayMeter(1, peak1)
  1090. self.ui.peak_out.displayMeter(2, peak2)
  1091. else:
  1092. peak = Carla.host.get_output_peak_value(self.fPluginId, 1)
  1093. ledState = bool(peak != 0.0)
  1094. self.ui.peak_out.displayMeter(1, peak)
  1095. if self.fLastBlueLedState != ledState:
  1096. self.fLastBlueLedState = ledState
  1097. self.ui.led_audio_out.setChecked(ledState)
  1098. def idleSlow(self):
  1099. # Parameter Activity LED
  1100. if self.fParameterIconTimer == ICON_STATE_ON:
  1101. self.fParameterIconTimer = ICON_STATE_WAIT
  1102. self.ui.led_control.setChecked(True)
  1103. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  1104. self.fParameterIconTimer = ICON_STATE_OFF
  1105. elif self.fParameterIconTimer == ICON_STATE_OFF:
  1106. self.fParameterIconTimer = ICON_STATE_NULL
  1107. self.ui.led_control.setChecked(False)
  1108. # Update edit dialog
  1109. self.ui.edit_dialog.idleSlow()
  1110. def editClosed(self):
  1111. self.ui.b_edit.setChecked(False)
  1112. def recheckPluginHints(self, hints):
  1113. self.fPluginInfo['hints'] = hints
  1114. self.ui.b_gui.setEnabled(hints & PLUGIN_HAS_GUI)
  1115. def setActive(self, active, sendGui=False, sendCallback=True):
  1116. if sendGui: self.ui.b_enable.setChecked(active)
  1117. if sendCallback: Carla.host.set_active(self.fPluginId, active)
  1118. if active:
  1119. self.ui.edit_dialog.clearNotes()
  1120. self.ui.led_midi.setChecked(False)
  1121. def setParameterDefault(self, parameterId, value):
  1122. self.ui.edit_dialog.setParameterDefault(parameterId, value)
  1123. def setParameterValue(self, parameterId, value):
  1124. self.fParameterIconTimer = ICON_STATE_ON
  1125. if parameterId == PARAMETER_ACTIVE:
  1126. return self.setActive(bool(value), True, False)
  1127. self.ui.edit_dialog.setParameterValue(parameterId, value)
  1128. def setParameterMidiControl(self, parameterId, control):
  1129. self.ui.edit_dialog.setParameterMidiControl(parameterId, control)
  1130. def setParameterMidiChannel(self, parameterId, channel):
  1131. self.ui.edit_dialog.setParameterMidiChannel(parameterId, channel)
  1132. def setProgram(self, index):
  1133. self.fParameterIconTimer = ICON_STATE_ON
  1134. self.ui.edit_dialog.setProgram(index)
  1135. def setMidiProgram(self, index):
  1136. self.fParameterIconTimer = ICON_STATE_ON
  1137. self.ui.edit_dialog.setMidiProgram(index)
  1138. def sendNoteOn(self, channel, note):
  1139. self.ui.edit_dialog.sendNoteOn(channel, note)
  1140. def sendNoteOff(self, channel, note):
  1141. self.ui.edit_dialog.sendNoteOff(channel, note)
  1142. def setId(self, idx):
  1143. self.fPluginId = idx
  1144. self.ui.edit_dialog.fPluginId = idx
  1145. @pyqtSlot()
  1146. def slot_showCustomMenu(self):
  1147. menu = QMenu(self)
  1148. actActive = menu.addAction(self.tr("Disable") if self.ui.b_enable.isChecked() else self.tr("Enable"))
  1149. menu.addSeparator()
  1150. actGui = menu.addAction(self.tr("Show GUI"))
  1151. actGui.setCheckable(True)
  1152. actGui.setChecked(self.ui.b_gui.isChecked())
  1153. actGui.setEnabled(self.ui.b_gui.isEnabled())
  1154. actEdit = menu.addAction(self.tr("Edit"))
  1155. actEdit.setCheckable(True)
  1156. actEdit.setChecked(self.ui.b_edit.isChecked())
  1157. menu.addSeparator()
  1158. actClone = menu.addAction(self.tr("Clone"))
  1159. actRename = menu.addAction(self.tr("Rename..."))
  1160. actRemove = menu.addAction(self.tr("Remove"))
  1161. actSel = menu.exec_(QCursor.pos())
  1162. if not actSel:
  1163. return
  1164. if actSel == actActive:
  1165. self.setActive(not self.ui.b_enable.isChecked(), True, True)
  1166. elif actSel == actGui:
  1167. self.ui.b_gui.click()
  1168. elif actSel == actEdit:
  1169. self.ui.b_edit.click()
  1170. elif actSel == actClone:
  1171. if not Carla.host.clone_plugin(self.fPluginId):
  1172. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1173. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1174. elif actSel == actRename:
  1175. oldName = self.fPluginInfo['name']
  1176. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  1177. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  1178. return
  1179. newName = newNameTry[0]
  1180. if Carla.host.rename_plugin(self.fPluginId, newName):
  1181. self.fPluginInfo['name'] = newName
  1182. self.ui.edit_dialog.fPluginInfo['name'] = newName
  1183. self.ui.edit_dialog.reloadInfo()
  1184. self.ui.label_name.setText(newName)
  1185. else:
  1186. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1187. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1188. elif actSel == actRemove:
  1189. if not Carla.host.remove_plugin(self.fPluginId):
  1190. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1191. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1192. @pyqtSlot(bool)
  1193. def slot_enableClicked(self, yesNo):
  1194. self.setActive(yesNo, False, True)
  1195. @pyqtSlot(bool)
  1196. def slot_guiClicked(self, show):
  1197. Carla.host.show_gui(self.fPluginId, show)
  1198. @pyqtSlot(bool)
  1199. def slot_editClicked(self, show):
  1200. self.ui.edit_dialog.setVisible(show)
  1201. def paintEvent(self, event):
  1202. painter = QPainter(self)
  1203. painter.save()
  1204. areaX = self.ui.area_right.x()+7
  1205. painter.setPen(self.fColorSeprtr.lighter(110))
  1206. painter.setBrush(self.fColorBottom)
  1207. painter.setRenderHint(QPainter.Antialiasing, True)
  1208. # name -> leds arc
  1209. path = QPainterPath()
  1210. path.moveTo(areaX-20, self.height()-4)
  1211. path.cubicTo(areaX, self.height()-5, areaX-20, 4.75, areaX, 4.75)
  1212. path.lineTo(areaX, self.height()-5)
  1213. painter.drawPath(path)
  1214. painter.setPen(self.fColorSeprtr)
  1215. painter.setRenderHint(QPainter.Antialiasing, False)
  1216. # separator lines
  1217. painter.drawLine(0, self.height()-5, areaX-20, self.height()-5)
  1218. painter.drawLine(areaX, 4, self.width(), 4)
  1219. painter.setPen(self.fColorBottom)
  1220. painter.setBrush(self.fColorBottom)
  1221. # top, bottom and left lines
  1222. painter.drawLine(0, 0, self.width(), 0)
  1223. painter.drawRect(0, self.height()-4, areaX, 4)
  1224. painter.drawRoundedRect(areaX-20, self.height()-5, areaX, 5, 22, 22)
  1225. painter.drawLine(0, 0, 0, self.height())
  1226. # fill the rest
  1227. painter.drawRect(areaX-1, 5, self.width(), self.height())
  1228. # bottom 1px line
  1229. painter.setPen(self.fColorSeprtr)
  1230. painter.drawLine(0, self.height()-1, self.width(), self.height()-1)
  1231. painter.restore()
  1232. QFrame.paintEvent(self, event)
  1233. # ------------------------------------------------------------------------------------------------------------
  1234. # TESTING
  1235. Carla.isControl = True
  1236. pInfo = {
  1237. 'type': PARAMETER_INPUT,
  1238. 'hints': PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE,
  1239. 'name': "Parameter Name",
  1240. 'unit': "",
  1241. 'scalePoints': [],
  1242. 'index': 0,
  1243. 'default': 0.0,
  1244. 'minimum': 0.0,
  1245. 'maximum': 1.0,
  1246. 'step': 0.01,
  1247. 'stepSmall': 0.01,
  1248. 'stepLarge': 0.01,
  1249. 'midiCC': -1,
  1250. 'midiChannel': 1,
  1251. 'current': 0.0
  1252. }
  1253. from PyQt5.QtWidgets import QApplication
  1254. app = QApplication(sys.argv)
  1255. #gui = PluginParameter(None, pInfo, 0, 0)
  1256. gui = PluginEdit(None, 0)
  1257. gui.show()
  1258. app.exec_()