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.

1592 lines
64KB

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