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.

1615 lines
65KB

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