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.

1571 lines
63KB

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