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.

1575 lines
64KB

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