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.

1510 lines
58KB

  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'], False)
  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, send=True):
  269. self.ui.widget.setValue(value, send)
  270. def setMidiControl(self, control):
  271. self.fMidiControl = control
  272. self.ui.sb_control.blockSignals(True)
  273. self.ui.sb_control.setValue(control)
  274. self.ui.sb_control.blockSignals(False)
  275. def setMidiChannel(self, channel):
  276. self.fMidiChannel = channel
  277. self.ui.sb_channel.blockSignals(True)
  278. self.ui.sb_channel.setValue(channel)
  279. self.ui.sb_channel.blockSignals(False)
  280. def setLabelWidth(self, width):
  281. self.ui.label.setFixedWidth(width)
  282. @pyqtSlot()
  283. def slot_controlSpinboxCustomMenu(self):
  284. menu = QMenu(self)
  285. actNone = menu.addAction(self.tr("None"))
  286. if self.fMidiControl == -1:
  287. actNone.setCheckable(True)
  288. actNone.setChecked(True)
  289. for cc in MIDI_CC_LIST:
  290. action = menu.addAction(cc)
  291. if self.fMidiControl != -1 and int(cc.split(" ", 1)[0], 16) == self.fMidiControl:
  292. action.setCheckable(True)
  293. action.setChecked(True)
  294. actSel = menu.exec_(QCursor.pos())
  295. if not actSel:
  296. pass
  297. elif actSel == actNone:
  298. self.ui.sb_control.setValue(-1)
  299. else:
  300. selControlStr = actSel.text()
  301. selControl = int(selControlStr.split(" ", 1)[0], 16)
  302. self.ui.sb_control.setValue(selControl)
  303. @pyqtSlot()
  304. def slot_channelSpinboxCustomMenu(self):
  305. menu = QMenu(self)
  306. for i in range(1, 16+1):
  307. action = menu.addAction("%i" % i)
  308. if self.fMidiChannel == i:
  309. action.setCheckable(True)
  310. action.setChecked(True)
  311. actSel = menu.exec_(QCursor.pos())
  312. if actSel:
  313. selChannel = int(actSel.text())
  314. self.ui.sb_channel.setValue(selChannel)
  315. @pyqtSlot(int)
  316. def slot_controlSpinboxChanged(self, control):
  317. self.fMidiControl = control
  318. self.midiControlChanged.emit(self.fParameterId, control)
  319. @pyqtSlot(int)
  320. def slot_channelSpinboxChanged(self, channel):
  321. self.fMidiChannel = channel
  322. self.midiChannelChanged.emit(self.fParameterId, channel)
  323. @pyqtSlot(float)
  324. def slot_widgetValueChanged(self, value):
  325. self.valueChanged.emit(self.fParameterId, value)
  326. def _textCallBack(self):
  327. return self.host.get_parameter_text(self.fPluginId, self.fParameterId)
  328. # ------------------------------------------------------------------------------------------------------------
  329. # Plugin Editor Parent (Meta class)
  330. #class PluginEditParentMeta():
  331. class PluginEditParentMeta(metaclass=ABCMeta):
  332. @abstractmethod
  333. def editDialogChanged(self, visible):
  334. raise NotImplementedError
  335. @abstractmethod
  336. def pluginHintsChanged(self, hints):
  337. raise NotImplementedError
  338. @abstractmethod
  339. def parameterValueChanged(self, parameterId, value):
  340. raise NotImplementedError
  341. @abstractmethod
  342. def programChanged(self, index):
  343. raise NotImplementedError
  344. @abstractmethod
  345. def midiProgramChanged(self, index):
  346. raise NotImplementedError
  347. @abstractmethod
  348. def notePressed(self, note):
  349. raise NotImplementedError
  350. @abstractmethod
  351. def noteReleased(self, note):
  352. raise NotImplementedError
  353. # ------------------------------------------------------------------------------------------------------------
  354. # Plugin Editor (Built-in)
  355. class PluginEdit(QDialog):
  356. kParamsPerPage = 8
  357. def __init__(self, parent, host, pluginId):
  358. QDialog.__init__(self, parent.window() if parent is not None else None)
  359. self.host = host
  360. self.ui = ui_carla_edit.Ui_PluginEdit()
  361. self.ui.setupUi(self)
  362. if False:
  363. parent = PluginEditParentMeta()
  364. host = CarlaHostMeta()
  365. # -------------------------------------------------------------
  366. # Internal stuff
  367. self.fGeometry = QByteArray()
  368. self.fPluginId = pluginId
  369. self.fPuginInfo = None
  370. self.fRealParent = parent
  371. self.fCurrentProgram = -1
  372. self.fCurrentMidiProgram = -1
  373. self.fCurrentStateFilename = None
  374. self.fControlChannel = int(host.get_internal_parameter_value(pluginId, PARAMETER_CTRL_CHANNEL))
  375. self.fFirstInit = True
  376. self.fParameterCount = 0
  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.fTabIconCount = 0
  383. self.fTabIconTimers = []
  384. # -------------------------------------------------------------
  385. # Set-up GUI
  386. self.ui.dial_drywet.setCustomPaintMode(self.ui.dial_drywet.CUSTOM_PAINT_MODE_CARLA_WET)
  387. self.ui.dial_drywet.setPixmap(3)
  388. self.ui.dial_drywet.setLabel("Dry/Wet")
  389. self.ui.dial_drywet.setMinimum(0.0)
  390. self.ui.dial_drywet.setMaximum(1.0)
  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_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L)
  397. self.ui.dial_b_left.setPixmap(4)
  398. self.ui.dial_b_left.setLabel("L")
  399. self.ui.dial_b_left.setMinimum(-1.0)
  400. self.ui.dial_b_left.setMaximum(1.0)
  401. self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R)
  402. self.ui.dial_b_right.setPixmap(4)
  403. self.ui.dial_b_right.setLabel("R")
  404. self.ui.dial_b_right.setMinimum(-1.0)
  405. self.ui.dial_b_right.setMaximum(1.0)
  406. self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN)
  407. self.ui.dial_pan.setPixmap(4)
  408. self.ui.dial_pan.setLabel("Pan")
  409. self.ui.dial_pan.setMinimum(-1.0)
  410. self.ui.dial_pan.setMaximum(1.0)
  411. self.ui.dial_drywet.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_DRYWET))
  412. self.ui.dial_vol.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_VOLUME))
  413. self.ui.dial_b_left.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_LEFT))
  414. self.ui.dial_b_right.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_RIGHT))
  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. # -------------------------------------------------------------
  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), False)
  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. self.fFirstInit = False
  489. # Workaround for a Qt4 bug, see https://bugreports.qt-project.org/browse/QTBUG-7792
  490. 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. pluginName = 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. if pluginName:
  504. self.ui.label_name.setEnabled(True)
  505. self.ui.le_name.setEnabled(True)
  506. self.ui.le_name.setText(pluginName)
  507. self.ui.le_name.setToolTip(pluginName)
  508. else:
  509. self.ui.label_name.setEnabled(False)
  510. self.ui.le_name.setEnabled(False)
  511. self.ui.le_name.setText("")
  512. self.ui.le_name.setToolTip("")
  513. if self.fPluginInfo['label']:
  514. self.ui.label_label.setEnabled(True)
  515. self.ui.le_label.setEnabled(True)
  516. self.ui.le_label.setText(self.fPluginInfo['label'])
  517. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  518. else:
  519. self.ui.label_label.setEnabled(False)
  520. self.ui.le_label.setEnabled(False)
  521. self.ui.le_label.setText("")
  522. self.ui.le_label.setToolTip("")
  523. if self.fPluginInfo['maker']:
  524. self.ui.label_maker.setEnabled(True)
  525. self.ui.le_maker.setEnabled(True)
  526. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  527. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  528. else:
  529. self.ui.label_maker.setEnabled(False)
  530. self.ui.le_maker.setEnabled(False)
  531. self.ui.le_maker.setText("")
  532. self.ui.le_maker.setToolTip("")
  533. if self.fPluginInfo['copyright']:
  534. self.ui.label_copyright.setEnabled(True)
  535. self.ui.le_copyright.setEnabled(True)
  536. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  537. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  538. else:
  539. self.ui.label_copyright.setEnabled(False)
  540. self.ui.le_copyright.setEnabled(False)
  541. self.ui.le_copyright.setText("")
  542. self.ui.le_copyright.setToolTip("")
  543. if self.fPluginInfo['uniqueId'] != 0:
  544. self.ui.label_unique_id.setEnabled(True)
  545. self.ui.le_unique_id.setEnabled(True)
  546. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  547. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  548. else:
  549. self.ui.label_unique_id.setEnabled(False)
  550. self.ui.le_unique_id.setEnabled(False)
  551. self.ui.le_unique_id.setText("")
  552. self.ui.le_unique_id.setToolTip("")
  553. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  554. self.setWindowTitle(self.fPluginInfo['name'])
  555. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  556. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  557. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  558. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  559. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  560. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  561. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  562. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  563. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  564. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  565. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  566. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  567. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  568. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  569. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  570. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  571. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  572. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  573. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  574. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  575. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  576. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  577. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  578. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] in (PLUGIN_VST, PLUGIN_GIG, PLUGIN_SFZ) else 1)
  579. # Show/hide keyboard
  580. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  581. self.ui.scrollArea.setEnabled(showKeyboard)
  582. self.ui.scrollArea.setVisible(showKeyboard)
  583. # Force-Update parent for new hints
  584. if self.fRealParent and not self.fFirstInit:
  585. self.fRealParent.pluginHintsChanged(pluginHints)
  586. def reloadParameters(self):
  587. # Reset
  588. self.fParameterCount = 0
  589. self.fParameterList = []
  590. self.fParametersToUpdate = []
  591. self.fTabIconCount = 0
  592. self.fTabIconTimers = []
  593. # Remove all previous parameters
  594. for x in range(self.ui.tabWidget.count()-1):
  595. self.ui.tabWidget.widget(1).deleteLater()
  596. self.ui.tabWidget.removeTab(1)
  597. parameterCount = self.host.get_parameter_count(self.fPluginId)
  598. if parameterCount <= 0:
  599. pass
  600. elif parameterCount <= gCarla.maxParameters:
  601. paramInputListFull = []
  602. paramOutputListFull = []
  603. paramInputList = [] # ([params], width)
  604. paramInputWidth = 0
  605. paramOutputList = [] # ([params], width)
  606. paramOutputWidth = 0
  607. for i in range(parameterCount):
  608. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  609. paramData = self.host.get_parameter_data(self.fPluginId, i)
  610. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  611. paramValue = self.host.get_current_parameter_value(self.fPluginId, i)
  612. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  613. continue
  614. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  615. continue
  616. parameter = {
  617. 'type': paramData['type'],
  618. 'hints': paramData['hints'],
  619. 'name': paramInfo['name'],
  620. 'unit': paramInfo['unit'],
  621. 'scalePoints': [],
  622. 'index': paramData['index'],
  623. 'default': paramRanges['def'],
  624. 'minimum': paramRanges['min'],
  625. 'maximum': paramRanges['max'],
  626. 'step': paramRanges['step'],
  627. 'stepSmall': paramRanges['stepSmall'],
  628. 'stepLarge': paramRanges['stepLarge'],
  629. 'midiCC': paramData['midiCC'],
  630. 'midiChannel': paramData['midiChannel']+1,
  631. 'current': paramValue
  632. }
  633. for j in range(paramInfo['scalePointCount']):
  634. scalePointInfo = self.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  635. parameter['scalePoints'].append({
  636. 'value': scalePointInfo['value'],
  637. 'label': scalePointInfo['label']
  638. })
  639. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  640. # -----------------------------------------------------------------
  641. # Get width values, in packs of 10
  642. if parameter['type'] == PARAMETER_INPUT:
  643. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  644. if paramInputWidthTMP > paramInputWidth:
  645. paramInputWidth = paramInputWidthTMP
  646. paramInputList.append(parameter)
  647. if len(paramInputList) == self.kParamsPerPage:
  648. paramInputListFull.append((paramInputList, paramInputWidth))
  649. paramInputList = []
  650. paramInputWidth = 0
  651. else:
  652. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  653. if paramOutputWidthTMP > paramOutputWidth:
  654. paramOutputWidth = paramOutputWidthTMP
  655. paramOutputList.append(parameter)
  656. if len(paramOutputList) == self.kParamsPerPage:
  657. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  658. paramOutputList = []
  659. paramOutputWidth = 0
  660. # for i in range(parameterCount)
  661. else:
  662. # Final page width values
  663. if 0 < len(paramInputList) < 10:
  664. paramInputListFull.append((paramInputList, paramInputWidth))
  665. if 0 < len(paramOutputList) < 10:
  666. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  667. # -----------------------------------------------------------------
  668. # Create parameter tabs + widgets
  669. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  670. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  671. else: # > gCarla.maxParameters
  672. fakeName = self.tr("This plugin has too many parameters to display here!")
  673. paramFakeListFull = []
  674. paramFakeList = []
  675. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  676. parameter = {
  677. 'type': PARAMETER_UNKNOWN,
  678. 'hints': 0x0,
  679. 'name': fakeName,
  680. 'unit': "",
  681. 'scalePoints': [],
  682. 'index': 0,
  683. 'default': 0.0,
  684. 'minimum': 0.0,
  685. 'maximum': 1.0,
  686. 'step': 0.0,
  687. 'stepSmall': 0.0,
  688. 'stepLarge': 0.0,
  689. 'midiCC': -1,
  690. 'midiChannel': 1,
  691. 'current': 0.0
  692. }
  693. paramFakeList.append(parameter)
  694. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  695. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  696. def reloadPrograms(self):
  697. # Programs
  698. self.ui.cb_programs.blockSignals(True)
  699. self.ui.cb_programs.clear()
  700. programCount = self.host.get_program_count(self.fPluginId)
  701. if programCount > 0:
  702. self.ui.cb_programs.setEnabled(True)
  703. self.ui.label_programs.setEnabled(True)
  704. for i in range(programCount):
  705. pName = self.host.get_program_name(self.fPluginId, i)
  706. #pName = pName[:40] + (pName[40:] and "...")
  707. self.ui.cb_programs.addItem(pName)
  708. self.fCurrentProgram = self.host.get_current_program_index(self.fPluginId)
  709. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  710. else:
  711. self.fCurrentProgram = -1
  712. self.ui.cb_programs.setEnabled(False)
  713. self.ui.label_programs.setEnabled(False)
  714. self.ui.cb_programs.blockSignals(False)
  715. # MIDI Programs
  716. self.ui.cb_midi_programs.blockSignals(True)
  717. self.ui.cb_midi_programs.clear()
  718. midiProgramCount = self.host.get_midi_program_count(self.fPluginId)
  719. if midiProgramCount > 0:
  720. self.ui.cb_midi_programs.setEnabled(True)
  721. self.ui.label_midi_programs.setEnabled(True)
  722. for i in range(midiProgramCount):
  723. mpData = self.host.get_midi_program_data(self.fPluginId, i)
  724. mpBank = mpData['bank']
  725. mpProg = mpData['program']
  726. mpName = mpData['name']
  727. #mpName = mpName[:40] + (mpName[40:] and "...")
  728. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  729. self.fCurrentMidiProgram = self.host.get_current_midi_program_index(self.fPluginId)
  730. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  731. else:
  732. self.fCurrentMidiProgram = -1
  733. self.ui.cb_midi_programs.setEnabled(False)
  734. self.ui.label_midi_programs.setEnabled(False)
  735. self.ui.cb_midi_programs.blockSignals(False)
  736. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  737. if self.fPluginInfo['type'] == PLUGIN_LV2:
  738. self.ui.b_load_state.setEnabled(programCount > 0)
  739. #------------------------------------------------------------------
  740. def clearNotes(self):
  741. self.fPlayingNotes = []
  742. self.ui.keyboard.allNotesOff()
  743. #------------------------------------------------------------------
  744. def getHints(self):
  745. return self.fPluginInfo['hints']
  746. def setId(self, idx):
  747. self.fPluginId = idx
  748. def setName(self, name):
  749. self.fPluginInfo['name'] = name
  750. self.ui.label_plugin.setText("\n%s\n" % name)
  751. self.setWindowTitle(name)
  752. #------------------------------------------------------------------
  753. def setParameterValue(self, parameterId, value):
  754. for paramItem in self.fParametersToUpdate:
  755. if paramItem[0] == parameterId:
  756. paramItem[1] = value
  757. break
  758. else:
  759. self.fParametersToUpdate.append([parameterId, value])
  760. def setParameterDefault(self, parameterId, value):
  761. for paramType, paramId, paramWidget in self.fParameterList:
  762. if paramId == parameterId:
  763. paramWidget.setDefault(value)
  764. break
  765. def setParameterMidiControl(self, parameterId, control):
  766. for paramType, paramId, paramWidget in self.fParameterList:
  767. if paramId == parameterId:
  768. paramWidget.setMidiControl(control)
  769. break
  770. def setParameterMidiChannel(self, parameterId, channel):
  771. for paramType, paramId, paramWidget in self.fParameterList:
  772. if paramId == parameterId:
  773. paramWidget.setMidiChannel(channel+1)
  774. break
  775. def setProgram(self, index):
  776. self.ui.cb_programs.blockSignals(True)
  777. self.ui.cb_programs.setCurrentIndex(index)
  778. self.ui.cb_programs.blockSignals(False)
  779. def setMidiProgram(self, index):
  780. self.ui.cb_midi_programs.blockSignals(True)
  781. self.ui.cb_midi_programs.setCurrentIndex(index)
  782. self.ui.cb_midi_programs.blockSignals(False)
  783. def setOption(self, option, yesNo):
  784. if option == PLUGIN_OPTION_FIXED_BUFFERS:
  785. widget = self.ui.ch_fixed_buffer
  786. elif option == PLUGIN_OPTION_FORCE_STEREO:
  787. widget = self.ui.ch_force_stereo
  788. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  789. widget = self.ui.ch_map_program_changes
  790. elif option == PLUGIN_OPTION_USE_CHUNKS:
  791. widget = self.ui.ch_use_chunks
  792. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  793. widget = self.ui.ch_send_control_changes
  794. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  795. widget = self.ui.ch_send_channel_pressure
  796. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  797. widget = self.ui.ch_send_note_aftertouch
  798. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  799. widget = self.ui.ch_send_pitchbend
  800. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  801. widget = self.ui.ch_send_all_sound_off
  802. else:
  803. return
  804. widget.blockSignals(True)
  805. widget.setChecked(yesNo)
  806. widget.blockSignals(False)
  807. #------------------------------------------------------------------
  808. def sendNoteOn(self, channel, note):
  809. if self.fControlChannel == channel:
  810. self.ui.keyboard.sendNoteOn(note, False)
  811. playItem = (channel, note)
  812. if playItem not in self.fPlayingNotes:
  813. self.fPlayingNotes.append(playItem)
  814. return bool(len(self.fPlayingNotes) == 1)
  815. def sendNoteOff(self, channel, note):
  816. if self.fControlChannel == channel:
  817. self.ui.keyboard.sendNoteOff(note, False)
  818. playItem = (channel, note)
  819. if playItem in self.fPlayingNotes:
  820. self.fPlayingNotes.remove(playItem)
  821. return bool(len(self.fPlayingNotes) == 0)
  822. #------------------------------------------------------------------
  823. def setVisible(self, yesNo):
  824. if yesNo:
  825. if not self.fGeometry.isNull():
  826. self.restoreGeometry(self.fGeometry)
  827. else:
  828. self.fGeometry = self.saveGeometry()
  829. QDialog.setVisible(self, yesNo)
  830. #------------------------------------------------------------------
  831. def idleSlow(self):
  832. # Check Tab icons
  833. for i in range(len(self.fTabIconTimers)):
  834. if self.fTabIconTimers[i] == ICON_STATE_ON:
  835. self.fTabIconTimers[i] = ICON_STATE_WAIT1
  836. elif self.fTabIconTimers[i] == ICON_STATE_WAIT1:
  837. self.fTabIconTimers[i] = ICON_STATE_WAIT2
  838. elif self.fTabIconTimers[i] == ICON_STATE_WAIT2:
  839. self.fTabIconTimers[i] = ICON_STATE_OFF
  840. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  841. # Check parameters needing update
  842. for index, value in self.fParametersToUpdate:
  843. if index == PARAMETER_DRYWET:
  844. self.ui.dial_drywet.blockSignals(True)
  845. self.ui.dial_drywet.setValue(value)
  846. self.ui.dial_drywet.blockSignals(False)
  847. elif index == PARAMETER_VOLUME:
  848. self.ui.dial_vol.blockSignals(True)
  849. self.ui.dial_vol.setValue(value)
  850. self.ui.dial_vol.blockSignals(False)
  851. elif index == PARAMETER_BALANCE_LEFT:
  852. self.ui.dial_b_left.blockSignals(True)
  853. self.ui.dial_b_left.setValue(value)
  854. self.ui.dial_b_left.blockSignals(False)
  855. elif index == PARAMETER_BALANCE_RIGHT:
  856. self.ui.dial_b_right.blockSignals(True)
  857. self.ui.dial_b_right.setValue(value)
  858. self.ui.dial_b_right.blockSignals(False)
  859. elif index == PARAMETER_PANNING:
  860. self.ui.dial_pan.blockSignals(True)
  861. self.ui.dial_pan.setValue(value)
  862. self.ui.dial_pan.blockSignals(False)
  863. elif index == PARAMETER_CTRL_CHANNEL:
  864. self.fControlChannel = int(value)
  865. self.ui.sb_ctrl_channel.blockSignals(True)
  866. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  867. self.ui.sb_ctrl_channel.blockSignals(False)
  868. self.ui.keyboard.allNotesOff()
  869. self._updateCtrlPrograms()
  870. elif index >= 0:
  871. for paramType, paramId, paramWidget in self.fParameterList:
  872. if paramId != index:
  873. continue
  874. paramWidget.setValue(value, False)
  875. if paramType == PARAMETER_INPUT:
  876. tabIndex = paramWidget.getTabIndex()
  877. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_OFF:
  878. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  879. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  880. break
  881. # Clear all parameters
  882. self.fParametersToUpdate = []
  883. # Update parameter outputs
  884. for paramType, paramId, paramWidget in self.fParameterList:
  885. if paramType == PARAMETER_OUTPUT:
  886. value = self.host.get_current_parameter_value(self.fPluginId, paramId)
  887. paramWidget.setValue(value, False)
  888. #------------------------------------------------------------------
  889. @pyqtSlot()
  890. def slot_stateSave(self):
  891. if self.fPluginInfo['type'] == PLUGIN_LV2:
  892. # TODO
  893. return
  894. if self.fCurrentStateFilename:
  895. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  896. if askTry == QMessageBox.Ok:
  897. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  898. return
  899. self.fCurrentStateFilename = None
  900. fileFilter = self.tr("Carla State File (*.carxs)")
  901. filename = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  902. if config_UseQt5:
  903. filename = filename[0]
  904. if not filename:
  905. return
  906. if not filename.lower().endswith(".carxs"):
  907. filename += ".carxs"
  908. self.fCurrentStateFilename = filename
  909. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  910. @pyqtSlot()
  911. def slot_stateLoad(self):
  912. if self.fPluginInfo['type'] == PLUGIN_LV2:
  913. presetList = []
  914. for i in range(self.host.get_program_count(self.fPluginId)):
  915. presetList.append("%03i - %s" % (i+1, self.host.get_program_name(self.fPluginId, i)))
  916. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  917. if ret[1]:
  918. index = int(ret[0].split(" - ", 1)[0])-1
  919. self.host.set_midi_program(self.fPluginId, -1)
  920. self.host.set_program(self.fPluginId, index)
  921. self.setMidiProgram(-1)
  922. return
  923. fileFilter = self.tr("Carla State File (*.carxs)")
  924. filename = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  925. if config_UseQt5:
  926. filename = filename[0]
  927. if not filename:
  928. return
  929. self.fCurrentStateFilename = filename
  930. self.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  931. #------------------------------------------------------------------
  932. @pyqtSlot(bool)
  933. def slot_optionChanged(self, clicked):
  934. sender = self.sender()
  935. if sender == self.ui.ch_fixed_buffer:
  936. option = PLUGIN_OPTION_FIXED_BUFFERS
  937. elif sender == self.ui.ch_force_stereo:
  938. option = PLUGIN_OPTION_FORCE_STEREO
  939. elif sender == self.ui.ch_map_program_changes:
  940. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  941. elif sender == self.ui.ch_use_chunks:
  942. option = PLUGIN_OPTION_USE_CHUNKS
  943. elif sender == self.ui.ch_send_control_changes:
  944. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  945. elif sender == self.ui.ch_send_channel_pressure:
  946. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  947. elif sender == self.ui.ch_send_note_aftertouch:
  948. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  949. elif sender == self.ui.ch_send_pitchbend:
  950. option = PLUGIN_OPTION_SEND_PITCHBEND
  951. elif sender == self.ui.ch_send_all_sound_off:
  952. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  953. else:
  954. return
  955. self.host.set_option(self.fPluginId, option, clicked)
  956. #------------------------------------------------------------------
  957. @pyqtSlot(int)
  958. def slot_dryWetChanged(self, value):
  959. self.host.set_drywet(self.fPluginId, value)
  960. if self.fRealParent is not None:
  961. self.fRealParent.parameterValueChanged(PARAMETER_DRYWET, value)
  962. @pyqtSlot(int)
  963. def slot_volumeChanged(self, value):
  964. self.host.set_volume(self.fPluginId, value)
  965. if self.fRealParent is not None:
  966. self.fRealParent.parameterValueChanged(PARAMETER_VOLUME, value)
  967. @pyqtSlot(int)
  968. def slot_balanceLeftChanged(self, value):
  969. self.host.set_balance_left(self.fPluginId, value)
  970. if self.fRealParent is not None:
  971. self.fRealParent.parameterValueChanged(PARAMETER_BALANCE_LEFT, value)
  972. @pyqtSlot(int)
  973. def slot_balanceRightChanged(self, value):
  974. self.host.set_balance_right(self.fPluginId, value)
  975. if self.fRealParent is not None:
  976. self.fRealParent.parameterValueChanged(PARAMETER_BALANCE_RIGHT, value)
  977. @pyqtSlot(int)
  978. def slot_panChanged(self, value):
  979. self.host.set_panning(self.fPluginId, value)
  980. if self.fRealParent is not None:
  981. self.fRealParent.parameterValueChanged(PARAMETER_PANNING, value)
  982. @pyqtSlot(int)
  983. def slot_ctrlChannelChanged(self, value):
  984. self.fControlChannel = value-1
  985. self.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  986. self.ui.keyboard.allNotesOff()
  987. self._updateCtrlPrograms()
  988. #------------------------------------------------------------------
  989. @pyqtSlot(int, float)
  990. def slot_parameterValueChanged(self, parameterId, value):
  991. self.host.set_parameter_value(self.fPluginId, parameterId, value)
  992. if self.fRealParent is not None:
  993. self.fRealParent.parameterValueChanged(parameterId, value)
  994. @pyqtSlot(int, int)
  995. def slot_parameterMidiControlChanged(self, parameterId, control):
  996. self.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  997. @pyqtSlot(int, int)
  998. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  999. self.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1000. #------------------------------------------------------------------
  1001. @pyqtSlot(int)
  1002. def slot_programIndexChanged(self, index):
  1003. self.fCurrentProgram = index
  1004. self.host.set_program(self.fPluginId, index)
  1005. if self.fRealParent is not None:
  1006. self.fRealParent.programChanged(index)
  1007. @pyqtSlot(int)
  1008. def slot_midiProgramIndexChanged(self, index):
  1009. self.fCurrentMidiProgram = index
  1010. self.host.set_midi_program(self.fPluginId, index)
  1011. if self.fRealParent is not None:
  1012. self.fRealParent.midiProgramChanged(index)
  1013. #------------------------------------------------------------------
  1014. @pyqtSlot(int)
  1015. def slot_noteOn(self, note):
  1016. if self.fControlChannel >= 0:
  1017. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1018. if self.fRealParent is not None:
  1019. self.fRealParent.notePressed(note)
  1020. @pyqtSlot(int)
  1021. def slot_noteOff(self, note):
  1022. if self.fControlChannel >= 0:
  1023. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1024. if self.fRealParent is not None:
  1025. self.fRealParent.noteReleased(note)
  1026. #------------------------------------------------------------------
  1027. @pyqtSlot()
  1028. def slot_finished(self):
  1029. if self.fRealParent is not None:
  1030. self.fRealParent.editDialogChanged(False)
  1031. #------------------------------------------------------------------
  1032. @pyqtSlot()
  1033. def slot_knobCustomMenu(self):
  1034. knobName = self.sender().objectName()
  1035. if knobName == "dial_drywet":
  1036. minimum = 0.0
  1037. maximum = 1.0
  1038. default = 1.0
  1039. label = "Dry/Wet"
  1040. elif knobName == "dial_vol":
  1041. minimum = 0.0
  1042. maximum = 1.27
  1043. default = 1.0
  1044. label = "Volume"
  1045. elif knobName == "dial_b_left":
  1046. minimum = -1.0
  1047. maximum = 1.0
  1048. default = -1.0
  1049. label = "Balance-Left"
  1050. elif knobName == "dial_b_right":
  1051. minimum = -1.0
  1052. maximum = 1.0
  1053. default = 1.0
  1054. label = "Balance-Right"
  1055. elif knobName == "dial_pan":
  1056. minimum = -1.0
  1057. maximum = 1.0
  1058. default = 0.0
  1059. label = "Panning"
  1060. else:
  1061. minimum = 0.0
  1062. maximum = 1.0
  1063. default = 0.5
  1064. label = "Unknown"
  1065. current = self.sender().value() / 10
  1066. menu = QMenu(self)
  1067. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1068. menu.addSeparator()
  1069. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1070. actCenter = menu.addAction(self.tr("Set to Center"))
  1071. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1072. menu.addSeparator()
  1073. actSet = menu.addAction(self.tr("Set value..."))
  1074. if label not in ("Balance-Left", "Balance-Right"):
  1075. menu.removeAction(actCenter)
  1076. actSelected = menu.exec_(QCursor.pos())
  1077. if actSelected == actSet:
  1078. valueTry = QInputDialog.getDouble(self, self.tr("Set value"), label, current, minimum, maximum, 3)
  1079. if valueTry[1]:
  1080. value = valueTry[0] * 10
  1081. else:
  1082. return
  1083. elif actSelected == actMinimum:
  1084. value = minimum
  1085. elif actSelected == actMaximum:
  1086. value = maximum
  1087. elif actSelected == actReset:
  1088. value = default
  1089. elif actSelected == actCenter:
  1090. value = 0.0
  1091. else:
  1092. return
  1093. self.sender().setValue(value)
  1094. #------------------------------------------------------------------
  1095. @pyqtSlot()
  1096. def slot_channelCustomMenu(self):
  1097. menu = QMenu(self)
  1098. actNone = menu.addAction(self.tr("None"))
  1099. if self.fControlChannel+1 == 0:
  1100. actNone.setCheckable(True)
  1101. actNone.setChecked(True)
  1102. for i in range(1, 16+1):
  1103. action = menu.addAction("%i" % i)
  1104. if self.fControlChannel+1 == i:
  1105. action.setCheckable(True)
  1106. action.setChecked(True)
  1107. actSel = menu.exec_(QCursor.pos())
  1108. if not actSel:
  1109. pass
  1110. elif actSel == actNone:
  1111. self.ui.sb_ctrl_channel.setValue(0)
  1112. elif actSel:
  1113. selChannel = int(actSel.text())
  1114. self.ui.sb_ctrl_channel.setValue(selChannel)
  1115. #------------------------------------------------------------------
  1116. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1117. i = 1
  1118. for paramList, width in paramListFull:
  1119. if len(paramList) == 0:
  1120. break
  1121. tabIndex = self.ui.tabWidget.count()
  1122. tabPageContainer = QWidget(self.ui.tabWidget)
  1123. tabPageLayout = QVBoxLayout(tabPageContainer)
  1124. tabPageContainer.setLayout(tabPageLayout)
  1125. for paramInfo in paramList:
  1126. paramWidget = PluginParameter(tabPageContainer, self.host, paramInfo, self.fPluginId, tabIndex)
  1127. paramWidget.setLabelWidth(width)
  1128. tabPageLayout.addWidget(paramWidget)
  1129. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1130. if paramType == PARAMETER_INPUT:
  1131. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1132. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1133. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1134. tabPageLayout.addStretch()
  1135. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1136. i += 1
  1137. if paramType == PARAMETER_INPUT:
  1138. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1139. self.fTabIconTimers.append(ICON_STATE_OFF)
  1140. def _updateCtrlPrograms(self):
  1141. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH or self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2, PLUGIN_GIG):
  1142. return
  1143. if self.fControlChannel < 0:
  1144. self.ui.cb_programs.setEnabled(False)
  1145. self.ui.cb_midi_programs.setEnabled(False)
  1146. return
  1147. self.ui.cb_programs.setEnabled(True)
  1148. self.ui.cb_midi_programs.setEnabled(True)
  1149. pIndex = self.host.get_current_program_index(self.fPluginId)
  1150. if self.ui.cb_programs.currentIndex() != pIndex:
  1151. self.setProgram(pIndex)
  1152. mpIndex = self.host.get_current_midi_program_index(self.fPluginId)
  1153. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1154. self.setMidiProgram(mpIndex)
  1155. #------------------------------------------------------------------
  1156. def done(self, r):
  1157. QDialog.done(self, r)
  1158. self.close()
  1159. # ------------------------------------------------------------------------------------------------------------
  1160. # Main
  1161. if __name__ == '__main__':
  1162. from carla_app import CarlaApplication
  1163. app = CarlaApplication()
  1164. host = CarlaHostNull()
  1165. #gui1 = CarlaAboutW(None)
  1166. #gui1.show()
  1167. #gui2 = PluginParameter(None, gFakeParamInfo, 0, 0)
  1168. #gui2.show()
  1169. gui3 = PluginEdit(None, host, 0)
  1170. gui3.show()
  1171. app.exit_exec()