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

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