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.

1591 lines
64KB

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