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.

1581 lines
63KB

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