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

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