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.

1852 lines
74KB

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