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.

1485 lines
58KB

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