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

11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  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. self.ui.le_name.setText(pluginName)
  444. self.ui.le_name.setToolTip(pluginName)
  445. self.ui.le_label.setText(self.fPluginInfo['label'])
  446. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  447. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  448. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  449. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  450. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  451. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  452. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  453. self.ui.label_plugin.setText("\n%s\n" % self.fPluginInfo['name'])
  454. self.setWindowTitle(self.fPluginInfo['name'])
  455. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  456. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  457. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  458. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  459. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  460. self.ui.ch_fixed_buffer.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FIXED_BUFFERS)
  461. self.ui.ch_fixed_buffer.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FIXED_BUFFERS)
  462. self.ui.ch_force_stereo.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_FORCE_STEREO)
  463. self.ui.ch_force_stereo.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_FORCE_STEREO)
  464. self.ui.ch_map_program_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  465. self.ui.ch_map_program_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  466. self.ui.ch_use_chunks.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_USE_CHUNKS)
  467. self.ui.ch_use_chunks.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_USE_CHUNKS)
  468. self.ui.ch_send_control_changes.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  469. self.ui.ch_send_control_changes.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  470. self.ui.ch_send_channel_pressure.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  471. self.ui.ch_send_channel_pressure.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  472. self.ui.ch_send_note_aftertouch.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  473. self.ui.ch_send_note_aftertouch.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  474. self.ui.ch_send_pitchbend.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PITCHBEND)
  475. self.ui.ch_send_pitchbend.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_PITCHBEND)
  476. self.ui.ch_send_all_sound_off.setEnabled(self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  477. self.ui.ch_send_all_sound_off.setChecked(self.fPluginInfo['optionsEnabled'] & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  478. if self.fPluginInfo['type'] != PLUGIN_VST:
  479. self.ui.sw_programs.setCurrentIndex(1)
  480. # Show/hide keyboard
  481. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0 < midiCountInfo['outs'])
  482. self.ui.scrollArea.setEnabled(showKeyboard)
  483. self.ui.scrollArea.setVisible(showKeyboard)
  484. # Force-Update parent for new hints
  485. if self.fRealParent:
  486. self.fRealParent.recheckPluginHints(pluginHints)
  487. def reloadParameters(self):
  488. # Reset
  489. self.fParameterCount = 0
  490. self.fParameterList = []
  491. self.fParametersToUpdate = []
  492. self.fTabIconCount = 0
  493. self.fTabIconTimers = []
  494. # Remove all previous parameters
  495. for x in range(self.ui.tabWidget.count()-1):
  496. self.ui.tabWidget.widget(1).deleteLater()
  497. self.ui.tabWidget.removeTab(1)
  498. if Carla.host is None:
  499. paramFakeListFull = []
  500. paramFakeList = []
  501. paramFakeWidth = QFontMetrics(self.font()).width(gFakeParamInfo['name'])
  502. paramFakeList.append(gFakeParamInfo)
  503. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  504. self._createParameterWidgets(PARAMETER_INPUT, paramFakeListFull, self.tr("Parameters"))
  505. return
  506. parameterCount = Carla.host.get_parameter_count(self.fPluginId)
  507. if parameterCount <= 0:
  508. pass
  509. elif parameterCount <= Carla.maxParameters:
  510. paramInputListFull = []
  511. paramOutputListFull = []
  512. paramInputList = [] # ([params], width)
  513. paramInputWidth = 0
  514. paramOutputList = [] # ([params], width)
  515. paramOutputWidth = 0
  516. for i in range(parameterCount):
  517. paramInfo = Carla.host.get_parameter_info(self.fPluginId, i)
  518. paramData = Carla.host.get_parameter_data(self.fPluginId, i)
  519. paramRanges = Carla.host.get_parameter_ranges(self.fPluginId, i)
  520. paramValue = Carla.host.get_current_parameter_value(self.fPluginId, i)
  521. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  522. continue
  523. parameter = {
  524. 'type': paramData['type'],
  525. 'hints': paramData['hints'],
  526. 'name': cString(paramInfo['name']),
  527. 'unit': cString(paramInfo['unit']),
  528. 'scalePoints': [],
  529. 'index': paramData['index'],
  530. 'default': paramRanges['def'],
  531. 'minimum': paramRanges['min'],
  532. 'maximum': paramRanges['max'],
  533. 'step': paramRanges['step'],
  534. 'stepSmall': paramRanges['stepSmall'],
  535. 'stepLarge': paramRanges['stepLarge'],
  536. 'midiCC': paramData['midiCC'],
  537. 'midiChannel': paramData['midiChannel']+1,
  538. 'current': paramValue
  539. }
  540. for j in range(paramInfo['scalePointCount']):
  541. scalePointInfo = Carla.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  542. parameter['scalePoints'].append({
  543. 'value': scalePointInfo['value'],
  544. 'label': cString(scalePointInfo['label'])
  545. })
  546. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  547. # -----------------------------------------------------------------
  548. # Get width values, in packs of 10
  549. if parameter['type'] == PARAMETER_INPUT:
  550. paramInputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  551. if paramInputWidthTMP > paramInputWidth:
  552. paramInputWidth = paramInputWidthTMP
  553. paramInputList.append(parameter)
  554. if len(paramInputList) == self.ParamsPerPage:
  555. paramInputListFull.append((paramInputList, paramInputWidth))
  556. paramInputList = []
  557. paramInputWidth = 0
  558. else:
  559. paramOutputWidthTMP = QFontMetrics(self.font()).width(parameter['name'])
  560. if paramOutputWidthTMP > paramOutputWidth:
  561. paramOutputWidth = paramOutputWidthTMP
  562. paramOutputList.append(parameter)
  563. if len(paramOutputList) == self.ParamsPerPage:
  564. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  565. paramOutputList = []
  566. paramOutputWidth = 0
  567. # for i in range(parameterCount)
  568. else:
  569. # Final page width values
  570. if 0 < len(paramInputList) < 10:
  571. paramInputListFull.append((paramInputList, paramInputWidth))
  572. if 0 < len(paramOutputList) < 10:
  573. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  574. # -----------------------------------------------------------------
  575. # Create parameter tabs + widgets
  576. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  577. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  578. else: # > Carla.maxParameters
  579. fakeName = self.tr("This plugin has too many parameters to display here!")
  580. paramFakeListFull = []
  581. paramFakeList = []
  582. paramFakeWidth = QFontMetrics(self.font()).width(fakeName)
  583. parameter = {
  584. 'type': PARAMETER_UNKNOWN,
  585. 'hints': 0,
  586. 'name': fakeName,
  587. 'unit': "",
  588. 'scalePoints': [],
  589. 'index': 0,
  590. 'default': 0.0,
  591. 'minimum': 0.0,
  592. 'maximum': 0.0,
  593. 'step': 0.0,
  594. 'stepSmall': 0.0,
  595. 'stepLarge': 0.0,
  596. 'midiCC': -1,
  597. 'midiChannel': 1,
  598. 'current': 0.0
  599. }
  600. paramFakeList.append(parameter)
  601. paramFakeListFull.append((paramFakeList, paramFakeWidth))
  602. self._createParameterWidgets(PARAMETER_UNKNOWN, paramFakeListFull, self.tr("Information"))
  603. def reloadPrograms(self):
  604. # Programs
  605. self.ui.cb_programs.blockSignals(True)
  606. self.ui.cb_programs.clear()
  607. programCount = Carla.host.get_program_count(self.fPluginId) if Carla.host is not None else 0
  608. if programCount > 0:
  609. self.ui.cb_programs.setEnabled(True)
  610. self.ui.label_programs.setEnabled(True)
  611. for i in range(programCount):
  612. pName = cString(Carla.host.get_program_name(self.fPluginId, i))
  613. #pName = pName[:40] + (pName[40:] and "...")
  614. self.ui.cb_programs.addItem(pName)
  615. self.fCurrentProgram = Carla.host.get_current_program_index(self.fPluginId)
  616. self.ui.cb_programs.setCurrentIndex(self.fCurrentProgram)
  617. else:
  618. self.fCurrentProgram = -1
  619. self.ui.cb_programs.setEnabled(False)
  620. self.ui.label_programs.setEnabled(False)
  621. self.ui.cb_programs.blockSignals(False)
  622. # MIDI Programs
  623. self.ui.cb_midi_programs.blockSignals(True)
  624. self.ui.cb_midi_programs.clear()
  625. midiProgramCount = Carla.host.get_midi_program_count(self.fPluginId) if Carla.host is not None else 0
  626. if midiProgramCount > 0:
  627. self.ui.cb_midi_programs.setEnabled(True)
  628. self.ui.label_midi_programs.setEnabled(True)
  629. for i in range(midiProgramCount):
  630. mpData = Carla.host.get_midi_program_data(self.fPluginId, i)
  631. mpBank = int(mpData['bank'])
  632. mpProg = int(mpData['program'])
  633. mpName = cString(mpData['name'])
  634. #mpName = mpName[:40] + (mpName[40:] and "...")
  635. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  636. self.fCurrentMidiProgram = Carla.host.get_current_midi_program_index(self.fPluginId)
  637. self.ui.cb_midi_programs.setCurrentIndex(self.fCurrentMidiProgram)
  638. else:
  639. self.fCurrentMidiProgram = -1
  640. self.ui.cb_midi_programs.setEnabled(False)
  641. self.ui.label_midi_programs.setEnabled(False)
  642. self.ui.cb_midi_programs.blockSignals(False)
  643. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  644. if self.fPluginInfo['type'] == PLUGIN_LV2:
  645. self.ui.b_load_state.setEnabled(programCount > 0)
  646. def updateInfo(self):
  647. # Update current program text
  648. if self.ui.cb_programs.count() > 0:
  649. pIndex = self.ui.cb_programs.currentIndex()
  650. pName = cString(Carla.host.get_program_name(self.fPluginId, pIndex))
  651. #pName = pName[:40] + (pName[40:] and "...")
  652. self.ui.cb_programs.setItemText(pIndex, pName)
  653. # Update current midi program text
  654. if self.ui.cb_midi_programs.count() > 0:
  655. mpIndex = self.ui.cb_midi_programs.currentIndex()
  656. mpData = Carla.host.get_midi_program_data(self.fPluginId, mpIndex)
  657. mpBank = int(mpData['bank'])
  658. mpProg = int(mpData['program'])
  659. mpName = cString(mpData['name'])
  660. #mpName = mpName[:40] + (mpName[40:] and "...")
  661. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  662. # Update all parameter values
  663. for paramType, paramId, paramWidget in self.fParameterList:
  664. paramWidget.setValue(Carla.host.get_current_parameter_value(self.fPluginId, paramId), False)
  665. paramWidget.update()
  666. self.fParametersToUpdate = []
  667. def clearNotes(self):
  668. self.fPlayingNotes = []
  669. self.ui.keyboard.allNotesOff()
  670. def setName(self, name):
  671. self.ui.label_plugin.setText("\n%s\n" % name)
  672. self.setWindowTitle(name)
  673. def setParameterValue(self, parameterId, value):
  674. for paramItem in self.fParametersToUpdate:
  675. if paramItem[0] == parameterId:
  676. paramItem[1] = value
  677. break
  678. else:
  679. self.fParametersToUpdate.append([parameterId, value])
  680. def setParameterDefault(self, parameterId, value):
  681. for paramType, paramId, paramWidget in self.fParameterList:
  682. if paramId == parameterId:
  683. paramWidget.setDefault(value)
  684. break
  685. def setParameterMidiControl(self, parameterId, control):
  686. for paramType, paramId, paramWidget in self.fParameterList:
  687. if paramId == parameterId:
  688. paramWidget.setMidiControl(control)
  689. break
  690. def setParameterMidiChannel(self, parameterId, channel):
  691. for paramType, paramId, paramWidget in self.fParameterList:
  692. if paramId == parameterId:
  693. paramWidget.setMidiChannel(channel+1)
  694. break
  695. def setProgram(self, index):
  696. self.ui.cb_programs.blockSignals(True)
  697. self.ui.cb_programs.setCurrentIndex(index)
  698. self.ui.cb_programs.blockSignals(False)
  699. def setMidiProgram(self, index):
  700. self.ui.cb_midi_programs.blockSignals(True)
  701. self.ui.cb_midi_programs.setCurrentIndex(index)
  702. self.ui.cb_midi_programs.blockSignals(False)
  703. def sendNoteOn(self, channel, note):
  704. if self.fControlChannel == channel:
  705. self.ui.keyboard.sendNoteOn(note, False)
  706. if len(self.fPlayingNotes) == 0 and self.fRealParent:
  707. self.fRealParent.ui.led_midi.setChecked(True)
  708. playItem = (channel, note)
  709. if playItem not in self.fPlayingNotes:
  710. self.fPlayingNotes.append(playItem)
  711. def sendNoteOff(self, channel, note):
  712. if self.fControlChannel == channel:
  713. self.ui.keyboard.sendNoteOff(note, False)
  714. if len(self.fPlayingNotes) == 1 and self.fRealParent:
  715. self.fRealParent.ui.led_midi.setChecked(False)
  716. playItem = (channel, note)
  717. if playItem in self.fPlayingNotes:
  718. self.fPlayingNotes.remove(playItem)
  719. def setVisible(self, yesNo):
  720. if yesNo:
  721. if not self.fGeometry.isNull():
  722. self.restoreGeometry(self.fGeometry)
  723. else:
  724. self.fGeometry = self.saveGeometry()
  725. QDialog.setVisible(self, yesNo)
  726. def idleSlow(self):
  727. # Check Tab icons
  728. for i in range(len(self.fTabIconTimers)):
  729. if self.fTabIconTimers[i] == ICON_STATE_ON:
  730. self.fTabIconTimers[i] = ICON_STATE_WAIT
  731. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  732. self.fTabIconTimers[i] = ICON_STATE_OFF
  733. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  734. self.fTabIconTimers[i] = ICON_STATE_NULL
  735. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  736. # Check parameters needing update
  737. for index, value in self.fParametersToUpdate:
  738. if index == PARAMETER_DRYWET:
  739. self.ui.dial_drywet.blockSignals(True)
  740. self.ui.dial_drywet.setValue(value * 1000)
  741. self.ui.dial_drywet.blockSignals(False)
  742. elif index == PARAMETER_VOLUME:
  743. self.ui.dial_vol.blockSignals(True)
  744. self.ui.dial_vol.setValue(value * 1000)
  745. self.ui.dial_vol.blockSignals(False)
  746. elif index == PARAMETER_BALANCE_LEFT:
  747. self.ui.dial_b_left.blockSignals(True)
  748. self.ui.dial_b_left.setValue(value * 1000)
  749. self.ui.dial_b_left.blockSignals(False)
  750. elif index == PARAMETER_BALANCE_RIGHT:
  751. self.ui.dial_b_right.blockSignals(True)
  752. self.ui.dial_b_right.setValue(value * 1000)
  753. self.ui.dial_b_right.blockSignals(False)
  754. #elif index == PARAMETER_PANNING:
  755. #self.ui.dial_pan.blockSignals(True)
  756. #self.ui.dial_pan.setValue(value * 1000, True, False)
  757. #self.ui.dial_pan.blockSignals(False)
  758. elif index == PARAMETER_CTRL_CHANNEL:
  759. self.fControlChannel = int(value)
  760. self.ui.sb_ctrl_channel.blockSignals(True)
  761. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  762. self.ui.sb_ctrl_channel.blockSignals(False)
  763. self.ui.keyboard.allNotesOff()
  764. self._updateCtrlMidiProgram()
  765. elif index >= 0:
  766. for paramType, paramId, paramWidget in self.fParameterList:
  767. if paramId != index:
  768. continue
  769. paramWidget.setValue(value, False)
  770. if paramType == PARAMETER_INPUT:
  771. tabIndex = paramWidget.tabIndex()
  772. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  773. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  774. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  775. break
  776. # Clear all parameters
  777. self.fParametersToUpdate = []
  778. # Update parameter outputs
  779. for paramType, paramId, paramWidget in self.fParameterList:
  780. if paramType == PARAMETER_OUTPUT:
  781. value = Carla.host.get_current_parameter_value(self.fPluginId, paramId)
  782. paramWidget.setValue(value, False)
  783. @pyqtSlot()
  784. def slot_stateSave(self):
  785. if self.fPluginInfo['type'] == PLUGIN_LV2:
  786. # TODO
  787. return
  788. if self.fCurrentStateFilename:
  789. askTry = QMessageBox.question(self, self.tr("Overwrite?"), self.tr("Overwrite previously created file?"), QMessageBox.Ok|QMessageBox.Cancel)
  790. if askTry == QMessageBox.Ok:
  791. Carla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  792. return
  793. self.fCurrentStateFilename = None
  794. fileFilter = self.tr("Carla State File (*.carxs)")
  795. filenameTry = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  796. if filenameTry:
  797. if not filenameTry.lower().endswith(".carxs"):
  798. filenameTry += ".carxs"
  799. self.fCurrentStateFilename = filenameTry
  800. Carla.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  801. @pyqtSlot()
  802. def slot_stateLoad(self):
  803. if self.fPluginInfo['type'] == PLUGIN_LV2:
  804. presetList = []
  805. for i in range(Carla.host.get_program_count(self.fPluginId)):
  806. presetList.append("%03i - %s" % (i+1, cString(Carla.host.get_program_name(self.fPluginId, i))))
  807. ret = QInputDialog.getItem(self, self.tr("Open LV2 Preset"), self.tr("Select an LV2 Preset:"), presetList, 0, False)
  808. if ret[1]:
  809. index = int(ret[0].split(" - ", 1)[0])-1
  810. Carla.host.set_midi_program(self.fPluginId, -1)
  811. Carla.host.set_program(self.fPluginId, index)
  812. self.setMidiProgram(-1)
  813. return
  814. fileFilter = self.tr("Carla State File (*.carxs)")
  815. filenameTry = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  816. if filenameTry:
  817. self.fCurrentStateFilename = filenameTry
  818. Carla.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  819. @pyqtSlot(bool)
  820. def slot_optionChanged(self, clicked):
  821. sender = self.sender()
  822. if sender == self.ui.ch_fixed_buffer:
  823. option = PLUGIN_OPTION_FIXED_BUFFERS
  824. elif sender == self.ui.ch_force_stereo:
  825. option = PLUGIN_OPTION_FORCE_STEREO
  826. elif sender == self.ui.ch_map_program_changes:
  827. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  828. elif sender == self.ui.ch_use_chunks:
  829. option = PLUGIN_OPTION_USE_CHUNKS
  830. elif sender == self.ui.ch_send_control_changes:
  831. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  832. elif sender == self.ui.ch_send_channel_pressure:
  833. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  834. elif sender == self.ui.ch_send_note_aftertouch:
  835. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  836. elif sender == self.ui.ch_send_pitchbend:
  837. option = PLUGIN_OPTION_SEND_PITCHBEND
  838. elif sender == self.ui.ch_send_all_sound_off:
  839. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  840. else:
  841. return
  842. Carla.host.set_option(self.fPluginId, option, clicked)
  843. @pyqtSlot(int)
  844. def slot_dryWetChanged(self, value):
  845. Carla.host.set_drywet(self.fPluginId, float(value)/1000)
  846. @pyqtSlot(int)
  847. def slot_volumeChanged(self, value):
  848. Carla.host.set_volume(self.fPluginId, float(value)/1000)
  849. @pyqtSlot(int)
  850. def slot_balanceLeftChanged(self, value):
  851. Carla.host.set_balance_left(self.fPluginId, float(value)/1000)
  852. @pyqtSlot(int)
  853. def slot_balanceRightChanged(self, value):
  854. Carla.host.set_balance_right(self.fPluginId, float(value)/1000)
  855. @pyqtSlot(int)
  856. def slot_panningChanged(self, value):
  857. Carla.host.set_panning(self.fPluginId, float(value)/1000)
  858. @pyqtSlot(int)
  859. def slot_ctrlChannelChanged(self, value):
  860. self.fControlChannel = value-1
  861. Carla.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  862. self.ui.keyboard.allNotesOff()
  863. self._updateCtrlMidiProgram()
  864. @pyqtSlot(int, float)
  865. def slot_parameterValueChanged(self, parameterId, value):
  866. Carla.host.set_parameter_value(self.fPluginId, parameterId, value)
  867. @pyqtSlot(int, int)
  868. def slot_parameterMidiControlChanged(self, parameterId, control):
  869. Carla.host.set_parameter_midi_cc(self.fPluginId, parameterId, control)
  870. @pyqtSlot(int, int)
  871. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  872. Carla.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  873. @pyqtSlot(int)
  874. def slot_programIndexChanged(self, index):
  875. self.fCurrentProgram = index
  876. Carla.host.set_program(self.fPluginId, index)
  877. @pyqtSlot(int)
  878. def slot_midiProgramIndexChanged(self, index):
  879. self.fCurrentMidiProgram = index
  880. Carla.host.set_midi_program(self.fPluginId, index)
  881. @pyqtSlot(int)
  882. def slot_noteOn(self, note):
  883. if self.fControlChannel >= 0:
  884. Carla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  885. @pyqtSlot(int)
  886. def slot_noteOff(self, note):
  887. if self.fControlChannel >= 0:
  888. Carla.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  889. @pyqtSlot()
  890. def slot_finished(self):
  891. if self.fRealParent:
  892. self.fRealParent.editClosed()
  893. @pyqtSlot()
  894. def slot_knobCustomMenu(self):
  895. dialName = self.sender().objectName()
  896. if dialName == "dial_drywet":
  897. minimum = 0
  898. maximum = 100
  899. default = 100
  900. label = "Dry/Wet"
  901. elif dialName == "dial_vol":
  902. minimum = 0
  903. maximum = 127
  904. default = 100
  905. label = "Volume"
  906. elif dialName == "dial_b_left":
  907. minimum = -100
  908. maximum = 100
  909. default = -100
  910. label = "Balance-Left"
  911. elif dialName == "dial_b_right":
  912. minimum = -100
  913. maximum = 100
  914. default = 100
  915. label = "Balance-Right"
  916. elif dialName == "dial_panning":
  917. minimum = -100
  918. maximum = 100
  919. default = 0
  920. label = "Panning"
  921. else:
  922. minimum = 0
  923. maximum = 100
  924. default = 100
  925. label = "Unknown"
  926. current = self.sender().value() / 10
  927. menu = QMenu(self)
  928. actReset = menu.addAction(self.tr("Reset (%i%%)" % default))
  929. menu.addSeparator()
  930. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % minimum))
  931. actCenter = menu.addAction(self.tr("Set to Center"))
  932. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % maximum))
  933. menu.addSeparator()
  934. actSet = menu.addAction(self.tr("Set value..."))
  935. if label not in ("Balance-Left", "Balance-Right"):
  936. menu.removeAction(actCenter)
  937. actSelected = menu.exec_(QCursor.pos())
  938. if actSelected == actSet:
  939. valueTry = QInputDialog.getInteger(self, self.tr("Set value"), label, current, minimum, maximum, 1)
  940. if valueTry[1]:
  941. value = valueTry[0] * 10
  942. else:
  943. return
  944. elif actSelected == actMinimum:
  945. value = minimum * 10
  946. elif actSelected == actMaximum:
  947. value = maximum * 10
  948. elif actSelected == actReset:
  949. value = default * 10
  950. elif actSelected == actCenter:
  951. value = 0
  952. else:
  953. return
  954. if label == "Dry/Wet":
  955. self.ui.dial_drywet.setValue(value)
  956. elif label == "Volume":
  957. self.ui.dial_vol.setValue(value)
  958. elif label == "Balance-Left":
  959. self.ui.dial_b_left.setValue(value)
  960. elif label == "Balance-Right":
  961. self.ui.dial_b_right.setValue(value)
  962. #elif label == "Panning":
  963. #self.ui.dial_panning.setValue(value)
  964. @pyqtSlot()
  965. def slot_channelCustomMenu(self):
  966. menu = QMenu(self)
  967. actNone = menu.addAction(self.tr("None"))
  968. if self.fControlChannel+1 == 0:
  969. actNone.setCheckable(True)
  970. actNone.setChecked(True)
  971. for i in range(1, 16+1):
  972. action = menu.addAction("%i" % i)
  973. if self.fControlChannel+1 == i:
  974. action.setCheckable(True)
  975. action.setChecked(True)
  976. actSel = menu.exec_(QCursor.pos())
  977. if not actSel:
  978. pass
  979. elif actSel == actNone:
  980. self.ui.sb_ctrl_channel.setValue(0)
  981. elif actSel:
  982. selChannel = int(actSel.text())
  983. self.ui.sb_ctrl_channel.setValue(selChannel)
  984. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  985. i = 1
  986. for paramList, width in paramListFull:
  987. if len(paramList) == 0:
  988. break
  989. tabIndex = self.ui.tabWidget.count()
  990. tabPageContainer = QWidget(self.ui.tabWidget)
  991. tabPageLayout = QVBoxLayout(tabPageContainer)
  992. tabPageContainer.setLayout(tabPageLayout)
  993. for paramInfo in paramList:
  994. paramWidget = PluginParameter(tabPageContainer, paramInfo, self.fPluginId, tabIndex)
  995. paramWidget.setLabelWidth(width)
  996. tabPageLayout.addWidget(paramWidget)
  997. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  998. if paramType == PARAMETER_INPUT:
  999. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1000. paramWidget.midiControlChanged.connect(self.slot_parameterMidiControlChanged)
  1001. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1002. tabPageLayout.addStretch()
  1003. self.ui.tabWidget.addTab(tabPageContainer, "%s (%i)" % (tabPageName, i))
  1004. i += 1
  1005. if paramType == PARAMETER_INPUT:
  1006. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1007. self.fTabIconTimers.append(ICON_STATE_NULL)
  1008. def _updateCtrlMidiProgram(self):
  1009. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2):
  1010. return
  1011. elif self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1012. return
  1013. if self.fControlChannel < 0:
  1014. self.ui.cb_midi_programs.setEnabled(False)
  1015. return
  1016. self.ui.cb_midi_programs.setEnabled(True)
  1017. mpIndex = Carla.host.get_current_midi_program_index(self.fPluginId)
  1018. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1019. self.setMidiProgram(mpIndex)
  1020. def showEvent(self, event):
  1021. if not self.fScrollAreaSetup:
  1022. self.fScrollAreaSetup = True
  1023. minHeight = self.ui.scrollArea.height()+2
  1024. self.ui.scrollArea.setMinimumHeight(minHeight)
  1025. self.ui.scrollArea.setMaximumHeight(minHeight)
  1026. QDialog.showEvent(self, event)
  1027. def done(self, r):
  1028. QDialog.done(self, r)
  1029. self.close()
  1030. # ------------------------------------------------------------------------------------------------------------
  1031. # Plugin Widget
  1032. class PluginWidget(QFrame):
  1033. def __init__(self, parent, pluginId):
  1034. QFrame.__init__(self, parent)
  1035. self.ui = ui_carla_plugin.Ui_PluginWidget()
  1036. self.ui.setupUi(self)
  1037. # -------------------------------------------------------------
  1038. # Internal stuff
  1039. self.fPluginId = pluginId
  1040. self.fPluginInfo = Carla.host.get_plugin_info(self.fPluginId) if Carla.host is not None else gFakePluginInfo
  1041. self.fPluginInfo['binary'] = cString(self.fPluginInfo['binary'])
  1042. self.fPluginInfo['name'] = cString(self.fPluginInfo['name'])
  1043. self.fPluginInfo['label'] = cString(self.fPluginInfo['label'])
  1044. self.fPluginInfo['maker'] = cString(self.fPluginInfo['maker'])
  1045. self.fPluginInfo['copyright'] = cString(self.fPluginInfo['copyright'])
  1046. self.fPluginInfo['iconName'] = cString(self.fPluginInfo['iconName'])
  1047. if not Carla.isLocal:
  1048. self.fPluginInfo['hints'] &= ~PLUGIN_HAS_GUI
  1049. self.fLastGreenLedState = False
  1050. self.fLastBlueLedState = False
  1051. self.fParameterIconTimer = ICON_STATE_NULL
  1052. if Carla.processMode == PROCESS_MODE_CONTINUOUS_RACK or Carla.host is None:
  1053. self.fPeaksInputCount = 2
  1054. self.fPeaksOutputCount = 2
  1055. else:
  1056. audioCountInfo = Carla.host.get_audio_port_count_info(self.fPluginId)
  1057. self.fPeaksInputCount = int(audioCountInfo['ins'])
  1058. self.fPeaksOutputCount = int(audioCountInfo['outs'])
  1059. if self.fPeaksInputCount > 2:
  1060. self.fPeaksInputCount = 2
  1061. if self.fPeaksOutputCount > 2:
  1062. self.fPeaksOutputCount = 2
  1063. if self.palette().window().color().lightness() > 100:
  1064. # Light background
  1065. labelColor = "333"
  1066. isLight = True
  1067. self.fColorTop = QColor(60, 60, 60)
  1068. self.fColorBottom = QColor(47, 47, 47)
  1069. self.fColorSeprtr = QColor(70, 70, 70)
  1070. else:
  1071. # Dark background
  1072. labelColor = "BBB"
  1073. isLight = False
  1074. self.fColorTop = QColor(60, 60, 60)
  1075. self.fColorBottom = QColor(47, 47, 47)
  1076. self.fColorSeprtr = QColor(70, 70, 70)
  1077. # -------------------------------------------------------------
  1078. # Set-up GUI
  1079. self.setStyleSheet("""
  1080. QLabel#label_name {
  1081. color: #%s;
  1082. }""" % labelColor)
  1083. if isLight:
  1084. self.ui.b_enable.setPixmaps(":/bitmaps/button_off2.png", ":/bitmaps/button_on2.png", ":/bitmaps/button_off2.png")
  1085. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit2.png", ":/bitmaps/button_edit_down2.png", ":/bitmaps/button_edit_hover2.png")
  1086. if self.fPluginInfo['iconName'] == "distrho":
  1087. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho2.png", ":/bitmaps/button_distrho_down2.png", ":/bitmaps/button_distrho_hover2.png")
  1088. elif self.fPluginInfo['iconName'] == "file":
  1089. self.ui.b_gui.setPixmaps(":/bitmaps/button_file2.png", ":/bitmaps/button_file_down2.png", ":/bitmaps/button_file_hover2.png")
  1090. else:
  1091. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui2.png", ":/bitmaps/button_gui_down2.png", ":/bitmaps/button_gui_hover2.png")
  1092. else:
  1093. self.ui.b_enable.setPixmaps(":/bitmaps/button_off.png", ":/bitmaps/button_on.png", ":/bitmaps/button_off.png")
  1094. self.ui.b_edit.setPixmaps(":/bitmaps/button_edit.png", ":/bitmaps/button_edit_down.png", ":/bitmaps/button_edit_hover.png")
  1095. if self.fPluginInfo['iconName'] == "distrho":
  1096. self.ui.b_gui.setPixmaps(":/bitmaps/button_distrho.png", ":/bitmaps/button_distrho_down.png", ":/bitmaps/button_distrho_hover.png")
  1097. elif self.fPluginInfo['iconName'] == "file":
  1098. self.ui.b_gui.setPixmaps(":/bitmaps/button_file.png", ":/bitmaps/button_file_down.png", ":/bitmaps/button_file_hover.png")
  1099. else:
  1100. self.ui.b_gui.setPixmaps(":/bitmaps/button_gui.png", ":/bitmaps/button_gui_down.png", ":/bitmaps/button_gui_hover.png")
  1101. self.ui.led_control.setColor(self.ui.led_control.YELLOW)
  1102. self.ui.led_control.setEnabled(False)
  1103. self.ui.led_midi.setColor(self.ui.led_midi.RED)
  1104. self.ui.led_midi.setEnabled(False)
  1105. self.ui.led_audio_in.setColor(self.ui.led_audio_in.GREEN)
  1106. self.ui.led_audio_in.setEnabled(False)
  1107. self.ui.led_audio_out.setColor(self.ui.led_audio_out.BLUE)
  1108. self.ui.led_audio_out.setEnabled(False)
  1109. self.ui.peak_in.setColor(self.ui.peak_in.GREEN)
  1110. self.ui.peak_in.setChannels(self.fPeaksInputCount)
  1111. self.ui.peak_in.setOrientation(self.ui.peak_in.HORIZONTAL)
  1112. self.ui.peak_out.setColor(self.ui.peak_in.BLUE)
  1113. self.ui.peak_out.setChannels(self.fPeaksOutputCount)
  1114. self.ui.peak_out.setOrientation(self.ui.peak_out.HORIZONTAL)
  1115. self.ui.label_name.setText(self.fPluginInfo['name'])
  1116. self.ui.edit_dialog = PluginEdit(self, self.fPluginId)
  1117. self.ui.edit_dialog.hide()
  1118. self.setFixedHeight(32)
  1119. # -------------------------------------------------------------
  1120. # Set-up connections
  1121. self.customContextMenuRequested.connect(self.slot_showCustomMenu)
  1122. self.ui.b_enable.clicked.connect(self.slot_enableClicked)
  1123. self.ui.b_gui.clicked.connect(self.slot_guiClicked)
  1124. self.ui.b_edit.clicked.connect(self.slot_editClicked)
  1125. # -------------------------------------------------------------
  1126. def idleFast(self):
  1127. # Input peaks
  1128. if self.fPeaksInputCount > 0:
  1129. if self.fPeaksInputCount > 1:
  1130. peak1 = Carla.host.get_input_peak_value(self.fPluginId, 1)
  1131. peak2 = Carla.host.get_input_peak_value(self.fPluginId, 2)
  1132. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  1133. self.ui.peak_in.displayMeter(1, peak1)
  1134. self.ui.peak_in.displayMeter(2, peak2)
  1135. else:
  1136. peak = Carla.host.get_input_peak_value(self.fPluginId, 1)
  1137. ledState = bool(peak != 0.0)
  1138. self.ui.peak_in.displayMeter(1, peak)
  1139. if self.fLastGreenLedState != ledState:
  1140. self.fLastGreenLedState = ledState
  1141. self.ui.led_audio_in.setChecked(ledState)
  1142. # Output peaks
  1143. if self.fPeaksOutputCount > 0:
  1144. if self.fPeaksOutputCount > 1:
  1145. peak1 = Carla.host.get_output_peak_value(self.fPluginId, 1)
  1146. peak2 = Carla.host.get_output_peak_value(self.fPluginId, 2)
  1147. ledState = bool(peak1 != 0.0 or peak2 != 0.0)
  1148. self.ui.peak_out.displayMeter(1, peak1)
  1149. self.ui.peak_out.displayMeter(2, peak2)
  1150. else:
  1151. peak = Carla.host.get_output_peak_value(self.fPluginId, 1)
  1152. ledState = bool(peak != 0.0)
  1153. self.ui.peak_out.displayMeter(1, peak)
  1154. if self.fLastBlueLedState != ledState:
  1155. self.fLastBlueLedState = ledState
  1156. self.ui.led_audio_out.setChecked(ledState)
  1157. def idleSlow(self):
  1158. # Parameter Activity LED
  1159. if self.fParameterIconTimer == ICON_STATE_ON:
  1160. self.fParameterIconTimer = ICON_STATE_WAIT
  1161. self.ui.led_control.setChecked(True)
  1162. elif self.fParameterIconTimer == ICON_STATE_WAIT:
  1163. self.fParameterIconTimer = ICON_STATE_OFF
  1164. elif self.fParameterIconTimer == ICON_STATE_OFF:
  1165. self.fParameterIconTimer = ICON_STATE_NULL
  1166. self.ui.led_control.setChecked(False)
  1167. # Update edit dialog
  1168. self.ui.edit_dialog.idleSlow()
  1169. def editClosed(self):
  1170. self.ui.b_edit.setChecked(False)
  1171. def recheckPluginHints(self, hints):
  1172. self.fPluginInfo['hints'] = hints
  1173. self.ui.b_gui.setEnabled(hints & PLUGIN_HAS_GUI)
  1174. def setActive(self, active, sendGui=False, sendCallback=True):
  1175. if sendGui: self.ui.b_enable.setChecked(active)
  1176. if sendCallback: Carla.host.set_active(self.fPluginId, active)
  1177. if active:
  1178. self.ui.edit_dialog.clearNotes()
  1179. self.ui.led_midi.setChecked(False)
  1180. def setParameterValue(self, parameterId, value):
  1181. self.fParameterIconTimer = ICON_STATE_ON
  1182. if parameterId == PARAMETER_ACTIVE:
  1183. return self.setActive(bool(value), True, False)
  1184. self.ui.edit_dialog.setParameterValue(parameterId, value)
  1185. def setParameterDefault(self, parameterId, value):
  1186. self.ui.edit_dialog.setParameterDefault(parameterId, value)
  1187. def setParameterMidiControl(self, parameterId, control):
  1188. self.ui.edit_dialog.setParameterMidiControl(parameterId, control)
  1189. def setParameterMidiChannel(self, parameterId, channel):
  1190. self.ui.edit_dialog.setParameterMidiChannel(parameterId, channel)
  1191. def setProgram(self, index):
  1192. self.fParameterIconTimer = ICON_STATE_ON
  1193. self.ui.edit_dialog.setProgram(index)
  1194. def setMidiProgram(self, index):
  1195. self.fParameterIconTimer = ICON_STATE_ON
  1196. self.ui.edit_dialog.setMidiProgram(index)
  1197. def sendNoteOn(self, channel, note):
  1198. self.ui.edit_dialog.sendNoteOn(channel, note)
  1199. def sendNoteOff(self, channel, note):
  1200. self.ui.edit_dialog.sendNoteOff(channel, note)
  1201. def setId(self, idx):
  1202. self.fPluginId = idx
  1203. self.ui.edit_dialog.fPluginId = idx
  1204. @pyqtSlot()
  1205. def slot_showCustomMenu(self):
  1206. menu = QMenu(self)
  1207. actActive = menu.addAction(self.tr("Disable") if self.ui.b_enable.isChecked() else self.tr("Enable"))
  1208. menu.addSeparator()
  1209. actGui = menu.addAction(self.tr("Show GUI"))
  1210. actGui.setCheckable(True)
  1211. actGui.setChecked(self.ui.b_gui.isChecked())
  1212. actGui.setEnabled(self.ui.b_gui.isEnabled())
  1213. actEdit = menu.addAction(self.tr("Edit"))
  1214. actEdit.setCheckable(True)
  1215. actEdit.setChecked(self.ui.b_edit.isChecked())
  1216. menu.addSeparator()
  1217. actClone = menu.addAction(self.tr("Clone"))
  1218. actRename = menu.addAction(self.tr("Rename..."))
  1219. actRemove = menu.addAction(self.tr("Remove"))
  1220. actSel = menu.exec_(QCursor.pos())
  1221. if not actSel:
  1222. return
  1223. if actSel == actActive:
  1224. self.setActive(not self.ui.b_enable.isChecked(), True, True)
  1225. elif actSel == actGui:
  1226. self.ui.b_gui.click()
  1227. elif actSel == actEdit:
  1228. self.ui.b_edit.click()
  1229. elif actSel == actClone:
  1230. if not Carla.host.clone_plugin(self.fPluginId):
  1231. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1232. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1233. elif actSel == actRename:
  1234. oldName = self.fPluginInfo['name']
  1235. newNameTry = QInputDialog.getText(self, self.tr("Rename Plugin"), self.tr("New plugin name:"), QLineEdit.Normal, oldName)
  1236. if not (newNameTry[1] and newNameTry[0] and oldName != newNameTry[0]):
  1237. return
  1238. newName = newNameTry[0]
  1239. if Carla.host is None or Carla.host.rename_plugin(self.fPluginId, newName):
  1240. self.fPluginInfo['name'] = newName
  1241. self.ui.edit_dialog.fPluginInfo['name'] = newName
  1242. self.ui.edit_dialog.reloadInfo()
  1243. self.ui.label_name.setText(newName)
  1244. else:
  1245. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1246. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1247. elif actSel == actRemove:
  1248. if not Carla.host.remove_plugin(self.fPluginId):
  1249. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1250. cString(Carla.host.get_last_error()), QMessageBox.Ok, QMessageBox.Ok)
  1251. @pyqtSlot(bool)
  1252. def slot_enableClicked(self, yesNo):
  1253. self.setActive(yesNo, False, True)
  1254. @pyqtSlot(bool)
  1255. def slot_guiClicked(self, show):
  1256. Carla.host.show_gui(self.fPluginId, show)
  1257. @pyqtSlot(bool)
  1258. def slot_editClicked(self, show):
  1259. self.ui.edit_dialog.setVisible(show)
  1260. def paintEvent(self, event):
  1261. painter = QPainter(self)
  1262. painter.save()
  1263. areaX = self.ui.area_right.x()+7
  1264. painter.setPen(self.fColorSeprtr.lighter(110))
  1265. painter.setBrush(self.fColorBottom)
  1266. painter.setRenderHint(QPainter.Antialiasing, True)
  1267. # name -> leds arc
  1268. path = QPainterPath()
  1269. path.moveTo(areaX-20, self.height()-4)
  1270. path.cubicTo(areaX, self.height()-5, areaX-20, 4.75, areaX, 4.75)
  1271. path.lineTo(areaX, self.height()-5)
  1272. painter.drawPath(path)
  1273. painter.setPen(self.fColorSeprtr)
  1274. painter.setRenderHint(QPainter.Antialiasing, False)
  1275. # separator lines
  1276. painter.drawLine(0, self.height()-5, areaX-20, self.height()-5)
  1277. painter.drawLine(areaX, 4, self.width(), 4)
  1278. painter.setPen(self.fColorBottom)
  1279. painter.setBrush(self.fColorBottom)
  1280. # top, bottom and left lines
  1281. painter.drawLine(0, 0, self.width(), 0)
  1282. painter.drawRect(0, self.height()-4, areaX, 4)
  1283. painter.drawRoundedRect(areaX-20, self.height()-5, areaX, 5, 22, 22)
  1284. painter.drawLine(0, 0, 0, self.height())
  1285. # fill the rest
  1286. painter.drawRect(areaX-1, 5, self.width(), self.height())
  1287. # bottom 1px line
  1288. painter.setPen(self.fColorSeprtr)
  1289. painter.drawLine(0, self.height()-1, self.width(), self.height()-1)
  1290. painter.restore()
  1291. QFrame.paintEvent(self, event)
  1292. # ------------------------------------------------------------------------------------------------------------
  1293. # Main
  1294. if __name__ == '__main__':
  1295. try:
  1296. from PyQt5.QtWidgets import QApplication
  1297. except:
  1298. from PyQt4.QtGui import QApplication
  1299. app = QApplication(sys.argv)
  1300. app.setApplicationName("Carla")
  1301. app.setApplicationVersion(VERSION)
  1302. app.setOrganizationName("falkTX")
  1303. app.setWindowIcon(QIcon(":/scalable/carla.svg"))
  1304. #gui = PluginParameter(None, gFakeParamInfo, 0, 0)
  1305. #gui = PluginEdit(None, 0)
  1306. gui = PluginWidget(None, 0)
  1307. gui.show()
  1308. sys.exit(app.exec_())