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.

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