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.

1438 lines
57KB

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