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 55KB

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