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.

1428 lines
56KB

  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:
  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 = 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_drywet.setValue(1.0)
  340. self.ui.dial_vol.setCustomPaintMode(self.ui.dial_vol.CUSTOM_PAINT_MODE_CARLA_VOL)
  341. self.ui.dial_vol.setPixmap(3)
  342. self.ui.dial_vol.setLabel("Volume")
  343. self.ui.dial_vol.setMinimum(0.0)
  344. self.ui.dial_vol.setMaximum(1.27)
  345. self.ui.dial_vol.setValue(1.0)
  346. self.ui.dial_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L)
  347. self.ui.dial_b_left.setPixmap(4)
  348. self.ui.dial_b_left.setLabel("L")
  349. self.ui.dial_b_left.setMinimum(-1.0)
  350. self.ui.dial_b_left.setMaximum(1.0)
  351. self.ui.dial_b_left.setValue(0.0)
  352. self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R)
  353. self.ui.dial_b_right.setPixmap(4)
  354. self.ui.dial_b_right.setLabel("R")
  355. self.ui.dial_b_right.setMinimum(-1.0)
  356. self.ui.dial_b_right.setMaximum(1.0)
  357. self.ui.dial_b_right.setValue(0.0)
  358. self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN)
  359. self.ui.dial_pan.setPixmap(4)
  360. self.ui.dial_pan.setLabel("Pan")
  361. self.ui.dial_pan.setMinimum(-1.0)
  362. self.ui.dial_pan.setMaximum(1.0)
  363. self.ui.dial_pan.setValue(0.0)
  364. self.ui.scrollArea = PixmapKeyboardHArea(self)
  365. self.layout().addWidget(self.ui.scrollArea)
  366. self.ui.keyboard = self.ui.scrollArea.keyboard
  367. self.ui.keyboard.setMode(self.ui.keyboard.HORIZONTAL)
  368. self.ui.keyboard.setOctaves(10)
  369. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  370. self.ui.scrollArea.setEnabled(False)
  371. self.ui.scrollArea.setVisible(False)
  372. # todo
  373. self.ui.rb_balance.setEnabled(False)
  374. self.ui.rb_pan.setEnabled(False)
  375. self.reloadAll()
  376. # -------------------------------------------------------------
  377. # Set-up connections
  378. self.finished.connect(self.slot_finished)
  379. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  380. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  381. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  382. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  383. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  384. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  385. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  386. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  387. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  388. self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged)
  389. self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged)
  390. self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged)
  391. self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged)
  392. self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged)
  393. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  394. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  395. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  396. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  397. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  398. self.ui.dial_pan.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  399. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  400. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  401. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  402. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  403. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  404. if gCarla.isLocal:
  405. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  406. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  407. else:
  408. self.ui.b_load_state.setEnabled(False)
  409. self.ui.b_save_state.setEnabled(False)
  410. #------------------------------------------------------------------
  411. def updateInfo(self):
  412. # Update current program text
  413. if self.ui.cb_programs.count() > 0:
  414. pIndex = self.ui.cb_programs.currentIndex()
  415. pName = gCarla.host.get_program_name(self.fPluginId, pIndex)
  416. #pName = pName[:40] + (pName[40:] and "...")
  417. self.ui.cb_programs.setItemText(pIndex, pName)
  418. # Update current midi program text
  419. if self.ui.cb_midi_programs.count() > 0:
  420. mpIndex = self.ui.cb_midi_programs.currentIndex()
  421. mpData = gCarla.host.get_midi_program_data(self.fPluginId, mpIndex)
  422. mpBank = mpData['bank']
  423. mpProg = mpData['program']
  424. mpName = mpData['name']
  425. #mpName = mpName[:40] + (mpName[40:] and "...")
  426. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  427. # Update all parameter values
  428. for paramType, paramId, paramWidget in self.fParameterList:
  429. paramWidget.setValue(gCarla.host.get_current_parameter_value(self.fPluginId, paramId), False)
  430. paramWidget.update()
  431. self.fParametersToUpdate = []
  432. #------------------------------------------------------------------
  433. def reloadAll(self):
  434. if gCarla.host is not None:
  435. self.fPluginInfo = gCarla.host.get_plugin_info(self.fPluginId)
  436. if not gCarla.isLocal:
  437. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_CUSTOM_UI
  438. else:
  439. self.fPluginInfo = gFakePluginInfo
  440. self.reloadInfo()
  441. self.reloadParameters()
  442. self.reloadPrograms()
  443. if self.fPluginInfo['type'] == PLUGIN_LV2:
  444. self.ui.b_save_state.setEnabled(False)
  445. if not self.ui.scrollArea.isEnabled():
  446. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  447. self.fFirstInit = False
  448. #------------------------------------------------------------------
  449. def reloadInfo(self):
  450. if gCarla.host is not None:
  451. pluginName = gCarla.host.get_real_plugin_name(self.fPluginId)
  452. #audioCountInfo = gCarla.host.get_audio_port_count_info(self.fPluginId)
  453. midiCountInfo = gCarla.host.get_midi_port_count_info(self.fPluginId)
  454. #paramCountInfo = gCarla.host.get_parameter_count_info(self.fPluginId)
  455. else:
  456. pluginName = ""
  457. #audioCountInfo = gFakePortCountInfo
  458. midiCountInfo = gFakePortCountInfo
  459. #paramCountInfo = gFakePortCountInfo
  460. pluginHints = self.fPluginInfo['hints']
  461. self.ui.le_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  462. if pluginName:
  463. self.ui.label_name.setEnabled(True)
  464. self.ui.le_name.setEnabled(True)
  465. self.ui.le_name.setText(pluginName)
  466. self.ui.le_name.setToolTip(pluginName)
  467. else:
  468. self.ui.label_name.setEnabled(False)
  469. self.ui.le_name.setEnabled(False)
  470. self.ui.le_name.setText("")
  471. self.ui.le_name.setToolTip("")
  472. if self.fPluginInfo['label']:
  473. self.ui.label_label.setEnabled(True)
  474. self.ui.le_label.setEnabled(True)
  475. self.ui.le_label.setText(self.fPluginInfo['label'])
  476. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  477. else:
  478. self.ui.label_label.setEnabled(False)
  479. self.ui.le_label.setEnabled(False)
  480. self.ui.le_label.setText("")
  481. self.ui.le_label.setToolTip("")
  482. if self.fPluginInfo['maker']:
  483. self.ui.label_maker.setEnabled(True)
  484. self.ui.le_maker.setEnabled(True)
  485. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  486. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  487. else:
  488. self.ui.label_maker.setEnabled(False)
  489. self.ui.le_maker.setEnabled(False)
  490. self.ui.le_maker.setText("")
  491. self.ui.le_maker.setToolTip("")
  492. if self.fPluginInfo['copyright']:
  493. self.ui.label_copyright.setEnabled(True)
  494. self.ui.le_copyright.setEnabled(True)
  495. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  496. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  497. else:
  498. self.ui.label_copyright.setEnabled(False)
  499. self.ui.le_copyright.setEnabled(False)
  500. self.ui.le_copyright.setText("")
  501. self.ui.le_copyright.setToolTip("")
  502. if self.fPluginInfo['uniqueId'] != 0:
  503. self.ui.label_unique_id.setEnabled(True)
  504. self.ui.le_unique_id.setEnabled(True)
  505. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  506. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  507. else:
  508. self.ui.label_unique_id.setEnabled(False)
  509. self.ui.le_unique_id.setEnabled(False)
  510. self.ui.le_unique_id.setText("")
  511. self.ui.le_unique_id.setToolTip("")
  512. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  513. self.setWindowTitle(self.fPluginInfo['name'])
  514. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  515. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  516. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  517. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  518. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  519. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  520. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  521. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  522. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  523. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  524. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  525. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  526. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  527. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  528. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  529. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  530. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  531. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  532. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  533. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  534. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  535. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  536. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  537. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] == PLUGIN_VST else 1)
  538. # Show/hide keyboard
  539. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  540. self.ui.scrollArea.setEnabled(showKeyboard)
  541. self.ui.scrollArea.setVisible(showKeyboard)
  542. # Force-Update parent for new hints
  543. if self.fRealParent and not self.fFirstInit:
  544. self.fRealParent.recheckPluginHints(pluginHints)
  545. def reloadParameters(self):
  546. # Reset
  547. self.fParameterCount = 0
  548. self.fParameterList = []
  549. self.fParametersToUpdate = []
  550. self.fTabIconCount = 0
  551. self.fTabIconTimers = []
  552. # Remove all previous parameters
  553. for x in range(self.ui.tabWidget.count()-1):
  554. self.ui.tabWidget.widget(1).deleteLater()
  555. self.ui.tabWidget.removeTab(1)
  556. if gCarla.host is None:
  557. paramFakeListFull = []
  558. paramFakeList = []
  559. paramFakeWidth = QFontMetrics(self.font()).width(gFakeParamInfo['name'])
  560. paramFakeList.append(gFakeParamInfo)
  561. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  562. self._createParameterWidgets(PARAMETER_INPUT, paramFakeListFull, self.tr("Parameters"))
  563. return
  564. parameterCount = gCarla.host.get_parameter_count(self.fPluginId)
  565. if parameterCount <= 0:
  566. pass
  567. elif parameterCount <= gCarla.maxParameters:
  568. paramInputListFull = []
  569. paramOutputListFull = []
  570. paramInputList = [] # ([params], width)
  571. paramInputWidth = 0
  572. paramOutputList = [] # ([params], width)
  573. paramOutputWidth = 0
  574. for i in range(parameterCount):
  575. paramInfo = gCarla.host.get_parameter_info(self.fPluginId, i)
  576. paramData = gCarla.host.get_parameter_data(self.fPluginId, i)
  577. paramRanges = gCarla.host.get_parameter_ranges(self.fPluginId, i)
  578. paramValue = gCarla.host.get_current_parameter_value(self.fPluginId, i)
  579. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  580. continue
  581. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  582. continue
  583. parameter = {
  584. 'type': paramData['type'],
  585. 'hints': paramData['hints'],
  586. 'name': paramInfo['name'],
  587. 'unit': paramInfo['unit'],
  588. 'scalePoints': [],
  589. 'index': paramData['index'],
  590. 'default': paramRanges['def'],
  591. 'minimum': paramRanges['min'],
  592. 'maximum': paramRanges['max'],
  593. 'step': paramRanges['step'],
  594. 'stepSmall': paramRanges['stepSmall'],
  595. 'stepLarge': paramRanges['stepLarge'],
  596. 'midiCC': paramData['midiCC'],
  597. 'midiChannel': paramData['midiChannel']+1,
  598. 'current': paramValue
  599. }
  600. for j in range(paramInfo['scalePointCount']):
  601. scalePointInfo = gCarla.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  602. parameter['scalePoints'].append({
  603. 'value': scalePointInfo['value'],
  604. 'label': scalePointInfo['label']
  605. })
  606. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  607. # -----------------------------------------------------------------
  608. # Get width values, in packs of 10
  609. if parameter['type'] == PARAMETER_INPUT:
  610. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  611. if paramInputWidthTMP > paramInputWidth:
  612. paramInputWidth = paramInputWidthTMP
  613. paramInputList.append(parameter)
  614. if len(paramInputList) == self.kParamsPerPage:
  615. paramInputListFull.append((paramInputList, paramInputWidth))
  616. paramInputList = []
  617. paramInputWidth = 0
  618. else:
  619. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  620. if paramOutputWidthTMP > paramOutputWidth:
  621. paramOutputWidth = paramOutputWidthTMP
  622. paramOutputList.append(parameter)
  623. if len(paramOutputList) == self.kParamsPerPage:
  624. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  625. paramOutputList = []
  626. paramOutputWidth = 0
  627. # for i in range(parameterCount)
  628. else:
  629. # Final page width values
  630. if 0 < len(paramInputList) < 10:
  631. paramInputListFull.append((paramInputList, paramInputWidth))
  632. if 0 < len(paramOutputList) < 10:
  633. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  634. # -----------------------------------------------------------------
  635. # Create parameter tabs + widgets
  636. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  637. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  638. else: # > gCarla.maxParameters
  639. fakeName = self.tr("This plugin has too many parameters to display here!")
  640. paramFakeListFull = []
  641. paramFakeList = []
  642. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  643. parameter = {
  644. 'type': PARAMETER_UNKNOWN,
  645. 'hints': 0x0,
  646. 'name': fakeName,
  647. 'unit': "",
  648. 'scalePoints': [],
  649. 'index': 0,
  650. 'default': 0.0,
  651. 'minimum': 0.0,
  652. 'maximum': 0.0,
  653. 'step': 0.0,
  654. 'stepSmall': 0.0,
  655. 'stepLarge': 0.0,
  656. 'midiCC': -1,
  657. 'midiChannel': 1,
  658. 'current': 0.0
  659. }
  660. paramFakeList.append(parameter)
  661. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  662. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  663. def reloadPrograms(self):
  664. # Programs
  665. self.ui.cb_programs.blockSignals(True)
  666. self.ui.cb_programs.clear()
  667. programCount = gCarla.host.get_program_count(self.fPluginId) if gCarla.host is not None else 0
  668. if programCount > 0:
  669. self.ui.cb_programs.setEnabled(True)
  670. self.ui.label_programs.setEnabled(True)
  671. for i in range(programCount):
  672. pName = gCarla.host.get_program_name(self.fPluginId, i)
  673. #pName = pName[:40] + (pName[40:] and "...")
  674. self.ui.cb_programs.addItem(pName)
  675. self.fCurrentProgram = gCarla.host.get_current_program_index(self.fPluginId)
  676. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  677. else:
  678. self.fCurrentProgram = -1
  679. self.ui.cb_programs.setEnabled(False)
  680. self.ui.label_programs.setEnabled(False)
  681. self.ui.cb_programs.blockSignals(False)
  682. # MIDI Programs
  683. self.ui.cb_midi_programs.blockSignals(True)
  684. self.ui.cb_midi_programs.clear()
  685. midiProgramCount = gCarla.host.get_midi_program_count(self.fPluginId) if gCarla.host is not None else 0
  686. if midiProgramCount > 0:
  687. self.ui.cb_midi_programs.setEnabled(True)
  688. self.ui.label_midi_programs.setEnabled(True)
  689. for i in range(midiProgramCount):
  690. mpData = gCarla.host.get_midi_program_data(self.fPluginId, i)
  691. mpBank = mpData['bank']
  692. mpProg = mpData['program']
  693. mpName = mpData['name']
  694. #mpName = mpName[:40] + (mpName[40:] and "...")
  695. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  696. self.fCurrentMidiProgram = gCarla.host.get_current_midi_program_index(self.fPluginId)
  697. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  698. else:
  699. self.fCurrentMidiProgram = -1
  700. self.ui.cb_midi_programs.setEnabled(False)
  701. self.ui.label_midi_programs.setEnabled(False)
  702. self.ui.cb_midi_programs.blockSignals(False)
  703. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  704. if self.fPluginInfo['type'] == PLUGIN_LV2:
  705. self.ui.b_load_state.setEnabled(programCount > 0)
  706. #------------------------------------------------------------------
  707. def clearNotes(self):
  708. self.fPlayingNotes = []
  709. self.ui.keyboard.allNotesOff()
  710. #------------------------------------------------------------------
  711. def getHints(self):
  712. return self.fPluginInfo['hints']
  713. def setId(self, idx):
  714. self.fPluginId = idx
  715. def setName(self, name):
  716. self.fPluginInfo['name'] = name
  717. self.ui.label_plugin.setText("\n%s\n" % name)
  718. self.setWindowTitle(name)
  719. #------------------------------------------------------------------
  720. def setParameterValue(self, parameterId, value):
  721. for paramItem in self.fParametersToUpdate:
  722. if paramItem[0] == parameterId:
  723. paramItem[1] = value
  724. break
  725. else:
  726. self.fParametersToUpdate.append([parameterId, value])
  727. def setParameterDefault(self, parameterId, value):
  728. for paramType, paramId, paramWidget in self.fParameterList:
  729. if paramId == parameterId:
  730. paramWidget.setDefault(value)
  731. break
  732. def setParameterMidiControl(self, parameterId, control):
  733. for paramType, paramId, paramWidget in self.fParameterList:
  734. if paramId == parameterId:
  735. paramWidget.setMidiControl(control)
  736. break
  737. def setParameterMidiChannel(self, parameterId, channel):
  738. for paramType, paramId, paramWidget in self.fParameterList:
  739. if paramId == parameterId:
  740. paramWidget.setMidiChannel(channel+1)
  741. break
  742. def setProgram(self, index):
  743. self.ui.cb_programs.blockSignals(True)
  744. self.ui.cb_programs.setCurrentIndex(index)
  745. self.ui.cb_programs.blockSignals(False)
  746. def setMidiProgram(self, index):
  747. self.ui.cb_midi_programs.blockSignals(True)
  748. self.ui.cb_midi_programs.setCurrentIndex(index)
  749. self.ui.cb_midi_programs.blockSignals(False)
  750. #------------------------------------------------------------------
  751. def sendNoteOn(self, channel, note):
  752. if self.fControlChannel == channel:
  753. self.ui.keyboard.sendNoteOn(note, False)
  754. playItem = (channel, note)
  755. if playItem not in self.fPlayingNotes:
  756. self.fPlayingNotes.append(playItem)
  757. return bool(len(self.fPlayingNotes) == 1)
  758. def sendNoteOff(self, channel, note):
  759. if self.fControlChannel == channel:
  760. self.ui.keyboard.sendNoteOff(note, False)
  761. playItem = (channel, note)
  762. if playItem in self.fPlayingNotes:
  763. self.fPlayingNotes.remove(playItem)
  764. return bool(len(self.fPlayingNotes) == 0)
  765. #------------------------------------------------------------------
  766. def setVisible(self, yesNo):
  767. if yesNo:
  768. if not self.fGeometry.isNull():
  769. self.restoreGeometry(self.fGeometry)
  770. else:
  771. self.fGeometry = self.saveGeometry()
  772. QDialog.setVisible(self, yesNo)
  773. #------------------------------------------------------------------
  774. def idleSlow(self):
  775. # Check Tab icons
  776. for i in range(len(self.fTabIconTimers)):
  777. if self.fTabIconTimers[i] == ICON_STATE_ON:
  778. self.fTabIconTimers[i] = ICON_STATE_WAIT
  779. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  780. self.fTabIconTimers[i] = ICON_STATE_OFF
  781. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  782. self.fTabIconTimers[i] = ICON_STATE_NULL
  783. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  784. # Check parameters needing update
  785. for index, value in self.fParametersToUpdate:
  786. if index == PARAMETER_DRYWET:
  787. self.ui.dial_drywet.blockSignals(True)
  788. self.ui.dial_drywet.setValue(value)
  789. self.ui.dial_drywet.blockSignals(False)
  790. elif index == PARAMETER_VOLUME:
  791. self.ui.dial_vol.blockSignals(True)
  792. self.ui.dial_vol.setValue(value)
  793. self.ui.dial_vol.blockSignals(False)
  794. elif index == PARAMETER_BALANCE_LEFT:
  795. self.ui.dial_b_left.blockSignals(True)
  796. self.ui.dial_b_left.setValue(value)
  797. self.ui.dial_b_left.blockSignals(False)
  798. elif index == PARAMETER_BALANCE_RIGHT:
  799. self.ui.dial_b_right.blockSignals(True)
  800. self.ui.dial_b_right.setValue(value)
  801. self.ui.dial_b_right.blockSignals(False)
  802. elif index == PARAMETER_PANNING:
  803. self.ui.dial_pan.blockSignals(True)
  804. self.ui.dial_pan.setValue(value)
  805. self.ui.dial_pan.blockSignals(False)
  806. elif index == PARAMETER_CTRL_CHANNEL:
  807. self.fControlChannel = int(value)
  808. self.ui.sb_ctrl_channel.blockSignals(True)
  809. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  810. self.ui.sb_ctrl_channel.blockSignals(False)
  811. self.ui.keyboard.allNotesOff()
  812. self._updateCtrlMidiProgram()
  813. elif index >= 0:
  814. for paramType, paramId, paramWidget in self.fParameterList:
  815. if paramId != index:
  816. continue
  817. paramWidget.setValue(value, False)
  818. if paramType == PARAMETER_INPUT:
  819. tabIndex = paramWidget.getTabIndex()
  820. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  821. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  822. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  823. break
  824. # Clear all parameters
  825. self.fParametersToUpdate = []
  826. # Update parameter outputs
  827. for paramType, paramId, paramWidget in self.fParameterList:
  828. if paramType == PARAMETER_OUTPUT:
  829. value = gCarla.host.get_current_parameter_value(self.fPluginId, paramId)
  830. paramWidget.setValue(value, False)
  831. #------------------------------------------------------------------
  832. @pyqtSlot()
  833. def slot_stateSave(self):
  834. if self.fPluginInfo['type'] == PLUGIN_LV2:
  835. # TODO
  836. return
  837. if self.fCurrentStateFilename:
  838. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  839. if askTry == QMessageBox.Ok:
  840. gCarla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  841. return
  842. self.fCurrentStateFilename = None
  843. fileFilter = self.tr("Carla State File (*.carxs)")
  844. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  845. if filenameTry:
  846. if not filenameTry.lower().endswith(".carxs"):
  847. filenameTry += ".carxs"
  848. self.fCurrentStateFilename = filenameTry
  849. gCarla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  850. @pyqtSlot()
  851. def slot_stateLoad(self):
  852. if self.fPluginInfo['type'] == PLUGIN_LV2:
  853. presetList = []
  854. for i in range(gCarla.host.get_program_count(self.fPluginId)):
  855. presetList.append("%03i - %s" % (i+1, gCarla.host.get_program_name(self.fPluginId, i)))
  856. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  857. if ret[1]:
  858. index = int(ret[0].split(" - ", 1)[0])-1
  859. gCarla.host.set_midi_program(self.fPluginId, -1)
  860. gCarla.host.set_program(self.fPluginId, index)
  861. self.setMidiProgram(-1)
  862. return
  863. fileFilter = self.tr("Carla State File (*.carxs)")
  864. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  865. if filenameTry:
  866. self.fCurrentStateFilename = filenameTry
  867. gCarla.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  868. #------------------------------------------------------------------
  869. @pyqtSlot(bool)
  870. def slot_optionChanged(self, clicked):
  871. if gCarla.host is None:
  872. return
  873. sender = self.sender()
  874. if sender == self.ui.ch_fixed_buffer:
  875. option = PLUGIN_OPTION_FIXED_BUFFERS
  876. elif sender == self.ui.ch_force_stereo:
  877. option = PLUGIN_OPTION_FORCE_STEREO
  878. elif sender == self.ui.ch_map_program_changes:
  879. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  880. elif sender == self.ui.ch_use_chunks:
  881. option = PLUGIN_OPTION_USE_CHUNKS
  882. elif sender == self.ui.ch_send_control_changes:
  883. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  884. elif sender == self.ui.ch_send_channel_pressure:
  885. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  886. elif sender == self.ui.ch_send_note_aftertouch:
  887. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  888. elif sender == self.ui.ch_send_pitchbend:
  889. option = PLUGIN_OPTION_SEND_PITCHBEND
  890. elif sender == self.ui.ch_send_all_sound_off:
  891. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  892. else:
  893. return
  894. gCarla.host.set_option(self.fPluginId, option, clicked)
  895. #------------------------------------------------------------------
  896. @pyqtSlot(int)
  897. def slot_dryWetChanged(self, value):
  898. if gCarla.host is not None:
  899. gCarla.host.set_drywet(self.fPluginId, value)
  900. @pyqtSlot(int)
  901. def slot_volumeChanged(self, value):
  902. if gCarla.host is not None:
  903. gCarla.host.set_volume(self.fPluginId, value)
  904. @pyqtSlot(int)
  905. def slot_balanceLeftChanged(self, value):
  906. if gCarla.host is not None:
  907. gCarla.host.set_balance_left(self.fPluginId, value)
  908. @pyqtSlot(int)
  909. def slot_balanceRightChanged(self, value):
  910. if gCarla.host is not None:
  911. gCarla.host.set_balance_right(self.fPluginId, value)
  912. @pyqtSlot(int)
  913. def slot_panChanged(self, value):
  914. if gCarla.host is not None:
  915. gCarla.host.set_panning(self.fPluginId, value)
  916. @pyqtSlot(int)
  917. def slot_panningChanged(self, value):
  918. if gCarla.host is not None:
  919. gCarla.host.set_panning(self.fPluginId, value)
  920. @pyqtSlot(int)
  921. def slot_ctrlChannelChanged(self, value):
  922. self.fControlChannel = value-1
  923. if gCarla.host is not None:
  924. gCarla.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  925. self.ui.keyboard.allNotesOff()
  926. self._updateCtrlMidiProgram()
  927. #------------------------------------------------------------------
  928. @pyqtSlot(int, float)
  929. def slot_parameterValueChanged(self, parameterId, value):
  930. if gCarla.host is not None:
  931. gCarla.host.set_parameter_value(self.fPluginId, parameterId, value)
  932. if self.fRealParent is not None:
  933. self.fRealParent.parameterValueChanged(parameterId, value)
  934. @pyqtSlot(int, int)
  935. def slot_parameterMidiControlChanged(self, parameterId, control):
  936. if gCarla.host is not None:
  937. gCarla.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  938. @pyqtSlot(int, int)
  939. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  940. if gCarla.host is not None:
  941. gCarla.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  942. #------------------------------------------------------------------
  943. @pyqtSlot(int)
  944. def slot_programIndexChanged(self, index):
  945. self.fCurrentProgram = index
  946. if gCarla.host is not None:
  947. gCarla.host.set_program(self.fPluginId, index)
  948. if self.fRealParent is not None:
  949. self.fRealParent.programChanged(index)
  950. @pyqtSlot(int)
  951. def slot_midiProgramIndexChanged(self, index):
  952. self.fCurrentMidiProgram = index
  953. if gCarla.host is not None:
  954. gCarla.host.set_midi_program(self.fPluginId, index)
  955. if self.fRealParent is not None:
  956. self.fRealParent.midiProgramChanged(index)
  957. #------------------------------------------------------------------
  958. @pyqtSlot(int)
  959. def slot_noteOn(self, note):
  960. if self.fControlChannel >= 0 and gCarla.host is not None:
  961. gCarla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  962. if self.fRealParent is not None:
  963. self.fRealParent.notePressed(note)
  964. @pyqtSlot(int)
  965. def slot_noteOff(self, note):
  966. if self.fControlChannel >= 0 and gCarla.host is not None:
  967. gCarla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  968. if self.fRealParent is not None:
  969. self.fRealParent.noteReleased(note)
  970. #------------------------------------------------------------------
  971. @pyqtSlot()
  972. def slot_finished(self):
  973. if self.fRealParent is not None:
  974. self.fRealParent.editDialogChanged(False)
  975. #------------------------------------------------------------------
  976. @pyqtSlot()
  977. def slot_knobCustomMenu(self):
  978. knobName = self.sender().objectName()
  979. if knobName == "dial_drywet":
  980. minimum = 0
  981. maximum = 100
  982. default = 100
  983. label = "Dry/Wet"
  984. elif knobName == "dial_vol":
  985. minimum = 0
  986. maximum = 127
  987. default = 100
  988. label = "Volume"
  989. elif knobName == "dial_b_left":
  990. minimum = -100
  991. maximum = 100
  992. default = -100
  993. label = "Balance-Left"
  994. elif knobName == "dial_b_right":
  995. minimum = -100
  996. maximum = 100
  997. default = 100
  998. label = "Balance-Right"
  999. elif knobName == "dial_pan":
  1000. minimum = -100
  1001. maximum = 100
  1002. default = 0
  1003. label = "Panning"
  1004. else:
  1005. minimum = 0
  1006. maximum = 100
  1007. default = 100
  1008. label = "Unknown"
  1009. current = self.sender().value() / 10
  1010. menu = QMenu(self)
  1011. actReset = menu.addAction(self.tr("Reset (%i%%)" % default))
  1012. menu.addSeparator()
  1013. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % minimum))
  1014. actCenter = menu.addAction(self.tr("Set to Center"))
  1015. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % maximum))
  1016. menu.addSeparator()
  1017. actSet = menu.addAction(self.tr("Set value..."))
  1018. if label not in ("Balance-Left", "Balance-Right"):
  1019. menu.removeAction(actCenter)
  1020. actSelected = menu.exec_(QCursor.pos())
  1021. if actSelected == actSet:
  1022. valueTry = QInputDialog.getInteger(self, self.tr("Set value"), label, current, minimum, maximum, 1)
  1023. if valueTry[1]:
  1024. value = valueTry[0] * 10
  1025. else:
  1026. return
  1027. elif actSelected == actMinimum:
  1028. value = minimum * 10
  1029. elif actSelected == actMaximum:
  1030. value = maximum * 10
  1031. elif actSelected == actReset:
  1032. value = default * 10
  1033. elif actSelected == actCenter:
  1034. value = 0
  1035. else:
  1036. return
  1037. if label == "Dry/Wet":
  1038. self.ui.dial_drywet.setValue(value)
  1039. elif label == "Volume":
  1040. self.ui.dial_vol.setValue(value)
  1041. elif label == "Balance-Left":
  1042. self.ui.dial_b_left.setValue(value)
  1043. elif label == "Balance-Right":
  1044. self.ui.dial_b_right.setValue(value)
  1045. elif label == "Panning":
  1046. self.ui.dial_pan.setValue(value)
  1047. #------------------------------------------------------------------
  1048. @pyqtSlot()
  1049. def slot_channelCustomMenu(self):
  1050. menu = QMenu(self)
  1051. actNone = menu.addAction(self.tr("None"))
  1052. if self.fControlChannel+1 == 0:
  1053. actNone.setCheckable(True)
  1054. actNone.setChecked(True)
  1055. for i in range(1, 16+1):
  1056. action = menu.addAction("%i" % i)
  1057. if self.fControlChannel+1 == i:
  1058. action.setCheckable(True)
  1059. action.setChecked(True)
  1060. actSel = menu.exec_(QCursor.pos())
  1061. if not actSel:
  1062. pass
  1063. elif actSel == actNone:
  1064. self.ui.sb_ctrl_channel.setValue(0)
  1065. elif actSel:
  1066. selChannel = int(actSel.text())
  1067. self.ui.sb_ctrl_channel.setValue(selChannel)
  1068. #------------------------------------------------------------------
  1069. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1070. i = 1
  1071. for paramList, width in paramListFull:
  1072. if len(paramList) == 0:
  1073. break
  1074. tabIndex = self.ui.tabWidget.count()
  1075. tabPageContainer = QWidget(self.ui.tabWidget)
  1076. tabPageLayout = QVBoxLayout(tabPageContainer)
  1077. tabPageContainer.setLayout(tabPageLayout)
  1078. for paramInfo in paramList:
  1079. paramWidget = PluginParameter(tabPageContainer, paramInfo, self.fPluginId, tabIndex)
  1080. paramWidget.setLabelWidth(width)
  1081. tabPageLayout.addWidget(paramWidget)
  1082. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1083. if paramType == PARAMETER_INPUT:
  1084. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1085. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1086. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1087. tabPageLayout.addStretch()
  1088. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1089. i += 1
  1090. if paramType == PARAMETER_INPUT:
  1091. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1092. self.fTabIconTimers.append(ICON_STATE_NULL)
  1093. def _updateCtrlMidiProgram(self):
  1094. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_FILE_SF2):
  1095. return
  1096. elif self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1097. return
  1098. if self.fControlChannel < 0:
  1099. self.ui.cb_midi_programs.setEnabled(False)
  1100. return
  1101. self.ui.cb_midi_programs.setEnabled(True)
  1102. mpIndex = gCarla.host.get_current_midi_program_index(self.fPluginId)
  1103. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1104. self.setMidiProgram(mpIndex)
  1105. #------------------------------------------------------------------
  1106. def done(self, r):
  1107. QDialog.done(self, r)
  1108. self.close()
  1109. # ------------------------------------------------------------------------------------------------------------
  1110. # Main
  1111. if __name__ == '__main__':
  1112. from carla_style import CarlaApplication
  1113. app = CarlaApplication()
  1114. #gui = CarlaAboutW(None)
  1115. #gui = PluginParameter(None, gFakeParamInfo, 0, 0)
  1116. gui = PluginEdit(None, 0)
  1117. gui.show()
  1118. sys.exit(app.exec_())