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.

1403 lines
55KB

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