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.

1398 lines
55KB

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