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.

1882 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_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-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_AUTOMABLE:
  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. paramInputListFull = [] # ([params], width)
  841. paramOutputListFull = [] # ([params], width)
  842. for i in range(min(parameterCount, self.host.maxParameters)):
  843. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  844. paramData = self.host.get_parameter_data(self.fPluginId, i)
  845. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  846. paramValue = self.host.get_current_parameter_value(self.fPluginId, i)
  847. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  848. continue
  849. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  850. continue
  851. parameter = {
  852. 'type': paramData['type'],
  853. 'hints': paramData['hints'],
  854. 'name': paramInfo['name'],
  855. 'unit': paramInfo['unit'],
  856. 'scalePoints': [],
  857. 'index': paramData['index'],
  858. 'default': paramRanges['def'],
  859. 'minimum': paramRanges['min'],
  860. 'maximum': paramRanges['max'],
  861. 'step': paramRanges['step'],
  862. 'stepSmall': paramRanges['stepSmall'],
  863. 'stepLarge': paramRanges['stepLarge'],
  864. 'mappedControlIndex': paramData['mappedControlIndex'],
  865. 'mappedMinimum': paramData['mappedMinimum'],
  866. 'mappedMaximum': paramData['mappedMaximum'],
  867. 'midiChannel': paramData['midiChannel']+1,
  868. 'comment': paramInfo['comment'],
  869. 'groupName': paramInfo['groupName'],
  870. 'current': paramValue
  871. }
  872. for j in range(paramInfo['scalePointCount']):
  873. scalePointInfo = self.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  874. parameter['scalePoints'].append({
  875. 'value': scalePointInfo['value'],
  876. 'label': scalePointInfo['label']
  877. })
  878. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  879. # -----------------------------------------------------------------
  880. # Get width values, in packs of 20
  881. if parameter['type'] == PARAMETER_INPUT:
  882. paramInputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])
  883. if paramInputWidthTMP > paramInputWidth:
  884. paramInputWidth = paramInputWidthTMP
  885. paramInputList.append(parameter)
  886. else:
  887. paramOutputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])
  888. if paramOutputWidthTMP > paramOutputWidth:
  889. paramOutputWidth = paramOutputWidthTMP
  890. paramOutputList.append(parameter)
  891. paramInputListFull.append((paramInputList, paramInputWidth))
  892. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  893. # Create parameter tabs + widgets
  894. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  895. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  896. # Restore tab state
  897. if tabIndex < self.ui.tabWidget.count():
  898. self.ui.tabWidget.setCurrentIndex(tabIndex)
  899. if scrollVal is not None:
  900. self.ui.tabWidget.currentWidget().verticalScrollBar().setValue(scrollVal)
  901. def reloadPrograms(self):
  902. # Programs
  903. self.ui.cb_programs.blockSignals(True)
  904. self.ui.cb_programs.clear()
  905. programCount = self.host.get_program_count(self.fPluginId)
  906. if programCount > 0:
  907. self.ui.cb_programs.setEnabled(True)
  908. self.ui.label_programs.setEnabled(True)
  909. for i in range(programCount):
  910. pName = self.host.get_program_name(self.fPluginId, i)
  911. #pName = pName[:40] + (pName[40:] and "...")
  912. self.ui.cb_programs.addItem(pName)
  913. self.ui.cb_programs.setCurrentIndex(self.host.get_current_program_index(self.fPluginId))
  914. else:
  915. self.ui.cb_programs.setEnabled(False)
  916. self.ui.label_programs.setEnabled(False)
  917. self.ui.cb_programs.blockSignals(False)
  918. # MIDI Programs
  919. self.ui.cb_midi_programs.blockSignals(True)
  920. self.ui.cb_midi_programs.clear()
  921. midiProgramCount = self.host.get_midi_program_count(self.fPluginId)
  922. if midiProgramCount > 0:
  923. self.ui.cb_midi_programs.setEnabled(True)
  924. self.ui.label_midi_programs.setEnabled(True)
  925. for i in range(midiProgramCount):
  926. mpData = self.host.get_midi_program_data(self.fPluginId, i)
  927. mpBank = mpData['bank']
  928. mpProg = mpData['program']
  929. mpName = mpData['name']
  930. #mpName = mpName[:40] + (mpName[40:] and "...")
  931. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  932. self.ui.cb_midi_programs.setCurrentIndex(self.host.get_current_midi_program_index(self.fPluginId))
  933. else:
  934. self.ui.cb_midi_programs.setEnabled(False)
  935. self.ui.label_midi_programs.setEnabled(False)
  936. self.ui.cb_midi_programs.blockSignals(False)
  937. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  938. if self.fPluginInfo['type'] == PLUGIN_LV2:
  939. self.ui.b_load_state.setEnabled(programCount > 0)
  940. #------------------------------------------------------------------
  941. def clearNotes(self):
  942. self.fPlayingNotes = []
  943. self.ui.keyboard.allNotesOff()
  944. def noteOn(self, channel, note, velocity):
  945. if self.fControlChannel == channel:
  946. self.ui.keyboard.sendNoteOn(note, False)
  947. def noteOff(self, channel, note):
  948. if self.fControlChannel == channel:
  949. self.ui.keyboard.sendNoteOff(note, False)
  950. #------------------------------------------------------------------
  951. def getHints(self):
  952. return self.fPluginInfo['hints']
  953. def setPluginId(self, idx):
  954. self.fPluginId = idx
  955. def setName(self, name):
  956. self.fPluginInfo['name'] = name
  957. self.ui.label_plugin.setText("\n%s\n" % name)
  958. self.setWindowTitle(name)
  959. #------------------------------------------------------------------
  960. def setParameterValue(self, parameterId, value):
  961. for paramItem in self.fParametersToUpdate:
  962. if paramItem[0] == parameterId:
  963. paramItem[1] = value
  964. break
  965. else:
  966. self.fParametersToUpdate.append([parameterId, value])
  967. def setParameterDefault(self, parameterId, value):
  968. for _, paramId, paramWidget in self.fParameterList:
  969. if paramId == parameterId:
  970. paramWidget.setDefault(value)
  971. break
  972. def setParameterMappedControlIndex(self, parameterId, control):
  973. for _, paramId, paramWidget in self.fParameterList:
  974. if paramId == parameterId:
  975. paramWidget.setMappedControlIndex(control)
  976. break
  977. def setParameterMappedRange(self, parameterId, minimum, maximum):
  978. for _, paramId, paramWidget in self.fParameterList:
  979. if paramId == parameterId:
  980. paramWidget.setMappedRange(minimum, maximum)
  981. break
  982. def setParameterMidiChannel(self, parameterId, channel):
  983. for _, paramId, paramWidget in self.fParameterList:
  984. if paramId == parameterId:
  985. paramWidget.setMidiChannel(channel+1)
  986. break
  987. def setProgram(self, index):
  988. self.ui.cb_programs.blockSignals(True)
  989. self.ui.cb_programs.setCurrentIndex(index)
  990. self.ui.cb_programs.blockSignals(False)
  991. self._updateParameterValues()
  992. def setMidiProgram(self, index):
  993. self.ui.cb_midi_programs.blockSignals(True)
  994. self.ui.cb_midi_programs.setCurrentIndex(index)
  995. self.ui.cb_midi_programs.blockSignals(False)
  996. self._updateParameterValues()
  997. def setOption(self, option, yesNo):
  998. if option == PLUGIN_OPTION_USE_CHUNKS:
  999. widget = self.ui.ch_use_chunks
  1000. elif option == PLUGIN_OPTION_FIXED_BUFFERS:
  1001. widget = self.ui.ch_fixed_buffer
  1002. elif option == PLUGIN_OPTION_FORCE_STEREO:
  1003. widget = self.ui.ch_force_stereo
  1004. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  1005. widget = self.ui.ch_map_program_changes
  1006. elif option == PLUGIN_OPTION_SKIP_SENDING_NOTES:
  1007. widget = self.ui.ch_send_notes
  1008. yesNo = not yesNo
  1009. elif option == PLUGIN_OPTION_SEND_PROGRAM_CHANGES:
  1010. widget = self.ui.ch_send_program_changes
  1011. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  1012. widget = self.ui.ch_send_control_changes
  1013. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  1014. widget = self.ui.ch_send_channel_pressure
  1015. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  1016. widget = self.ui.ch_send_note_aftertouch
  1017. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  1018. widget = self.ui.ch_send_pitchbend
  1019. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  1020. widget = self.ui.ch_send_all_sound_off
  1021. else:
  1022. return
  1023. widget.blockSignals(True)
  1024. widget.setChecked(yesNo)
  1025. widget.blockSignals(False)
  1026. #------------------------------------------------------------------
  1027. def setVisible(self, yesNo):
  1028. if yesNo:
  1029. if not self.fGeometry.isNull():
  1030. self.restoreGeometry(self.fGeometry)
  1031. else:
  1032. self.fGeometry = self.saveGeometry()
  1033. QDialog.setVisible(self, yesNo)
  1034. if MACOS and yesNo:
  1035. parent = self.parent()
  1036. if parent is None:
  1037. return
  1038. gCarla.utils.cocoa_set_transient_window_for(self.windowHandle().winId(), parent.windowHandle().winId())
  1039. #------------------------------------------------------------------
  1040. def idleSlow(self):
  1041. # Check Tab icons
  1042. for i in range(len(self.fTabIconTimers)):
  1043. if self.fTabIconTimers[i] == ICON_STATE_ON:
  1044. self.fTabIconTimers[i] = ICON_STATE_WAIT
  1045. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  1046. self.fTabIconTimers[i] = ICON_STATE_OFF
  1047. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  1048. self.fTabIconTimers[i] = ICON_STATE_NULL
  1049. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  1050. # Check parameters needing update
  1051. for index, value in self.fParametersToUpdate:
  1052. if index == PARAMETER_DRYWET:
  1053. self.ui.dial_drywet.blockSignals(True)
  1054. self.ui.dial_drywet.setValue(value)
  1055. self.ui.dial_drywet.blockSignals(False)
  1056. elif index == PARAMETER_VOLUME:
  1057. self.ui.dial_vol.blockSignals(True)
  1058. self.ui.dial_vol.setValue(value)
  1059. self.ui.dial_vol.blockSignals(False)
  1060. elif index == PARAMETER_BALANCE_LEFT:
  1061. self.ui.dial_b_left.blockSignals(True)
  1062. self.ui.dial_b_left.setValue(value)
  1063. self.ui.dial_b_left.blockSignals(False)
  1064. elif index == PARAMETER_BALANCE_RIGHT:
  1065. self.ui.dial_b_right.blockSignals(True)
  1066. self.ui.dial_b_right.setValue(value)
  1067. self.ui.dial_b_right.blockSignals(False)
  1068. elif index == PARAMETER_PANNING:
  1069. self.ui.dial_pan.blockSignals(True)
  1070. self.ui.dial_pan.setValue(value)
  1071. self.ui.dial_pan.blockSignals(False)
  1072. elif index == PARAMETER_CTRL_CHANNEL:
  1073. self.fControlChannel = round(value)
  1074. self.ui.sb_ctrl_channel.blockSignals(True)
  1075. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  1076. self.ui.sb_ctrl_channel.blockSignals(False)
  1077. self.ui.keyboard.allNotesOff()
  1078. self._updateCtrlPrograms()
  1079. elif index >= 0:
  1080. for paramType, paramId, paramWidget in self.fParameterList:
  1081. if paramId != index:
  1082. continue
  1083. # FIXME see below
  1084. if paramType != PARAMETER_INPUT:
  1085. continue
  1086. paramWidget.blockSignals(True)
  1087. paramWidget.setValue(value)
  1088. paramWidget.blockSignals(False)
  1089. #if paramType == PARAMETER_INPUT:
  1090. tabIndex = paramWidget.getTabIndex()
  1091. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  1092. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  1093. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  1094. break
  1095. # Clear all parameters
  1096. self.fParametersToUpdate = []
  1097. # Update parameter outputs | FIXME needed?
  1098. for paramType, paramId, paramWidget in self.fParameterList:
  1099. if paramType != PARAMETER_OUTPUT:
  1100. continue
  1101. paramWidget.blockSignals(True)
  1102. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  1103. paramWidget.blockSignals(False)
  1104. #------------------------------------------------------------------
  1105. @pyqtSlot()
  1106. def slot_stateSave(self):
  1107. if self.fPluginInfo['type'] == PLUGIN_LV2:
  1108. # TODO
  1109. return
  1110. if self.fCurrentStateFilename:
  1111. askTry = QMessageBox.question(self,
  1112. self.tr("Overwrite?"),
  1113. self.tr("Overwrite previously created file?"),
  1114. QMessageBox.Ok|QMessageBox.Cancel)
  1115. if askTry == QMessageBox.Ok:
  1116. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1117. return
  1118. self.fCurrentStateFilename = None
  1119. fileFilter = self.tr("Carla State File (*.carxs)")
  1120. filename, _ = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  1121. # FIXME use ok value, test if it works as expected
  1122. if not filename:
  1123. return
  1124. if not filename.lower().endswith(".carxs"):
  1125. filename += ".carxs"
  1126. self.fCurrentStateFilename = filename
  1127. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1128. @pyqtSlot()
  1129. def slot_stateLoad(self):
  1130. if self.fPluginInfo['type'] == PLUGIN_LV2:
  1131. presetList = []
  1132. for i in range(self.host.get_program_count(self.fPluginId)):
  1133. presetList.append("%03i - %s" % (i+1, self.host.get_program_name(self.fPluginId, i)))
  1134. ret = QInputDialog.getItem(self,
  1135. self.tr("Open LV2 Preset"),
  1136. self.tr("Select an LV2 Preset:"),
  1137. presetList, 0, False)
  1138. if ret[1]:
  1139. index = int(ret[0].split(" - ", 1)[0])-1
  1140. self.host.set_program(self.fPluginId, index)
  1141. self.setMidiProgram(-1)
  1142. return
  1143. fileFilter = self.tr("Carla State File (*.carxs)")
  1144. filename, _ = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  1145. # FIXME use ok value, test if it works as expected
  1146. if not filename:
  1147. return
  1148. self.fCurrentStateFilename = filename
  1149. self.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1150. #------------------------------------------------------------------
  1151. @pyqtSlot(bool)
  1152. def slot_optionChanged(self, clicked):
  1153. sender = self.sender()
  1154. if sender == self.ui.ch_use_chunks:
  1155. option = PLUGIN_OPTION_USE_CHUNKS
  1156. elif sender == self.ui.ch_fixed_buffer:
  1157. option = PLUGIN_OPTION_FIXED_BUFFERS
  1158. elif sender == self.ui.ch_force_stereo:
  1159. option = PLUGIN_OPTION_FORCE_STEREO
  1160. elif sender == self.ui.ch_map_program_changes:
  1161. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  1162. elif sender == self.ui.ch_send_notes:
  1163. option = PLUGIN_OPTION_SKIP_SENDING_NOTES
  1164. clicked = not clicked
  1165. elif sender == self.ui.ch_send_program_changes:
  1166. option = PLUGIN_OPTION_SEND_PROGRAM_CHANGES
  1167. elif sender == self.ui.ch_send_control_changes:
  1168. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  1169. elif sender == self.ui.ch_send_channel_pressure:
  1170. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  1171. elif sender == self.ui.ch_send_note_aftertouch:
  1172. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  1173. elif sender == self.ui.ch_send_pitchbend:
  1174. option = PLUGIN_OPTION_SEND_PITCHBEND
  1175. elif sender == self.ui.ch_send_all_sound_off:
  1176. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  1177. else:
  1178. return
  1179. #--------------------------------------------------------------
  1180. # handle map-program-changes and send-program-changes conflict
  1181. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and clicked:
  1182. self.ui.ch_send_program_changes.setEnabled(False)
  1183. # disable send-program-changes if needed
  1184. if self.ui.ch_send_program_changes.isChecked():
  1185. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, False)
  1186. #--------------------------------------------------------------
  1187. # set option
  1188. self.host.set_option(self.fPluginId, option, clicked)
  1189. #--------------------------------------------------------------
  1190. # handle map-program-changes and send-program-changes conflict
  1191. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and not clicked:
  1192. self.ui.ch_send_program_changes.setEnabled(
  1193. self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  1194. # restore send-program-changes if needed
  1195. if self.ui.ch_send_program_changes.isChecked():
  1196. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, True)
  1197. #------------------------------------------------------------------
  1198. @pyqtSlot(float)
  1199. def slot_dryWetChanged(self, value):
  1200. self.host.set_drywet(self.fPluginId, value)
  1201. if self.fParent is not None:
  1202. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_DRYWET, value)
  1203. @pyqtSlot(float)
  1204. def slot_volumeChanged(self, value):
  1205. self.host.set_volume(self.fPluginId, value)
  1206. if self.fParent is not None:
  1207. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_VOLUME, value)
  1208. @pyqtSlot(float)
  1209. def slot_balanceLeftChanged(self, value):
  1210. self.host.set_balance_left(self.fPluginId, value)
  1211. if self.fParent is not None:
  1212. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_LEFT, value)
  1213. @pyqtSlot(float)
  1214. def slot_balanceRightChanged(self, value):
  1215. self.host.set_balance_right(self.fPluginId, value)
  1216. if self.fParent is not None:
  1217. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_RIGHT, value)
  1218. @pyqtSlot(float)
  1219. def slot_panChanged(self, value):
  1220. self.host.set_panning(self.fPluginId, value)
  1221. if self.fParent is not None:
  1222. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_PANNING, value)
  1223. @pyqtSlot(int)
  1224. def slot_ctrlChannelChanged(self, value):
  1225. self.fControlChannel = value-1
  1226. self.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  1227. self.ui.keyboard.allNotesOff()
  1228. self._updateCtrlPrograms()
  1229. #------------------------------------------------------------------
  1230. @pyqtSlot(int, float)
  1231. def slot_parameterValueChanged(self, parameterId, value):
  1232. self.host.set_parameter_value(self.fPluginId, parameterId, value)
  1233. if self.fParent is not None:
  1234. self.fParent.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  1235. @pyqtSlot(int, int)
  1236. def slot_parameterMappedControlChanged(self, parameterId, control):
  1237. self.host.set_parameter_mapped_control_index(self.fPluginId, parameterId, control)
  1238. @pyqtSlot(int, float, float)
  1239. def slot_parameterMappedRangeChanged(self, parameterId, minimum, maximum):
  1240. self.host.set_parameter_mapped_range(self.fPluginId, parameterId, minimum, maximum)
  1241. @pyqtSlot(int, int)
  1242. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  1243. self.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1244. #------------------------------------------------------------------
  1245. @pyqtSlot(int)
  1246. def slot_programIndexChanged(self, index):
  1247. self.host.set_program(self.fPluginId, index)
  1248. if self.fParent is not None:
  1249. self.fParent.editDialogProgramChanged(self.fPluginId, index)
  1250. self._updateParameterValues()
  1251. @pyqtSlot(int)
  1252. def slot_midiProgramIndexChanged(self, index):
  1253. self.host.set_midi_program(self.fPluginId, index)
  1254. if self.fParent is not None:
  1255. self.fParent.editDialogMidiProgramChanged(self.fPluginId, index)
  1256. self._updateParameterValues()
  1257. #------------------------------------------------------------------
  1258. @pyqtSlot(int)
  1259. def slot_noteOn(self, note):
  1260. if self.fControlChannel >= 0:
  1261. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1262. if self.fParent is not None:
  1263. self.fParent.editDialogNotePressed(self.fPluginId, note)
  1264. @pyqtSlot(int)
  1265. def slot_noteOff(self, note):
  1266. if self.fControlChannel >= 0:
  1267. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1268. if self.fParent is not None:
  1269. self.fParent.editDialogNoteReleased(self.fPluginId, note)
  1270. #------------------------------------------------------------------
  1271. @pyqtSlot()
  1272. def slot_finished(self):
  1273. if self.fParent is not None:
  1274. self.fParent.editDialogVisibilityChanged(self.fPluginId, False)
  1275. #------------------------------------------------------------------
  1276. @pyqtSlot()
  1277. def slot_knobCustomMenu(self):
  1278. sender = self.sender()
  1279. knobName = sender.objectName()
  1280. if knobName == "dial_drywet":
  1281. minimum = 0.0
  1282. maximum = 1.0
  1283. default = 1.0
  1284. label = "Dry/Wet"
  1285. elif knobName == "dial_vol":
  1286. minimum = 0.0
  1287. maximum = 1.27
  1288. default = 1.0
  1289. label = "Volume"
  1290. elif knobName == "dial_b_left":
  1291. minimum = -1.0
  1292. maximum = 1.0
  1293. default = -1.0
  1294. label = "Balance-Left"
  1295. elif knobName == "dial_b_right":
  1296. minimum = -1.0
  1297. maximum = 1.0
  1298. default = 1.0
  1299. label = "Balance-Right"
  1300. elif knobName == "dial_pan":
  1301. minimum = -1.0
  1302. maximum = 1.0
  1303. default = 0.0
  1304. label = "Panning"
  1305. else:
  1306. minimum = 0.0
  1307. maximum = 1.0
  1308. default = 0.5
  1309. label = "Unknown"
  1310. menu = QMenu(self)
  1311. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1312. menu.addSeparator()
  1313. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1314. actCenter = menu.addAction(self.tr("Set to Center"))
  1315. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1316. menu.addSeparator()
  1317. actSet = menu.addAction(self.tr("Set value..."))
  1318. if label not in ("Balance-Left", "Balance-Right", "Panning"):
  1319. menu.removeAction(actCenter)
  1320. actSelected = menu.exec_(QCursor.pos())
  1321. if actSelected == actSet:
  1322. current = minimum + (maximum-minimum)*(float(sender.value())/10000)
  1323. value, ok = QInputDialog.getInt(self,
  1324. self.tr("Set value"),
  1325. label,
  1326. round(current*100.0),
  1327. round(minimum*100.0),
  1328. round(maximum*100.0),
  1329. 1)
  1330. if ok:
  1331. value = float(value)/100.0
  1332. if not ok:
  1333. return
  1334. elif actSelected == actMinimum:
  1335. value = minimum
  1336. elif actSelected == actMaximum:
  1337. value = maximum
  1338. elif actSelected == actReset:
  1339. value = default
  1340. elif actSelected == actCenter:
  1341. value = 0.0
  1342. else:
  1343. return
  1344. sender.setValue(value, True)
  1345. #------------------------------------------------------------------
  1346. @pyqtSlot()
  1347. def slot_channelCustomMenu(self):
  1348. menu = QMenu(self)
  1349. actNone = menu.addAction(self.tr("None"))
  1350. if self.fControlChannel+1 == 0:
  1351. actNone.setCheckable(True)
  1352. actNone.setChecked(True)
  1353. for i in range(1, 16+1):
  1354. action = menu.addAction("%i" % i)
  1355. if self.fControlChannel+1 == i:
  1356. action.setCheckable(True)
  1357. action.setChecked(True)
  1358. actSel = menu.exec_(QCursor.pos())
  1359. if not actSel:
  1360. pass
  1361. elif actSel == actNone:
  1362. self.ui.sb_ctrl_channel.setValue(0)
  1363. elif actSel:
  1364. selChannel = int(actSel.text())
  1365. self.ui.sb_ctrl_channel.setValue(selChannel)
  1366. #------------------------------------------------------------------
  1367. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1368. groupWidgets = {}
  1369. for paramList, width in paramListFull:
  1370. if not paramList:
  1371. break
  1372. tabIndex = self.ui.tabWidget.count()
  1373. scrollArea = QScrollArea(self.ui.tabWidget)
  1374. scrollArea.setWidgetResizable(True)
  1375. scrollArea.setFrameStyle(0)
  1376. palette1 = scrollArea.palette()
  1377. palette1.setColor(QPalette.Background, Qt.transparent)
  1378. scrollArea.setPalette(palette1)
  1379. palette2 = scrollArea.palette()
  1380. palette2.setColor(QPalette.Background, palette2.color(QPalette.Button))
  1381. scrollAreaWidget = QWidget(scrollArea)
  1382. scrollAreaLayout = QVBoxLayout(scrollAreaWidget)
  1383. scrollAreaLayout.setSpacing(3)
  1384. for paramInfo in paramList:
  1385. groupName = paramInfo['groupName']
  1386. if groupName:
  1387. groupSymbol, groupName = groupName.split(":",1)
  1388. groupLayout, groupWidget = groupWidgets.get(groupSymbol, (None, None))
  1389. if groupLayout is None:
  1390. groupWidget = CollapsibleBox(groupName, scrollAreaWidget)
  1391. groupLayout = groupWidget.getContentLayout()
  1392. groupWidget.setPalette(palette2)
  1393. scrollAreaLayout.addWidget(groupWidget)
  1394. groupWidgets[groupSymbol] = (groupLayout, groupWidget)
  1395. else:
  1396. groupLayout = scrollAreaLayout
  1397. groupWidget = scrollAreaWidget
  1398. paramWidget = PluginParameter(groupWidget, self.host, paramInfo, self.fPluginId, tabIndex)
  1399. paramWidget.setLabelWidth(width)
  1400. groupLayout.addWidget(paramWidget)
  1401. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1402. if paramType == PARAMETER_INPUT:
  1403. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1404. paramWidget.mappedControlChanged.connect(self.slot_parameterMappedControlChanged)
  1405. paramWidget.mappedRangeChanged.connect(self.slot_parameterMappedRangeChanged)
  1406. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1407. scrollAreaLayout.addStretch()
  1408. scrollArea.setWidget(scrollAreaWidget)
  1409. self.ui.tabWidget.addTab(scrollArea, tabPageName)
  1410. if paramType == PARAMETER_INPUT:
  1411. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1412. self.fTabIconTimers.append(ICON_STATE_NULL)
  1413. def _updateCtrlPrograms(self):
  1414. self.ui.keyboard.setEnabled(self.fControlChannel >= 0)
  1415. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1416. return
  1417. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2):
  1418. return
  1419. if self.fControlChannel < 0:
  1420. self.ui.cb_programs.setEnabled(False)
  1421. self.ui.cb_midi_programs.setEnabled(False)
  1422. return
  1423. self.ui.cb_programs.setEnabled(True)
  1424. self.ui.cb_midi_programs.setEnabled(True)
  1425. pIndex = self.host.get_current_program_index(self.fPluginId)
  1426. if self.ui.cb_programs.currentIndex() != pIndex:
  1427. self.setProgram(pIndex)
  1428. mpIndex = self.host.get_current_midi_program_index(self.fPluginId)
  1429. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1430. self.setMidiProgram(mpIndex)
  1431. def _updateParameterValues(self):
  1432. for _, paramId, paramWidget in self.fParameterList:
  1433. paramWidget.blockSignals(True)
  1434. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  1435. paramWidget.blockSignals(False)
  1436. #------------------------------------------------------------------
  1437. def testTimer(self):
  1438. self.fIdleTimerId = self.startTimer(50)
  1439. self.SIGTERM.connect(self.testTimerClose)
  1440. gCarla.gui = self
  1441. setUpSignals()
  1442. def testTimerClose(self):
  1443. self.close()
  1444. _app.quit()
  1445. #------------------------------------------------------------------
  1446. def closeEvent(self, event):
  1447. if self.fIdleTimerId != 0:
  1448. self.killTimer(self.fIdleTimerId)
  1449. self.fIdleTimerId = 0
  1450. self.host.engine_close()
  1451. QDialog.closeEvent(self, event)
  1452. def timerEvent(self, event):
  1453. if event.timerId() == self.fIdleTimerId:
  1454. self.host.engine_idle()
  1455. self.idleSlow()
  1456. QDialog.timerEvent(self, event)
  1457. # ------------------------------------------------------------------------------------------------------------
  1458. # Main
  1459. if __name__ == '__main__':
  1460. from carla_app import CarlaApplication
  1461. from carla_host import initHost as _initHost, loadHostSettings as _loadHostSettings
  1462. _app = CarlaApplication()
  1463. _host = _initHost("Widgets", None, False, False, False)
  1464. _loadHostSettings(_host)
  1465. _host.engine_init("JACK", "Carla-Widgets")
  1466. _host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, 0x0)
  1467. _host.set_active(0, True)
  1468. gui1 = CarlaAboutW(None, _host)
  1469. gui1.show()
  1470. gui2 = PluginEdit(None, _host, 0)
  1471. gui2.testTimer()
  1472. gui2.show()
  1473. _app.exit_exec()