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.

1865 lines
74KB

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