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.

1590 lines
62KB

  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. self.host = host
  208. # -------------------------------------------------------------
  209. # Internal stuff
  210. self.fMidiControl = -1
  211. self.fMidiChannel = 1
  212. self.fParameterId = pInfo['index']
  213. self.fPluginId = pluginId
  214. self.fTabIndex = tabIndex
  215. # -------------------------------------------------------------
  216. # Set-up GUI
  217. pType = pInfo['type']
  218. pHints = pInfo['hints']
  219. self.ui.label.setText(pInfo['name'])
  220. self.ui.widget.setName(pInfo['name'])
  221. self.ui.widget.setMinimum(pInfo['minimum'])
  222. self.ui.widget.setMaximum(pInfo['maximum'])
  223. self.ui.widget.setDefault(pInfo['default'])
  224. self.ui.widget.setValue(pInfo['current'])
  225. self.ui.widget.setLabel(pInfo['unit'])
  226. self.ui.widget.setStep(pInfo['step'])
  227. self.ui.widget.setStepSmall(pInfo['stepSmall'])
  228. self.ui.widget.setStepLarge(pInfo['stepLarge'])
  229. self.ui.widget.setScalePoints(pInfo['scalePoints'], bool(pHints & PARAMETER_USES_SCALEPOINTS))
  230. if not pHints & PARAMETER_IS_AUTOMABLE:
  231. self.ui.sb_control.setEnabled(False)
  232. self.ui.sb_channel.setEnabled(False)
  233. if pType == PARAMETER_INPUT:
  234. if not pHints & PARAMETER_IS_ENABLED:
  235. self.ui.label.setEnabled(False)
  236. self.ui.widget.setEnabled(False)
  237. self.ui.widget.setReadOnly(True)
  238. self.ui.sb_control.setEnabled(False)
  239. self.ui.sb_channel.setEnabled(False)
  240. if pHints & PARAMETER_IS_READ_ONLY:
  241. self.ui.widget.setReadOnly(True)
  242. elif pType == PARAMETER_OUTPUT:
  243. self.ui.widget.setReadOnly(True)
  244. else:
  245. self.ui.widget.setVisible(False)
  246. self.ui.sb_control.setVisible(False)
  247. self.ui.sb_channel.setVisible(False)
  248. if pHints & PARAMETER_USES_CUSTOM_TEXT and not host.isPlugin:
  249. self.ui.widget.setTextCallback(self._textCallBack)
  250. self.ui.widget.updateAll()
  251. self.setMidiControl(pInfo['midiCC'])
  252. self.setMidiChannel(pInfo['midiChannel'])
  253. # -------------------------------------------------------------
  254. # Set-up connections
  255. self.ui.sb_control.customContextMenuRequested.connect(self.slot_controlSpinboxCustomMenu)
  256. self.ui.sb_channel.customContextMenuRequested.connect(self.slot_channelSpinboxCustomMenu)
  257. self.ui.sb_control.valueChanged.connect(self.slot_controlSpinboxChanged)
  258. self.ui.sb_channel.valueChanged.connect(self.slot_channelSpinboxChanged)
  259. self.ui.widget.valueChanged.connect(self.slot_widgetValueChanged)
  260. # -------------------------------------------------------------
  261. def getPluginId(self):
  262. return self.fPluginId
  263. def getTabIndex(self):
  264. return self.fTabIndex
  265. def setPluginId(self, pluginId):
  266. self.fPluginId = pluginId
  267. def setDefault(self, value):
  268. self.ui.widget.setDefault(value)
  269. def setValue(self, value):
  270. self.ui.widget.blockSignals(True)
  271. self.ui.widget.setValue(value)
  272. self.ui.widget.blockSignals(False)
  273. def setMidiControl(self, control):
  274. self.fMidiControl = control
  275. self.ui.sb_control.blockSignals(True)
  276. self.ui.sb_control.setValue(control)
  277. self.ui.sb_control.blockSignals(False)
  278. def setMidiChannel(self, channel):
  279. self.fMidiChannel = channel
  280. self.ui.sb_channel.blockSignals(True)
  281. self.ui.sb_channel.setValue(channel)
  282. self.ui.sb_channel.blockSignals(False)
  283. def setLabelWidth(self, width):
  284. self.ui.label.setFixedWidth(width)
  285. @pyqtSlot()
  286. def slot_controlSpinboxCustomMenu(self):
  287. menu = QMenu(self)
  288. actNone = menu.addAction(self.tr("None"))
  289. if self.fMidiControl == -1:
  290. actNone.setCheckable(True)
  291. actNone.setChecked(True)
  292. for cc in MIDI_CC_LIST:
  293. action = menu.addAction(cc)
  294. if self.fMidiControl != -1 and int(cc.split(" ", 1)[0], 16) == self.fMidiControl:
  295. action.setCheckable(True)
  296. action.setChecked(True)
  297. actSel = menu.exec_(QCursor.pos())
  298. if not actSel:
  299. pass
  300. elif actSel == actNone:
  301. self.ui.sb_control.setValue(-1)
  302. else:
  303. selControlStr = actSel.text()
  304. selControl = int(selControlStr.split(" ", 1)[0], 16)
  305. self.ui.sb_control.setValue(selControl)
  306. @pyqtSlot()
  307. def slot_channelSpinboxCustomMenu(self):
  308. menu = QMenu(self)
  309. for i in range(1, 16+1):
  310. action = menu.addAction("%i" % i)
  311. if self.fMidiChannel == i:
  312. action.setCheckable(True)
  313. action.setChecked(True)
  314. actSel = menu.exec_(QCursor.pos())
  315. if actSel:
  316. selChannel = int(actSel.text())
  317. self.ui.sb_channel.setValue(selChannel)
  318. @pyqtSlot(int)
  319. def slot_controlSpinboxChanged(self, control):
  320. self.fMidiControl = control
  321. self.midiControlChanged.emit(self.fParameterId, control)
  322. @pyqtSlot(int)
  323. def slot_channelSpinboxChanged(self, channel):
  324. self.fMidiChannel = channel
  325. self.midiChannelChanged.emit(self.fParameterId, channel)
  326. @pyqtSlot(float)
  327. def slot_widgetValueChanged(self, value):
  328. self.valueChanged.emit(self.fParameterId, value)
  329. def _textCallBack(self):
  330. return self.host.get_parameter_text(self.fPluginId, self.fParameterId)
  331. # ------------------------------------------------------------------------------------------------------------
  332. # Plugin Editor Parent (Meta class)
  333. class PluginEditParentMeta():
  334. #class PluginEditParentMeta(metaclass=ABCMeta):
  335. @abstractmethod
  336. def editDialogVisibilityChanged(self, pluginId, visible):
  337. raise NotImplementedError
  338. @abstractmethod
  339. def editDialogPluginHintsChanged(self, pluginId, hints):
  340. raise NotImplementedError
  341. @abstractmethod
  342. def editDialogParameterValueChanged(self, pluginId, parameterId, value):
  343. raise NotImplementedError
  344. @abstractmethod
  345. def editDialogProgramChanged(self, pluginId, index):
  346. raise NotImplementedError
  347. @abstractmethod
  348. def editDialogMidiProgramChanged(self, pluginId, index):
  349. raise NotImplementedError
  350. @abstractmethod
  351. def editDialogNotePressed(self, pluginId, note):
  352. raise NotImplementedError
  353. @abstractmethod
  354. def editDialogNoteReleased(self, pluginId, note):
  355. raise NotImplementedError
  356. @abstractmethod
  357. def editDialogMidiActivityChanged(self, pluginId, onOff):
  358. raise NotImplementedError
  359. # ------------------------------------------------------------------------------------------------------------
  360. # Plugin Editor (Built-in)
  361. class PluginEdit(QDialog):
  362. kParamsPerPage = 8
  363. def __init__(self, parent, host, pluginId):
  364. QDialog.__init__(self, parent.window() if parent is not None else None)
  365. self.host = host
  366. self.ui = ui_carla_edit.Ui_PluginEdit()
  367. self.ui.setupUi(self)
  368. if False:
  369. # kdevelop likes this :)
  370. parent = PluginEditParentMeta()
  371. host = CarlaHostMeta()
  372. self.host = host
  373. # -------------------------------------------------------------
  374. # Internal stuff
  375. self.fGeometry = QByteArray()
  376. self.fParent = parent
  377. self.fPluginId = pluginId
  378. self.fPluginInfo = None
  379. self.fCurrentStateFilename = None
  380. self.fControlChannel = int(host.get_internal_parameter_value(pluginId, PARAMETER_CTRL_CHANNEL))
  381. self.fFirstInit = True
  382. self.fParameterList = [] # (type, id, widget)
  383. self.fParametersToUpdate = [] # (id, value)
  384. self.fPlayingNotes = [] # (channel, note)
  385. self.fTabIconOff = QIcon(":/bitmaps/led_off.png")
  386. self.fTabIconOn = QIcon(":/bitmaps/led_yellow.png")
  387. self.fTabIconTimers = []
  388. # used during testing
  389. self.fIdleTimerId = 0
  390. # -------------------------------------------------------------
  391. # Set-up GUI
  392. self.ui.dial_drywet.setCustomPaintMode(self.ui.dial_drywet.CUSTOM_PAINT_MODE_CARLA_WET)
  393. self.ui.dial_drywet.setPixmap(3)
  394. self.ui.dial_drywet.setLabel("Dry/Wet")
  395. self.ui.dial_drywet.setMinimum(0.0)
  396. self.ui.dial_drywet.setMaximum(1.0)
  397. self.ui.dial_drywet.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_DRYWET))
  398. self.ui.dial_vol.setCustomPaintMode(self.ui.dial_vol.CUSTOM_PAINT_MODE_CARLA_VOL)
  399. self.ui.dial_vol.setPixmap(3)
  400. self.ui.dial_vol.setLabel("Volume")
  401. self.ui.dial_vol.setMinimum(0.0)
  402. self.ui.dial_vol.setMaximum(1.27)
  403. self.ui.dial_vol.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_VOLUME))
  404. self.ui.dial_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L)
  405. self.ui.dial_b_left.setPixmap(4)
  406. self.ui.dial_b_left.setLabel("L")
  407. self.ui.dial_b_left.setMinimum(-1.0)
  408. self.ui.dial_b_left.setMaximum(1.0)
  409. self.ui.dial_b_left.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_LEFT))
  410. self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R)
  411. self.ui.dial_b_right.setPixmap(4)
  412. self.ui.dial_b_right.setLabel("R")
  413. self.ui.dial_b_right.setMinimum(-1.0)
  414. self.ui.dial_b_right.setMaximum(1.0)
  415. self.ui.dial_b_right.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_RIGHT))
  416. self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN)
  417. self.ui.dial_pan.setPixmap(4)
  418. self.ui.dial_pan.setLabel("Pan")
  419. self.ui.dial_pan.setMinimum(-1.0)
  420. self.ui.dial_pan.setMaximum(1.0)
  421. self.ui.dial_pan.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_PANNING))
  422. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  423. self.ui.scrollArea = PixmapKeyboardHArea(self)
  424. self.ui.keyboard = self.ui.scrollArea.keyboard
  425. self.layout().addWidget(self.ui.scrollArea)
  426. self.ui.scrollArea.setEnabled(False)
  427. self.ui.scrollArea.setVisible(False)
  428. # todo
  429. self.ui.rb_balance.setEnabled(False)
  430. self.ui.rb_pan.setEnabled(False)
  431. self.reloadAll()
  432. self.fFirstInit = False
  433. # -------------------------------------------------------------
  434. # Set-up connections
  435. self.finished.connect(self.slot_finished)
  436. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  437. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  438. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  439. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  440. self.ui.ch_send_program_changes.clicked.connect(self.slot_optionChanged)
  441. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  442. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  443. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  444. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  445. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  446. self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged)
  447. self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged)
  448. self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged)
  449. self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged)
  450. self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged)
  451. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  452. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  453. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  454. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  455. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  456. self.ui.dial_pan.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  457. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  458. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  459. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  460. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  461. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  462. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  463. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  464. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  465. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  466. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  467. host.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  468. host.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  469. host.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  470. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  471. #------------------------------------------------------------------
  472. @pyqtSlot(int, int, int, int)
  473. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  474. if self.fPluginId != pluginId: return
  475. if self.fControlChannel == channel:
  476. self.ui.keyboard.sendNoteOn(note, False)
  477. playItem = (channel, note)
  478. if playItem not in self.fPlayingNotes:
  479. self.fPlayingNotes.append(playItem)
  480. if len(self.fPlayingNotes) == 1 and self.fParent is not None:
  481. self.fParent.editDialogMidiActivityChanged(self.fPluginId, True)
  482. @pyqtSlot(int, int, int)
  483. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  484. if self.fPluginId != pluginId: return
  485. if self.fControlChannel == channel:
  486. self.ui.keyboard.sendNoteOff(note, False)
  487. playItem = (channel, note)
  488. if playItem in self.fPlayingNotes:
  489. self.fPlayingNotes.remove(playItem)
  490. if len(self.fPlayingNotes) == 0 and self.fParent is not None:
  491. self.fParent.editDialogMidiActivityChanged(self.fPluginId, False)
  492. @pyqtSlot(int)
  493. def slot_handleUpdateCallback(self, pluginId):
  494. if self.fPluginId == pluginId:
  495. self.updateInfo()
  496. @pyqtSlot(int)
  497. def slot_handleReloadInfoCallback(self, pluginId):
  498. if self.fPluginId == pluginId:
  499. self.reloadInfo()
  500. @pyqtSlot(int)
  501. def slot_handleReloadParametersCallback(self, pluginId):
  502. if self.fPluginId == pluginId:
  503. self.reloadParameters()
  504. @pyqtSlot(int)
  505. def slot_handleReloadProgramsCallback(self, pluginId):
  506. if self.fPluginId == pluginId:
  507. self.reloadPrograms()
  508. @pyqtSlot(int)
  509. def slot_handleReloadAllCallback(self, pluginId):
  510. if self.fPluginId == pluginId:
  511. self.reloadAll()
  512. #------------------------------------------------------------------
  513. def updateInfo(self):
  514. # Update current program text
  515. if self.ui.cb_programs.count() > 0:
  516. pIndex = self.ui.cb_programs.currentIndex()
  517. pName = self.host.get_program_name(self.fPluginId, pIndex)
  518. #pName = pName[:40] + (pName[40:] and "...")
  519. self.ui.cb_programs.setItemText(pIndex, pName)
  520. # Update current midi program text
  521. if self.ui.cb_midi_programs.count() > 0:
  522. mpIndex = self.ui.cb_midi_programs.currentIndex()
  523. mpData = self.host.get_midi_program_data(self.fPluginId, mpIndex)
  524. mpBank = mpData['bank']
  525. mpProg = mpData['program']
  526. mpName = mpData['name']
  527. #mpName = mpName[:40] + (mpName[40:] and "...")
  528. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  529. # Update all parameter values
  530. for paramType, paramId, paramWidget in self.fParameterList:
  531. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  532. paramWidget.update()
  533. self.fParametersToUpdate = []
  534. #------------------------------------------------------------------
  535. def reloadAll(self):
  536. self.fPluginInfo = self.host.get_plugin_info(self.fPluginId)
  537. self.reloadInfo()
  538. self.reloadParameters()
  539. self.reloadPrograms()
  540. if self.fPluginInfo['type'] == PLUGIN_LV2:
  541. self.ui.b_save_state.setEnabled(False)
  542. if not self.ui.scrollArea.isEnabled():
  543. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  544. # Workaround for a Qt4 bug, see https://bugreports.qt-project.org/browse/QTBUG-7792
  545. if LINUX: QTimer.singleShot(0, self.slot_fixNameWordWrap)
  546. @pyqtSlot()
  547. def slot_fixNameWordWrap(self):
  548. self.adjustSize()
  549. self.setMinimumSize(self.width(), self.height())
  550. #------------------------------------------------------------------
  551. def reloadInfo(self):
  552. realPluginName = self.host.get_real_plugin_name(self.fPluginId)
  553. #audioCountInfo = self.host.get_audio_port_count_info(self.fPluginId)
  554. midiCountInfo = self.host.get_midi_port_count_info(self.fPluginId)
  555. #paramCountInfo = self.host.get_parameter_count_info(self.fPluginId)
  556. pluginHints = self.fPluginInfo['hints']
  557. self.ui.le_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  558. self.ui.label_name.setEnabled(bool(realPluginName))
  559. self.ui.le_name.setEnabled(bool(realPluginName))
  560. self.ui.le_name.setText(realPluginName)
  561. self.ui.le_name.setToolTip(realPluginName)
  562. self.ui.label_label.setEnabled(bool(self.fPluginInfo['label']))
  563. self.ui.le_label.setEnabled(bool(self.fPluginInfo['label']))
  564. self.ui.le_label.setText(self.fPluginInfo['label'])
  565. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  566. self.ui.label_maker.setEnabled(bool(self.fPluginInfo['maker']))
  567. self.ui.le_maker.setEnabled(bool(self.fPluginInfo['maker']))
  568. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  569. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  570. self.ui.label_copyright.setEnabled(bool(self.fPluginInfo['copyright']))
  571. self.ui.le_copyright.setEnabled(bool(self.fPluginInfo['copyright']))
  572. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  573. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  574. self.ui.label_unique_id.setEnabled(bool(self.fPluginInfo['uniqueId']))
  575. self.ui.le_unique_id.setEnabled(bool(self.fPluginInfo['uniqueId']))
  576. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  577. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  578. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  579. self.setWindowTitle(self.fPluginInfo['name'])
  580. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  581. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  582. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  583. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  584. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  585. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  586. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  587. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  588. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  589. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  590. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  591. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  592. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  593. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  594. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  595. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  596. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  597. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  598. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  599. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  600. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  601. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  602. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  603. canSendPrograms = bool((self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PROGRAM_CHANGES) != 0 and
  604. (self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) == 0)
  605. self.ui.ch_send_program_changes.setEnabled(canSendPrograms)
  606. self.ui.ch_send_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  607. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] in (PLUGIN_VST, PLUGIN_GIG, PLUGIN_SFZ) else 1)
  608. # Show/hide keyboard
  609. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  610. self.ui.scrollArea.setEnabled(showKeyboard)
  611. self.ui.scrollArea.setVisible(showKeyboard)
  612. # Force-update parent for new hints
  613. if self.fParent is not None and not self.fFirstInit:
  614. self.fParent.editDialogPluginHintsChanged(self.fPluginId, pluginHints)
  615. def reloadParameters(self):
  616. # Reset
  617. self.fParameterList = []
  618. self.fParametersToUpdate = []
  619. self.fTabIconTimers = []
  620. # Remove all previous parameters
  621. for x in range(self.ui.tabWidget.count()-1):
  622. self.ui.tabWidget.widget(1).deleteLater()
  623. self.ui.tabWidget.removeTab(1)
  624. parameterCount = self.host.get_parameter_count(self.fPluginId)
  625. # -----------------------------------------------------------------
  626. if parameterCount <= 0:
  627. return
  628. # -----------------------------------------------------------------
  629. if parameterCount > self.host.maxParameters:
  630. fakeName = self.tr("This plugin has too many parameters to display here!")
  631. paramFakeListFull = []
  632. paramFakeList = []
  633. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  634. parameter = {
  635. 'type': PARAMETER_UNKNOWN,
  636. 'hints': 0x0,
  637. 'name': fakeName,
  638. 'unit': "",
  639. 'scalePoints': [],
  640. 'index': 0,
  641. 'default': 0.0,
  642. 'minimum': 0.0,
  643. 'maximum': 1.0,
  644. 'step': 0.0,
  645. 'stepSmall': 0.0,
  646. 'stepLarge': 0.0,
  647. 'midiCC': -1,
  648. 'midiChannel': 1,
  649. 'current': 0.0
  650. }
  651. paramFakeList.append(parameter)
  652. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  653. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  654. return
  655. # -----------------------------------------------------------------
  656. paramInputList = []
  657. paramOutputList = []
  658. paramInputWidth = 0
  659. paramOutputWidth = 0
  660. paramInputListFull = [] # ([params], width)
  661. paramOutputListFull = [] # ([params], width)
  662. for i in range(parameterCount):
  663. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  664. paramData = self.host.get_parameter_data(self.fPluginId, i)
  665. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  666. paramValue = self.host.get_current_parameter_value(self.fPluginId, i)
  667. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  668. continue
  669. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  670. continue
  671. parameter = {
  672. 'type': paramData['type'],
  673. 'hints': paramData['hints'],
  674. 'name': paramInfo['name'],
  675. 'unit': paramInfo['unit'],
  676. 'scalePoints': [],
  677. 'index': paramData['index'],
  678. 'default': paramRanges['def'],
  679. 'minimum': paramRanges['min'],
  680. 'maximum': paramRanges['max'],
  681. 'step': paramRanges['step'],
  682. 'stepSmall': paramRanges['stepSmall'],
  683. 'stepLarge': paramRanges['stepLarge'],
  684. 'midiCC': paramData['midiCC'],
  685. 'midiChannel': paramData['midiChannel']+1,
  686. 'current': paramValue
  687. }
  688. for j in range(paramInfo['scalePointCount']):
  689. scalePointInfo = self.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  690. parameter['scalePoints'].append({
  691. 'value': scalePointInfo['value'],
  692. 'label': scalePointInfo['label']
  693. })
  694. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  695. # -----------------------------------------------------------------
  696. # Get width values, in packs of 10
  697. if parameter['type'] == PARAMETER_INPUT:
  698. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  699. if paramInputWidthTMP > paramInputWidth:
  700. paramInputWidth = paramInputWidthTMP
  701. paramInputList.append(parameter)
  702. if len(paramInputList) == self.kParamsPerPage:
  703. paramInputListFull.append((paramInputList, paramInputWidth))
  704. paramInputList = []
  705. paramInputWidth = 0
  706. else:
  707. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  708. if paramOutputWidthTMP > paramOutputWidth:
  709. paramOutputWidth = paramOutputWidthTMP
  710. paramOutputList.append(parameter)
  711. if len(paramOutputList) == self.kParamsPerPage:
  712. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  713. paramOutputList = []
  714. paramOutputWidth = 0
  715. # for i in range(parameterCount)
  716. else:
  717. # Final page width values
  718. if 0 < len(paramInputList) < 10:
  719. paramInputListFull.append((paramInputList, paramInputWidth))
  720. if 0 < len(paramOutputList) < 10:
  721. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  722. # Create parameter tabs + widgets
  723. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  724. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  725. def reloadPrograms(self):
  726. # Programs
  727. self.ui.cb_programs.blockSignals(True)
  728. self.ui.cb_programs.clear()
  729. programCount = self.host.get_program_count(self.fPluginId)
  730. if programCount > 0:
  731. self.ui.cb_programs.setEnabled(True)
  732. self.ui.label_programs.setEnabled(True)
  733. for i in range(programCount):
  734. pName = self.host.get_program_name(self.fPluginId, i)
  735. #pName = pName[:40] + (pName[40:] and "...")
  736. self.ui.cb_programs.addItem(pName)
  737. self.ui.cb_programs.setCurrentIndex(self.host.get_current_program_index(self.fPluginId))
  738. else:
  739. self.ui.cb_programs.setEnabled(False)
  740. self.ui.label_programs.setEnabled(False)
  741. self.ui.cb_programs.blockSignals(False)
  742. # MIDI Programs
  743. self.ui.cb_midi_programs.blockSignals(True)
  744. self.ui.cb_midi_programs.clear()
  745. midiProgramCount = self.host.get_midi_program_count(self.fPluginId)
  746. if midiProgramCount > 0:
  747. self.ui.cb_midi_programs.setEnabled(True)
  748. self.ui.label_midi_programs.setEnabled(True)
  749. for i in range(midiProgramCount):
  750. mpData = self.host.get_midi_program_data(self.fPluginId, i)
  751. mpBank = mpData['bank']
  752. mpProg = mpData['program']
  753. mpName = mpData['name']
  754. #mpName = mpName[:40] + (mpName[40:] and "...")
  755. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  756. self.ui.cb_midi_programs.setCurrentIndex(self.host.get_current_midi_program_index(self.fPluginId))
  757. else:
  758. self.ui.cb_midi_programs.setEnabled(False)
  759. self.ui.label_midi_programs.setEnabled(False)
  760. self.ui.cb_midi_programs.blockSignals(False)
  761. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  762. if self.fPluginInfo['type'] == PLUGIN_LV2:
  763. self.ui.b_load_state.setEnabled(programCount > 0)
  764. #------------------------------------------------------------------
  765. def clearNotes(self):
  766. self.fPlayingNotes = []
  767. self.ui.keyboard.allNotesOff()
  768. def noteOn(self, channel, note, velocity):
  769. if self.fControlChannel == channel:
  770. self.ui.keyboard.sendNoteOn(note, False)
  771. def noteOff(self, channel, note):
  772. if self.fControlChannel == channel:
  773. self.ui.keyboard.sendNoteOff(note, False)
  774. #------------------------------------------------------------------
  775. def getHints(self):
  776. return self.fPluginInfo['hints']
  777. def setPluginId(self, idx):
  778. self.fPluginId = idx
  779. def setName(self, name):
  780. self.fPluginInfo['name'] = name
  781. self.ui.label_plugin.setText("\n%s\n" % name)
  782. self.setWindowTitle(name)
  783. #------------------------------------------------------------------
  784. def setParameterValue(self, parameterId, value):
  785. for paramItem in self.fParametersToUpdate:
  786. if paramItem[0] == parameterId:
  787. paramItem[1] = value
  788. break
  789. else:
  790. self.fParametersToUpdate.append([parameterId, value])
  791. def setParameterDefault(self, parameterId, value):
  792. for paramType, paramId, paramWidget in self.fParameterList:
  793. if paramId == parameterId:
  794. paramWidget.setDefault(value)
  795. break
  796. def setParameterMidiControl(self, parameterId, control):
  797. for paramType, paramId, paramWidget in self.fParameterList:
  798. if paramId == parameterId:
  799. paramWidget.setMidiControl(control)
  800. break
  801. def setParameterMidiChannel(self, parameterId, channel):
  802. for paramType, paramId, paramWidget in self.fParameterList:
  803. if paramId == parameterId:
  804. paramWidget.setMidiChannel(channel+1)
  805. break
  806. def setProgram(self, index):
  807. self.ui.cb_programs.blockSignals(True)
  808. self.ui.cb_programs.setCurrentIndex(index)
  809. self.ui.cb_programs.blockSignals(False)
  810. def setMidiProgram(self, index):
  811. self.ui.cb_midi_programs.blockSignals(True)
  812. self.ui.cb_midi_programs.setCurrentIndex(index)
  813. self.ui.cb_midi_programs.blockSignals(False)
  814. def setOption(self, option, yesNo):
  815. if option == PLUGIN_OPTION_USE_CHUNKS:
  816. widget = self.ui.ch_use_chunks
  817. elif option == PLUGIN_OPTION_FIXED_BUFFERS:
  818. widget = self.ui.ch_fixed_buffer
  819. elif option == PLUGIN_OPTION_FORCE_STEREO:
  820. widget = self.ui.ch_force_stereo
  821. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  822. widget = self.ui.ch_map_program_changes
  823. elif option == PLUGIN_OPTION_SEND_PROGRAM_CHANGES:
  824. widget = self.ui.ch_send_program_changes
  825. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  826. widget = self.ui.ch_send_control_changes
  827. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  828. widget = self.ui.ch_send_channel_pressure
  829. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  830. widget = self.ui.ch_send_note_aftertouch
  831. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  832. widget = self.ui.ch_send_pitchbend
  833. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  834. widget = self.ui.ch_send_all_sound_off
  835. else:
  836. return
  837. widget.blockSignals(True)
  838. widget.setChecked(yesNo)
  839. widget.blockSignals(False)
  840. #------------------------------------------------------------------
  841. def setVisible(self, yesNo):
  842. if yesNo:
  843. if not self.fGeometry.isNull():
  844. self.restoreGeometry(self.fGeometry)
  845. else:
  846. self.fGeometry = self.saveGeometry()
  847. QDialog.setVisible(self, yesNo)
  848. #------------------------------------------------------------------
  849. def idleSlow(self):
  850. # Check Tab icons
  851. for i in range(len(self.fTabIconTimers)):
  852. if self.fTabIconTimers[i] == ICON_STATE_ON:
  853. self.fTabIconTimers[i] = ICON_STATE_WAIT1
  854. elif self.fTabIconTimers[i] == ICON_STATE_WAIT1:
  855. self.fTabIconTimers[i] = ICON_STATE_WAIT2
  856. elif self.fTabIconTimers[i] == ICON_STATE_WAIT2:
  857. self.fTabIconTimers[i] = ICON_STATE_OFF
  858. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  859. # Check parameters needing update
  860. for index, value in self.fParametersToUpdate:
  861. if index == PARAMETER_DRYWET:
  862. self.ui.dial_drywet.blockSignals(True)
  863. self.ui.dial_drywet.setValue(value)
  864. self.ui.dial_drywet.blockSignals(False)
  865. elif index == PARAMETER_VOLUME:
  866. self.ui.dial_vol.blockSignals(True)
  867. self.ui.dial_vol.setValue(value)
  868. self.ui.dial_vol.blockSignals(False)
  869. elif index == PARAMETER_BALANCE_LEFT:
  870. self.ui.dial_b_left.blockSignals(True)
  871. self.ui.dial_b_left.setValue(value)
  872. self.ui.dial_b_left.blockSignals(False)
  873. elif index == PARAMETER_BALANCE_RIGHT:
  874. self.ui.dial_b_right.blockSignals(True)
  875. self.ui.dial_b_right.setValue(value)
  876. self.ui.dial_b_right.blockSignals(False)
  877. elif index == PARAMETER_PANNING:
  878. self.ui.dial_pan.blockSignals(True)
  879. self.ui.dial_pan.setValue(value)
  880. self.ui.dial_pan.blockSignals(False)
  881. elif index == PARAMETER_CTRL_CHANNEL:
  882. self.fControlChannel = int(value)
  883. self.ui.sb_ctrl_channel.blockSignals(True)
  884. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  885. self.ui.sb_ctrl_channel.blockSignals(False)
  886. self.ui.keyboard.allNotesOff()
  887. self._updateCtrlPrograms()
  888. elif index >= 0:
  889. for paramType, paramId, paramWidget in self.fParameterList:
  890. if paramId != index:
  891. continue
  892. paramWidget.setValue(value)
  893. if paramType == PARAMETER_INPUT:
  894. tabIndex = paramWidget.getTabIndex()
  895. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_OFF:
  896. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  897. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  898. break
  899. # Clear all parameters
  900. self.fParametersToUpdate = []
  901. # Update parameter outputs
  902. for paramType, paramId, paramWidget in self.fParameterList:
  903. if paramType != PARAMETER_OUTPUT:
  904. continue
  905. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  906. #------------------------------------------------------------------
  907. @pyqtSlot()
  908. def slot_stateSave(self):
  909. if self.fPluginInfo['type'] == PLUGIN_LV2:
  910. # TODO
  911. return
  912. if self.fCurrentStateFilename:
  913. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  914. if askTry == QMessageBox.Ok:
  915. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  916. return
  917. self.fCurrentStateFilename = None
  918. fileFilter = self.tr("Carla State File (*.carxs)")
  919. filename = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  920. if config_UseQt5:
  921. filename = filename[0]
  922. if not filename:
  923. return
  924. if not filename.lower().endswith(".carxs"):
  925. filename += ".carxs"
  926. self.fCurrentStateFilename = filename
  927. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  928. @pyqtSlot()
  929. def slot_stateLoad(self):
  930. if self.fPluginInfo['type'] == PLUGIN_LV2:
  931. presetList = []
  932. for i in range(self.host.get_program_count(self.fPluginId)):
  933. presetList.append("%03i - %s" % (i+1, self.host.get_program_name(self.fPluginId, i)))
  934. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  935. if ret[1]:
  936. index = int(ret[0].split(" - ", 1)[0])-1
  937. self.host.set_midi_program(self.fPluginId, -1)
  938. self.host.set_program(self.fPluginId, index)
  939. self.setMidiProgram(-1)
  940. return
  941. fileFilter = self.tr("Carla State File (*.carxs)")
  942. filename = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  943. if config_UseQt5:
  944. filename = filename[0]
  945. if not filename:
  946. return
  947. self.fCurrentStateFilename = filename
  948. self.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  949. #------------------------------------------------------------------
  950. @pyqtSlot(bool)
  951. def slot_optionChanged(self, clicked):
  952. sender = self.sender()
  953. if sender == self.ui.ch_use_chunks:
  954. option = PLUGIN_OPTION_USE_CHUNKS
  955. elif sender == self.ui.ch_fixed_buffer:
  956. option = PLUGIN_OPTION_FIXED_BUFFERS
  957. elif sender == self.ui.ch_force_stereo:
  958. option = PLUGIN_OPTION_FORCE_STEREO
  959. elif sender == self.ui.ch_map_program_changes:
  960. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  961. elif sender == self.ui.ch_send_program_changes:
  962. option = PLUGIN_OPTION_SEND_PROGRAM_CHANGES
  963. elif sender == self.ui.ch_send_control_changes:
  964. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  965. elif sender == self.ui.ch_send_channel_pressure:
  966. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  967. elif sender == self.ui.ch_send_note_aftertouch:
  968. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  969. elif sender == self.ui.ch_send_pitchbend:
  970. option = PLUGIN_OPTION_SEND_PITCHBEND
  971. elif sender == self.ui.ch_send_all_sound_off:
  972. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  973. else:
  974. return
  975. #--------------------------------------------------------------
  976. # handle map-program-changes and send-program-changes conflict
  977. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and clicked:
  978. self.ui.ch_send_program_changes.setEnabled(False)
  979. # disable send-program-changes if needed
  980. if self.ui.ch_send_program_changes.isChecked():
  981. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, False)
  982. #--------------------------------------------------------------
  983. # set option
  984. self.host.set_option(self.fPluginId, option, clicked)
  985. #--------------------------------------------------------------
  986. # handle map-program-changes and send-program-changes conflict
  987. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and not clicked:
  988. self.ui.ch_send_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  989. # restore send-program-changes if needed
  990. if self.ui.ch_send_program_changes.isChecked():
  991. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, True)
  992. #------------------------------------------------------------------
  993. @pyqtSlot(int)
  994. def slot_dryWetChanged(self, value):
  995. self.host.set_drywet(self.fPluginId, value)
  996. if self.fParent is not None:
  997. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_DRYWET, value)
  998. @pyqtSlot(int)
  999. def slot_volumeChanged(self, value):
  1000. self.host.set_volume(self.fPluginId, value)
  1001. if self.fParent is not None:
  1002. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_VOLUME, value)
  1003. @pyqtSlot(int)
  1004. def slot_balanceLeftChanged(self, value):
  1005. self.host.set_balance_left(self.fPluginId, value)
  1006. if self.fParent is not None:
  1007. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_LEFT, value)
  1008. @pyqtSlot(int)
  1009. def slot_balanceRightChanged(self, value):
  1010. self.host.set_balance_right(self.fPluginId, value)
  1011. if self.fParent is not None:
  1012. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_RIGHT, value)
  1013. @pyqtSlot(int)
  1014. def slot_panChanged(self, value):
  1015. self.host.set_panning(self.fPluginId, value)
  1016. if self.fParent is not None:
  1017. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_PANNING, value)
  1018. @pyqtSlot(int)
  1019. def slot_ctrlChannelChanged(self, value):
  1020. self.fControlChannel = value-1
  1021. self.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  1022. self.ui.keyboard.allNotesOff()
  1023. self._updateCtrlPrograms()
  1024. #------------------------------------------------------------------
  1025. @pyqtSlot(int, float)
  1026. def slot_parameterValueChanged(self, parameterId, value):
  1027. self.host.set_parameter_value(self.fPluginId, parameterId, value)
  1028. if self.fParent is not None:
  1029. self.fParent.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  1030. @pyqtSlot(int, int)
  1031. def slot_parameterMidiControlChanged(self, parameterId, control):
  1032. self.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  1033. @pyqtSlot(int, int)
  1034. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  1035. self.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1036. #------------------------------------------------------------------
  1037. @pyqtSlot(int)
  1038. def slot_programIndexChanged(self, index):
  1039. self.host.set_program(self.fPluginId, index)
  1040. if self.fParent is not None:
  1041. self.fParent.editDialogProgramChanged(self.fPluginId, index)
  1042. @pyqtSlot(int)
  1043. def slot_midiProgramIndexChanged(self, index):
  1044. self.host.set_midi_program(self.fPluginId, index)
  1045. if self.fParent is not None:
  1046. self.fParent.editDialogMidiProgramChanged(self.fPluginId, index)
  1047. #------------------------------------------------------------------
  1048. @pyqtSlot(int)
  1049. def slot_noteOn(self, note):
  1050. if self.fControlChannel >= 0:
  1051. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1052. if self.fParent is not None:
  1053. self.fParent.editDialogNotePressed(self.fPluginId, note)
  1054. @pyqtSlot(int)
  1055. def slot_noteOff(self, note):
  1056. if self.fControlChannel >= 0:
  1057. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1058. if self.fParent is not None:
  1059. self.fParent.editDialogNoteReleased(self.fPluginId, note)
  1060. #------------------------------------------------------------------
  1061. @pyqtSlot()
  1062. def slot_finished(self):
  1063. if self.fParent is not None:
  1064. self.fParent.editDialogVisibilityChanged(self.fPluginId, False)
  1065. #------------------------------------------------------------------
  1066. @pyqtSlot()
  1067. def slot_knobCustomMenu(self):
  1068. knobName = self.sender().objectName()
  1069. if knobName == "dial_drywet":
  1070. minimum = 0.0
  1071. maximum = 1.0
  1072. default = 1.0
  1073. label = "Dry/Wet"
  1074. elif knobName == "dial_vol":
  1075. minimum = 0.0
  1076. maximum = 1.27
  1077. default = 1.0
  1078. label = "Volume"
  1079. elif knobName == "dial_b_left":
  1080. minimum = -1.0
  1081. maximum = 1.0
  1082. default = -1.0
  1083. label = "Balance-Left"
  1084. elif knobName == "dial_b_right":
  1085. minimum = -1.0
  1086. maximum = 1.0
  1087. default = 1.0
  1088. label = "Balance-Right"
  1089. elif knobName == "dial_pan":
  1090. minimum = -1.0
  1091. maximum = 1.0
  1092. default = 0.0
  1093. label = "Panning"
  1094. else:
  1095. minimum = 0.0
  1096. maximum = 1.0
  1097. default = 0.5
  1098. label = "Unknown"
  1099. current = self.sender().value() / 10
  1100. menu = QMenu(self)
  1101. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1102. menu.addSeparator()
  1103. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1104. actCenter = menu.addAction(self.tr("Set to Center"))
  1105. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1106. menu.addSeparator()
  1107. actSet = menu.addAction(self.tr("Set value..."))
  1108. if label not in ("Balance-Left", "Balance-Right"):
  1109. menu.removeAction(actCenter)
  1110. actSelected = menu.exec_(QCursor.pos())
  1111. if actSelected == actSet:
  1112. valueTry = QInputDialog.getDouble(self, self.tr("Set value"), label, current, minimum, maximum, 3)
  1113. if valueTry[1]:
  1114. value = valueTry[0] * 10
  1115. else:
  1116. return
  1117. elif actSelected == actMinimum:
  1118. value = minimum
  1119. elif actSelected == actMaximum:
  1120. value = maximum
  1121. elif actSelected == actReset:
  1122. value = default
  1123. elif actSelected == actCenter:
  1124. value = 0.0
  1125. else:
  1126. return
  1127. self.sender().setValue(value)
  1128. #------------------------------------------------------------------
  1129. @pyqtSlot()
  1130. def slot_channelCustomMenu(self):
  1131. menu = QMenu(self)
  1132. actNone = menu.addAction(self.tr("None"))
  1133. if self.fControlChannel+1 == 0:
  1134. actNone.setCheckable(True)
  1135. actNone.setChecked(True)
  1136. for i in range(1, 16+1):
  1137. action = menu.addAction("%i" % i)
  1138. if self.fControlChannel+1 == i:
  1139. action.setCheckable(True)
  1140. action.setChecked(True)
  1141. actSel = menu.exec_(QCursor.pos())
  1142. if not actSel:
  1143. pass
  1144. elif actSel == actNone:
  1145. self.ui.sb_ctrl_channel.setValue(0)
  1146. elif actSel:
  1147. selChannel = int(actSel.text())
  1148. self.ui.sb_ctrl_channel.setValue(selChannel)
  1149. #------------------------------------------------------------------
  1150. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1151. i = 1
  1152. for paramList, width in paramListFull:
  1153. if len(paramList) == 0:
  1154. break
  1155. tabIndex = self.ui.tabWidget.count()
  1156. tabPageContainer = QWidget(self.ui.tabWidget)
  1157. tabPageLayout = QVBoxLayout(tabPageContainer)
  1158. tabPageContainer.setLayout(tabPageLayout)
  1159. for paramInfo in paramList:
  1160. paramWidget = PluginParameter(tabPageContainer, self.host, paramInfo, self.fPluginId, tabIndex)
  1161. paramWidget.setLabelWidth(width)
  1162. tabPageLayout.addWidget(paramWidget)
  1163. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1164. if paramType == PARAMETER_INPUT:
  1165. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1166. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1167. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1168. tabPageLayout.addStretch()
  1169. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1170. i += 1
  1171. if paramType == PARAMETER_INPUT:
  1172. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1173. self.fTabIconTimers.append(ICON_STATE_OFF)
  1174. def _updateCtrlPrograms(self):
  1175. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH or self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2, PLUGIN_GIG):
  1176. return
  1177. if self.fControlChannel < 0:
  1178. self.ui.cb_programs.setEnabled(False)
  1179. self.ui.cb_midi_programs.setEnabled(False)
  1180. return
  1181. self.ui.cb_programs.setEnabled(True)
  1182. self.ui.cb_midi_programs.setEnabled(True)
  1183. pIndex = self.host.get_current_program_index(self.fPluginId)
  1184. if self.ui.cb_programs.currentIndex() != pIndex:
  1185. self.setProgram(pIndex)
  1186. mpIndex = self.host.get_current_midi_program_index(self.fPluginId)
  1187. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1188. self.setMidiProgram(mpIndex)
  1189. #------------------------------------------------------------------
  1190. def testTimer(self):
  1191. self.fIdleTimerId = self.startTimer(50)
  1192. #------------------------------------------------------------------
  1193. def closeEvent(self, event):
  1194. if self.fIdleTimerId != 0:
  1195. self.killTimer(self.fIdleTimerId)
  1196. self.fIdleTimerId = 0
  1197. self.host.engine_close()
  1198. QDialog.closeEvent(self, event)
  1199. def timerEvent(self, event):
  1200. if event.timerId() == self.fIdleTimerId:
  1201. self.host.engine_idle()
  1202. self.idleSlow()
  1203. QDialog.timerEvent(self, event)
  1204. def done(self, r):
  1205. QDialog.done(self, r)
  1206. self.close()
  1207. # ------------------------------------------------------------------------------------------------------------
  1208. # Main
  1209. if __name__ == '__main__':
  1210. from carla_app import CarlaApplication
  1211. from carla_host import initHost, loadHostSettings
  1212. app = CarlaApplication()
  1213. host = initHost("Widgets", None, False, False, False)
  1214. loadHostSettings(host)
  1215. host.engine_init("JACK", "Carla-Widgets")
  1216. host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None)
  1217. host.set_active(0, True)
  1218. #gui1 = CarlaAboutW(None, host)
  1219. #gui1.show()
  1220. gui2 = PluginEdit(None, host, 0)
  1221. gui2.testTimer()
  1222. gui2.show()
  1223. app.exit_exec()