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.

1797 lines
71KB

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