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.

1818 lines
71KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla widgets code
  4. # Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt4.QtCore import pyqtSignal, pyqtSlot, QByteArray, QSettings
  20. from PyQt4.QtGui import QColor, QCursor, QFontMetrics, QPainter, QPainterPath
  21. from PyQt4.QtGui import QDialog, QFrame, QInputDialog, QLineEdit, QMenu, QVBoxLayout, QWidget
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. import ui_carla_about
  25. import ui_carla_edit
  26. import ui_carla_parameter
  27. import ui_carla_plugin
  28. from carla_shared import *
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Carla GUI defines
  31. ICON_STATE_NULL = 0
  32. ICON_STATE_OFF = 1
  33. ICON_STATE_WAIT = 2
  34. ICON_STATE_ON = 3
  35. # ------------------------------------------------------------------------------------------------------------
  36. # Fake plugin info for easy testing
  37. gFakePluginInfo = {
  38. "type": PLUGIN_NONE,
  39. "category": PLUGIN_CATEGORY_SYNTH,
  40. "hints": PLUGIN_IS_SYNTH|PLUGIN_CAN_DRYWET|PLUGIN_CAN_VOLUME|PLUGIN_CAN_PANNING,
  41. "optionsAvailable": 0x1FF, # all
  42. "optionsEnabled": 0x1FF, # all
  43. "filename": "AwesoomeFilename.what",
  44. "name": "Awesoome Name",
  45. "label": "awesoomeLabel",
  46. "maker": "Awesoome Maker",
  47. "copyright": "Awesoome Copyright",
  48. "iconName": "plugin",
  49. "uniqueId": 0
  50. }
  51. gFakeParamInfo = {
  52. "type": PARAMETER_INPUT,
  53. "hints": PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE,
  54. "name": "Parameter Name",
  55. "unit": "",
  56. "scalePoints": [],
  57. "index": 0,
  58. "default": 0.0,
  59. "minimum": 0.0,
  60. "maximum": 1.0,
  61. "step": 0.01,
  62. "stepSmall": 0.01,
  63. "stepLarge": 0.01, # FIXME
  64. "midiCC": -1,
  65. "midiChannel": 1,
  66. "current": 0.0
  67. }
  68. gFakePortCountInfo = {
  69. "ins": 0,
  70. "outs": 0
  71. }
  72. # ------------------------------------------------------------------------------------------------------------
  73. # Carla About dialog
  74. class CarlaAboutW(QDialog):
  75. def __init__(self, parent):
  76. QDialog.__init__(self, parent)
  77. self.ui = ui_carla_about.Ui_CarlaAboutW()
  78. self.ui.setupUi(self)
  79. if Carla.isControl:
  80. extraInfo = " - <b>%s</b>" % self.tr("OSC Bridge Version")
  81. elif Carla.isPlugin:
  82. extraInfo = " - <b>%s</b>" % self.tr("Plugin Version")
  83. else:
  84. extraInfo = ""
  85. self.ui.l_about.setText(self.tr(""
  86. "<br>Version %s"
  87. "<br>Carla is a Multi-Plugin Host for JACK%s.<br>"
  88. "<br>Copyright (C) 2011-2013 falkTX<br>"
  89. "" % (VERSION, extraInfo)))
  90. if Carla.isControl or Carla.isPlugin or Carla.host is None:
  91. self.ui.l_extended.hide()
  92. self.ui.tabWidget.removeTab(1)
  93. self.ui.tabWidget.removeTab(1)
  94. self.adjustSize()
  95. else:
  96. self.ui.l_extended.setText(Carla.host.get_complete_license_text())
  97. if Carla.host.is_engine_running():
  98. self.ui.le_osc_url_tcp.setText(Carla.host.get_host_osc_url_tcp())
  99. self.ui.le_osc_url_udp.setText(Carla.host.get_host_osc_url_udp())
  100. else:
  101. self.ui.le_osc_url_tcp.setText(self.tr("(Engine not running)"))
  102. self.ui.le_osc_url_udp.setText(self.tr("(Engine not running)"))
  103. self.ui.l_osc_cmds.setText(""
  104. " /set_active <i-value>\n"
  105. " /set_drywet <f-value>\n"
  106. " /set_volume <f-value>\n"
  107. " /set_balance_left <f-value>\n"
  108. " /set_balance_right <f-value>\n"
  109. " /set_panning <f-value>\n"
  110. " /set_parameter_value <i-index> <f-value>\n"
  111. " /set_parameter_midi_cc <i-index> <i-cc>\n"
  112. " /set_parameter_midi_channel <i-index> <i-channel>\n"
  113. " /set_program <i-index>\n"
  114. " /set_midi_program <i-index>\n"
  115. " /note_on <i-note> <i-velo>\n"
  116. " /note_off <i-note>\n"
  117. )
  118. self.ui.l_example.setText("/Carla/2/set_parameter_value 5 1.0")
  119. self.ui.l_example_help.setText("<i>(as in this example, \"2\" is the plugin number and \"5\" the parameter)</i>")
  120. self.ui.l_ladspa.setText(self.tr("Everything! (Including LRDF)"))
  121. self.ui.l_dssi.setText(self.tr("Everything! (Including CustomData/Chunks)"))
  122. self.ui.l_lv2.setText(self.tr("About 80&#37; complete (using custom extensions)<br/>"
  123. "Implemented Feature/Extensions:"
  124. "<ul>"
  125. "<li>http://lv2plug.in/ns/ext/atom</li>"
  126. "<li>http://lv2plug.in/ns/ext/buf-size</li>"
  127. "<li>http://lv2plug.in/ns/ext/data-access</li>"
  128. #"<li>http://lv2plug.in/ns/ext/dynmanifest</li>"
  129. "<li>http://lv2plug.in/ns/ext/event</li>"
  130. "<li>http://lv2plug.in/ns/ext/instance-access</li>"
  131. "<li>http://lv2plug.in/ns/ext/log</li>"
  132. "<li>http://lv2plug.in/ns/ext/midi</li>"
  133. #"<li>http://lv2plug.in/ns/ext/morph</li>"
  134. "<li>http://lv2plug.in/ns/ext/options</li>"
  135. "<li>http://lv2plug.in/ns/ext/parameters</li>"
  136. #"<li>http://lv2plug.in/ns/ext/patch</li>"
  137. #"<li>http://lv2plug.in/ns/ext/port-groups</li>"
  138. #"<li>http://lv2plug.in/ns/ext/port-props</li>"
  139. "<li>http://lv2plug.in/ns/ext/presets</li>"
  140. #"<li>http://lv2plug.in/ns/ext/resize-port</li>"
  141. "<li>http://lv2plug.in/ns/ext/state</li>"
  142. "<li>http://lv2plug.in/ns/ext/time</li>"
  143. "<li>http://lv2plug.in/ns/ext/uri-map</li>"
  144. "<li>http://lv2plug.in/ns/ext/urid</li>"
  145. #"<li>http://lv2plug.in/ns/ext/worker</li>"
  146. "<li>http://lv2plug.in/ns/extensions/ui</li>"
  147. "<li>http://lv2plug.in/ns/extensions/units</li>"
  148. "<li>http://kxstudio.sf.net/ns/lv2ext/external-ui</li>"
  149. "<li>http://kxstudio.sf.net/ns/lv2ext/programs</li>"
  150. "<li>http://kxstudio.sf.net/ns/lv2ext/rtmempool</li>"
  151. "<li>http://ll-plugins.nongnu.org/lv2/ext/midimap</li>"
  152. "<li>http://ll-plugins.nongnu.org/lv2/ext/miditype</li>"
  153. "</ul>"))
  154. self.ui.l_vst.setText(self.tr("<p>About 85&#37; complete (missing vst bank/presets and some minor stuff)</p>"))
  155. def done(self, r):
  156. QDialog.done(self, r)
  157. self.close()
  158. # ------------------------------------------------------------------------------------------------------------
  159. # Plugin Parameter
  160. class PluginParameter(QWidget):
  161. midiControlChanged = pyqtSignal(int, int)
  162. midiChannelChanged = pyqtSignal(int, int)
  163. valueChanged = pyqtSignal(int, float)
  164. def __init__(self, parent, pInfo, pluginId, tabIndex):
  165. QWidget.__init__(self, parent)
  166. self.ui = ui_carla_parameter.Ui_PluginParameter()
  167. self.ui.setupUi(self)
  168. # -------------------------------------------------------------
  169. # Internal stuff
  170. self.fMidiControl = -1
  171. self.fMidiChannel = 1
  172. self.fParameterId = pInfo['index']
  173. self.fPluginId = pluginId
  174. self.fTabIndex = tabIndex
  175. # -------------------------------------------------------------
  176. # Set-up GUI
  177. pType = pInfo['type']
  178. pHints = pInfo['hints']
  179. self.ui.label.setText(pInfo['name'])
  180. self.ui.widget.setName(pInfo['name'])
  181. if pType == PARAMETER_INPUT:
  182. self.ui.widget.setMinimum(pInfo['minimum'])
  183. self.ui.widget.setMaximum(pInfo['maximum'])
  184. self.ui.widget.setDefault(pInfo['default'])
  185. self.ui.widget.setValue(pInfo['current'], False)
  186. self.ui.widget.setLabel(pInfo['unit'])
  187. self.ui.widget.setStep(pInfo['step'])
  188. self.ui.widget.setStepSmall(pInfo['stepSmall'])
  189. self.ui.widget.setStepLarge(pInfo['stepLarge'])
  190. self.ui.widget.setScalePoints(pInfo['scalePoints'], bool(pHints & PARAMETER_USES_SCALEPOINTS))
  191. if not pHints & PARAMETER_IS_ENABLED:
  192. self.ui.label.setEnabled(False)
  193. self.ui.widget.setEnabled(False)
  194. self.ui.widget.setReadOnly(True)
  195. self.ui.sb_control.setEnabled(False)
  196. self.ui.sb_channel.setEnabled(False)
  197. elif not pHints & PARAMETER_IS_AUTOMABLE:
  198. self.ui.sb_control.setEnabled(False)
  199. self.ui.sb_channel.setEnabled(False)
  200. if pHints & PARAMETER_IS_READ_ONLY:
  201. self.ui.widget.setReadOnly(True)
  202. elif pType == PARAMETER_OUTPUT:
  203. self.ui.widget.setMinimum(pInfo['minimum'])
  204. self.ui.widget.setMaximum(pInfo['maximum'])
  205. self.ui.widget.setValue(pInfo['current'], False)
  206. self.ui.widget.setLabel(pInfo['unit'])
  207. self.ui.widget.setReadOnly(True)
  208. if not pHints & PARAMETER_IS_AUTOMABLE:
  209. self.ui.sb_control.setEnabled(False)
  210. self.ui.sb_channel.setEnabled(False)
  211. else:
  212. self.ui.widget.setVisible(False)
  213. self.ui.sb_control.setVisible(False)
  214. self.ui.sb_channel.setVisible(False)
  215. if pHints & PARAMETER_USES_CUSTOM_TEXT:
  216. self.ui.widget.setTextCallback(self._textCallBack)
  217. self.ui.widget.updateAll()
  218. self.setMidiControl(pInfo['midiCC'])
  219. self.setMidiChannel(pInfo['midiChannel'])
  220. # -------------------------------------------------------------
  221. # Set-up connections
  222. self.ui.sb_control.customContextMenuRequested.connect(self.slot_controlSpinboxCustomMenu)
  223. self.ui.sb_channel.customContextMenuRequested.connect(self.slot_channelSpinboxCustomMenu)
  224. self.ui.sb_control.valueChanged.connect(self.slot_controlSpinboxChanged)
  225. self.ui.sb_channel.valueChanged.connect(self.slot_channelSpinboxChanged)
  226. self.ui.widget.valueChanged.connect(self.slot_widgetValueChanged)
  227. # -------------------------------------------------------------
  228. def getPluginId(self):
  229. return self.fPluginId
  230. def getTabIndex(self):
  231. return self.fTabIndex
  232. def setDefault(self, value):
  233. self.ui.widget.setDefault(value)
  234. def setValue(self, value, send=True):
  235. self.ui.widget.setValue(value, send)
  236. def setMidiControl(self, control):
  237. self.fMidiControl = control
  238. self.ui.sb_control.blockSignals(True)
  239. self.ui.sb_control.setValue(control)
  240. self.ui.sb_control.blockSignals(False)
  241. def setMidiChannel(self, channel):
  242. self.fMidiChannel = channel
  243. self.ui.sb_channel.blockSignals(True)
  244. self.ui.sb_channel.setValue(channel)
  245. self.ui.sb_channel.blockSignals(False)
  246. def setLabelWidth(self, width):
  247. self.ui.label.setMinimumWidth(width)
  248. self.ui.label.setMaximumWidth(width)
  249. @pyqtSlot()
  250. def slot_controlSpinboxCustomMenu(self):
  251. menu = QMenu(self)
  252. actNone = menu.addAction(self.tr("None"))
  253. if self.fMidiControl == -1:
  254. actNone.setCheckable(True)
  255. actNone.setChecked(True)
  256. for cc in MIDI_CC_LIST:
  257. action = menu.addAction(cc)
  258. if self.fMidiControl != -1 and int(cc.split(" ")[0], 16) == self.fMidiControl:
  259. action.setCheckable(True)
  260. action.setChecked(True)
  261. actSel = menu.exec_(QCursor.pos())
  262. if not actSel:
  263. pass
  264. elif actSel == actNone:
  265. self.ui.sb_control.setValue(-1)
  266. else:
  267. selControlStr = actSel.text()
  268. selControl = int(selControlStr.split(" ")[0], 16)
  269. self.ui.sb_control.setValue(selControl)
  270. @pyqtSlot()
  271. def slot_channelSpinboxCustomMenu(self):
  272. menu = QMenu(self)
  273. for i in range(1, 16+1):
  274. action = menu.addAction("%i" % i)
  275. if self.fMidiChannel == i:
  276. action.setCheckable(True)
  277. action.setChecked(True)
  278. actSel = menu.exec_(QCursor.pos())
  279. if actSel:
  280. selChannel = int(actSel.text())
  281. self.ui.sb_channel.setValue(selChannel)
  282. @pyqtSlot(int)
  283. def slot_controlSpinboxChanged(self, control):
  284. if self.fMidiControl != control:
  285. self.midiControlChanged.emit(self.fParameterId, control)
  286. self.fMidiControl = control
  287. @pyqtSlot(int)
  288. def slot_channelSpinboxChanged(self, channel):
  289. if self.fMidiChannel != channel:
  290. self.midiChannelChanged.emit(self.fParameterId, channel)
  291. self.fMidiChannel = channel
  292. @pyqtSlot(float)
  293. def slot_widgetValueChanged(self, value):
  294. self.valueChanged.emit(self.fParameterId, value)
  295. def _textCallBack(self):
  296. return Carla.host.get_parameter_text(self.fPluginId, self.fParameterId)
  297. # ------------------------------------------------------------------------------------------------------------
  298. # Plugin Editor (Built-in)
  299. class PluginEdit(QDialog):
  300. kParamsPerPage = 8
  301. def __init__(self, parent, pluginId):
  302. QDialog.__init__(self, Carla.gui)
  303. self.ui = ui_carla_edit.Ui_PluginEdit()
  304. self.ui.setupUi(self)
  305. # -------------------------------------------------------------
  306. # Internal stuff
  307. self.fGeometry = QByteArray()
  308. self.fPluginId = pluginId
  309. self.fPuginInfo = None
  310. self.fRealParent = parent
  311. self.fCurrentProgram = -1
  312. self.fCurrentMidiProgram = -1
  313. self.fCurrentStateFilename = None
  314. self.fControlChannel = 0
  315. self.fScrollAreaSetup = False
  316. self.fParameterCount = 0
  317. self.fParameterList = [] # (type, id, widget)
  318. self.fParametersToUpdate = [] # (id, value)
  319. self.fPlayingNotes = [] # (channel, note)
  320. self.fTabIconOff = QIcon(":/bitmaps/led_off.png")
  321. self.fTabIconOn = QIcon(":/bitmaps/led_yellow.png")
  322. self.fTabIconCount = 0
  323. self.fTabIconTimers = []
  324. # -------------------------------------------------------------
  325. # Set-up GUI
  326. self.ui.dial_drywet.setCustomPaint(self.ui.dial_drywet.CUSTOM_PAINT_CARLA_WET)
  327. self.ui.dial_drywet.setPixmap(3)
  328. self.ui.dial_drywet.setLabel("Dry/Wet")
  329. self.ui.dial_vol.setCustomPaint(self.ui.dial_vol.CUSTOM_PAINT_CARLA_VOL)
  330. self.ui.dial_vol.setPixmap(3)
  331. self.ui.dial_vol.setLabel("Volume")
  332. self.ui.dial_b_left.setCustomPaint(self.ui.dial_b_left.CUSTOM_PAINT_CARLA_L)
  333. self.ui.dial_b_left.setPixmap(4)
  334. self.ui.dial_b_left.setLabel("L")
  335. self.ui.dial_b_right.setCustomPaint(self.ui.dial_b_right.CUSTOM_PAINT_CARLA_R)
  336. self.ui.dial_b_right.setPixmap(4)
  337. self.ui.dial_b_right.setLabel("R")
  338. self.ui.dial_pan.setCustomPaint(self.ui.dial_b_right.CUSTOM_PAINT_CARLA_R) # FIXME
  339. self.ui.dial_pan.setPixmap(4)
  340. self.ui.dial_pan.setLabel("Pan")
  341. self.ui.keyboard.setMode(self.ui.keyboard.HORIZONTAL)
  342. self.ui.keyboard.setOctaves(10)
  343. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  344. self.ui.scrollArea.ensureVisible(self.ui.keyboard.width() / 3, 0)
  345. self.ui.scrollArea.setEnabled(False)
  346. self.ui.scrollArea.setVisible(False)
  347. self.reloadAll()
  348. # -------------------------------------------------------------
  349. # Set-up connections
  350. self.finished.connect(self.slot_finished)
  351. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  352. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  353. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  354. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  355. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  356. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  357. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  358. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  359. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  360. self.ui.dial_drywet.valueChanged.connect(self.slot_dryWetChanged)
  361. self.ui.dial_vol.valueChanged.connect(self.slot_volumeChanged)
  362. self.ui.dial_b_left.valueChanged.connect(self.slot_balanceLeftChanged)
  363. self.ui.dial_b_right.valueChanged.connect(self.slot_balanceRightChanged)
  364. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  365. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  366. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  367. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  368. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  369. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  370. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  371. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  372. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  373. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  374. if Carla.isLocal:
  375. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  376. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  377. else:
  378. self.ui.b_load_state.setEnabled(False)
  379. self.ui.b_save_state.setEnabled(False)
  380. #------------------------------------------------------------------
  381. def updateInfo(self):
  382. # Update current program text
  383. if self.ui.cb_programs.count() > 0:
  384. pIndex = self.ui.cb_programs.currentIndex()
  385. pName = charPtrToString(Carla.host.get_program_name(self.fPluginId, pIndex))
  386. #pName = pName[:40] + (pName[40:] and "...")
  387. self.ui.cb_programs.setItemText(pIndex, pName)
  388. # Update current midi program text
  389. if self.ui.cb_midi_programs.count() > 0:
  390. mpIndex = self.ui.cb_midi_programs.currentIndex()
  391. mpData = Carla.host.get_midi_program_data(self.fPluginId, mpIndex)
  392. mpBank = int(mpData['bank'])
  393. mpProg = int(mpData['program'])
  394. mpName = charPtrToString(mpData['name'])
  395. #mpName = mpName[:40] + (mpName[40:] and "...")
  396. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  397. # Update all parameter values
  398. for paramType, paramId, paramWidget in self.fParameterList:
  399. paramWidget.setValue(Carla.host.get_current_parameter_value(self.fPluginId, paramId), False)
  400. paramWidget.update()
  401. self.fParametersToUpdate = []
  402. #------------------------------------------------------------------
  403. def reloadAll(self):
  404. if Carla.host is not None:
  405. self.fPluginInfo = Carla.host.get_plugin_info(self.fPluginId)
  406. self.fPluginInfo['filename'] = charPtrToString(self.fPluginInfo['filename'])
  407. self.fPluginInfo['name'] = charPtrToString(self.fPluginInfo['name'])
  408. self.fPluginInfo['label'] = charPtrToString(self.fPluginInfo['label'])
  409. self.fPluginInfo['maker'] = charPtrToString(self.fPluginInfo['maker'])
  410. self.fPluginInfo['copyright'] = charPtrToString(self.fPluginInfo['copyright'])
  411. self.fPluginInfo['iconName'] = charPtrToString(self.fPluginInfo['iconName'])
  412. if not Carla.isLocal:
  413. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_CUSTOM_UI
  414. else:
  415. self.fPluginInfo = gFakePluginInfo
  416. self.reloadInfo()
  417. self.reloadParameters()
  418. self.reloadPrograms()
  419. if self.fPluginInfo['type'] == PLUGIN_LV2:
  420. self.ui.b_save_state.setEnabled(False)
  421. if not self.ui.scrollArea.isEnabled():
  422. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  423. #------------------------------------------------------------------
  424. def reloadInfo(self):
  425. if Carla.host is not None:
  426. pluginName = Carla.host.get_real_plugin_name(self.fPluginId)
  427. audioCountInfo = Carla.host.get_audio_port_count_info(self.fPluginId)
  428. midiCountInfo = Carla.host.get_midi_port_count_info(self.fPluginId)
  429. paramCountInfo = Carla.host.get_parameter_count_info(self.fPluginId)
  430. else:
  431. pluginName = ""
  432. audioCountInfo = gFakePortCountInfo
  433. midiCountInfo = gFakePortCountInfo
  434. paramCountInfo = gFakePortCountInfo
  435. pluginType = self.fPluginInfo['type']
  436. pluginHints = self.fPluginInfo['hints']
  437. if pluginType == PLUGIN_INTERNAL:
  438. self.ui.le_type.setText(self.tr("Internal"))
  439. elif pluginType == PLUGIN_LADSPA:
  440. self.ui.le_type.setText("LADSPA")
  441. elif pluginType == PLUGIN_DSSI:
  442. self.ui.le_type.setText("DSSI")
  443. elif pluginType == PLUGIN_LV2:
  444. self.ui.le_type.setText("LV2")
  445. elif pluginType == PLUGIN_VST:
  446. self.ui.le_type.setText("VST")
  447. elif pluginType == PLUGIN_AU:
  448. self.ui.le_type.setText("AU")
  449. elif pluginType == PLUGIN_CSOUND:
  450. self.ui.le_type.setText("CSOUND")
  451. elif pluginType == PLUGIN_GIG:
  452. self.ui.le_type.setText("GIG")
  453. elif pluginType == PLUGIN_SF2:
  454. self.ui.le_type.setText("SF2")
  455. elif pluginType == PLUGIN_SFZ:
  456. self.ui.le_type.setText("SFZ")
  457. else:
  458. self.ui.le_type.setText(self.tr("Unknown"))
  459. if pluginName:
  460. self.ui.label_name.setEnabled(True)
  461. self.ui.le_name.setEnabled(True)
  462. self.ui.le_name.setText(pluginName)
  463. self.ui.le_name.setToolTip(pluginName)
  464. else:
  465. self.ui.label_name.setEnabled(False)
  466. self.ui.le_name.setEnabled(False)
  467. self.ui.le_name.setText("")
  468. self.ui.le_name.setToolTip("")
  469. if self.fPluginInfo['label']:
  470. self.ui.label_label.setEnabled(True)
  471. self.ui.le_label.setEnabled(True)
  472. self.ui.le_label.setText(self.fPluginInfo['label'])
  473. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  474. else:
  475. self.ui.label_label.setEnabled(False)
  476. self.ui.le_label.setEnabled(False)
  477. self.ui.le_label.setText("")
  478. self.ui.le_label.setToolTip("")
  479. if self.fPluginInfo['maker']:
  480. self.ui.label_maker.setEnabled(True)
  481. self.ui.le_maker.setEnabled(True)
  482. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  483. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  484. else:
  485. self.ui.label_maker.setEnabled(False)
  486. self.ui.le_maker.setEnabled(False)
  487. self.ui.le_maker.setText("")
  488. self.ui.le_maker.setToolTip("")
  489. if self.fPluginInfo['copyright']:
  490. self.ui.label_copyright.setEnabled(True)
  491. self.ui.le_copyright.setEnabled(True)
  492. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  493. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  494. else:
  495. self.ui.label_copyright.setEnabled(False)
  496. self.ui.le_copyright.setEnabled(False)
  497. self.ui.le_copyright.setText("")
  498. self.ui.le_copyright.setToolTip("")
  499. if self.fPluginInfo['uniqueId'] != 0:
  500. self.ui.label_unique_id.setEnabled(True)
  501. self.ui.le_unique_id.setEnabled(True)
  502. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  503. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  504. else:
  505. self.ui.label_unique_id.setEnabled(False)
  506. self.ui.le_unique_id.setEnabled(False)
  507. self.ui.le_unique_id.setText("")
  508. self.ui.le_unique_id.setToolTip("")
  509. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  510. self.setWindowTitle(self.fPluginInfo['name'])
  511. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  512. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  513. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  514. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  515. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  516. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  517. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  518. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  519. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  520. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  521. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  522. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  523. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  524. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  525. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  526. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  527. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  528. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  529. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  530. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  531. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  532. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  533. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  534. if self.fPluginInfo['type'] != PLUGIN_VST:
  535. self.ui.sw_programs.setCurrentIndex(1)
  536. # Show/hide keyboard
  537. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  538. self.ui.scrollArea.setEnabled(showKeyboard)
  539. self.ui.scrollArea.setVisible(showKeyboard)
  540. # Force-Update parent for new hints
  541. if self.fRealParent:
  542. self.fRealParent.recheckPluginHints(pluginHints)
  543. def reloadParameters(self):
  544. # Reset
  545. self.fParameterCount = 0
  546. self.fParameterList = []
  547. self.fParametersToUpdate = []
  548. self.fTabIconCount = 0
  549. self.fTabIconTimers = []
  550. # Remove all previous parameters
  551. for x in range(self.ui.tabWidget.count()-1):
  552. self.ui.tabWidget.widget(1).deleteLater()
  553. self.ui.tabWidget.removeTab(1)
  554. if Carla.host is None:
  555. paramFakeListFull = []
  556. paramFakeList = []
  557. paramFakeWidth = QFontMetrics(self.font()).width(gFakeParamInfo['name'])
  558. paramFakeList.append(gFakeParamInfo)
  559. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  560. self._createParameterWidgets(PARAMETER_INPUT, paramFakeListFull, self.tr("Parameters"))
  561. return
  562. parameterCount = Carla.host.get_parameter_count(self.fPluginId)
  563. if parameterCount <= 0:
  564. pass
  565. elif parameterCount <= Carla.maxParameters:
  566. paramInputListFull = []
  567. paramOutputListFull = []
  568. paramInputList = [] # ([params], width)
  569. paramInputWidth = 0
  570. paramOutputList = [] # ([params], width)
  571. paramOutputWidth = 0
  572. for i in range(parameterCount):
  573. paramInfo = Carla.host.get_parameter_info(self.fPluginId, i)
  574. paramData = Carla.host.get_parameter_data(self.fPluginId, i)
  575. paramRanges = Carla.host.get_parameter_ranges(self.fPluginId, i)
  576. paramValue = Carla.host.get_current_parameter_value(self.fPluginId, i)
  577. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  578. continue
  579. parameter = {
  580. 'type': paramData['type'],
  581. 'hints': paramData['hints'],
  582. 'name': charPtrToString(paramInfo['name']),
  583. 'unit': charPtrToString(paramInfo['unit']),
  584. 'scalePoints': [],
  585. 'index': paramData['index'],
  586. 'default': paramRanges['def'],
  587. 'minimum': paramRanges['min'],
  588. 'maximum': paramRanges['max'],
  589. 'step': paramRanges['step'],
  590. 'stepSmall': paramRanges['stepSmall'],
  591. 'stepLarge': paramRanges['stepLarge'],
  592. 'midiCC': paramData['midiCC'],
  593. 'midiChannel': paramData['midiChannel']+1,
  594. 'current': paramValue
  595. }
  596. for j in range(paramInfo['scalePointCount']):
  597. scalePointInfo = Carla.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  598. parameter['scalePoints'].append({
  599. 'value': scalePointInfo['value'],
  600. 'label': charPtrToString(scalePointInfo['label'])
  601. })
  602. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  603. # -----------------------------------------------------------------
  604. # Get width values, in packs of 10
  605. if parameter['type'] == PARAMETER_INPUT:
  606. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  607. if paramInputWidthTMP > paramInputWidth:
  608. paramInputWidth = paramInputWidthTMP
  609. paramInputList.append(parameter)
  610. if len(paramInputList) == self.kParamsPerPage:
  611. paramInputListFull.append((paramInputList, paramInputWidth))
  612. paramInputList = []
  613. paramInputWidth = 0
  614. else:
  615. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  616. if paramOutputWidthTMP > paramOutputWidth:
  617. paramOutputWidth = paramOutputWidthTMP
  618. paramOutputList.append(parameter)
  619. if len(paramOutputList) == self.kParamsPerPage:
  620. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  621. paramOutputList = []
  622. paramOutputWidth = 0
  623. # for i in range(parameterCount)
  624. else:
  625. # Final page width values
  626. if 0 < len(paramInputList) < 10:
  627. paramInputListFull.append((paramInputList, paramInputWidth))
  628. if 0 < len(paramOutputList) < 10:
  629. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  630. # -----------------------------------------------------------------
  631. # Create parameter tabs + widgets
  632. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  633. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  634. else: # > Carla.maxParameters
  635. fakeName = self.tr("This plugin has too many parameters to display here!")
  636. paramFakeListFull = []
  637. paramFakeList = []
  638. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  639. parameter = {
  640. 'type': PARAMETER_UNKNOWN,
  641. 'hints': 0x0,
  642. 'name': fakeName,
  643. 'unit': "",
  644. 'scalePoints': [],
  645. 'index': 0,
  646. 'default': 0.0,
  647. 'minimum': 0.0,
  648. 'maximum': 0.0,
  649. 'step': 0.0,
  650. 'stepSmall': 0.0,
  651. 'stepLarge': 0.0,
  652. 'midiCC': -1,
  653. 'midiChannel': 1,
  654. 'current': 0.0
  655. }
  656. paramFakeList.append(parameter)
  657. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  658. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  659. def reloadPrograms(self):
  660. # Programs
  661. self.ui.cb_programs.blockSignals(True)
  662. self.ui.cb_programs.clear()
  663. programCount = Carla.host.get_program_count(self.fPluginId) if Carla.host is not None else 0
  664. if programCount > 0:
  665. self.ui.cb_programs.setEnabled(True)
  666. self.ui.label_programs.setEnabled(True)
  667. for i in range(programCount):
  668. pName = charPtrToString(Carla.host.get_program_name(self.fPluginId, i))
  669. #pName = pName[:40] + (pName[40:] and "...")
  670. self.ui.cb_programs.addItem(pName)
  671. self.fCurrentProgram = Carla.host.get_current_program_index(self.fPluginId)
  672. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  673. else:
  674. self.fCurrentProgram = -1
  675. self.ui.cb_programs.setEnabled(False)
  676. self.ui.label_programs.setEnabled(False)
  677. self.ui.cb_programs.blockSignals(False)
  678. # MIDI Programs
  679. self.ui.cb_midi_programs.blockSignals(True)
  680. self.ui.cb_midi_programs.clear()
  681. midiProgramCount = Carla.host.get_midi_program_count(self.fPluginId) if Carla.host is not None else 0
  682. if midiProgramCount > 0:
  683. self.ui.cb_midi_programs.setEnabled(True)
  684. self.ui.label_midi_programs.setEnabled(True)
  685. for i in range(midiProgramCount):
  686. mpData = Carla.host.get_midi_program_data(self.fPluginId, i)
  687. mpBank = int(mpData['bank'])
  688. mpProg = int(mpData['program'])
  689. mpName = charPtrToString(mpData['name'])
  690. #mpName = mpName[:40] + (mpName[40:] and "...")
  691. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  692. self.fCurrentMidiProgram = Carla.host.get_current_midi_program_index(self.fPluginId)
  693. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  694. else:
  695. self.fCurrentMidiProgram = -1
  696. self.ui.cb_midi_programs.setEnabled(False)
  697. self.ui.label_midi_programs.setEnabled(False)
  698. self.ui.cb_midi_programs.blockSignals(False)
  699. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  700. if self.fPluginInfo['type'] == PLUGIN_LV2:
  701. self.ui.b_load_state.setEnabled(programCount > 0)
  702. #------------------------------------------------------------------
  703. def clearNotes(self):
  704. self.fPlayingNotes = []
  705. self.ui.keyboard.allNotesOff()
  706. #------------------------------------------------------------------
  707. def getHints(self):
  708. return self.fPluginInfo['hints']
  709. def setId(self, idx):
  710. self.fPluginId = idx
  711. def setName(self, name):
  712. self.ui.label_plugin.setText("\n%s\n" % name)
  713. self.setWindowTitle(name)
  714. #------------------------------------------------------------------
  715. def setParameterValue(self, parameterId, value):
  716. for paramItem in self.fParametersToUpdate:
  717. if paramItem[0] == parameterId:
  718. paramItem[1] = value
  719. break
  720. else:
  721. self.fParametersToUpdate.append([parameterId, value])
  722. def setParameterDefault(self, parameterId, value):
  723. for paramType, paramId, paramWidget in self.fParameterList:
  724. if paramId == parameterId:
  725. paramWidget.setDefault(value)
  726. break
  727. def setParameterMidiControl(self, parameterId, control):
  728. for paramType, paramId, paramWidget in self.fParameterList:
  729. if paramId == parameterId:
  730. paramWidget.setMidiControl(control)
  731. break
  732. def setParameterMidiChannel(self, parameterId, channel):
  733. for paramType, paramId, paramWidget in self.fParameterList:
  734. if paramId == parameterId:
  735. paramWidget.setMidiChannel(channel+1)
  736. break
  737. def setProgram(self, index):
  738. self.ui.cb_programs.blockSignals(True)
  739. self.ui.cb_programs.setCurrentIndex(index)
  740. self.ui.cb_programs.blockSignals(False)
  741. def setMidiProgram(self, index):
  742. self.ui.cb_midi_programs.blockSignals(True)
  743. self.ui.cb_midi_programs.setCurrentIndex(index)
  744. self.ui.cb_midi_programs.blockSignals(False)
  745. #------------------------------------------------------------------
  746. def sendNoteOn(self, channel, note):
  747. if self.fControlChannel == channel:
  748. self.ui.keyboard.sendNoteOn(note, False)
  749. playItem = (channel, note)
  750. if playItem not in self.fPlayingNotes:
  751. self.fPlayingNotes.append(playItem)
  752. return bool(len(self.fPlayingNotes) == 1)
  753. def sendNoteOff(self, channel, note):
  754. if self.fControlChannel == channel:
  755. self.ui.keyboard.sendNoteOff(note, False)
  756. playItem = (channel, note)
  757. if playItem in self.fPlayingNotes:
  758. self.fPlayingNotes.remove(playItem)
  759. return bool(len(self.fPlayingNotes) == 0)
  760. #------------------------------------------------------------------
  761. def setVisible(self, yesNo):
  762. if yesNo:
  763. if not self.fGeometry.isNull():
  764. self.restoreGeometry(self.fGeometry)
  765. else:
  766. self.fGeometry = self.saveGeometry()
  767. QDialog.setVisible(self, yesNo)
  768. #------------------------------------------------------------------
  769. def idleSlow(self):
  770. # Check Tab icons
  771. for i in range(len(self.fTabIconTimers)):
  772. if self.fTabIconTimers[i] == ICON_STATE_ON:
  773. self.fTabIconTimers[i] = ICON_STATE_WAIT
  774. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  775. self.fTabIconTimers[i] = ICON_STATE_OFF
  776. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  777. self.fTabIconTimers[i] = ICON_STATE_NULL
  778. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  779. # Check parameters needing update
  780. for index, value in self.fParametersToUpdate:
  781. if index == PARAMETER_DRYWET:
  782. self.ui.dial_drywet.blockSignals(True)
  783. self.ui.dial_drywet.setValue(value * 1000)
  784. self.ui.dial_drywet.blockSignals(False)
  785. elif index == PARAMETER_VOLUME:
  786. self.ui.dial_vol.blockSignals(True)
  787. self.ui.dial_vol.setValue(value * 1000)
  788. self.ui.dial_vol.blockSignals(False)
  789. elif index == PARAMETER_BALANCE_LEFT:
  790. self.ui.dial_b_left.blockSignals(True)
  791. self.ui.dial_b_left.setValue(value * 1000)
  792. self.ui.dial_b_left.blockSignals(False)
  793. elif index == PARAMETER_BALANCE_RIGHT:
  794. self.ui.dial_b_right.blockSignals(True)
  795. self.ui.dial_b_right.setValue(value * 1000)
  796. self.ui.dial_b_right.blockSignals(False)
  797. elif index == PARAMETER_PANNING:
  798. self.ui.dial_pan.blockSignals(True)
  799. self.ui.dial_pan.setValue(value * 1000)
  800. self.ui.dial_pan.blockSignals(False)
  801. elif index == PARAMETER_CTRL_CHANNEL:
  802. self.fControlChannel = int(value)
  803. self.ui.sb_ctrl_channel.blockSignals(True)
  804. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  805. self.ui.sb_ctrl_channel.blockSignals(False)
  806. self.ui.keyboard.allNotesOff()
  807. self._updateCtrlMidiProgram()
  808. elif index >= 0:
  809. for paramType, paramId, paramWidget in self.fParameterList:
  810. if paramId != index:
  811. continue
  812. paramWidget.setValue(value, False)
  813. if paramType == PARAMETER_INPUT:
  814. tabIndex = paramWidget.getTabIndex()
  815. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  816. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  817. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  818. break
  819. # Clear all parameters
  820. self.fParametersToUpdate = []
  821. # Update parameter outputs
  822. for paramType, paramId, paramWidget in self.fParameterList:
  823. if paramType == PARAMETER_OUTPUT:
  824. value = Carla.host.get_current_parameter_value(self.fPluginId, paramId)
  825. paramWidget.setValue(value, False)
  826. #------------------------------------------------------------------
  827. @pyqtSlot()
  828. def slot_stateSave(self):
  829. if self.fPluginInfo['type'] == PLUGIN_LV2:
  830. # TODO
  831. return
  832. if self.fCurrentStateFilename:
  833. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  834. if askTry == QMessageBox.Ok:
  835. Carla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  836. return
  837. self.fCurrentStateFilename = None
  838. fileFilter = self.tr("Carla State File (*.carxs)")
  839. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  840. if filenameTry:
  841. if not filenameTry.lower().endswith(".carxs"):
  842. filenameTry += ".carxs"
  843. self.fCurrentStateFilename = filenameTry
  844. Carla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  845. @pyqtSlot()
  846. def slot_stateLoad(self):
  847. if self.fPluginInfo['type'] == PLUGIN_LV2:
  848. presetList = []
  849. for i in range(Carla.host.get_program_count(self.fPluginId)):
  850. presetList.append("%03i - %s" % (i+1, charPtrToString(Carla.host.get_program_name(self.fPluginId, i))))
  851. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  852. if ret[1]:
  853. index = int(ret[0].split(" - ", 1)[0])-1
  854. Carla.host.set_midi_program(self.fPluginId, -1)
  855. Carla.host.set_program(self.fPluginId, index)
  856. self.setMidiProgram(-1)
  857. return
  858. fileFilter = self.tr("Carla State File (*.carxs)")
  859. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  860. if filenameTry:
  861. self.fCurrentStateFilename = filenameTry
  862. Carla.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  863. #------------------------------------------------------------------
  864. @pyqtSlot(bool)
  865. def slot_optionChanged(self, clicked):
  866. if Carla.host is None:
  867. return
  868. sender = self.sender()
  869. if sender == self.ui.ch_fixed_buffer:
  870. option = PLUGIN_OPTION_FIXED_BUFFERS
  871. elif sender == self.ui.ch_force_stereo:
  872. option = PLUGIN_OPTION_FORCE_STEREO
  873. elif sender == self.ui.ch_map_program_changes:
  874. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  875. elif sender == self.ui.ch_use_chunks:
  876. option = PLUGIN_OPTION_USE_CHUNKS
  877. elif sender == self.ui.ch_send_control_changes:
  878. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  879. elif sender == self.ui.ch_send_channel_pressure:
  880. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  881. elif sender == self.ui.ch_send_note_aftertouch:
  882. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  883. elif sender == self.ui.ch_send_pitchbend:
  884. option = PLUGIN_OPTION_SEND_PITCHBEND
  885. elif sender == self.ui.ch_send_all_sound_off:
  886. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  887. else:
  888. return
  889. Carla.host.set_option(self.fPluginId, option, clicked)
  890. #------------------------------------------------------------------
  891. @pyqtSlot(int)
  892. def slot_dryWetChanged(self, value):
  893. if Carla.host is not None:
  894. Carla.host.set_drywet(self.fPluginId, float(value)/1000)
  895. @pyqtSlot(int)
  896. def slot_volumeChanged(self, value):
  897. if Carla.host is not None:
  898. Carla.host.set_volume(self.fPluginId, float(value)/1000)
  899. @pyqtSlot(int)
  900. def slot_balanceLeftChanged(self, value):
  901. if Carla.host is not None:
  902. Carla.host.set_balance_left(self.fPluginId, float(value)/1000)
  903. @pyqtSlot(int)
  904. def slot_balanceRightChanged(self, value):
  905. if Carla.host is not None:
  906. Carla.host.set_balance_right(self.fPluginId, float(value)/1000)
  907. @pyqtSlot(int)
  908. def slot_panningChanged(self, value):
  909. if Carla.host is not None:
  910. Carla.host.set_panning(self.fPluginId, float(value)/1000)
  911. @pyqtSlot(int)
  912. def slot_ctrlChannelChanged(self, value):
  913. self.fControlChannel = value-1
  914. if Carla.host is not None:
  915. Carla.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  916. self.ui.keyboard.allNotesOff()
  917. self._updateCtrlMidiProgram()
  918. #------------------------------------------------------------------
  919. @pyqtSlot(int, float)
  920. def slot_parameterValueChanged(self, parameterId, value):
  921. if Carla.host is not None:
  922. Carla.host.set_parameter_value(self.fPluginId, parameterId, value)
  923. @pyqtSlot(int, int)
  924. def slot_parameterMidiControlChanged(self, parameterId, control):
  925. if Carla.host is not None:
  926. Carla.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  927. @pyqtSlot(int, int)
  928. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  929. if Carla.host is not None:
  930. Carla.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  931. #------------------------------------------------------------------
  932. @pyqtSlot(int)
  933. def slot_programIndexChanged(self, index):
  934. self.fCurrentProgram = index
  935. if Carla.host is not None:
  936. Carla.host.set_program(self.fPluginId, index)
  937. @pyqtSlot(int)
  938. def slot_midiProgramIndexChanged(self, index):
  939. self.fCurrentMidiProgram = index
  940. if Carla.host is not None:
  941. Carla.host.set_midi_program(self.fPluginId, index)
  942. #------------------------------------------------------------------
  943. @pyqtSlot(int)
  944. def slot_noteOn(self, note):
  945. if self.fControlChannel >= 0 and Carla.host is not None:
  946. Carla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  947. @pyqtSlot(int)
  948. def slot_noteOff(self, note):
  949. if self.fControlChannel >= 0 and Carla.host is not None:
  950. Carla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  951. #------------------------------------------------------------------
  952. @pyqtSlot()
  953. def slot_finished(self):
  954. if self.fRealParent is not None:
  955. self.fRealParent.editClosed()
  956. #------------------------------------------------------------------
  957. @pyqtSlot()
  958. def slot_knobCustomMenu(self):
  959. knobName = self.sender().objectName()
  960. if knobName == "dial_drywet":
  961. minimum = 0
  962. maximum = 100
  963. default = 100
  964. label = "Dry/Wet"
  965. elif knobName == "dial_vol":
  966. minimum = 0
  967. maximum = 127
  968. default = 100
  969. label = "Volume"
  970. elif knobName == "dial_b_left":
  971. minimum = -100
  972. maximum = 100
  973. default = -100
  974. label = "Balance-Left"
  975. elif knobName == "dial_b_right":
  976. minimum = -100
  977. maximum = 100
  978. default = 100
  979. label = "Balance-Right"
  980. elif knobName == "dial_pan":
  981. minimum = -100
  982. maximum = 100
  983. default = 0
  984. label = "Panning"
  985. else:
  986. minimum = 0
  987. maximum = 100
  988. default = 100
  989. label = "Unknown"
  990. current = self.sender().value() / 10
  991. menu = QMenu(self)
  992. actReset = menu.addAction(self.tr("Reset (%i%%)" % default))
  993. menu.addSeparator()
  994. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % minimum))
  995. actCenter = menu.addAction(self.tr("Set to Center"))
  996. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % maximum))
  997. menu.addSeparator()
  998. actSet = menu.addAction(self.tr("Set value..."))
  999. if label not in ("Balance-Left", "Balance-Right"):
  1000. menu.removeAction(actCenter)
  1001. actSelected = menu.exec_(QCursor.pos())
  1002. if actSelected == actSet:
  1003. valueTry = QInputDialog.getInteger(self, self.tr("Set value"), label, current, minimum, maximum, 1)
  1004. if valueTry[1]:
  1005. value = valueTry[0] * 10
  1006. else:
  1007. return
  1008. elif actSelected == actMinimum:
  1009. value = minimum * 10
  1010. elif actSelected == actMaximum:
  1011. value = maximum * 10
  1012. elif actSelected == actReset:
  1013. value = default * 10
  1014. elif actSelected == actCenter:
  1015. value = 0
  1016. else:
  1017. return
  1018. if label == "Dry/Wet":
  1019. self.ui.dial_drywet.setValue(value)
  1020. elif label == "Volume":
  1021. self.ui.dial_vol.setValue(value)
  1022. elif label == "Balance-Left":
  1023. self.ui.dial_b_left.setValue(value)
  1024. elif label == "Balance-Right":
  1025. self.ui.dial_b_right.setValue(value)
  1026. elif label == "Panning":
  1027. self.ui.dial_pan.setValue(value)
  1028. #------------------------------------------------------------------
  1029. @pyqtSlot()
  1030. def slot_channelCustomMenu(self):
  1031. menu = QMenu(self)
  1032. actNone = menu.addAction(self.tr("None"))
  1033. if self.fControlChannel+1 == 0:
  1034. actNone.setCheckable(True)
  1035. actNone.setChecked(True)
  1036. for i in range(1, 16+1):
  1037. action = menu.addAction("%i" % i)
  1038. if self.fControlChannel+1 == i:
  1039. action.setCheckable(True)
  1040. action.setChecked(True)
  1041. actSel = menu.exec_(QCursor.pos())
  1042. if not actSel:
  1043. pass
  1044. elif actSel == actNone:
  1045. self.ui.sb_ctrl_channel.setValue(0)
  1046. elif actSel:
  1047. selChannel = int(actSel.text())
  1048. self.ui.sb_ctrl_channel.setValue(selChannel)
  1049. #------------------------------------------------------------------
  1050. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1051. i = 1
  1052. for paramList, width in paramListFull:
  1053. if len(paramList) == 0:
  1054. break
  1055. tabIndex = self.ui.tabWidget.count()
  1056. tabPageContainer = QWidget(self.ui.tabWidget)
  1057. tabPageLayout = QVBoxLayout(tabPageContainer)
  1058. tabPageContainer.setLayout(tabPageLayout)
  1059. for paramInfo in paramList:
  1060. paramWidget = PluginParameter(tabPageContainer, paramInfo, self.fPluginId, tabIndex)
  1061. paramWidget.setLabelWidth(width)
  1062. tabPageLayout.addWidget(paramWidget)
  1063. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1064. if paramType == PARAMETER_INPUT:
  1065. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1066. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1067. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1068. tabPageLayout.addStretch()
  1069. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1070. i += 1
  1071. if paramType == PARAMETER_INPUT:
  1072. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1073. self.fTabIconTimers.append(ICON_STATE_NULL)
  1074. def _updateCtrlMidiProgram(self):
  1075. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2):
  1076. return
  1077. elif self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1078. return
  1079. if self.fControlChannel < 0:
  1080. self.ui.cb_midi_programs.setEnabled(False)
  1081. return
  1082. self.ui.cb_midi_programs.setEnabled(True)
  1083. mpIndex = Carla.host.get_current_midi_program_index(self.fPluginId)
  1084. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1085. self.setMidiProgram(mpIndex)
  1086. #------------------------------------------------------------------
  1087. def showEvent(self, event):
  1088. if not self.fScrollAreaSetup:
  1089. self.fScrollAreaSetup = True
  1090. minHeight = self.ui.scrollArea.height()+2
  1091. self.ui.scrollArea.setMinimumHeight(minHeight)
  1092. self.ui.scrollArea.setMaximumHeight(minHeight)
  1093. QDialog.showEvent(self, event)
  1094. def done(self, r):
  1095. QDialog.done(self, r)
  1096. self.close()
  1097. # ------------------------------------------------------------------------------------------------------------
  1098. # Plugin Widget
  1099. class PluginWidget(QFrame):
  1100. def __init__(self, parent, pluginId):
  1101. QFrame.__init__(self, parent)
  1102. self.ui = ui_carla_plugin.Ui_PluginWidget()
  1103. self.ui.setupUi(self)
  1104. # -------------------------------------------------------------
  1105. # Internal stuff
  1106. self.fPluginId = pluginId
  1107. self.fPluginInfo = Carla.host.get_plugin_info(self.fPluginId) if Carla.host is not None else gFakePluginInfo
  1108. self.fPluginInfo['filename'] = charPtrToString(self.fPluginInfo['filename'])
  1109. self.fPluginInfo['name'] = charPtrToString(self.fPluginInfo['name'])
  1110. self.fPluginInfo['label'] = charPtrToString(self.fPluginInfo['label'])
  1111. self.fPluginInfo['maker'] = charPtrToString(self.fPluginInfo['maker'])
  1112. self.fPluginInfo['copyright'] = charPtrToString(self.fPluginInfo['copyright'])
  1113. self.fPluginInfo['iconName'] = charPtrToString(self.fPluginInfo['iconName'])
  1114. if not Carla.isLocal:
  1115. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_CUSTOM_UI
  1116. self.fLastGreenLedState = False
  1117. self.fLastBlueLedState = False
  1118. self.fParameterIconTimer = ICON_STATE_NULL
  1119. if Carla.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK or Carla.host is None:
  1120. self.fPeaksInputCount = 2
  1121. self.fPeaksOutputCount = 2
  1122. else:
  1123. audioCountInfo = Carla.host.get_audio_port_count_info(self.fPluginId)
  1124. self.fPeaksInputCount = int(audioCountInfo['ins'])
  1125. self.fPeaksOutputCount = int(audioCountInfo['outs'])
  1126. if self.fPeaksInputCount > 2:
  1127. self.fPeaksInputCount = 2
  1128. if self.fPeaksOutputCount > 2:
  1129. self.fPeaksOutputCount = 2
  1130. if self.palette().window().color().lightness() > 100:
  1131. # Light background
  1132. labelColor = "333"
  1133. isLight = True
  1134. self.fColorTop = QColor(60, 60, 60)
  1135. self.fColorBottom = QColor(47, 47, 47)
  1136. self.fColorSeprtr = QColor(70, 70, 70)
  1137. else:
  1138. # Dark background
  1139. labelColor = "BBB"
  1140. isLight = False
  1141. self.fColorTop = QColor(60, 60, 60)
  1142. self.fColorBottom = QColor(47, 47, 47)
  1143. self.fColorSeprtr = QColor(70, 70, 70)
  1144. # -------------------------------------------------------------
  1145. # Set-up GUI
  1146. self.setStyleSheet("""
  1147. QLabel#label_name {
  1148. color: #%s;
  1149. }""" % labelColor)
  1150. if isLight:
  1151. self.ui.b_enable.setPixmaps(":/bitmaps/button_off2.png", ":/bitmaps/button_on2.png", ":/bitmaps/button_off2.png")
  1152. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit2.png", ":/bitmaps/button_edit_down2.png", ":/bitmaps/button_edit_hover2.png")
  1153. if self.fPluginInfo['iconName'] == "distrho":
  1154. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho2.png", ":/bitmaps/button_distrho_down2.png", ":/bitmaps/button_distrho_hover2.png")
  1155. elif self.fPluginInfo['iconName'] == "file":
  1156. self.ui.b_gui.setPixmaps(":/bitmaps/button_file2.png", ":/bitmaps/button_file_down2.png", ":/bitmaps/button_file_hover2.png")
  1157. else:
  1158. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui2.png", ":/bitmaps/button_gui_down2.png", ":/bitmaps/button_gui_hover2.png")
  1159. else:
  1160. self.ui.b_enable.setPixmaps(":/bitmaps/button_off.png", ":/bitmaps/button_on.png", ":/bitmaps/button_off.png")
  1161. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit.png", ":/bitmaps/button_edit_down.png", ":/bitmaps/button_edit_hover.png")
  1162. if self.fPluginInfo['iconName'] == "distrho":
  1163. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho.png", ":/bitmaps/button_distrho_down.png", ":/bitmaps/button_distrho_hover.png")
  1164. elif self.fPluginInfo['iconName'] == "file":
  1165. self.ui.b_gui.setPixmaps(":/bitmaps/button_file.png", ":/bitmaps/button_file_down.png", ":/bitmaps/button_file_hover.png")
  1166. else:
  1167. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui.png", ":/bitmaps/button_gui_down.png", ":/bitmaps/button_gui_hover.png")
  1168. self.ui.led_control.setColor(self.ui.led_control.YELLOW)
  1169. self.ui.led_control.setEnabled(False)
  1170. self.ui.led_midi.setColor(self.ui.led_midi.RED)
  1171. self.ui.led_midi.setEnabled(False)
  1172. self.ui.led_audio_in.setColor(self.ui.led_audio_in.GREEN)
  1173. self.ui.led_audio_in.setEnabled(False)
  1174. self.ui.led_audio_out.setColor(self.ui.led_audio_out.BLUE)
  1175. self.ui.led_audio_out.setEnabled(False)
  1176. self.ui.peak_in.setColor(self.ui.peak_in.GREEN)
  1177. self.ui.peak_in.setChannels(self.fPeaksInputCount)
  1178. self.ui.peak_in.setOrientation(self.ui.peak_in.HORIZONTAL)
  1179. self.ui.peak_out.setColor(self.ui.peak_in.BLUE)
  1180. self.ui.peak_out.setChannels(self.fPeaksOutputCount)
  1181. self.ui.peak_out.setOrientation(self.ui.peak_out.HORIZONTAL)
  1182. self.ui.label_name.setText(self.fPluginInfo['name'])
  1183. self.ui.edit_dialog = PluginEdit(self, self.fPluginId)
  1184. self.ui.edit_dialog.hide()
  1185. self.setFixedHeight(32)
  1186. # -------------------------------------------------------------
  1187. # Set-up connections
  1188. self.customContextMenuRequested.connect(self.slot_showCustomMenu)
  1189. self.ui.b_enable.clicked.connect(self.slot_enableClicked)
  1190. self.ui.b_gui.clicked.connect(self.slot_guiClicked)
  1191. self.ui.b_edit.clicked.connect(self.slot_editClicked)
  1192. #------------------------------------------------------------------
  1193. def idleFast(self):
  1194. # Input peaks
  1195. if self.fPeaksInputCount > 0:
  1196. if self.fPeaksInputCount > 1:
  1197. peak1 = Carla.host.get_input_peak_value(self.fPluginId, 1)
  1198. peak2 = Carla.host.get_input_peak_value(self.fPluginId, 2)
  1199. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  1200. self.ui.peak_in.displayMeter(1, peak1)
  1201. self.ui.peak_in.displayMeter(2, peak2)
  1202. else:
  1203. peak = Carla.host.get_input_peak_value(self.fPluginId, 1)
  1204. ledState = bool(peak != 0.0)
  1205. self.ui.peak_in.displayMeter(1, peak)
  1206. if self.fLastGreenLedState != ledState:
  1207. self.fLastGreenLedState = ledState
  1208. self.ui.led_audio_in.setChecked(ledState)
  1209. # Output peaks
  1210. if self.fPeaksOutputCount > 0:
  1211. if self.fPeaksOutputCount > 1:
  1212. peak1 = Carla.host.get_output_peak_value(self.fPluginId, 1)
  1213. peak2 = Carla.host.get_output_peak_value(self.fPluginId, 2)
  1214. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  1215. self.ui.peak_out.displayMeter(1, peak1)
  1216. self.ui.peak_out.displayMeter(2, peak2)
  1217. else:
  1218. peak = Carla.host.get_output_peak_value(self.fPluginId, 1)
  1219. ledState = bool(peak != 0.0)
  1220. self.ui.peak_out.displayMeter(1, peak)
  1221. if self.fLastBlueLedState != ledState:
  1222. self.fLastBlueLedState = ledState
  1223. self.ui.led_audio_out.setChecked(ledState)
  1224. def idleSlow(self):
  1225. # Parameter Activity LED
  1226. if self.fParameterIconTimer == ICON_STATE_ON:
  1227. self.fParameterIconTimer = ICON_STATE_WAIT
  1228. self.ui.led_control.setChecked(True)
  1229. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  1230. self.fParameterIconTimer = ICON_STATE_OFF
  1231. elif self.fParameterIconTimer == ICON_STATE_OFF:
  1232. self.fParameterIconTimer = ICON_STATE_NULL
  1233. self.ui.led_control.setChecked(False)
  1234. # Update edit dialog
  1235. self.ui.edit_dialog.idleSlow()
  1236. #------------------------------------------------------------------
  1237. def editClosed(self):
  1238. self.ui.b_edit.setChecked(False)
  1239. def recheckPluginHints(self, hints):
  1240. self.fPluginInfo['hints'] = hints
  1241. self.ui.b_gui.setEnabled(hints & PLUGIN_HAS_CUSTOM_UI)
  1242. #------------------------------------------------------------------
  1243. def getHints(self):
  1244. return self.fPluginInfo['hints']
  1245. def setId(self, idx):
  1246. self.fPluginId = idx
  1247. self.ui.edit_dialog.setId(idx)
  1248. def setName(self, name):
  1249. self.ui.label_name.setText(name)
  1250. self.ui.edit_dialog.setName(name)
  1251. #------------------------------------------------------------------
  1252. def setActive(self, active, sendGui=False, sendCallback=True):
  1253. if sendGui: self.ui.b_enable.setChecked(active)
  1254. if sendCallback: Carla.host.set_active(self.fPluginId, active)
  1255. if active:
  1256. self.ui.edit_dialog.clearNotes()
  1257. self.ui.led_midi.setChecked(False)
  1258. # called from rack, checks if param is possible first
  1259. def setInternalParameter(self, parameterId, value):
  1260. if parameterId <= PARAMETER_MAX or parameterId >= PARAMETER_NULL:
  1261. return
  1262. if parameterId == PARAMETER_ACTIVE:
  1263. return self.setActive(bool(value), True, True)
  1264. elif parameterId == PARAMETER_DRYWET:
  1265. if (self.fPluginInfo['hints'] & PLUGIN_CAN_DRYWET) == 0: return
  1266. Carla.host.set_drywet(self.fPluginId, value)
  1267. elif parameterId == PARAMETER_VOLUME:
  1268. if (self.fPluginInfo['hints'] & PLUGIN_CAN_VOLUME) == 0: return
  1269. Carla.host.set_volume(self.fPluginId, value)
  1270. elif parameterId == PARAMETER_BALANCE_LEFT:
  1271. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  1272. Carla.host.set_balance_left(self.fPluginId, value)
  1273. elif parameterId == PARAMETER_BALANCE_RIGHT:
  1274. if (self.fPluginInfo['hints'] & PLUGIN_CAN_BALANCE) == 0: return
  1275. Carla.host.set_balance_right(self.fPluginId, value)
  1276. elif parameterId == PARAMETER_PANNING:
  1277. if (self.fPluginInfo['hints'] & PLUGIN_CAN_PANNING) == 0: return
  1278. Carla.host.set_panning(self.fPluginId, value)
  1279. elif parameterId == PARAMETER_CTRL_CHANNEL:
  1280. Carla.host.set_ctrl_channel(self.fPluginId, value)
  1281. self.ui.edit_dialog.setParameterValue(parameterId, value)
  1282. def setParameterValue(self, parameterId, value):
  1283. self.fParameterIconTimer = ICON_STATE_ON
  1284. if parameterId == PARAMETER_ACTIVE:
  1285. return self.setActive(bool(value), True, False)
  1286. self.ui.edit_dialog.setParameterValue(parameterId, value)
  1287. def setParameterDefault(self, parameterId, value):
  1288. self.ui.edit_dialog.setParameterDefault(parameterId, value)
  1289. def setParameterMidiControl(self, parameterId, control):
  1290. self.ui.edit_dialog.setParameterMidiControl(parameterId, control)
  1291. def setParameterMidiChannel(self, parameterId, channel):
  1292. self.ui.edit_dialog.setParameterMidiChannel(parameterId, channel)
  1293. def setProgram(self, index):
  1294. self.fParameterIconTimer = ICON_STATE_ON
  1295. self.ui.edit_dialog.setProgram(index)
  1296. def setMidiProgram(self, index):
  1297. self.fParameterIconTimer = ICON_STATE_ON
  1298. self.ui.edit_dialog.setMidiProgram(index)
  1299. #------------------------------------------------------------------
  1300. def sendNoteOn(self, channel, note):
  1301. if self.ui.edit_dialog.sendNoteOn(channel, note):
  1302. self.ui.led_midi.setChecked(True)
  1303. def sendNoteOff(self, channel, note):
  1304. if self.ui.edit_dialog.sendNoteOff(channel, note):
  1305. self.ui.led_midi.setChecked(False)
  1306. #------------------------------------------------------------------
  1307. @pyqtSlot()
  1308. def slot_showCustomMenu(self):
  1309. menu = QMenu(self)
  1310. actActive = menu.addAction(self.tr("Disable") if self.ui.b_enable.isChecked() else self.tr("Enable"))
  1311. menu.addSeparator()
  1312. actGui = menu.addAction(self.tr("Show GUI"))
  1313. actGui.setCheckable(True)
  1314. actGui.setChecked(self.ui.b_gui.isChecked())
  1315. actGui.setEnabled(self.ui.b_gui.isEnabled())
  1316. actEdit = menu.addAction(self.tr("Edit"))
  1317. actEdit.setCheckable(True)
  1318. actEdit.setChecked(self.ui.b_edit.isChecked())
  1319. menu.addSeparator()
  1320. actClone = menu.addAction(self.tr("Clone"))
  1321. actRename = menu.addAction(self.tr("Rename..."))
  1322. actRemove = menu.addAction(self.tr("Remove"))
  1323. actSel = menu.exec_(QCursor.pos())
  1324. if not actSel:
  1325. return
  1326. if actSel == actActive:
  1327. self.setActive(not self.ui.b_enable.isChecked(), True, True)
  1328. elif actSel == actGui:
  1329. self.ui.b_gui.click()
  1330. elif actSel == actEdit:
  1331. self.ui.b_edit.click()
  1332. elif actSel == actClone:
  1333. if not Carla.host.clone_plugin(self.fPluginId):
  1334. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1335. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1336. elif actSel == actRename:
  1337. oldName = self.fPluginInfo['name']
  1338. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  1339. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  1340. return
  1341. newName = newNameTry[0]
  1342. if Carla.host is None or Carla.host.rename_plugin(self.fPluginId, newName):
  1343. self.fPluginInfo['name'] = newName
  1344. self.ui.edit_dialog.fPluginInfo['name'] = newName
  1345. self.ui.edit_dialog.reloadInfo()
  1346. self.ui.label_name.setText(newName)
  1347. else:
  1348. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1349. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1350. elif actSel == actRemove:
  1351. if not Carla.host.remove_plugin(self.fPluginId):
  1352. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1353. Carla.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1354. #------------------------------------------------------------------
  1355. @pyqtSlot(bool)
  1356. def slot_enableClicked(self, yesNo):
  1357. self.setActive(yesNo, False, True)
  1358. @pyqtSlot(bool)
  1359. def slot_guiClicked(self, show):
  1360. Carla.host.show_custom_ui(self.fPluginId, show)
  1361. @pyqtSlot(bool)
  1362. def slot_editClicked(self, show):
  1363. self.ui.edit_dialog.setVisible(show)
  1364. #------------------------------------------------------------------
  1365. def paintEvent(self, event):
  1366. painter = QPainter(self)
  1367. painter.save()
  1368. areaX = self.ui.area_right.x()+7
  1369. painter.setPen(self.fColorSeprtr.lighter(110))
  1370. painter.setBrush(self.fColorBottom)
  1371. painter.setRenderHint(QPainter.Antialiasing, True)
  1372. # name -> leds arc
  1373. path = QPainterPath()
  1374. path.moveTo(areaX-20, self.height()-4)
  1375. path.cubicTo(areaX, self.height()-5, areaX-20, 4.75, areaX, 4.75)
  1376. path.lineTo(areaX, self.height()-5)
  1377. painter.drawPath(path)
  1378. painter.setPen(self.fColorSeprtr)
  1379. painter.setRenderHint(QPainter.Antialiasing, False)
  1380. # separator lines
  1381. painter.drawLine(0, self.height()-5, areaX-20, self.height()-5)
  1382. painter.drawLine(areaX, 4, self.width(), 4)
  1383. painter.setPen(self.fColorBottom)
  1384. painter.setBrush(self.fColorBottom)
  1385. # top, bottom and left lines
  1386. painter.drawLine(0, 0, self.width(), 0)
  1387. painter.drawRect(0, self.height()-4, areaX, 4)
  1388. painter.drawRoundedRect(areaX-20, self.height()-5, areaX, 5, 22, 22)
  1389. painter.drawLine(0, 0, 0, self.height())
  1390. # fill the rest
  1391. painter.drawRect(areaX-1, 5, self.width(), self.height())
  1392. # bottom 1px line
  1393. painter.setPen(self.fColorSeprtr)
  1394. painter.drawLine(0, self.height()-1, self.width(), self.height()-1)
  1395. painter.restore()
  1396. QFrame.paintEvent(self, event)
  1397. # ------------------------------------------------------------------------------------------------------------
  1398. # Main
  1399. if __name__ == '__main__':
  1400. from carla_style import *
  1401. app = CarlaApplication()
  1402. #gui = CarlaAboutW(None)
  1403. #gui = PluginParameter(None, gFakeParamInfo, 0, 0)
  1404. gui = PluginEdit(None, 0)
  1405. #gui = PluginWidget(None, 0)
  1406. gui.show()
  1407. sys.exit(app.exec_())