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.

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