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.

1611 lines
65KB

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