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.

1588 lines
64KB

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