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.

carla_widgets.py 56KB

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