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