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