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.

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