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.

1475 lines
57KB

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