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.

1536 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():
  321. class PluginEditParentMeta(metaclass=ABCMeta):
  322. @abstractmethod
  323. def editDialogChanged(self, visible):
  324. raise NotImplementedError
  325. @abstractmethod
  326. def pluginHintsChanged(self, hints):
  327. raise NotImplementedError
  328. @abstractmethod
  329. def parameterValueChanged(self, parameterId, value):
  330. raise NotImplementedError
  331. @abstractmethod
  332. def programChanged(self, index):
  333. raise NotImplementedError
  334. @abstractmethod
  335. def midiProgramChanged(self, index):
  336. raise NotImplementedError
  337. @abstractmethod
  338. def notePressed(self, note):
  339. raise NotImplementedError
  340. @abstractmethod
  341. def noteReleased(self, note):
  342. raise NotImplementedError
  343. # ------------------------------------------------------------------------------------------------------------
  344. # Plugin Editor (Built-in)
  345. class PluginEdit(QDialog):
  346. kParamsPerPage = 8
  347. def __init__(self, parent, pluginId):
  348. QDialog.__init__(self, parent.window() if parent is not None else None)
  349. self.ui = ui_carla_edit.Ui_PluginEdit()
  350. self.ui.setupUi(self)
  351. if False:
  352. parent = PluginEditParentMeta()
  353. # -------------------------------------------------------------
  354. # Internal stuff
  355. self.fGeometry = QByteArray()
  356. self.fPluginId = pluginId
  357. self.fPuginInfo = None
  358. self.fRealParent = parent
  359. self.fCurrentProgram = -1
  360. self.fCurrentMidiProgram = -1
  361. self.fCurrentStateFilename = None
  362. self.fControlChannel = int(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_CTRL_CHANNEL)) if gCarla.host is not None else 0
  363. self.fFirstInit = True
  364. self.fParameterCount = 0
  365. self.fParameterList = [] # (type, id, widget)
  366. self.fParametersToUpdate = [] # (id, value)
  367. self.fPlayingNotes = [] # (channel, note)
  368. self.fTabIconOff = QIcon(":/bitmaps/led_off.png")
  369. self.fTabIconOn = QIcon(":/bitmaps/led_yellow.png")
  370. self.fTabIconCount = 0
  371. self.fTabIconTimers = []
  372. # -------------------------------------------------------------
  373. # Set-up GUI
  374. self.ui.dial_drywet.setCustomPaintMode(self.ui.dial_drywet.CUSTOM_PAINT_MODE_CARLA_WET)
  375. self.ui.dial_drywet.setPixmap(3)
  376. self.ui.dial_drywet.setLabel("Dry/Wet")
  377. self.ui.dial_drywet.setMinimum(0.0)
  378. self.ui.dial_drywet.setMaximum(1.0)
  379. self.ui.dial_vol.setCustomPaintMode(self.ui.dial_vol.CUSTOM_PAINT_MODE_CARLA_VOL)
  380. self.ui.dial_vol.setPixmap(3)
  381. self.ui.dial_vol.setLabel("Volume")
  382. self.ui.dial_vol.setMinimum(0.0)
  383. self.ui.dial_vol.setMaximum(1.27)
  384. self.ui.dial_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L)
  385. self.ui.dial_b_left.setPixmap(4)
  386. self.ui.dial_b_left.setLabel("L")
  387. self.ui.dial_b_left.setMinimum(-1.0)
  388. self.ui.dial_b_left.setMaximum(1.0)
  389. self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R)
  390. self.ui.dial_b_right.setPixmap(4)
  391. self.ui.dial_b_right.setLabel("R")
  392. self.ui.dial_b_right.setMinimum(-1.0)
  393. self.ui.dial_b_right.setMaximum(1.0)
  394. self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN)
  395. self.ui.dial_pan.setPixmap(4)
  396. self.ui.dial_pan.setLabel("Pan")
  397. self.ui.dial_pan.setMinimum(-1.0)
  398. self.ui.dial_pan.setMaximum(1.0)
  399. if gCarla.host is not None:
  400. self.ui.dial_drywet.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_DRYWET))
  401. self.ui.dial_vol.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_VOLUME))
  402. self.ui.dial_b_left.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_LEFT))
  403. self.ui.dial_b_right.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_RIGHT))
  404. self.ui.dial_pan.setValue(gCarla.host.get_internal_parameter_value(pluginId, PARAMETER_PANNING))
  405. else:
  406. self.ui.dial_drywet.setValue(1.0)
  407. self.ui.dial_vol.setValue(1.0)
  408. self.ui.dial_b_left.setValue(-1.0)
  409. self.ui.dial_b_right.setValue(1.0)
  410. self.ui.dial_pan.setValue(0.0)
  411. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  412. self.ui.scrollArea = PixmapKeyboardHArea(self)
  413. self.ui.keyboard = self.ui.scrollArea.keyboard
  414. self.layout().addWidget(self.ui.scrollArea)
  415. self.ui.scrollArea.setEnabled(False)
  416. self.ui.scrollArea.setVisible(False)
  417. # todo
  418. self.ui.rb_balance.setEnabled(False)
  419. self.ui.rb_pan.setEnabled(False)
  420. self.reloadAll()
  421. # -------------------------------------------------------------
  422. # Set-up connections
  423. self.finished.connect(self.slot_finished)
  424. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  425. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  426. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  427. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  428. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  429. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  430. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  431. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  432. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  433. self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged)
  434. self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged)
  435. self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged)
  436. self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged)
  437. self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged)
  438. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  439. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  440. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  441. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  442. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  443. self.ui.dial_pan.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  444. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  445. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  446. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  447. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  448. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  449. if gCarla.isLocal:
  450. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  451. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  452. else:
  453. self.ui.b_load_state.setEnabled(False)
  454. self.ui.b_save_state.setEnabled(False)
  455. #------------------------------------------------------------------
  456. def updateInfo(self):
  457. # Update current program text
  458. if self.ui.cb_programs.count() > 0:
  459. pIndex = self.ui.cb_programs.currentIndex()
  460. pName = gCarla.host.get_program_name(self.fPluginId, pIndex)
  461. #pName = pName[:40] + (pName[40:] and "...")
  462. self.ui.cb_programs.setItemText(pIndex, pName)
  463. # Update current midi program text
  464. if self.ui.cb_midi_programs.count() > 0:
  465. mpIndex = self.ui.cb_midi_programs.currentIndex()
  466. mpData = gCarla.host.get_midi_program_data(self.fPluginId, mpIndex)
  467. mpBank = mpData['bank']
  468. mpProg = mpData['program']
  469. mpName = mpData['name']
  470. #mpName = mpName[:40] + (mpName[40:] and "...")
  471. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  472. # Update all parameter values
  473. for paramType, paramId, paramWidget in self.fParameterList:
  474. paramWidget.setValue(gCarla.host.get_current_parameter_value(self.fPluginId, paramId), False)
  475. paramWidget.update()
  476. self.fParametersToUpdate = []
  477. #------------------------------------------------------------------
  478. def reloadAll(self):
  479. if gCarla.host is not None:
  480. self.fPluginInfo = gCarla.host.get_plugin_info(self.fPluginId)
  481. if not gCarla.isLocal:
  482. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_CUSTOM_UI
  483. else:
  484. self.fPluginInfo = gFakePluginInfo
  485. self.reloadInfo()
  486. self.reloadParameters()
  487. self.reloadPrograms()
  488. if self.fPluginInfo['type'] == PLUGIN_LV2:
  489. self.ui.b_save_state.setEnabled(False)
  490. if not self.ui.scrollArea.isEnabled():
  491. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  492. self.fFirstInit = False
  493. # Workaround for a Qt4 bug, see https://bugreports.qt-project.org/browse/QTBUG-7792
  494. QTimer.singleShot(0, self.slot_fixNameWordWrap)
  495. @pyqtSlot()
  496. def slot_fixNameWordWrap(self):
  497. self.adjustSize()
  498. self.setMinimumSize(self.width(), self.height())
  499. #------------------------------------------------------------------
  500. def reloadInfo(self):
  501. if gCarla.host is not None:
  502. pluginName = gCarla.host.get_real_plugin_name(self.fPluginId)
  503. #audioCountInfo = gCarla.host.get_audio_port_count_info(self.fPluginId)
  504. midiCountInfo = gCarla.host.get_midi_port_count_info(self.fPluginId)
  505. #paramCountInfo = gCarla.host.get_parameter_count_info(self.fPluginId)
  506. else:
  507. pluginName = ""
  508. #audioCountInfo = gFakePortCountInfo
  509. midiCountInfo = gFakePortCountInfo
  510. #paramCountInfo = gFakePortCountInfo
  511. pluginHints = self.fPluginInfo['hints']
  512. self.ui.le_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  513. if pluginName:
  514. self.ui.label_name.setEnabled(True)
  515. self.ui.le_name.setEnabled(True)
  516. self.ui.le_name.setText(pluginName)
  517. self.ui.le_name.setToolTip(pluginName)
  518. else:
  519. self.ui.label_name.setEnabled(False)
  520. self.ui.le_name.setEnabled(False)
  521. self.ui.le_name.setText("")
  522. self.ui.le_name.setToolTip("")
  523. if self.fPluginInfo['label']:
  524. self.ui.label_label.setEnabled(True)
  525. self.ui.le_label.setEnabled(True)
  526. self.ui.le_label.setText(self.fPluginInfo['label'])
  527. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  528. else:
  529. self.ui.label_label.setEnabled(False)
  530. self.ui.le_label.setEnabled(False)
  531. self.ui.le_label.setText("")
  532. self.ui.le_label.setToolTip("")
  533. if self.fPluginInfo['maker']:
  534. self.ui.label_maker.setEnabled(True)
  535. self.ui.le_maker.setEnabled(True)
  536. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  537. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  538. else:
  539. self.ui.label_maker.setEnabled(False)
  540. self.ui.le_maker.setEnabled(False)
  541. self.ui.le_maker.setText("")
  542. self.ui.le_maker.setToolTip("")
  543. if self.fPluginInfo['copyright']:
  544. self.ui.label_copyright.setEnabled(True)
  545. self.ui.le_copyright.setEnabled(True)
  546. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  547. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  548. else:
  549. self.ui.label_copyright.setEnabled(False)
  550. self.ui.le_copyright.setEnabled(False)
  551. self.ui.le_copyright.setText("")
  552. self.ui.le_copyright.setToolTip("")
  553. if self.fPluginInfo['uniqueId'] != 0:
  554. self.ui.label_unique_id.setEnabled(True)
  555. self.ui.le_unique_id.setEnabled(True)
  556. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  557. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  558. else:
  559. self.ui.label_unique_id.setEnabled(False)
  560. self.ui.le_unique_id.setEnabled(False)
  561. self.ui.le_unique_id.setText("")
  562. self.ui.le_unique_id.setToolTip("")
  563. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  564. self.setWindowTitle(self.fPluginInfo['name'])
  565. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  566. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  567. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  568. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  569. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  570. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  571. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  572. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  573. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  574. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  575. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  576. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  577. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  578. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  579. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  580. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  581. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  582. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  583. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  584. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  585. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  586. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  587. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  588. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] in (PLUGIN_VST, PLUGIN_GIG, PLUGIN_SFZ) else 1)
  589. # Show/hide keyboard
  590. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  591. self.ui.scrollArea.setEnabled(showKeyboard)
  592. self.ui.scrollArea.setVisible(showKeyboard)
  593. # Force-Update parent for new hints
  594. if self.fRealParent and not self.fFirstInit:
  595. self.fRealParent.pluginHintsChanged(pluginHints)
  596. def reloadParameters(self):
  597. # Reset
  598. self.fParameterCount = 0
  599. self.fParameterList = []
  600. self.fParametersToUpdate = []
  601. self.fTabIconCount = 0
  602. self.fTabIconTimers = []
  603. # Remove all previous parameters
  604. for x in range(self.ui.tabWidget.count()-1):
  605. self.ui.tabWidget.widget(1).deleteLater()
  606. self.ui.tabWidget.removeTab(1)
  607. if gCarla.host is None:
  608. paramFakeListFull = []
  609. paramFakeList = []
  610. paramFakeWidth = QFontMetrics(self.font()).width(gFakeParamInfo['name'])
  611. paramFakeList.append(gFakeParamInfo)
  612. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  613. self._createParameterWidgets(PARAMETER_INPUT, paramFakeListFull, self.tr("Parameters"))
  614. return
  615. parameterCount = gCarla.host.get_parameter_count(self.fPluginId)
  616. if parameterCount <= 0:
  617. pass
  618. elif parameterCount <= gCarla.maxParameters:
  619. paramInputListFull = []
  620. paramOutputListFull = []
  621. paramInputList = [] # ([params], width)
  622. paramInputWidth = 0
  623. paramOutputList = [] # ([params], width)
  624. paramOutputWidth = 0
  625. for i in range(parameterCount):
  626. paramInfo = gCarla.host.get_parameter_info(self.fPluginId, i)
  627. paramData = gCarla.host.get_parameter_data(self.fPluginId, i)
  628. paramRanges = gCarla.host.get_parameter_ranges(self.fPluginId, i)
  629. paramValue = gCarla.host.get_current_parameter_value(self.fPluginId, i)
  630. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  631. continue
  632. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  633. continue
  634. parameter = {
  635. 'type': paramData['type'],
  636. 'hints': paramData['hints'],
  637. 'name': paramInfo['name'],
  638. 'unit': paramInfo['unit'],
  639. 'scalePoints': [],
  640. 'index': paramData['index'],
  641. 'default': paramRanges['def'],
  642. 'minimum': paramRanges['min'],
  643. 'maximum': paramRanges['max'],
  644. 'step': paramRanges['step'],
  645. 'stepSmall': paramRanges['stepSmall'],
  646. 'stepLarge': paramRanges['stepLarge'],
  647. 'midiCC': paramData['midiCC'],
  648. 'midiChannel': paramData['midiChannel']+1,
  649. 'current': paramValue
  650. }
  651. for j in range(paramInfo['scalePointCount']):
  652. scalePointInfo = gCarla.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  653. parameter['scalePoints'].append({
  654. 'value': scalePointInfo['value'],
  655. 'label': scalePointInfo['label']
  656. })
  657. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  658. # -----------------------------------------------------------------
  659. # Get width values, in packs of 10
  660. if parameter['type'] == PARAMETER_INPUT:
  661. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  662. if paramInputWidthTMP > paramInputWidth:
  663. paramInputWidth = paramInputWidthTMP
  664. paramInputList.append(parameter)
  665. if len(paramInputList) == self.kParamsPerPage:
  666. paramInputListFull.append((paramInputList, paramInputWidth))
  667. paramInputList = []
  668. paramInputWidth = 0
  669. else:
  670. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  671. if paramOutputWidthTMP > paramOutputWidth:
  672. paramOutputWidth = paramOutputWidthTMP
  673. paramOutputList.append(parameter)
  674. if len(paramOutputList) == self.kParamsPerPage:
  675. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  676. paramOutputList = []
  677. paramOutputWidth = 0
  678. # for i in range(parameterCount)
  679. else:
  680. # Final page width values
  681. if 0 < len(paramInputList) < 10:
  682. paramInputListFull.append((paramInputList, paramInputWidth))
  683. if 0 < len(paramOutputList) < 10:
  684. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  685. # -----------------------------------------------------------------
  686. # Create parameter tabs + widgets
  687. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  688. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  689. else: # > gCarla.maxParameters
  690. fakeName = self.tr("This plugin has too many parameters to display here!")
  691. paramFakeListFull = []
  692. paramFakeList = []
  693. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  694. parameter = {
  695. 'type': PARAMETER_UNKNOWN,
  696. 'hints': 0x0,
  697. 'name': fakeName,
  698. 'unit': "",
  699. 'scalePoints': [],
  700. 'index': 0,
  701. 'default': 0.0,
  702. 'minimum': 0.0,
  703. 'maximum': 1.0,
  704. 'step': 0.0,
  705. 'stepSmall': 0.0,
  706. 'stepLarge': 0.0,
  707. 'midiCC': -1,
  708. 'midiChannel': 1,
  709. 'current': 0.0
  710. }
  711. paramFakeList.append(parameter)
  712. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  713. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  714. def reloadPrograms(self):
  715. # Programs
  716. self.ui.cb_programs.blockSignals(True)
  717. self.ui.cb_programs.clear()
  718. programCount = gCarla.host.get_program_count(self.fPluginId) if gCarla.host is not None else 0
  719. if programCount > 0:
  720. self.ui.cb_programs.setEnabled(True)
  721. self.ui.label_programs.setEnabled(True)
  722. for i in range(programCount):
  723. pName = gCarla.host.get_program_name(self.fPluginId, i)
  724. #pName = pName[:40] + (pName[40:] and "...")
  725. self.ui.cb_programs.addItem(pName)
  726. self.fCurrentProgram = gCarla.host.get_current_program_index(self.fPluginId)
  727. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  728. else:
  729. self.fCurrentProgram = -1
  730. self.ui.cb_programs.setEnabled(False)
  731. self.ui.label_programs.setEnabled(False)
  732. self.ui.cb_programs.blockSignals(False)
  733. # MIDI Programs
  734. self.ui.cb_midi_programs.blockSignals(True)
  735. self.ui.cb_midi_programs.clear()
  736. midiProgramCount = gCarla.host.get_midi_program_count(self.fPluginId) if gCarla.host is not None else 0
  737. if midiProgramCount > 0:
  738. self.ui.cb_midi_programs.setEnabled(True)
  739. self.ui.label_midi_programs.setEnabled(True)
  740. for i in range(midiProgramCount):
  741. mpData = gCarla.host.get_midi_program_data(self.fPluginId, i)
  742. mpBank = mpData['bank']
  743. mpProg = mpData['program']
  744. mpName = mpData['name']
  745. #mpName = mpName[:40] + (mpName[40:] and "...")
  746. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  747. self.fCurrentMidiProgram = gCarla.host.get_current_midi_program_index(self.fPluginId)
  748. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  749. else:
  750. self.fCurrentMidiProgram = -1
  751. self.ui.cb_midi_programs.setEnabled(False)
  752. self.ui.label_midi_programs.setEnabled(False)
  753. self.ui.cb_midi_programs.blockSignals(False)
  754. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  755. if self.fPluginInfo['type'] == PLUGIN_LV2:
  756. self.ui.b_load_state.setEnabled(programCount > 0)
  757. #------------------------------------------------------------------
  758. def clearNotes(self):
  759. self.fPlayingNotes = []
  760. self.ui.keyboard.allNotesOff()
  761. #------------------------------------------------------------------
  762. def getHints(self):
  763. return self.fPluginInfo['hints']
  764. def setId(self, idx):
  765. self.fPluginId = idx
  766. def setName(self, name):
  767. self.fPluginInfo['name'] = name
  768. self.ui.label_plugin.setText("\n%s\n" % name)
  769. self.setWindowTitle(name)
  770. #------------------------------------------------------------------
  771. def setParameterValue(self, parameterId, value):
  772. for paramItem in self.fParametersToUpdate:
  773. if paramItem[0] == parameterId:
  774. paramItem[1] = value
  775. break
  776. else:
  777. self.fParametersToUpdate.append([parameterId, value])
  778. def setParameterDefault(self, parameterId, value):
  779. for paramType, paramId, paramWidget in self.fParameterList:
  780. if paramId == parameterId:
  781. paramWidget.setDefault(value)
  782. break
  783. def setParameterMidiControl(self, parameterId, control):
  784. for paramType, paramId, paramWidget in self.fParameterList:
  785. if paramId == parameterId:
  786. paramWidget.setMidiControl(control)
  787. break
  788. def setParameterMidiChannel(self, parameterId, channel):
  789. for paramType, paramId, paramWidget in self.fParameterList:
  790. if paramId == parameterId:
  791. paramWidget.setMidiChannel(channel+1)
  792. break
  793. def setProgram(self, index):
  794. self.ui.cb_programs.blockSignals(True)
  795. self.ui.cb_programs.setCurrentIndex(index)
  796. self.ui.cb_programs.blockSignals(False)
  797. def setMidiProgram(self, index):
  798. self.ui.cb_midi_programs.blockSignals(True)
  799. self.ui.cb_midi_programs.setCurrentIndex(index)
  800. self.ui.cb_midi_programs.blockSignals(False)
  801. def setOption(self, option, yesNo):
  802. if option == PLUGIN_OPTION_FIXED_BUFFERS:
  803. widget = self.ui.ch_fixed_buffer
  804. elif option == PLUGIN_OPTION_FORCE_STEREO:
  805. widget = self.ui.ch_force_stereo
  806. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  807. widget = self.ui.ch_map_program_changes
  808. elif option == PLUGIN_OPTION_USE_CHUNKS:
  809. widget = self.ui.ch_use_chunks
  810. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  811. widget = self.ui.ch_send_control_changes
  812. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  813. widget = self.ui.ch_send_channel_pressure
  814. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  815. widget = self.ui.ch_send_note_aftertouch
  816. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  817. widget = self.ui.ch_send_pitchbend
  818. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  819. widget = self.ui.ch_send_all_sound_off
  820. else:
  821. return
  822. widget.blockSignals(True)
  823. widget.setChecked(yesNo)
  824. widget.blockSignals(False)
  825. #------------------------------------------------------------------
  826. def sendNoteOn(self, channel, note):
  827. if self.fControlChannel == channel:
  828. self.ui.keyboard.sendNoteOn(note, False)
  829. playItem = (channel, note)
  830. if playItem not in self.fPlayingNotes:
  831. self.fPlayingNotes.append(playItem)
  832. return bool(len(self.fPlayingNotes) == 1)
  833. def sendNoteOff(self, channel, note):
  834. if self.fControlChannel == channel:
  835. self.ui.keyboard.sendNoteOff(note, False)
  836. playItem = (channel, note)
  837. if playItem in self.fPlayingNotes:
  838. self.fPlayingNotes.remove(playItem)
  839. return bool(len(self.fPlayingNotes) == 0)
  840. #------------------------------------------------------------------
  841. def setVisible(self, yesNo):
  842. if yesNo:
  843. if not self.fGeometry.isNull():
  844. self.restoreGeometry(self.fGeometry)
  845. else:
  846. self.fGeometry = self.saveGeometry()
  847. QDialog.setVisible(self, yesNo)
  848. #------------------------------------------------------------------
  849. def idleSlow(self):
  850. # Check Tab icons
  851. for i in range(len(self.fTabIconTimers)):
  852. if self.fTabIconTimers[i] == ICON_STATE_ON:
  853. self.fTabIconTimers[i] = ICON_STATE_WAIT1
  854. elif self.fTabIconTimers[i] == ICON_STATE_WAIT1:
  855. self.fTabIconTimers[i] = ICON_STATE_WAIT2
  856. elif self.fTabIconTimers[i] == ICON_STATE_WAIT2:
  857. self.fTabIconTimers[i] = ICON_STATE_OFF
  858. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  859. # Check parameters needing update
  860. for index, value in self.fParametersToUpdate:
  861. if index == PARAMETER_DRYWET:
  862. self.ui.dial_drywet.blockSignals(True)
  863. self.ui.dial_drywet.setValue(value)
  864. self.ui.dial_drywet.blockSignals(False)
  865. elif index == PARAMETER_VOLUME:
  866. self.ui.dial_vol.blockSignals(True)
  867. self.ui.dial_vol.setValue(value)
  868. self.ui.dial_vol.blockSignals(False)
  869. elif index == PARAMETER_BALANCE_LEFT:
  870. self.ui.dial_b_left.blockSignals(True)
  871. self.ui.dial_b_left.setValue(value)
  872. self.ui.dial_b_left.blockSignals(False)
  873. elif index == PARAMETER_BALANCE_RIGHT:
  874. self.ui.dial_b_right.blockSignals(True)
  875. self.ui.dial_b_right.setValue(value)
  876. self.ui.dial_b_right.blockSignals(False)
  877. elif index == PARAMETER_PANNING:
  878. self.ui.dial_pan.blockSignals(True)
  879. self.ui.dial_pan.setValue(value)
  880. self.ui.dial_pan.blockSignals(False)
  881. elif index == PARAMETER_CTRL_CHANNEL:
  882. self.fControlChannel = int(value)
  883. self.ui.sb_ctrl_channel.blockSignals(True)
  884. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  885. self.ui.sb_ctrl_channel.blockSignals(False)
  886. self.ui.keyboard.allNotesOff()
  887. self._updateCtrlPrograms()
  888. elif index >= 0:
  889. for paramType, paramId, paramWidget in self.fParameterList:
  890. if paramId != index:
  891. continue
  892. paramWidget.setValue(value, False)
  893. if paramType == PARAMETER_INPUT:
  894. tabIndex = paramWidget.getTabIndex()
  895. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_OFF:
  896. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  897. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  898. break
  899. # Clear all parameters
  900. self.fParametersToUpdate = []
  901. # Update parameter outputs
  902. for paramType, paramId, paramWidget in self.fParameterList:
  903. if paramType == PARAMETER_OUTPUT:
  904. value = gCarla.host.get_current_parameter_value(self.fPluginId, paramId)
  905. paramWidget.setValue(value, False)
  906. #------------------------------------------------------------------
  907. @pyqtSlot()
  908. def slot_stateSave(self):
  909. if self.fPluginInfo['type'] == PLUGIN_LV2:
  910. # TODO
  911. return
  912. if self.fCurrentStateFilename:
  913. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  914. if askTry == QMessageBox.Ok:
  915. gCarla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  916. return
  917. self.fCurrentStateFilename = None
  918. fileFilter = self.tr("Carla State File (*.carxs)")
  919. filename = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  920. if config_UseQt5:
  921. filename = filename[0]
  922. if not filename:
  923. return
  924. if not filename.lower().endswith(".carxs"):
  925. filename += ".carxs"
  926. self.fCurrentStateFilename = filename
  927. gCarla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  928. @pyqtSlot()
  929. def slot_stateLoad(self):
  930. if self.fPluginInfo['type'] == PLUGIN_LV2:
  931. presetList = []
  932. for i in range(gCarla.host.get_program_count(self.fPluginId)):
  933. presetList.append("%03i - %s" % (i+1, gCarla.host.get_program_name(self.fPluginId, i)))
  934. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  935. if ret[1]:
  936. index = int(ret[0].split(" - ", 1)[0])-1
  937. gCarla.host.set_midi_program(self.fPluginId, -1)
  938. gCarla.host.set_program(self.fPluginId, index)
  939. self.setMidiProgram(-1)
  940. return
  941. fileFilter = self.tr("Carla State File (*.carxs)")
  942. filename = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  943. if config_UseQt5:
  944. filename = filename[0]
  945. if not filename:
  946. return
  947. self.fCurrentStateFilename = filename
  948. gCarla.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  949. #------------------------------------------------------------------
  950. @pyqtSlot(bool)
  951. def slot_optionChanged(self, clicked):
  952. if gCarla.host is None:
  953. return
  954. sender = self.sender()
  955. if sender == self.ui.ch_fixed_buffer:
  956. option = PLUGIN_OPTION_FIXED_BUFFERS
  957. elif sender == self.ui.ch_force_stereo:
  958. option = PLUGIN_OPTION_FORCE_STEREO
  959. elif sender == self.ui.ch_map_program_changes:
  960. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  961. elif sender == self.ui.ch_use_chunks:
  962. option = PLUGIN_OPTION_USE_CHUNKS
  963. elif sender == self.ui.ch_send_control_changes:
  964. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  965. elif sender == self.ui.ch_send_channel_pressure:
  966. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  967. elif sender == self.ui.ch_send_note_aftertouch:
  968. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  969. elif sender == self.ui.ch_send_pitchbend:
  970. option = PLUGIN_OPTION_SEND_PITCHBEND
  971. elif sender == self.ui.ch_send_all_sound_off:
  972. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  973. else:
  974. return
  975. gCarla.host.set_option(self.fPluginId, option, clicked)
  976. #------------------------------------------------------------------
  977. @pyqtSlot(int)
  978. def slot_dryWetChanged(self, value):
  979. if gCarla.host is not None:
  980. gCarla.host.set_drywet(self.fPluginId, value)
  981. if self.fRealParent is not None:
  982. self.fRealParent.parameterValueChanged(PARAMETER_DRYWET, value)
  983. @pyqtSlot(int)
  984. def slot_volumeChanged(self, value):
  985. if gCarla.host is not None:
  986. gCarla.host.set_volume(self.fPluginId, value)
  987. if self.fRealParent is not None:
  988. self.fRealParent.parameterValueChanged(PARAMETER_VOLUME, value)
  989. @pyqtSlot(int)
  990. def slot_balanceLeftChanged(self, value):
  991. if gCarla.host is not None:
  992. gCarla.host.set_balance_left(self.fPluginId, value)
  993. if self.fRealParent is not None:
  994. self.fRealParent.parameterValueChanged(PARAMETER_BALANCE_LEFT, value)
  995. @pyqtSlot(int)
  996. def slot_balanceRightChanged(self, value):
  997. if gCarla.host is not None:
  998. gCarla.host.set_balance_right(self.fPluginId, value)
  999. if self.fRealParent is not None:
  1000. self.fRealParent.parameterValueChanged(PARAMETER_BALANCE_RIGHT, value)
  1001. @pyqtSlot(int)
  1002. def slot_panChanged(self, value):
  1003. if gCarla.host is not None:
  1004. gCarla.host.set_panning(self.fPluginId, value)
  1005. if self.fRealParent is not None:
  1006. self.fRealParent.parameterValueChanged(PARAMETER_PANNING, value)
  1007. @pyqtSlot(int)
  1008. def slot_ctrlChannelChanged(self, value):
  1009. self.fControlChannel = value-1
  1010. if gCarla.host is not None:
  1011. gCarla.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  1012. self.ui.keyboard.allNotesOff()
  1013. self._updateCtrlPrograms()
  1014. #------------------------------------------------------------------
  1015. @pyqtSlot(int, float)
  1016. def slot_parameterValueChanged(self, parameterId, value):
  1017. if gCarla.host is not None:
  1018. gCarla.host.set_parameter_value(self.fPluginId, parameterId, value)
  1019. if self.fRealParent is not None:
  1020. self.fRealParent.parameterValueChanged(parameterId, value)
  1021. @pyqtSlot(int, int)
  1022. def slot_parameterMidiControlChanged(self, parameterId, control):
  1023. if gCarla.host is not None:
  1024. gCarla.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  1025. @pyqtSlot(int, int)
  1026. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  1027. if gCarla.host is not None:
  1028. gCarla.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1029. #------------------------------------------------------------------
  1030. @pyqtSlot(int)
  1031. def slot_programIndexChanged(self, index):
  1032. self.fCurrentProgram = index
  1033. if gCarla.host is not None:
  1034. gCarla.host.set_program(self.fPluginId, index)
  1035. if self.fRealParent is not None:
  1036. self.fRealParent.programChanged(index)
  1037. @pyqtSlot(int)
  1038. def slot_midiProgramIndexChanged(self, index):
  1039. self.fCurrentMidiProgram = index
  1040. if gCarla.host is not None:
  1041. gCarla.host.set_midi_program(self.fPluginId, index)
  1042. if self.fRealParent is not None:
  1043. self.fRealParent.midiProgramChanged(index)
  1044. #------------------------------------------------------------------
  1045. @pyqtSlot(int)
  1046. def slot_noteOn(self, note):
  1047. if self.fControlChannel >= 0 and gCarla.host is not None:
  1048. gCarla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1049. if self.fRealParent is not None:
  1050. self.fRealParent.notePressed(note)
  1051. @pyqtSlot(int)
  1052. def slot_noteOff(self, note):
  1053. if self.fControlChannel >= 0 and gCarla.host is not None:
  1054. gCarla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1055. if self.fRealParent is not None:
  1056. self.fRealParent.noteReleased(note)
  1057. #------------------------------------------------------------------
  1058. @pyqtSlot()
  1059. def slot_finished(self):
  1060. if self.fRealParent is not None:
  1061. self.fRealParent.editDialogChanged(False)
  1062. #------------------------------------------------------------------
  1063. @pyqtSlot()
  1064. def slot_knobCustomMenu(self):
  1065. knobName = self.sender().objectName()
  1066. if knobName == "dial_drywet":
  1067. minimum = 0.0
  1068. maximum = 1.0
  1069. default = 1.0
  1070. label = "Dry/Wet"
  1071. elif knobName == "dial_vol":
  1072. minimum = 0.0
  1073. maximum = 1.27
  1074. default = 1.0
  1075. label = "Volume"
  1076. elif knobName == "dial_b_left":
  1077. minimum = -1.0
  1078. maximum = 1.0
  1079. default = -1.0
  1080. label = "Balance-Left"
  1081. elif knobName == "dial_b_right":
  1082. minimum = -1.0
  1083. maximum = 1.0
  1084. default = 1.0
  1085. label = "Balance-Right"
  1086. elif knobName == "dial_pan":
  1087. minimum = -1.0
  1088. maximum = 1.0
  1089. default = 0.0
  1090. label = "Panning"
  1091. else:
  1092. minimum = 0.0
  1093. maximum = 1.0
  1094. default = 0.5
  1095. label = "Unknown"
  1096. current = self.sender().value() / 10
  1097. menu = QMenu(self)
  1098. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1099. menu.addSeparator()
  1100. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1101. actCenter = menu.addAction(self.tr("Set to Center"))
  1102. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1103. menu.addSeparator()
  1104. actSet = menu.addAction(self.tr("Set value..."))
  1105. if label not in ("Balance-Left", "Balance-Right"):
  1106. menu.removeAction(actCenter)
  1107. actSelected = menu.exec_(QCursor.pos())
  1108. if actSelected == actSet:
  1109. valueTry = QInputDialog.getDouble(self, self.tr("Set value"), label, current, minimum, maximum, 3)
  1110. if valueTry[1]:
  1111. value = valueTry[0] * 10
  1112. else:
  1113. return
  1114. elif actSelected == actMinimum:
  1115. value = minimum
  1116. elif actSelected == actMaximum:
  1117. value = maximum
  1118. elif actSelected == actReset:
  1119. value = default
  1120. elif actSelected == actCenter:
  1121. value = 0.0
  1122. else:
  1123. return
  1124. self.sender().setValue(value)
  1125. #------------------------------------------------------------------
  1126. @pyqtSlot()
  1127. def slot_channelCustomMenu(self):
  1128. menu = QMenu(self)
  1129. actNone = menu.addAction(self.tr("None"))
  1130. if self.fControlChannel+1 == 0:
  1131. actNone.setCheckable(True)
  1132. actNone.setChecked(True)
  1133. for i in range(1, 16+1):
  1134. action = menu.addAction("%i" % i)
  1135. if self.fControlChannel+1 == i:
  1136. action.setCheckable(True)
  1137. action.setChecked(True)
  1138. actSel = menu.exec_(QCursor.pos())
  1139. if not actSel:
  1140. pass
  1141. elif actSel == actNone:
  1142. self.ui.sb_ctrl_channel.setValue(0)
  1143. elif actSel:
  1144. selChannel = int(actSel.text())
  1145. self.ui.sb_ctrl_channel.setValue(selChannel)
  1146. #------------------------------------------------------------------
  1147. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1148. i = 1
  1149. for paramList, width in paramListFull:
  1150. if len(paramList) == 0:
  1151. break
  1152. tabIndex = self.ui.tabWidget.count()
  1153. tabPageContainer = QWidget(self.ui.tabWidget)
  1154. tabPageLayout = QVBoxLayout(tabPageContainer)
  1155. tabPageContainer.setLayout(tabPageLayout)
  1156. for paramInfo in paramList:
  1157. paramWidget = PluginParameter(tabPageContainer, paramInfo, self.fPluginId, tabIndex)
  1158. paramWidget.setLabelWidth(width)
  1159. tabPageLayout.addWidget(paramWidget)
  1160. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1161. if paramType == PARAMETER_INPUT:
  1162. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1163. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1164. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1165. tabPageLayout.addStretch()
  1166. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1167. i += 1
  1168. if paramType == PARAMETER_INPUT:
  1169. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1170. self.fTabIconTimers.append(ICON_STATE_OFF)
  1171. def _updateCtrlPrograms(self):
  1172. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH or self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2, PLUGIN_GIG):
  1173. return
  1174. if self.fControlChannel < 0:
  1175. self.ui.cb_programs.setEnabled(False)
  1176. self.ui.cb_midi_programs.setEnabled(False)
  1177. return
  1178. self.ui.cb_programs.setEnabled(True)
  1179. self.ui.cb_midi_programs.setEnabled(True)
  1180. pIndex = gCarla.host.get_current_program_index(self.fPluginId)
  1181. if self.ui.cb_programs.currentIndex() != pIndex:
  1182. self.setProgram(pIndex)
  1183. mpIndex = gCarla.host.get_current_midi_program_index(self.fPluginId)
  1184. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1185. self.setMidiProgram(mpIndex)
  1186. #------------------------------------------------------------------
  1187. def done(self, r):
  1188. QDialog.done(self, r)
  1189. self.close()
  1190. # ------------------------------------------------------------------------------------------------------------
  1191. # Main
  1192. if __name__ == '__main__':
  1193. from carla_app import CarlaApplication
  1194. app = CarlaApplication()
  1195. #gui1 = CarlaAboutW(None)
  1196. #gui1.show()
  1197. #gui2 = PluginParameter(None, gFakeParamInfo, 0, 0)
  1198. #gui2.show()
  1199. gui3 = PluginEdit(None, 0)
  1200. gui3.show()
  1201. app.exit_exec()