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.

1535 lines
60KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla widgets code
  4. # Copyright (C) 2011-2014 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 (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import pyqtSignal, pyqtSlot, pyqtWrapperType, Qt, QByteArray, QSettings, QTimer
  24. from PyQt5.QtGui import QColor, QCursor, QFontMetrics, QPainter, QPainterPath
  25. from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit, QMenu, QVBoxLayout, QWidget
  26. else:
  27. from PyQt4.QtCore import pyqtSignal, pyqtSlot, pyqtWrapperType, Qt, QByteArray, QSettings, QTimer
  28. from PyQt4.QtGui import QColor, QCursor, QFontMetrics, QPainter, QPainterPath
  29. from PyQt4.QtGui import QDialog, QInputDialog, QLineEdit, QMenu, QVBoxLayout, QWidget
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (Custom)
  32. import ui_carla_about
  33. import ui_carla_about_juce
  34. import ui_carla_edit
  35. import ui_carla_parameter
  36. from carla_shared import *
  37. from carla_utils import *
  38. from pixmapkeyboard import PixmapKeyboardHArea
  39. # ------------------------------------------------------------------------------------------------------------
  40. # Carla GUI defines
  41. ICON_STATE_ON = 3 # turns on, sets as wait1
  42. ICON_STATE_WAIT1 = 2 # sets as wait2
  43. ICON_STATE_WAIT2 = 1 # turns off, sets as off
  44. ICON_STATE_OFF = 0 # do nothing
  45. # ------------------------------------------------------------------------------------------------------------
  46. # Fake plugin info for easy testing
  47. gFakePluginInfo = {
  48. "type": PLUGIN_NONE,
  49. "category": PLUGIN_CATEGORY_SYNTH,
  50. "hints": PLUGIN_IS_SYNTH|PLUGIN_CAN_DRYWET|PLUGIN_CAN_VOLUME|PLUGIN_CAN_PANNING,
  51. "optionsAvailable": 0x1FF, # all
  52. "optionsEnabled": 0x1FF, # all
  53. "filename": "AwesoomeFilename.what",
  54. "name": "Awesoome Name",
  55. "label": "awesoomeLabel",
  56. "maker": "Awesoome Maker",
  57. "copyright": "Awesoome Copyright",
  58. "iconName": "plugin",
  59. "uniqueId": 0
  60. }
  61. gFakeParamInfo = {
  62. "type": PARAMETER_INPUT,
  63. "hints": PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE,
  64. "name": "Parameter Name",
  65. "unit": "",
  66. "scalePoints": [],
  67. "index": 0,
  68. "default": 0.0,
  69. "minimum": 0.0,
  70. "maximum": 1.0,
  71. "step": 0.001,
  72. "stepSmall": 0.0001,
  73. "stepLarge": 0.01,
  74. "midiCC": -1,
  75. "midiChannel": 1,
  76. "current": 0.0
  77. }
  78. gFakePortCountInfo = {
  79. "ins": 0,
  80. "outs": 0
  81. }
  82. # ------------------------------------------------------------------------------------------------------------
  83. # Carla About dialog
  84. class CarlaAboutW(QDialog):
  85. def __init__(self, parent):
  86. QDialog.__init__(self, parent)
  87. self.ui = ui_carla_about.Ui_CarlaAboutW()
  88. self.ui.setupUi(self)
  89. if gCarla.isControl:
  90. extraInfo = " - <b>%s</b>" % self.tr("OSC Bridge Version")
  91. elif gCarla.isPlugin:
  92. extraInfo = " - <b>%s</b>" % self.tr("Plugin Version")
  93. else:
  94. extraInfo = ""
  95. self.ui.l_about.setText(self.tr(""
  96. "<br>Version %s"
  97. "<br>Carla is a fully-featured audio plugin host%s.<br>"
  98. "<br>Copyright (C) 2011-2014 falkTX<br>"
  99. "" % (VERSION, extraInfo)))
  100. if gCarla.isControl or gCarla.isPlugin or gCarla.host is None:
  101. self.ui.l_extended.hide()
  102. self.ui.tabWidget.removeTab(1)
  103. self.ui.tabWidget.removeTab(1)
  104. else:
  105. self.ui.l_extended.setText(gCarla.host.get_complete_license_text())
  106. if gCarla.host.is_engine_running():
  107. self.ui.le_osc_url_tcp.setText(gCarla.host.get_host_osc_url_tcp())
  108. self.ui.le_osc_url_udp.setText(gCarla.host.get_host_osc_url_udp())
  109. else:
  110. self.ui.le_osc_url_tcp.setText(self.tr("(Engine not running)"))
  111. self.ui.le_osc_url_udp.setText(self.tr("(Engine not running)"))
  112. self.ui.l_osc_cmds.setText(""
  113. " /set_active <i-value>\n"
  114. " /set_drywet <f-value>\n"
  115. " /set_volume <f-value>\n"
  116. " /set_balance_left <f-value>\n"
  117. " /set_balance_right <f-value>\n"
  118. " /set_panning <f-value>\n"
  119. " /set_parameter_value <i-index> <f-value>\n"
  120. " /set_parameter_midi_cc <i-index> <i-cc>\n"
  121. " /set_parameter_midi_channel <i-index> <i-channel>\n"
  122. " /set_program <i-index>\n"
  123. " /set_midi_program <i-index>\n"
  124. " /note_on <i-note> <i-velo>\n"
  125. " /note_off <i-note>\n"
  126. )
  127. self.ui.l_example.setText("/Carla/2/set_parameter_value 5 1.0")
  128. self.ui.l_example_help.setText("<i>(as in this example, \"2\" is the plugin number and \"5\" the parameter)</i>")
  129. self.ui.l_ladspa.setText(self.tr("Everything! (Including LRDF)"))
  130. self.ui.l_dssi.setText(self.tr("Everything! (Including CustomData/Chunks)"))
  131. self.ui.l_lv2.setText(self.tr("About 90&#37; complete (using custom extensions)<br/>"
  132. "Implemented Feature/Extensions:"
  133. "<ul>"
  134. "<li>http://lv2plug.in/ns/ext/atom</li>"
  135. "<li>http://lv2plug.in/ns/ext/buf-size</li>"
  136. "<li>http://lv2plug.in/ns/ext/data-access</li>"
  137. #"<li>http://lv2plug.in/ns/ext/dynmanifest</li>"
  138. "<li>http://lv2plug.in/ns/ext/event</li>"
  139. "<li>http://lv2plug.in/ns/ext/instance-access</li>"
  140. "<li>http://lv2plug.in/ns/ext/log</li>"
  141. "<li>http://lv2plug.in/ns/ext/midi</li>"
  142. #"<li>http://lv2plug.in/ns/ext/morph</li>"
  143. "<li>http://lv2plug.in/ns/ext/options</li>"
  144. "<li>http://lv2plug.in/ns/ext/parameters</li>"
  145. #"<li>http://lv2plug.in/ns/ext/patch</li>"
  146. #"<li>http://lv2plug.in/ns/ext/port-groups</li>"
  147. "<li>http://lv2plug.in/ns/ext/port-props</li>"
  148. "<li>http://lv2plug.in/ns/ext/presets</li>"
  149. "<li>http://lv2plug.in/ns/ext/resize-port</li>"
  150. "<li>http://lv2plug.in/ns/ext/state</li>"
  151. "<li>http://lv2plug.in/ns/ext/time</li>"
  152. "<li>http://lv2plug.in/ns/ext/uri-map</li>"
  153. "<li>http://lv2plug.in/ns/ext/urid</li>"
  154. "<li>http://lv2plug.in/ns/ext/worker</li>"
  155. "<li>http://lv2plug.in/ns/extensions/ui</li>"
  156. "<li>http://lv2plug.in/ns/extensions/units</li>"
  157. "<li>http://home.gna.org/lv2dynparam/rtmempool/v1</li>"
  158. "<li>http://kxstudio.sf.net/ns/lv2ext/external-ui</li>"
  159. "<li>http://kxstudio.sf.net/ns/lv2ext/programs</li>"
  160. "<li>http://kxstudio.sf.net/ns/lv2ext/rtmempool</li>"
  161. "<li>http://ll-plugins.nongnu.org/lv2/ext/midimap</li>"
  162. "<li>http://ll-plugins.nongnu.org/lv2/ext/miditype</li>"
  163. "</ul>"))
  164. self.ui.l_vst.setText(self.tr("<p>About 85&#37; complete (missing vst bank/presets and some minor stuff)</p>"))
  165. self.adjustSize()
  166. self.setFixedSize(self.size())
  167. if WINDOWS:
  168. self.setWindowFlags(self.windowFlags()|Qt.MSWindowsFixedSizeDialogHint)
  169. def done(self, r):
  170. QDialog.done(self, r)
  171. self.close()
  172. # ------------------------------------------------------------------------------------------------------------
  173. # JUCE About dialog
  174. class JuceAboutW(QDialog):
  175. def __init__(self, parent):
  176. QDialog.__init__(self, parent)
  177. self.ui = ui_carla_about_juce.Ui_JuceAboutW()
  178. self.ui.setupUi(self)
  179. self.ui.l_text2.setText(self.tr("This program uses JUCE version %s." % (gCarla.host.get_juce_version() if gCarla.host is not None else "3.0")))
  180. self.adjustSize()
  181. self.setFixedSize(self.size())
  182. if WINDOWS:
  183. self.setWindowFlags(self.windowFlags()|Qt.MSWindowsFixedSizeDialogHint)
  184. def done(self, r):
  185. QDialog.done(self, r)
  186. self.close()
  187. # ------------------------------------------------------------------------------------------------------------
  188. # Plugin Parameter
  189. class PluginParameter(QWidget):
  190. midiControlChanged = pyqtSignal(int, int)
  191. midiChannelChanged = pyqtSignal(int, int)
  192. valueChanged = pyqtSignal(int, float)
  193. def __init__(self, parent, pInfo, pluginId, tabIndex):
  194. QWidget.__init__(self, parent)
  195. self.ui = ui_carla_parameter.Ui_PluginParameter()
  196. self.ui.setupUi(self)
  197. # -------------------------------------------------------------
  198. # Internal stuff
  199. self.fMidiControl = -1
  200. self.fMidiChannel = 1
  201. self.fParameterId = pInfo['index']
  202. self.fPluginId = pluginId
  203. self.fTabIndex = tabIndex
  204. # -------------------------------------------------------------
  205. # Set-up GUI
  206. pType = pInfo['type']
  207. pHints = pInfo['hints']
  208. self.ui.label.setText(pInfo['name'])
  209. self.ui.widget.setName(pInfo['name'])
  210. self.ui.widget.setMinimum(pInfo['minimum'])
  211. self.ui.widget.setMaximum(pInfo['maximum'])
  212. self.ui.widget.setDefault(pInfo['default'])
  213. self.ui.widget.setValue(pInfo['current'], False)
  214. self.ui.widget.setLabel(pInfo['unit'])
  215. self.ui.widget.setStep(pInfo['step'])
  216. self.ui.widget.setStepSmall(pInfo['stepSmall'])
  217. self.ui.widget.setStepLarge(pInfo['stepLarge'])
  218. self.ui.widget.setScalePoints(pInfo['scalePoints'], bool(pHints & PARAMETER_USES_SCALEPOINTS))
  219. if not pHints & PARAMETER_IS_AUTOMABLE:
  220. self.ui.sb_control.setEnabled(False)
  221. self.ui.sb_channel.setEnabled(False)
  222. if pType == PARAMETER_INPUT:
  223. if not pHints & PARAMETER_IS_ENABLED:
  224. self.ui.label.setEnabled(False)
  225. self.ui.widget.setEnabled(False)
  226. self.ui.widget.setReadOnly(True)
  227. self.ui.sb_control.setEnabled(False)
  228. self.ui.sb_channel.setEnabled(False)
  229. if pHints & PARAMETER_IS_READ_ONLY:
  230. self.ui.widget.setReadOnly(True)
  231. elif pType == PARAMETER_OUTPUT:
  232. self.ui.widget.setReadOnly(True)
  233. else:
  234. self.ui.widget.setVisible(False)
  235. self.ui.sb_control.setVisible(False)
  236. self.ui.sb_channel.setVisible(False)
  237. if pHints & PARAMETER_USES_CUSTOM_TEXT and not gCarla.isPlugin:
  238. self.ui.widget.setTextCallback(self._textCallBack)
  239. self.ui.widget.updateAll()
  240. self.setMidiControl(pInfo['midiCC'])
  241. self.setMidiChannel(pInfo['midiChannel'])
  242. # -------------------------------------------------------------
  243. # Set-up connections
  244. self.ui.sb_control.customContextMenuRequested.connect(self.slot_controlSpinboxCustomMenu)
  245. self.ui.sb_channel.customContextMenuRequested.connect(self.slot_channelSpinboxCustomMenu)
  246. self.ui.sb_control.valueChanged.connect(self.slot_controlSpinboxChanged)
  247. self.ui.sb_channel.valueChanged.connect(self.slot_channelSpinboxChanged)
  248. self.ui.widget.valueChanged.connect(self.slot_widgetValueChanged)
  249. # -------------------------------------------------------------
  250. def getPluginId(self):
  251. return self.fPluginId
  252. def getTabIndex(self):
  253. return self.fTabIndex
  254. def setPluginId(self, pluginId):
  255. self.fPluginId = pluginId
  256. def setDefault(self, value):
  257. self.ui.widget.setDefault(value)
  258. def setValue(self, value, send=True):
  259. self.ui.widget.setValue(value, send)
  260. def setMidiControl(self, control):
  261. self.fMidiControl = control
  262. self.ui.sb_control.blockSignals(True)
  263. self.ui.sb_control.setValue(control)
  264. self.ui.sb_control.blockSignals(False)
  265. def setMidiChannel(self, channel):
  266. self.fMidiChannel = channel
  267. self.ui.sb_channel.blockSignals(True)
  268. self.ui.sb_channel.setValue(channel)
  269. self.ui.sb_channel.blockSignals(False)
  270. def setLabelWidth(self, width):
  271. self.ui.label.setFixedWidth(width)
  272. @pyqtSlot()
  273. def slot_controlSpinboxCustomMenu(self):
  274. menu = QMenu(self)
  275. actNone = menu.addAction(self.tr("None"))
  276. if self.fMidiControl == -1:
  277. actNone.setCheckable(True)
  278. actNone.setChecked(True)
  279. for cc in MIDI_CC_LIST:
  280. action = menu.addAction(cc)
  281. if self.fMidiControl != -1 and int(cc.split(" ", 1)[0], 16) == self.fMidiControl:
  282. action.setCheckable(True)
  283. action.setChecked(True)
  284. actSel = menu.exec_(QCursor.pos())
  285. if not actSel:
  286. pass
  287. elif actSel == actNone:
  288. self.ui.sb_control.setValue(-1)
  289. else:
  290. selControlStr = actSel.text()
  291. selControl = int(selControlStr.split(" ", 1)[0], 16)
  292. self.ui.sb_control.setValue(selControl)
  293. @pyqtSlot()
  294. def slot_channelSpinboxCustomMenu(self):
  295. menu = QMenu(self)
  296. for i in range(1, 16+1):
  297. action = menu.addAction("%i" % i)
  298. if self.fMidiChannel == i:
  299. action.setCheckable(True)
  300. action.setChecked(True)
  301. actSel = menu.exec_(QCursor.pos())
  302. if actSel:
  303. selChannel = int(actSel.text())
  304. self.ui.sb_channel.setValue(selChannel)
  305. @pyqtSlot(int)
  306. def slot_controlSpinboxChanged(self, control):
  307. self.fMidiControl = control
  308. self.midiControlChanged.emit(self.fParameterId, control)
  309. @pyqtSlot(int)
  310. def slot_channelSpinboxChanged(self, channel):
  311. self.fMidiChannel = channel
  312. self.midiChannelChanged.emit(self.fParameterId, channel)
  313. @pyqtSlot(float)
  314. def slot_widgetValueChanged(self, value):
  315. self.valueChanged.emit(self.fParameterId, value)
  316. def _textCallBack(self):
  317. return gCarla.host.get_parameter_text(self.fPluginId, self.fParameterId)
  318. # ------------------------------------------------------------------------------------------------------------
  319. # Plugin Editor Parent (Meta class)
  320. class PluginEditParentMeta(metaclass=ABCMeta):
  321. @abstractmethod
  322. def editDialogChanged(self, visible):
  323. raise NotImplementedError
  324. @abstractmethod
  325. def pluginHintsChanged(self, hints):
  326. raise NotImplementedError
  327. @abstractmethod
  328. def parameterValueChanged(self, parameterId, value):
  329. raise NotImplementedError
  330. @abstractmethod
  331. def programChanged(self, index):
  332. raise NotImplementedError
  333. @abstractmethod
  334. def midiProgramChanged(self, index):
  335. raise NotImplementedError
  336. @abstractmethod
  337. def notePressed(self, note):
  338. raise NotImplementedError
  339. @abstractmethod
  340. def noteReleased(self, note):
  341. raise NotImplementedError
  342. # ------------------------------------------------------------------------------------------------------------
  343. # Plugin Editor (Built-in)
  344. class PluginEdit(QDialog):
  345. kParamsPerPage = 8
  346. def __init__(self, parent, pluginId):
  347. QDialog.__init__(self, gCarla.gui)
  348. self.ui = ui_carla_edit.Ui_PluginEdit()
  349. self.ui.setupUi(self)
  350. if False:
  351. parent = PluginEditParent()
  352. # -------------------------------------------------------------
  353. # Internal stuff
  354. self.fGeometry = QByteArray()
  355. self.fPluginId = pluginId
  356. self.fPuginInfo = None
  357. self.fRealParent = parent
  358. self.fCurrentProgram = -1
  359. self.fCurrentMidiProgram = -1
  360. self.fCurrentStateFilename = None
  361. self.fControlChannel = int(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_CTRL_CHANNEL)) if gCarla.host is not None else 0
  362. self.fFirstInit = True
  363. self.fParameterCount = 0
  364. self.fParameterList = [] # (type, id, widget)
  365. self.fParametersToUpdate = [] # (id, value)
  366. self.fPlayingNotes = [] # (channel, note)
  367. self.fTabIconOff = QIcon(":/bitmaps/led_off.png")
  368. self.fTabIconOn = QIcon(":/bitmaps/led_yellow.png")
  369. self.fTabIconCount = 0
  370. self.fTabIconTimers = []
  371. # -------------------------------------------------------------
  372. # Set-up GUI
  373. self.ui.dial_drywet.setCustomPaintMode(self.ui.dial_drywet.CUSTOM_PAINT_MODE_CARLA_WET)
  374. self.ui.dial_drywet.setPixmap(3)
  375. self.ui.dial_drywet.setLabel("Dry/Wet")
  376. self.ui.dial_drywet.setMinimum(0.0)
  377. self.ui.dial_drywet.setMaximum(1.0)
  378. self.ui.dial_vol.setCustomPaintMode(self.ui.dial_vol.CUSTOM_PAINT_MODE_CARLA_VOL)
  379. self.ui.dial_vol.setPixmap(3)
  380. self.ui.dial_vol.setLabel("Volume")
  381. self.ui.dial_vol.setMinimum(0.0)
  382. self.ui.dial_vol.setMaximum(1.27)
  383. self.ui.dial_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L)
  384. self.ui.dial_b_left.setPixmap(4)
  385. self.ui.dial_b_left.setLabel("L")
  386. self.ui.dial_b_left.setMinimum(-1.0)
  387. self.ui.dial_b_left.setMaximum(1.0)
  388. self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R)
  389. self.ui.dial_b_right.setPixmap(4)
  390. self.ui.dial_b_right.setLabel("R")
  391. self.ui.dial_b_right.setMinimum(-1.0)
  392. self.ui.dial_b_right.setMaximum(1.0)
  393. self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN)
  394. self.ui.dial_pan.setPixmap(4)
  395. self.ui.dial_pan.setLabel("Pan")
  396. self.ui.dial_pan.setMinimum(-1.0)
  397. self.ui.dial_pan.setMaximum(1.0)
  398. if gCarla.host is not None:
  399. self.ui.dial_drywet.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_DRYWET))
  400. self.ui.dial_vol.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_VOLUME))
  401. self.ui.dial_b_left.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_LEFT))
  402. self.ui.dial_b_right.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_RIGHT))
  403. self.ui.dial_pan.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_PANNING))
  404. else:
  405. self.ui.dial_drywet.setValue(1.0)
  406. self.ui.dial_vol.setValue(1.0)
  407. self.ui.dial_b_left.setValue(-1.0)
  408. self.ui.dial_b_right.setValue(1.0)
  409. self.ui.dial_pan.setValue(0.0)
  410. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  411. self.ui.scrollArea = PixmapKeyboardHArea(self)
  412. self.ui.keyboard = self.ui.scrollArea.keyboard
  413. self.layout().addWidget(self.ui.scrollArea)
  414. self.ui.scrollArea.setEnabled(False)
  415. self.ui.scrollArea.setVisible(False)
  416. # todo
  417. self.ui.rb_balance.setEnabled(False)
  418. self.ui.rb_pan.setEnabled(False)
  419. self.reloadAll()
  420. # -------------------------------------------------------------
  421. # Set-up connections
  422. self.finished.connect(self.slot_finished)
  423. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  424. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  425. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  426. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  427. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  428. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  429. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  430. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  431. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  432. self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged)
  433. self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged)
  434. self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged)
  435. self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged)
  436. self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged)
  437. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  438. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  439. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  440. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  441. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  442. self.ui.dial_pan.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  443. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  444. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  445. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  446. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  447. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  448. if gCarla.isLocal:
  449. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  450. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  451. else:
  452. self.ui.b_load_state.setEnabled(False)
  453. self.ui.b_save_state.setEnabled(False)
  454. #------------------------------------------------------------------
  455. def updateInfo(self):
  456. # Update current program text
  457. if self.ui.cb_programs.count() > 0:
  458. pIndex = self.ui.cb_programs.currentIndex()
  459. pName = gCarla.host.get_program_name(self.fPluginId, pIndex)
  460. #pName = pName[:40] + (pName[40:] and "...")
  461. self.ui.cb_programs.setItemText(pIndex, pName)
  462. # Update current midi program text
  463. if self.ui.cb_midi_programs.count() > 0:
  464. mpIndex = self.ui.cb_midi_programs.currentIndex()
  465. mpData = gCarla.host.get_midi_program_data(self.fPluginId, mpIndex)
  466. mpBank = mpData['bank']
  467. mpProg = mpData['program']
  468. mpName = mpData['name']
  469. #mpName = mpName[:40] + (mpName[40:] and "...")
  470. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  471. # Update all parameter values
  472. for paramType, paramId, paramWidget in self.fParameterList:
  473. paramWidget.setValue(gCarla.host.get_current_parameter_value(self.fPluginId, paramId), False)
  474. paramWidget.update()
  475. self.fParametersToUpdate = []
  476. #------------------------------------------------------------------
  477. def reloadAll(self):
  478. if gCarla.host is not None:
  479. self.fPluginInfo = gCarla.host.get_plugin_info(self.fPluginId)
  480. if not gCarla.isLocal:
  481. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_CUSTOM_UI
  482. else:
  483. self.fPluginInfo = gFakePluginInfo
  484. self.reloadInfo()
  485. self.reloadParameters()
  486. self.reloadPrograms()
  487. if self.fPluginInfo['type'] == PLUGIN_LV2:
  488. self.ui.b_save_state.setEnabled(False)
  489. if not self.ui.scrollArea.isEnabled():
  490. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  491. self.fFirstInit = False
  492. # Workaround for a Qt4 bug, see https://bugreports.qt-project.org/browse/QTBUG-7792
  493. QTimer.singleShot(0, self.slot_fixNameWordWrap)
  494. @pyqtSlot()
  495. def slot_fixNameWordWrap(self):
  496. self.adjustSize()
  497. self.setMinimumSize(self.width(), self.height())
  498. #------------------------------------------------------------------
  499. def reloadInfo(self):
  500. if gCarla.host is not None:
  501. pluginName = gCarla.host.get_real_plugin_name(self.fPluginId)
  502. #audioCountInfo = gCarla.host.get_audio_port_count_info(self.fPluginId)
  503. midiCountInfo = gCarla.host.get_midi_port_count_info(self.fPluginId)
  504. #paramCountInfo = gCarla.host.get_parameter_count_info(self.fPluginId)
  505. else:
  506. pluginName = ""
  507. #audioCountInfo = gFakePortCountInfo
  508. midiCountInfo = gFakePortCountInfo
  509. #paramCountInfo = gFakePortCountInfo
  510. pluginHints = self.fPluginInfo['hints']
  511. self.ui.le_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  512. if pluginName:
  513. self.ui.label_name.setEnabled(True)
  514. self.ui.le_name.setEnabled(True)
  515. self.ui.le_name.setText(pluginName)
  516. self.ui.le_name.setToolTip(pluginName)
  517. else:
  518. self.ui.label_name.setEnabled(False)
  519. self.ui.le_name.setEnabled(False)
  520. self.ui.le_name.setText("")
  521. self.ui.le_name.setToolTip("")
  522. if self.fPluginInfo['label']:
  523. self.ui.label_label.setEnabled(True)
  524. self.ui.le_label.setEnabled(True)
  525. self.ui.le_label.setText(self.fPluginInfo['label'])
  526. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  527. else:
  528. self.ui.label_label.setEnabled(False)
  529. self.ui.le_label.setEnabled(False)
  530. self.ui.le_label.setText("")
  531. self.ui.le_label.setToolTip("")
  532. if self.fPluginInfo['maker']:
  533. self.ui.label_maker.setEnabled(True)
  534. self.ui.le_maker.setEnabled(True)
  535. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  536. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  537. else:
  538. self.ui.label_maker.setEnabled(False)
  539. self.ui.le_maker.setEnabled(False)
  540. self.ui.le_maker.setText("")
  541. self.ui.le_maker.setToolTip("")
  542. if self.fPluginInfo['copyright']:
  543. self.ui.label_copyright.setEnabled(True)
  544. self.ui.le_copyright.setEnabled(True)
  545. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  546. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  547. else:
  548. self.ui.label_copyright.setEnabled(False)
  549. self.ui.le_copyright.setEnabled(False)
  550. self.ui.le_copyright.setText("")
  551. self.ui.le_copyright.setToolTip("")
  552. if self.fPluginInfo['uniqueId'] != 0:
  553. self.ui.label_unique_id.setEnabled(True)
  554. self.ui.le_unique_id.setEnabled(True)
  555. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  556. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  557. else:
  558. self.ui.label_unique_id.setEnabled(False)
  559. self.ui.le_unique_id.setEnabled(False)
  560. self.ui.le_unique_id.setText("")
  561. self.ui.le_unique_id.setToolTip("")
  562. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  563. self.setWindowTitle(self.fPluginInfo['name'])
  564. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  565. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  566. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  567. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  568. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  569. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  570. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  571. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  572. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  573. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  574. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  575. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  576. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  577. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  578. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  579. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  580. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  581. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  582. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  583. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  584. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  585. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  586. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  587. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] in (PLUGIN_VST, PLUGIN_GIG, PLUGIN_SFZ) else 1)
  588. # Show/hide keyboard
  589. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  590. self.ui.scrollArea.setEnabled(showKeyboard)
  591. self.ui.scrollArea.setVisible(showKeyboard)
  592. # Force-Update parent for new hints
  593. if self.fRealParent and not self.fFirstInit:
  594. self.fRealParent.pluginHintsChanged(pluginHints)
  595. def reloadParameters(self):
  596. # Reset
  597. self.fParameterCount = 0
  598. self.fParameterList = []
  599. self.fParametersToUpdate = []
  600. self.fTabIconCount = 0
  601. self.fTabIconTimers = []
  602. # Remove all previous parameters
  603. for x in range(self.ui.tabWidget.count()-1):
  604. self.ui.tabWidget.widget(1).deleteLater()
  605. self.ui.tabWidget.removeTab(1)
  606. if gCarla.host is None:
  607. paramFakeListFull = []
  608. paramFakeList = []
  609. paramFakeWidth = QFontMetrics(self.font()).width(gFakeParamInfo['name'])
  610. paramFakeList.append(gFakeParamInfo)
  611. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  612. self._createParameterWidgets(PARAMETER_INPUT, paramFakeListFull, self.tr("Parameters"))
  613. return
  614. parameterCount = gCarla.host.get_parameter_count(self.fPluginId)
  615. if parameterCount <= 0:
  616. pass
  617. elif parameterCount <= gCarla.maxParameters:
  618. paramInputListFull = []
  619. paramOutputListFull = []
  620. paramInputList = [] # ([params], width)
  621. paramInputWidth = 0
  622. paramOutputList = [] # ([params], width)
  623. paramOutputWidth = 0
  624. for i in range(parameterCount):
  625. paramInfo = gCarla.host.get_parameter_info(self.fPluginId, i)
  626. paramData = gCarla.host.get_parameter_data(self.fPluginId, i)
  627. paramRanges = gCarla.host.get_parameter_ranges(self.fPluginId, i)
  628. paramValue = gCarla.host.get_current_parameter_value(self.fPluginId, i)
  629. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  630. continue
  631. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  632. continue
  633. parameter = {
  634. 'type': paramData['type'],
  635. 'hints': paramData['hints'],
  636. 'name': paramInfo['name'],
  637. 'unit': paramInfo['unit'],
  638. 'scalePoints': [],
  639. 'index': paramData['index'],
  640. 'default': paramRanges['def'],
  641. 'minimum': paramRanges['min'],
  642. 'maximum': paramRanges['max'],
  643. 'step': paramRanges['step'],
  644. 'stepSmall': paramRanges['stepSmall'],
  645. 'stepLarge': paramRanges['stepLarge'],
  646. 'midiCC': paramData['midiCC'],
  647. 'midiChannel': paramData['midiChannel']+1,
  648. 'current': paramValue
  649. }
  650. for j in range(paramInfo['scalePointCount']):
  651. scalePointInfo = gCarla.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  652. parameter['scalePoints'].append({
  653. 'value': scalePointInfo['value'],
  654. 'label': scalePointInfo['label']
  655. })
  656. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  657. # -----------------------------------------------------------------
  658. # Get width values, in packs of 10
  659. if parameter['type'] == PARAMETER_INPUT:
  660. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  661. if paramInputWidthTMP > paramInputWidth:
  662. paramInputWidth = paramInputWidthTMP
  663. paramInputList.append(parameter)
  664. if len(paramInputList) == self.kParamsPerPage:
  665. paramInputListFull.append((paramInputList, paramInputWidth))
  666. paramInputList = []
  667. paramInputWidth = 0
  668. else:
  669. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  670. if paramOutputWidthTMP > paramOutputWidth:
  671. paramOutputWidth = paramOutputWidthTMP
  672. paramOutputList.append(parameter)
  673. if len(paramOutputList) == self.kParamsPerPage:
  674. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  675. paramOutputList = []
  676. paramOutputWidth = 0
  677. # for i in range(parameterCount)
  678. else:
  679. # Final page width values
  680. if 0 < len(paramInputList) < 10:
  681. paramInputListFull.append((paramInputList, paramInputWidth))
  682. if 0 < len(paramOutputList) < 10:
  683. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  684. # -----------------------------------------------------------------
  685. # Create parameter tabs + widgets
  686. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  687. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  688. else: # > gCarla.maxParameters
  689. fakeName = self.tr("This plugin has too many parameters to display here!")
  690. paramFakeListFull = []
  691. paramFakeList = []
  692. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  693. parameter = {
  694. 'type': PARAMETER_UNKNOWN,
  695. 'hints': 0x0,
  696. 'name': fakeName,
  697. 'unit': "",
  698. 'scalePoints': [],
  699. 'index': 0,
  700. 'default': 0.0,
  701. 'minimum': 0.0,
  702. 'maximum': 1.0,
  703. 'step': 0.0,
  704. 'stepSmall': 0.0,
  705. 'stepLarge': 0.0,
  706. 'midiCC': -1,
  707. 'midiChannel': 1,
  708. 'current': 0.0
  709. }
  710. paramFakeList.append(parameter)
  711. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  712. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  713. def reloadPrograms(self):
  714. # Programs
  715. self.ui.cb_programs.blockSignals(True)
  716. self.ui.cb_programs.clear()
  717. programCount = gCarla.host.get_program_count(self.fPluginId) if gCarla.host is not None else 0
  718. if programCount > 0:
  719. self.ui.cb_programs.setEnabled(True)
  720. self.ui.label_programs.setEnabled(True)
  721. for i in range(programCount):
  722. pName = gCarla.host.get_program_name(self.fPluginId, i)
  723. #pName = pName[:40] + (pName[40:] and "...")
  724. self.ui.cb_programs.addItem(pName)
  725. self.fCurrentProgram = gCarla.host.get_current_program_index(self.fPluginId)
  726. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  727. else:
  728. self.fCurrentProgram = -1
  729. self.ui.cb_programs.setEnabled(False)
  730. self.ui.label_programs.setEnabled(False)
  731. self.ui.cb_programs.blockSignals(False)
  732. # MIDI Programs
  733. self.ui.cb_midi_programs.blockSignals(True)
  734. self.ui.cb_midi_programs.clear()
  735. midiProgramCount = gCarla.host.get_midi_program_count(self.fPluginId) if gCarla.host is not None else 0
  736. if midiProgramCount > 0:
  737. self.ui.cb_midi_programs.setEnabled(True)
  738. self.ui.label_midi_programs.setEnabled(True)
  739. for i in range(midiProgramCount):
  740. mpData = gCarla.host.get_midi_program_data(self.fPluginId, i)
  741. mpBank = mpData['bank']
  742. mpProg = mpData['program']
  743. mpName = mpData['name']
  744. #mpName = mpName[:40] + (mpName[40:] and "...")
  745. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  746. self.fCurrentMidiProgram = gCarla.host.get_current_midi_program_index(self.fPluginId)
  747. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  748. else:
  749. self.fCurrentMidiProgram = -1
  750. self.ui.cb_midi_programs.setEnabled(False)
  751. self.ui.label_midi_programs.setEnabled(False)
  752. self.ui.cb_midi_programs.blockSignals(False)
  753. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  754. if self.fPluginInfo['type'] == PLUGIN_LV2:
  755. self.ui.b_load_state.setEnabled(programCount > 0)
  756. #------------------------------------------------------------------
  757. def clearNotes(self):
  758. self.fPlayingNotes = []
  759. self.ui.keyboard.allNotesOff()
  760. #------------------------------------------------------------------
  761. def getHints(self):
  762. return self.fPluginInfo['hints']
  763. def setId(self, idx):
  764. self.fPluginId = idx
  765. def setName(self, name):
  766. self.fPluginInfo['name'] = name
  767. self.ui.label_plugin.setText("\n%s\n" % name)
  768. self.setWindowTitle(name)
  769. #------------------------------------------------------------------
  770. def setParameterValue(self, parameterId, value):
  771. for paramItem in self.fParametersToUpdate:
  772. if paramItem[0] == parameterId:
  773. paramItem[1] = value
  774. break
  775. else:
  776. self.fParametersToUpdate.append([parameterId, value])
  777. def setParameterDefault(self, parameterId, value):
  778. for paramType, paramId, paramWidget in self.fParameterList:
  779. if paramId == parameterId:
  780. paramWidget.setDefault(value)
  781. break
  782. def setParameterMidiControl(self, parameterId, control):
  783. for paramType, paramId, paramWidget in self.fParameterList:
  784. if paramId == parameterId:
  785. paramWidget.setMidiControl(control)
  786. break
  787. def setParameterMidiChannel(self, parameterId, channel):
  788. for paramType, paramId, paramWidget in self.fParameterList:
  789. if paramId == parameterId:
  790. paramWidget.setMidiChannel(channel+1)
  791. break
  792. def setProgram(self, index):
  793. self.ui.cb_programs.blockSignals(True)
  794. self.ui.cb_programs.setCurrentIndex(index)
  795. self.ui.cb_programs.blockSignals(False)
  796. def setMidiProgram(self, index):
  797. self.ui.cb_midi_programs.blockSignals(True)
  798. self.ui.cb_midi_programs.setCurrentIndex(index)
  799. self.ui.cb_midi_programs.blockSignals(False)
  800. def setOption(self, option, yesNo):
  801. if option == PLUGIN_OPTION_FIXED_BUFFERS:
  802. widget = self.ui.ch_fixed_buffer
  803. elif option == PLUGIN_OPTION_FORCE_STEREO:
  804. widget = self.ui.ch_force_stereo
  805. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  806. widget = self.ui.ch_map_program_changes
  807. elif option == PLUGIN_OPTION_USE_CHUNKS:
  808. widget = self.ui.ch_use_chunks
  809. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  810. widget = self.ui.ch_send_control_changes
  811. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  812. widget = self.ui.ch_send_channel_pressure
  813. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  814. widget = self.ui.ch_send_note_aftertouch
  815. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  816. widget = self.ui.ch_send_pitchbend
  817. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  818. widget = self.ui.ch_send_all_sound_off
  819. else:
  820. return
  821. widget.blockSignals(True)
  822. widget.setChecked(yesNo)
  823. widget.blockSignals(False)
  824. #------------------------------------------------------------------
  825. def sendNoteOn(self, channel, note):
  826. if self.fControlChannel == channel:
  827. self.ui.keyboard.sendNoteOn(note, False)
  828. playItem = (channel, note)
  829. if playItem not in self.fPlayingNotes:
  830. self.fPlayingNotes.append(playItem)
  831. return bool(len(self.fPlayingNotes) == 1)
  832. def sendNoteOff(self, channel, note):
  833. if self.fControlChannel == channel:
  834. self.ui.keyboard.sendNoteOff(note, False)
  835. playItem = (channel, note)
  836. if playItem in self.fPlayingNotes:
  837. self.fPlayingNotes.remove(playItem)
  838. return bool(len(self.fPlayingNotes) == 0)
  839. #------------------------------------------------------------------
  840. def setVisible(self, yesNo):
  841. if yesNo:
  842. if not self.fGeometry.isNull():
  843. self.restoreGeometry(self.fGeometry)
  844. else:
  845. self.fGeometry = self.saveGeometry()
  846. QDialog.setVisible(self, yesNo)
  847. #------------------------------------------------------------------
  848. def idleSlow(self):
  849. # Check Tab icons
  850. for i in range(len(self.fTabIconTimers)):
  851. if self.fTabIconTimers[i] == ICON_STATE_ON:
  852. self.fTabIconTimers[i] = ICON_STATE_WAIT1
  853. elif self.fTabIconTimers[i] == ICON_STATE_WAIT1:
  854. self.fTabIconTimers[i] = ICON_STATE_WAIT2
  855. elif self.fTabIconTimers[i] == ICON_STATE_WAIT2:
  856. self.fTabIconTimers[i] = ICON_STATE_OFF
  857. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  858. # Check parameters needing update
  859. for index, value in self.fParametersToUpdate:
  860. if index == PARAMETER_DRYWET:
  861. self.ui.dial_drywet.blockSignals(True)
  862. self.ui.dial_drywet.setValue(value)
  863. self.ui.dial_drywet.blockSignals(False)
  864. elif index == PARAMETER_VOLUME:
  865. self.ui.dial_vol.blockSignals(True)
  866. self.ui.dial_vol.setValue(value)
  867. self.ui.dial_vol.blockSignals(False)
  868. elif index == PARAMETER_BALANCE_LEFT:
  869. self.ui.dial_b_left.blockSignals(True)
  870. self.ui.dial_b_left.setValue(value)
  871. self.ui.dial_b_left.blockSignals(False)
  872. elif index == PARAMETER_BALANCE_RIGHT:
  873. self.ui.dial_b_right.blockSignals(True)
  874. self.ui.dial_b_right.setValue(value)
  875. self.ui.dial_b_right.blockSignals(False)
  876. elif index == PARAMETER_PANNING:
  877. self.ui.dial_pan.blockSignals(True)
  878. self.ui.dial_pan.setValue(value)
  879. self.ui.dial_pan.blockSignals(False)
  880. elif index == PARAMETER_CTRL_CHANNEL:
  881. self.fControlChannel = int(value)
  882. self.ui.sb_ctrl_channel.blockSignals(True)
  883. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  884. self.ui.sb_ctrl_channel.blockSignals(False)
  885. self.ui.keyboard.allNotesOff()
  886. self._updateCtrlPrograms()
  887. elif index >= 0:
  888. for paramType, paramId, paramWidget in self.fParameterList:
  889. if paramId != index:
  890. continue
  891. paramWidget.setValue(value, False)
  892. if paramType == PARAMETER_INPUT:
  893. tabIndex = paramWidget.getTabIndex()
  894. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_OFF:
  895. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  896. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  897. break
  898. # Clear all parameters
  899. self.fParametersToUpdate = []
  900. # Update parameter outputs
  901. for paramType, paramId, paramWidget in self.fParameterList:
  902. if paramType == PARAMETER_OUTPUT:
  903. value = gCarla.host.get_current_parameter_value(self.fPluginId, paramId)
  904. paramWidget.setValue(value, False)
  905. #------------------------------------------------------------------
  906. @pyqtSlot()
  907. def slot_stateSave(self):
  908. if self.fPluginInfo['type'] == PLUGIN_LV2:
  909. # TODO
  910. return
  911. if self.fCurrentStateFilename:
  912. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  913. if askTry == QMessageBox.Ok:
  914. gCarla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  915. return
  916. self.fCurrentStateFilename = None
  917. fileFilter = self.tr("Carla State File (*.carxs)")
  918. filename = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  919. if config_UseQt5:
  920. filename = filename[0]
  921. if not filename:
  922. return
  923. if not filename.lower().endswith(".carxs"):
  924. filename += ".carxs"
  925. self.fCurrentStateFilename = filename
  926. gCarla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  927. @pyqtSlot()
  928. def slot_stateLoad(self):
  929. if self.fPluginInfo['type'] == PLUGIN_LV2:
  930. presetList = []
  931. for i in range(gCarla.host.get_program_count(self.fPluginId)):
  932. presetList.append("%03i - %s" % (i+1, gCarla.host.get_program_name(self.fPluginId, i)))
  933. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  934. if ret[1]:
  935. index = int(ret[0].split(" - ", 1)[0])-1
  936. gCarla.host.set_midi_program(self.fPluginId, -1)
  937. gCarla.host.set_program(self.fPluginId, index)
  938. self.setMidiProgram(-1)
  939. return
  940. fileFilter = self.tr("Carla State File (*.carxs)")
  941. filename = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  942. if config_UseQt5:
  943. filename = filename[0]
  944. if not filename:
  945. return
  946. self.fCurrentStateFilename = filename
  947. gCarla.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  948. #------------------------------------------------------------------
  949. @pyqtSlot(bool)
  950. def slot_optionChanged(self, clicked):
  951. if gCarla.host is None:
  952. return
  953. sender = self.sender()
  954. if sender == self.ui.ch_fixed_buffer:
  955. option = PLUGIN_OPTION_FIXED_BUFFERS
  956. elif sender == self.ui.ch_force_stereo:
  957. option = PLUGIN_OPTION_FORCE_STEREO
  958. elif sender == self.ui.ch_map_program_changes:
  959. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  960. elif sender == self.ui.ch_use_chunks:
  961. option = PLUGIN_OPTION_USE_CHUNKS
  962. elif sender == self.ui.ch_send_control_changes:
  963. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  964. elif sender == self.ui.ch_send_channel_pressure:
  965. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  966. elif sender == self.ui.ch_send_note_aftertouch:
  967. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  968. elif sender == self.ui.ch_send_pitchbend:
  969. option = PLUGIN_OPTION_SEND_PITCHBEND
  970. elif sender == self.ui.ch_send_all_sound_off:
  971. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  972. else:
  973. return
  974. gCarla.host.set_option(self.fPluginId, option, clicked)
  975. #------------------------------------------------------------------
  976. @pyqtSlot(int)
  977. def slot_dryWetChanged(self, value):
  978. if gCarla.host is not None:
  979. gCarla.host.set_drywet(self.fPluginId, value)
  980. if self.fRealParent is not None:
  981. self.fRealParent.parameterValueChanged(PARAMETER_DRYWET, value)
  982. @pyqtSlot(int)
  983. def slot_volumeChanged(self, value):
  984. if gCarla.host is not None:
  985. gCarla.host.set_volume(self.fPluginId, value)
  986. if self.fRealParent is not None:
  987. self.fRealParent.parameterValueChanged(PARAMETER_VOLUME, value)
  988. @pyqtSlot(int)
  989. def slot_balanceLeftChanged(self, value):
  990. if gCarla.host is not None:
  991. gCarla.host.set_balance_left(self.fPluginId, value)
  992. if self.fRealParent is not None:
  993. self.fRealParent.parameterValueChanged(PARAMETER_BALANCE_LEFT, value)
  994. @pyqtSlot(int)
  995. def slot_balanceRightChanged(self, value):
  996. if gCarla.host is not None:
  997. gCarla.host.set_balance_right(self.fPluginId, value)
  998. if self.fRealParent is not None:
  999. self.fRealParent.parameterValueChanged(PARAMETER_BALANCE_RIGHT, value)
  1000. @pyqtSlot(int)
  1001. def slot_panChanged(self, value):
  1002. if gCarla.host is not None:
  1003. gCarla.host.set_panning(self.fPluginId, value)
  1004. if self.fRealParent is not None:
  1005. self.fRealParent.parameterValueChanged(PARAMETER_PANNING, value)
  1006. @pyqtSlot(int)
  1007. def slot_ctrlChannelChanged(self, value):
  1008. self.fControlChannel = value-1
  1009. if gCarla.host is not None:
  1010. gCarla.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  1011. self.ui.keyboard.allNotesOff()
  1012. self._updateCtrlPrograms()
  1013. #------------------------------------------------------------------
  1014. @pyqtSlot(int, float)
  1015. def slot_parameterValueChanged(self, parameterId, value):
  1016. if gCarla.host is not None:
  1017. gCarla.host.set_parameter_value(self.fPluginId, parameterId, value)
  1018. if self.fRealParent is not None:
  1019. self.fRealParent.parameterValueChanged(parameterId, value)
  1020. @pyqtSlot(int, int)
  1021. def slot_parameterMidiControlChanged(self, parameterId, control):
  1022. if gCarla.host is not None:
  1023. gCarla.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  1024. @pyqtSlot(int, int)
  1025. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  1026. if gCarla.host is not None:
  1027. gCarla.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1028. #------------------------------------------------------------------
  1029. @pyqtSlot(int)
  1030. def slot_programIndexChanged(self, index):
  1031. self.fCurrentProgram = index
  1032. if gCarla.host is not None:
  1033. gCarla.host.set_program(self.fPluginId, index)
  1034. if self.fRealParent is not None:
  1035. self.fRealParent.programChanged(index)
  1036. @pyqtSlot(int)
  1037. def slot_midiProgramIndexChanged(self, index):
  1038. self.fCurrentMidiProgram = index
  1039. if gCarla.host is not None:
  1040. gCarla.host.set_midi_program(self.fPluginId, index)
  1041. if self.fRealParent is not None:
  1042. self.fRealParent.midiProgramChanged(index)
  1043. #------------------------------------------------------------------
  1044. @pyqtSlot(int)
  1045. def slot_noteOn(self, note):
  1046. if self.fControlChannel >= 0 and gCarla.host is not None:
  1047. gCarla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1048. if self.fRealParent is not None:
  1049. self.fRealParent.notePressed(note)
  1050. @pyqtSlot(int)
  1051. def slot_noteOff(self, note):
  1052. if self.fControlChannel >= 0 and gCarla.host is not None:
  1053. gCarla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1054. if self.fRealParent is not None:
  1055. self.fRealParent.noteReleased(note)
  1056. #------------------------------------------------------------------
  1057. @pyqtSlot()
  1058. def slot_finished(self):
  1059. if self.fRealParent is not None:
  1060. self.fRealParent.editDialogChanged(False)
  1061. #------------------------------------------------------------------
  1062. @pyqtSlot()
  1063. def slot_knobCustomMenu(self):
  1064. knobName = self.sender().objectName()
  1065. if knobName == "dial_drywet":
  1066. minimum = 0.0
  1067. maximum = 1.0
  1068. default = 1.0
  1069. label = "Dry/Wet"
  1070. elif knobName == "dial_vol":
  1071. minimum = 0.0
  1072. maximum = 1.27
  1073. default = 1.0
  1074. label = "Volume"
  1075. elif knobName == "dial_b_left":
  1076. minimum = -1.0
  1077. maximum = 1.0
  1078. default = -1.0
  1079. label = "Balance-Left"
  1080. elif knobName == "dial_b_right":
  1081. minimum = -1.0
  1082. maximum = 1.0
  1083. default = 1.0
  1084. label = "Balance-Right"
  1085. elif knobName == "dial_pan":
  1086. minimum = -1.0
  1087. maximum = 1.0
  1088. default = 0.0
  1089. label = "Panning"
  1090. else:
  1091. minimum = 0.0
  1092. maximum = 1.0
  1093. default = 0.5
  1094. label = "Unknown"
  1095. current = self.sender().value() / 10
  1096. menu = QMenu(self)
  1097. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1098. menu.addSeparator()
  1099. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1100. actCenter = menu.addAction(self.tr("Set to Center"))
  1101. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1102. menu.addSeparator()
  1103. actSet = menu.addAction(self.tr("Set value..."))
  1104. if label not in ("Balance-Left", "Balance-Right"):
  1105. menu.removeAction(actCenter)
  1106. actSelected = menu.exec_(QCursor.pos())
  1107. if actSelected == actSet:
  1108. valueTry = QInputDialog.getDouble(self, self.tr("Set value"), label, current, minimum, maximum, 3)
  1109. if valueTry[1]:
  1110. value = valueTry[0] * 10
  1111. else:
  1112. return
  1113. elif actSelected == actMinimum:
  1114. value = minimum
  1115. elif actSelected == actMaximum:
  1116. value = maximum
  1117. elif actSelected == actReset:
  1118. value = default
  1119. elif actSelected == actCenter:
  1120. value = 0.0
  1121. else:
  1122. return
  1123. self.sender().setValue(value)
  1124. #------------------------------------------------------------------
  1125. @pyqtSlot()
  1126. def slot_channelCustomMenu(self):
  1127. menu = QMenu(self)
  1128. actNone = menu.addAction(self.tr("None"))
  1129. if self.fControlChannel+1 == 0:
  1130. actNone.setCheckable(True)
  1131. actNone.setChecked(True)
  1132. for i in range(1, 16+1):
  1133. action = menu.addAction("%i" % i)
  1134. if self.fControlChannel+1 == i:
  1135. action.setCheckable(True)
  1136. action.setChecked(True)
  1137. actSel = menu.exec_(QCursor.pos())
  1138. if not actSel:
  1139. pass
  1140. elif actSel == actNone:
  1141. self.ui.sb_ctrl_channel.setValue(0)
  1142. elif actSel:
  1143. selChannel = int(actSel.text())
  1144. self.ui.sb_ctrl_channel.setValue(selChannel)
  1145. #------------------------------------------------------------------
  1146. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1147. i = 1
  1148. for paramList, width in paramListFull:
  1149. if len(paramList) == 0:
  1150. break
  1151. tabIndex = self.ui.tabWidget.count()
  1152. tabPageContainer = QWidget(self.ui.tabWidget)
  1153. tabPageLayout = QVBoxLayout(tabPageContainer)
  1154. tabPageContainer.setLayout(tabPageLayout)
  1155. for paramInfo in paramList:
  1156. paramWidget = PluginParameter(tabPageContainer, paramInfo, self.fPluginId, tabIndex)
  1157. paramWidget.setLabelWidth(width)
  1158. tabPageLayout.addWidget(paramWidget)
  1159. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1160. if paramType == PARAMETER_INPUT:
  1161. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1162. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1163. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1164. tabPageLayout.addStretch()
  1165. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1166. i += 1
  1167. if paramType == PARAMETER_INPUT:
  1168. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1169. self.fTabIconTimers.append(ICON_STATE_OFF)
  1170. def _updateCtrlPrograms(self):
  1171. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH or self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2, PLUGIN_GIG):
  1172. return
  1173. if self.fControlChannel < 0:
  1174. self.ui.cb_programs.setEnabled(False)
  1175. self.ui.cb_midi_programs.setEnabled(False)
  1176. return
  1177. self.ui.cb_programs.setEnabled(True)
  1178. self.ui.cb_midi_programs.setEnabled(True)
  1179. pIndex = gCarla.host.get_current_program_index(self.fPluginId)
  1180. if self.ui.cb_programs.currentIndex() != pIndex:
  1181. self.setProgram(pIndex)
  1182. mpIndex = gCarla.host.get_current_midi_program_index(self.fPluginId)
  1183. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1184. self.setMidiProgram(mpIndex)
  1185. #------------------------------------------------------------------
  1186. def done(self, r):
  1187. QDialog.done(self, r)
  1188. self.close()
  1189. # ------------------------------------------------------------------------------------------------------------
  1190. # Main
  1191. if __name__ == '__main__':
  1192. from carla_app import CarlaApplication
  1193. app = CarlaApplication()
  1194. #gui1 = CarlaAboutW(None)
  1195. #gui1.show()
  1196. #gui2 = PluginParameter(None, gFakeParamInfo, 0, 0)
  1197. #gui2.show()
  1198. gui3 = PluginEdit(None, 0)
  1199. gui3.show()
  1200. app.exit_exec()