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

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