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.

1595 lines
62KB

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