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.

1889 lines
75KB

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