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

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