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.

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