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.

1617 lines
65KB

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