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

11 years ago
10 years ago
10 years ago
9 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
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
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
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
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla widgets code
  4. # Copyright (C) 2011-2021 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from abc import abstractmethod
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (PyQt5)
  22. from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QByteArray
  23. from PyQt5.QtGui import QCursor, QIcon, QPalette, QPixmap
  24. from PyQt5.QtWidgets import QDialog, QFileDialog, QInputDialog, QMenu, QMessageBox, QScrollArea, QVBoxLayout, QWidget
  25. # ------------------------------------------------------------------------------------------------------------
  26. # Imports (Custom)
  27. import ui_carla_about
  28. import ui_carla_about_juce
  29. import ui_carla_edit
  30. import ui_carla_parameter
  31. from carla_backend import (
  32. MACOS, WINDOWS,
  33. BINARY_NATIVE,
  34. PLUGIN_INTERNAL,
  35. PLUGIN_DSSI,
  36. PLUGIN_LV2,
  37. PLUGIN_VST2,
  38. PLUGIN_SF2,
  39. PLUGIN_SFZ,
  40. PLUGIN_CAN_DRYWET,
  41. PLUGIN_CAN_VOLUME,
  42. PLUGIN_CAN_BALANCE,
  43. PLUGIN_CAN_PANNING,
  44. PLUGIN_CATEGORY_SYNTH,
  45. PLUGIN_OPTION_FIXED_BUFFERS,
  46. PLUGIN_OPTION_FORCE_STEREO,
  47. PLUGIN_OPTION_MAP_PROGRAM_CHANGES,
  48. PLUGIN_OPTION_USE_CHUNKS,
  49. PLUGIN_OPTION_SEND_CONTROL_CHANGES,
  50. PLUGIN_OPTION_SEND_CHANNEL_PRESSURE,
  51. PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH,
  52. PLUGIN_OPTION_SEND_PITCHBEND,
  53. PLUGIN_OPTION_SEND_ALL_SOUND_OFF,
  54. PLUGIN_OPTION_SEND_PROGRAM_CHANGES,
  55. PLUGIN_OPTION_SKIP_SENDING_NOTES,
  56. PARAMETER_DRYWET,
  57. PARAMETER_VOLUME,
  58. PARAMETER_BALANCE_LEFT,
  59. PARAMETER_BALANCE_RIGHT,
  60. PARAMETER_PANNING,
  61. PARAMETER_CTRL_CHANNEL,
  62. PARAMETER_IS_ENABLED,
  63. PARAMETER_IS_AUTOMABLE,
  64. PARAMETER_IS_READ_ONLY,
  65. PARAMETER_USES_SCALEPOINTS,
  66. PARAMETER_USES_CUSTOM_TEXT,
  67. PARAMETER_CAN_BE_CV_CONTROLLED,
  68. PARAMETER_INPUT, PARAMETER_OUTPUT,
  69. CONTROL_INDEX_NONE,
  70. CONTROL_INDEX_MIDI_PITCHBEND,
  71. CONTROL_INDEX_MIDI_LEARN,
  72. CONTROL_INDEX_CV
  73. )
  74. from carla_shared import (
  75. MIDI_CC_LIST, MAX_MIDI_CC_LIST_ITEM,
  76. VERSION,
  77. countDecimalPoints,
  78. fontMetricsHorizontalAdvance,
  79. setUpSignals,
  80. gCarla
  81. )
  82. from carla_utils import getPluginTypeAsString
  83. #)
  84. from widgets.collapsablewidget import CollapsibleBox
  85. from widgets.pixmapkeyboard import PixmapKeyboardHArea
  86. # ------------------------------------------------------------------------------------------------------------
  87. # Carla GUI defines
  88. ICON_STATE_ON = 3 # turns on, sets as wait
  89. ICON_STATE_WAIT = 2 # nothing, sets as off
  90. ICON_STATE_OFF = 1 # turns off, sets as null
  91. ICON_STATE_NULL = 0 # nothing
  92. # ------------------------------------------------------------------------------------------------------------
  93. # Carla About dialog
  94. class CarlaAboutW(QDialog):
  95. def __init__(self, parent, host):
  96. QDialog.__init__(self, parent)
  97. self.ui = ui_carla_about.Ui_CarlaAboutW()
  98. self.ui.setupUi(self)
  99. if host.isControl:
  100. extraInfo = " - <b>%s</b>" % self.tr("OSC Bridge Version")
  101. elif host.isPlugin:
  102. extraInfo = " - <b>%s</b>" % self.tr("Plugin Version")
  103. else:
  104. extraInfo = ""
  105. self.ui.l_about.setText(self.tr(""
  106. "<br>Version %s"
  107. "<br>Carla is a fully-featured audio plugin host%s.<br>"
  108. "<br>Copyright (C) 2011-2021 falkTX<br>"
  109. "" % (VERSION, extraInfo)))
  110. if self.ui.about.palette().color(QPalette.Background).blackF() < 0.5:
  111. self.ui.l_icons.setPixmap(QPixmap(":/bitmaps/carla_about_black.png"))
  112. self.ui.ico_example_edit.setPixmap(QPixmap(":/bitmaps/button_file-black.png"))
  113. self.ui.ico_example_file.setPixmap(QPixmap(":/scalable/button_edit-black.svg"))
  114. self.ui.ico_example_gui.setPixmap(QPixmap(":/bitmaps/button_gui-black.png"))
  115. if host.isControl:
  116. self.ui.l_extended.hide()
  117. self.ui.tabWidget.removeTab(3)
  118. self.ui.tabWidget.removeTab(2)
  119. self.ui.l_extended.setText(gCarla.utils.get_complete_license_text())
  120. if host.is_engine_running() and not host.isControl:
  121. self.ui.le_osc_url_tcp.setText(host.get_host_osc_url_tcp())
  122. self.ui.le_osc_url_udp.setText(host.get_host_osc_url_udp())
  123. else:
  124. self.ui.le_osc_url_tcp.setText(self.tr("(Engine not running)"))
  125. self.ui.le_osc_url_udp.setText(self.tr("(Engine not running)"))
  126. # pylint: disable=line-too-long
  127. self.ui.l_osc_cmds.setText("<table>"
  128. "<tr><td>" "/set_active" "&nbsp;</td><td>&lt;i-value&gt;</td></tr>"
  129. "<tr><td>" "/set_drywet" "&nbsp;</td><td>&lt;f-value&gt;</td></tr>"
  130. "<tr><td>" "/set_volume" "&nbsp;</td><td>&lt;f-value&gt;</td></tr>"
  131. "<tr><td>" "/set_balance_left" "&nbsp;</td><td>&lt;f-value&gt;</td></tr>"
  132. "<tr><td>" "/set_balance_right" "&nbsp;</td><td>&lt;f-value&gt;</td></tr>"
  133. "<tr><td>" "/set_panning" "&nbsp;</td><td>&lt;f-value&gt;</td></tr>"
  134. "<tr><td>" "/set_parameter_value" "&nbsp;</td><td>&lt;i-index&gt; &lt;f-value&gt;</td></tr>"
  135. "<tr><td>" "/set_parameter_midi_cc" "&nbsp;</td><td>&lt;i-index&gt; &lt;i-cc&gt;</td></tr>"
  136. "<tr><td>" "/set_parameter_midi_channel" "&nbsp;</td><td>&lt;i-index&gt; &lt;i-channel&gt;</td></tr>"
  137. "<tr><td>" "/set_program" "&nbsp;</td><td>&lt;i-index&gt;</td></tr>"
  138. "<tr><td>" "/set_midi_program" "&nbsp;</td><td>&lt;i-index&gt;</td></tr>"
  139. "<tr><td>" "/note_on" "&nbsp;</td><td>&lt;i-channel&gt; &lt;i-note&gt; &lt;i-velo&gt;</td></tr>"
  140. "<tr><td>" "/note_off" "&nbsp;</td><td>&lt;i-channel&gt; &lt;i-note</td></tr>"
  141. "</table>"
  142. )
  143. self.ui.l_example.setText("/Carla/2/set_parameter_value 5 1.0")
  144. self.ui.l_example_help.setText("<i>(as in this example, \"2\" is the plugin number and \"5\" the parameter)</i>")
  145. # pylint: enable=line-too-long
  146. self.ui.l_ladspa.setText(self.tr("Everything! (Including LRDF)"))
  147. self.ui.l_dssi.setText(self.tr("Everything! (Including CustomData/Chunks)"))
  148. self.ui.l_lv2.setText(self.tr("About 110&#37; complete (using custom extensions)<br/>"
  149. "Implemented Feature/Extensions:"
  150. "<ul>"
  151. "<li>http://lv2plug.in/ns/ext/atom</li>"
  152. "<li>http://lv2plug.in/ns/ext/buf-size</li>"
  153. "<li>http://lv2plug.in/ns/ext/data-access</li>"
  154. #"<li>http://lv2plug.in/ns/ext/dynmanifest</li>"
  155. "<li>http://lv2plug.in/ns/ext/event</li>"
  156. "<li>http://lv2plug.in/ns/ext/instance-access</li>"
  157. "<li>http://lv2plug.in/ns/ext/log</li>"
  158. "<li>http://lv2plug.in/ns/ext/midi</li>"
  159. #"<li>http://lv2plug.in/ns/ext/morph</li>"
  160. "<li>http://lv2plug.in/ns/ext/options</li>"
  161. "<li>http://lv2plug.in/ns/ext/parameters</li>"
  162. #"<li>http://lv2plug.in/ns/ext/patch</li>"
  163. "<li>http://lv2plug.in/ns/ext/port-props</li>"
  164. "<li>http://lv2plug.in/ns/ext/presets</li>"
  165. "<li>http://lv2plug.in/ns/ext/resize-port</li>"
  166. "<li>http://lv2plug.in/ns/ext/state</li>"
  167. "<li>http://lv2plug.in/ns/ext/time</li>"
  168. "<li>http://lv2plug.in/ns/ext/uri-map</li>"
  169. "<li>http://lv2plug.in/ns/ext/urid</li>"
  170. "<li>http://lv2plug.in/ns/ext/worker</li>"
  171. "<li>http://lv2plug.in/ns/extensions/ui</li>"
  172. "<li>http://lv2plug.in/ns/extensions/units</li>"
  173. "<li>http://home.gna.org/lv2dynparam/rtmempool/v1</li>"
  174. "<li>http://kxstudio.sf.net/ns/lv2ext/external-ui</li>"
  175. "<li>http://kxstudio.sf.net/ns/lv2ext/programs</li>"
  176. "<li>http://kxstudio.sf.net/ns/lv2ext/props</li>"
  177. "<li>http://kxstudio.sf.net/ns/lv2ext/rtmempool</li>"
  178. "<li>http://ll-plugins.nongnu.org/lv2/ext/midimap</li>"
  179. "<li>http://ll-plugins.nongnu.org/lv2/ext/miditype</li>"
  180. "</ul>"))
  181. usingJuce = "juce" in gCarla.utils.get_supported_features()
  182. if usingJuce and (MACOS or WINDOWS):
  183. self.ui.l_vst2.setText(self.tr("Using JUCE host"))
  184. else:
  185. self.ui.l_vst2.setText(self.tr("About 85&#37; complete (missing vst bank/presets and some minor stuff)"))
  186. if usingJuce:
  187. self.ui.l_vst3.setText(self.tr("Using JUCE host"))
  188. else:
  189. self.ui.line_vst2.hide()
  190. self.ui.l_vst3.hide()
  191. self.ui.lid_vst3.hide()
  192. if MACOS:
  193. self.ui.l_au.setText(self.tr("Using JUCE host"))
  194. else:
  195. self.ui.line_vst3.hide()
  196. self.ui.l_au.hide()
  197. self.ui.lid_au.hide()
  198. # 3rd tab is usually longer than the 1st
  199. # adjust appropriately
  200. self.ui.tabWidget.setCurrentIndex(2)
  201. self.adjustSize()
  202. self.ui.tabWidget.setCurrentIndex(0)
  203. self.setFixedSize(self.size())
  204. flags = self.windowFlags()
  205. flags &= ~Qt.WindowContextHelpButtonHint
  206. if WINDOWS:
  207. flags |= Qt.MSWindowsFixedSizeDialogHint
  208. self.setWindowFlags(flags)
  209. # ------------------------------------------------------------------------------------------------------------
  210. # JUCE About dialog
  211. class JuceAboutW(QDialog):
  212. def __init__(self, parent):
  213. QDialog.__init__(self, parent)
  214. self.ui = ui_carla_about_juce.Ui_JuceAboutW()
  215. self.ui.setupUi(self)
  216. self.ui.l_text2.setText(self.tr("This program uses JUCE version %s." % gCarla.utils.get_juce_version()))
  217. self.adjustSize()
  218. self.setFixedSize(self.size())
  219. flags = self.windowFlags()
  220. flags &= ~Qt.WindowContextHelpButtonHint
  221. if WINDOWS:
  222. flags |= Qt.MSWindowsFixedSizeDialogHint
  223. self.setWindowFlags(flags)
  224. # ------------------------------------------------------------------------------------------------------------
  225. # Plugin Parameter
  226. class PluginParameter(QWidget):
  227. mappedControlChanged = pyqtSignal(int, int)
  228. mappedRangeChanged = pyqtSignal(int, float, float)
  229. midiChannelChanged = pyqtSignal(int, int)
  230. valueChanged = pyqtSignal(int, float)
  231. def __init__(self, parent, host, pInfo, pluginId, tabIndex):
  232. QWidget.__init__(self, parent)
  233. self.host = host
  234. self.ui = ui_carla_parameter.Ui_PluginParameter()
  235. self.ui.setupUi(self)
  236. # -------------------------------------------------------------
  237. # Internal stuff
  238. self.fDecimalPoints = max(2, countDecimalPoints(pInfo['step'], pInfo['stepSmall']))
  239. self.fCanBeInCV = pInfo['hints'] & PARAMETER_CAN_BE_CV_CONTROLLED
  240. self.fMappedCtrl = pInfo['mappedControlIndex']
  241. self.fMappedMinimum = pInfo['mappedMinimum']
  242. self.fMappedMaximum = pInfo['mappedMaximum']
  243. self.fMinimum = pInfo['minimum']
  244. self.fMaximum = pInfo['maximum']
  245. self.fMidiChannel = pInfo['midiChannel']
  246. self.fParameterId = pInfo['index']
  247. self.fPluginId = pluginId
  248. self.fTabIndex = tabIndex
  249. # -------------------------------------------------------------
  250. # Set-up GUI
  251. pType = pInfo['type']
  252. pHints = pInfo['hints']
  253. self.ui.l_name.setText(pInfo['name'])
  254. self.ui.widget.setName(pInfo['name'])
  255. self.ui.widget.setMinimum(pInfo['minimum'])
  256. self.ui.widget.setMaximum(pInfo['maximum'])
  257. self.ui.widget.setDefault(pInfo['default'])
  258. self.ui.widget.setLabel(pInfo['unit'])
  259. self.ui.widget.setStep(pInfo['step'])
  260. self.ui.widget.setStepSmall(pInfo['stepSmall'])
  261. self.ui.widget.setStepLarge(pInfo['stepLarge'])
  262. self.ui.widget.setScalePoints(pInfo['scalePoints'], bool(pHints & PARAMETER_USES_SCALEPOINTS))
  263. if pInfo['comment']:
  264. self.ui.l_name.setToolTip(pInfo['comment'])
  265. self.ui.widget.setToolTip(pInfo['comment'])
  266. if pType == PARAMETER_INPUT:
  267. if not pHints & PARAMETER_IS_ENABLED:
  268. self.ui.l_name.setEnabled(False)
  269. self.ui.l_status.setEnabled(False)
  270. self.ui.widget.setEnabled(False)
  271. self.ui.widget.setReadOnly(True)
  272. self.ui.tb_options.setEnabled(False)
  273. elif not pHints & PARAMETER_IS_AUTOMABLE:
  274. self.ui.l_status.setEnabled(False)
  275. self.ui.tb_options.setEnabled(False)
  276. if pHints & PARAMETER_IS_READ_ONLY:
  277. self.ui.l_status.setEnabled(False)
  278. self.ui.widget.setReadOnly(True)
  279. self.ui.tb_options.setEnabled(False)
  280. elif pType == PARAMETER_OUTPUT:
  281. self.ui.widget.setReadOnly(True)
  282. else:
  283. self.ui.l_status.setVisible(False)
  284. self.ui.widget.setVisible(False)
  285. self.ui.tb_options.setVisible(False)
  286. # Only set value after all hints are handled
  287. self.ui.widget.setValue(pInfo['current'])
  288. if pHints & PARAMETER_USES_CUSTOM_TEXT and not host.isPlugin:
  289. self.ui.widget.setTextCallback(self._textCallBack)
  290. self.ui.l_status.setFixedWidth(fontMetricsHorizontalAdvance(self.ui.l_status.fontMetrics(),
  291. self.tr("CC%i Ch%i" % (119,16))))
  292. self.ui.widget.setValueCallback(self._valueCallBack)
  293. self.ui.widget.updateAll()
  294. self.setMappedControlIndex(pInfo['mappedControlIndex'])
  295. self.setMidiChannel(pInfo['midiChannel'])
  296. self.updateStatusLabel()
  297. # -------------------------------------------------------------
  298. # Set-up connections
  299. self.ui.tb_options.clicked.connect(self.slot_optionsCustomMenu)
  300. self.ui.widget.dragStateChanged.connect(self.slot_parameterDragStateChanged)
  301. # -------------------------------------------------------------
  302. def getPluginId(self):
  303. return self.fPluginId
  304. def getTabIndex(self):
  305. return self.fTabIndex
  306. def setPluginId(self, pluginId):
  307. self.fPluginId = pluginId
  308. def setDefault(self, value):
  309. self.ui.widget.setDefault(value)
  310. def setValue(self, value):
  311. self.ui.widget.blockSignals(True)
  312. self.ui.widget.setValue(value)
  313. self.ui.widget.blockSignals(False)
  314. def setMappedControlIndex(self, control):
  315. self.fMappedCtrl = control
  316. self.updateStatusLabel()
  317. def setMappedRange(self, minimum, maximum):
  318. self.fMappedMinimum = minimum
  319. self.fMappedMaximum = maximum
  320. def setMidiChannel(self, channel):
  321. self.fMidiChannel = channel
  322. self.updateStatusLabel()
  323. def setLabelWidth(self, width):
  324. self.ui.l_name.setFixedWidth(width)
  325. def updateStatusLabel(self):
  326. if self.fMappedCtrl == CONTROL_INDEX_NONE:
  327. text = self.tr("Unmapped")
  328. elif self.fMappedCtrl == CONTROL_INDEX_CV:
  329. text = self.tr("CV export")
  330. elif self.fMappedCtrl == CONTROL_INDEX_MIDI_PITCHBEND:
  331. text = self.tr("PBend Ch%i" % (self.fMidiChannel,))
  332. elif self.fMappedCtrl == CONTROL_INDEX_MIDI_LEARN:
  333. text = self.tr("MIDI Learn")
  334. else:
  335. text = self.tr("CC%i Ch%i" % (self.fMappedCtrl, self.fMidiChannel))
  336. self.ui.l_status.setText(text)
  337. @pyqtSlot()
  338. def slot_optionsCustomMenu(self):
  339. menu = QMenu(self)
  340. if self.fMappedCtrl == CONTROL_INDEX_NONE:
  341. title = self.tr("Unmapped")
  342. elif self.fMappedCtrl == CONTROL_INDEX_CV:
  343. title = self.tr("Exposed as CV port")
  344. elif self.fMappedCtrl == CONTROL_INDEX_MIDI_PITCHBEND:
  345. title = self.tr("Mapped to MIDI Pitchbend, channel %i" % (self.fMidiChannel,))
  346. elif self.fMappedCtrl == CONTROL_INDEX_MIDI_LEARN:
  347. title = self.tr("MIDI Learn active")
  348. else:
  349. title = self.tr("Mapped to MIDI control %i, channel %i" % (self.fMappedCtrl, self.fMidiChannel))
  350. if self.fMappedCtrl != CONTROL_INDEX_NONE:
  351. title += " (range: %g-%g)" % (self.fMappedMinimum, self.fMappedMaximum)
  352. actTitle = menu.addAction(title)
  353. actTitle.setEnabled(False)
  354. menu.addSeparator()
  355. actUnmap = menu.addAction(self.tr("Unmap"))
  356. if self.fMappedCtrl == CONTROL_INDEX_NONE:
  357. actUnmap.setCheckable(True)
  358. actUnmap.setChecked(True)
  359. if self.fCanBeInCV:
  360. menu.addSection("CV")
  361. actCV = menu.addAction(self.tr("Expose as CV port"))
  362. if self.fMappedCtrl == CONTROL_INDEX_CV:
  363. actCV.setCheckable(True)
  364. actCV.setChecked(True)
  365. else:
  366. actCV = None
  367. menu.addSection("MIDI")
  368. if not self.ui.widget.isReadOnly():
  369. actLearn = menu.addAction(self.tr("MIDI Learn"))
  370. if self.fMappedCtrl == CONTROL_INDEX_MIDI_LEARN:
  371. actLearn.setCheckable(True)
  372. actLearn.setChecked(True)
  373. else:
  374. actLearn = None
  375. menuMIDI = menu.addMenu(self.tr("MIDI Control"))
  376. if self.fMappedCtrl not in (CONTROL_INDEX_NONE,
  377. CONTROL_INDEX_CV,
  378. CONTROL_INDEX_MIDI_PITCHBEND,
  379. CONTROL_INDEX_MIDI_LEARN):
  380. action = menuMIDI.menuAction()
  381. action.setCheckable(True)
  382. action.setChecked(True)
  383. inlist = False
  384. actCCs = []
  385. for cc in MIDI_CC_LIST:
  386. action = menuMIDI.addAction(cc)
  387. actCCs.append(action)
  388. if self.fMappedCtrl >= 0 and self.fMappedCtrl <= MAX_MIDI_CC_LIST_ITEM:
  389. ccx = int(cc.split(" [", 1)[0], 10)
  390. if ccx > self.fMappedCtrl and not inlist:
  391. inlist = True
  392. action = menuMIDI.addAction(self.tr("%02i [0x%02X] (Custom)" % (self.fMappedCtrl,
  393. self.fMappedCtrl)))
  394. action.setCheckable(True)
  395. action.setChecked(True)
  396. actCCs.append(action)
  397. elif ccx == self.fMappedCtrl:
  398. inlist = True
  399. action.setCheckable(True)
  400. action.setChecked(True)
  401. if self.fMappedCtrl > MAX_MIDI_CC_LIST_ITEM and self.fMappedCtrl <= 0x77:
  402. action = menuMIDI.addAction(self.tr("%02i [0x%02X] (Custom)" % (self.fMappedCtrl, self.fMappedCtrl)))
  403. action.setCheckable(True)
  404. action.setChecked(True)
  405. actCCs.append(action)
  406. actCustomCC = menuMIDI.addAction(self.tr("Custom..."))
  407. # TODO
  408. #actPitchbend = menu.addAction(self.tr("MIDI Pitchbend"))
  409. #if self.fMappedCtrl == CONTROL_INDEX_MIDI_PITCHBEND:
  410. #actPitchbend.setCheckable(True)
  411. #actPitchbend.setChecked(True)
  412. menuChannel = menu.addMenu(self.tr("MIDI Channel"))
  413. actChannels = []
  414. for i in range(1, 16+1):
  415. action = menuChannel.addAction("%i" % i)
  416. actChannels.append(action)
  417. if self.fMidiChannel == i:
  418. action.setCheckable(True)
  419. action.setChecked(True)
  420. if self.fMappedCtrl != CONTROL_INDEX_NONE:
  421. if self.fMappedCtrl == CONTROL_INDEX_CV:
  422. menu.addSection("Range (Scaled CV input)")
  423. else:
  424. menu.addSection("Range (MIDI bounds)")
  425. actRangeMinimum = menu.addAction(self.tr("Set minimum... (%g)" % self.fMappedMinimum))
  426. actRangeMaximum = menu.addAction(self.tr("Set maximum... (%g)" % self.fMappedMaximum))
  427. else:
  428. actRangeMinimum = actRangeMaximum = None
  429. actSel = menu.exec_(QCursor.pos())
  430. if not actSel:
  431. return
  432. if actSel in actChannels:
  433. channel = int(actSel.text())
  434. self.fMidiChannel = channel
  435. self.updateStatusLabel()
  436. self.midiChannelChanged.emit(self.fParameterId, channel)
  437. return
  438. if actSel == actRangeMinimum:
  439. value, ok = QInputDialog.getDouble(self,
  440. self.tr("Custom Minimum"),
  441. "Custom minimum value to use:",
  442. self.fMappedMinimum,
  443. self.fMinimum if self.fMappedCtrl != CONTROL_INDEX_CV else -9e6,
  444. self.fMaximum if self.fMappedCtrl != CONTROL_INDEX_CV else 9e6,
  445. self.fDecimalPoints)
  446. if not ok:
  447. return
  448. self.fMappedMinimum = value
  449. self.mappedRangeChanged.emit(self.fParameterId, self.fMappedMinimum, self.fMappedMaximum)
  450. return
  451. if actSel == actRangeMaximum:
  452. value, ok = QInputDialog.getDouble(self,
  453. self.tr("Custom Maximum"),
  454. "Custom maximum value to use:",
  455. self.fMappedMaximum,
  456. self.fMinimum if self.fMappedCtrl != CONTROL_INDEX_CV else -9e6,
  457. self.fMaximum if self.fMappedCtrl != CONTROL_INDEX_CV else 9e6,
  458. self.fDecimalPoints)
  459. if not ok:
  460. return
  461. self.fMappedMaximum = value
  462. self.mappedRangeChanged.emit(self.fParameterId, self.fMappedMinimum, self.fMappedMaximum)
  463. return
  464. if actSel == actUnmap:
  465. ctrl = CONTROL_INDEX_NONE
  466. elif actSel == actCV:
  467. ctrl = CONTROL_INDEX_CV
  468. elif actSel == actCustomCC:
  469. value = self.fMappedCtrl if self.fMappedCtrl >= 0x01 and self.fMappedCtrl <= 0x77 else 1
  470. ctrl, ok = QInputDialog.getInt(self,
  471. self.tr("Custom CC"),
  472. "Custom MIDI CC to use:",
  473. value,
  474. 0x01, 0x77, 1)
  475. if not ok:
  476. return
  477. #elif actSel == actPitchbend:
  478. #ctrl = CONTROL_INDEX_MIDI_PITCHBEND
  479. elif actSel == actLearn:
  480. ctrl = CONTROL_INDEX_MIDI_LEARN
  481. elif actSel in actCCs:
  482. ctrl = int(actSel.text().split(" ", 1)[0].replace("&",""), 10)
  483. else:
  484. return
  485. self.fMappedCtrl = ctrl
  486. self.updateStatusLabel()
  487. self.mappedControlChanged.emit(self.fParameterId, ctrl)
  488. @pyqtSlot(bool)
  489. def slot_parameterDragStateChanged(self, touch):
  490. self.host.set_parameter_touch(self.fPluginId, self.fParameterId, touch)
  491. def _textCallBack(self):
  492. return self.host.get_parameter_text(self.fPluginId, self.fParameterId)
  493. def _valueCallBack(self, value):
  494. self.valueChanged.emit(self.fParameterId, value)
  495. # ------------------------------------------------------------------------------------------------------------
  496. # Plugin Editor Parent (Meta class)
  497. class PluginEditParentMeta():
  498. #class PluginEditParentMeta(metaclass=ABCMeta):
  499. @abstractmethod
  500. def editDialogVisibilityChanged(self, pluginId, visible):
  501. raise NotImplementedError
  502. @abstractmethod
  503. def editDialogPluginHintsChanged(self, pluginId, hints):
  504. raise NotImplementedError
  505. @abstractmethod
  506. def editDialogParameterValueChanged(self, pluginId, parameterId, value):
  507. raise NotImplementedError
  508. @abstractmethod
  509. def editDialogProgramChanged(self, pluginId, index):
  510. raise NotImplementedError
  511. @abstractmethod
  512. def editDialogMidiProgramChanged(self, pluginId, index):
  513. raise NotImplementedError
  514. @abstractmethod
  515. def editDialogNotePressed(self, pluginId, note):
  516. raise NotImplementedError
  517. @abstractmethod
  518. def editDialogNoteReleased(self, pluginId, note):
  519. raise NotImplementedError
  520. @abstractmethod
  521. def editDialogMidiActivityChanged(self, pluginId, onOff):
  522. raise NotImplementedError
  523. # ------------------------------------------------------------------------------------------------------------
  524. # Plugin Editor (Built-in)
  525. class PluginEdit(QDialog):
  526. # signals
  527. SIGTERM = pyqtSignal()
  528. SIGUSR1 = pyqtSignal()
  529. def __init__(self, parent, host, pluginId):
  530. QDialog.__init__(self, parent.window() if parent is not None else None)
  531. self.host = host
  532. self.ui = ui_carla_edit.Ui_PluginEdit()
  533. self.ui.setupUi(self)
  534. # -------------------------------------------------------------
  535. # Internal stuff
  536. self.fGeometry = QByteArray()
  537. self.fParent = parent
  538. self.fPluginId = pluginId
  539. self.fPluginInfo = None
  540. self.fCurrentStateFilename = None
  541. self.fControlChannel = round(host.get_internal_parameter_value(pluginId, PARAMETER_CTRL_CHANNEL))
  542. self.fFirstInit = True
  543. self.fParameterList = [] # (type, id, widget)
  544. self.fParametersToUpdate = [] # (id, value)
  545. self.fPlayingNotes = [] # (channel, note)
  546. self.fTabIconOff = QIcon(":/scalable/led_off.svg")
  547. self.fTabIconOn = QIcon(":/scalable/led_yellow.svg")
  548. self.fTabIconTimers = []
  549. # used during testing
  550. self.fIdleTimerId = 0
  551. # -------------------------------------------------------------
  552. # Set-up GUI
  553. labelPluginFont = self.ui.label_plugin.font()
  554. labelPluginFont.setPixelSize(15)
  555. labelPluginFont.setWeight(75)
  556. self.ui.label_plugin.setFont(labelPluginFont)
  557. self.ui.dial_drywet.setCustomPaintMode(self.ui.dial_drywet.CUSTOM_PAINT_MODE_CARLA_WET)
  558. self.ui.dial_drywet.setImage(3)
  559. self.ui.dial_drywet.setLabel("Dry/Wet")
  560. self.ui.dial_drywet.setMinimum(0.0)
  561. self.ui.dial_drywet.setMaximum(1.0)
  562. self.ui.dial_drywet.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_DRYWET))
  563. self.ui.dial_vol.setCustomPaintMode(self.ui.dial_vol.CUSTOM_PAINT_MODE_CARLA_VOL)
  564. self.ui.dial_vol.setImage(3)
  565. self.ui.dial_vol.setLabel("Volume")
  566. self.ui.dial_vol.setMinimum(0.0)
  567. self.ui.dial_vol.setMaximum(1.27)
  568. self.ui.dial_vol.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_VOLUME))
  569. self.ui.dial_b_left.setCustomPaintMode(self.ui.dial_b_left.CUSTOM_PAINT_MODE_CARLA_L)
  570. self.ui.dial_b_left.setImage(4)
  571. self.ui.dial_b_left.setLabel("L")
  572. self.ui.dial_b_left.setMinimum(-1.0)
  573. self.ui.dial_b_left.setMaximum(1.0)
  574. self.ui.dial_b_left.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_LEFT))
  575. self.ui.dial_b_right.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_R)
  576. self.ui.dial_b_right.setImage(4)
  577. self.ui.dial_b_right.setLabel("R")
  578. self.ui.dial_b_right.setMinimum(-1.0)
  579. self.ui.dial_b_right.setMaximum(1.0)
  580. self.ui.dial_b_right.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_BALANCE_RIGHT))
  581. self.ui.dial_pan.setCustomPaintMode(self.ui.dial_b_right.CUSTOM_PAINT_MODE_CARLA_PAN)
  582. self.ui.dial_pan.setImage(4)
  583. self.ui.dial_pan.setLabel("Pan")
  584. self.ui.dial_pan.setMinimum(-1.0)
  585. self.ui.dial_pan.setMaximum(1.0)
  586. self.ui.dial_pan.setValue(host.get_internal_parameter_value(pluginId, PARAMETER_PANNING))
  587. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  588. self.ui.scrollArea = PixmapKeyboardHArea(self)
  589. self.ui.keyboard = self.ui.scrollArea.keyboard
  590. self.ui.keyboard.setEnabled(self.fControlChannel >= 0)
  591. self.layout().addWidget(self.ui.scrollArea)
  592. self.ui.scrollArea.setEnabled(False)
  593. self.ui.scrollArea.setVisible(False)
  594. # todo
  595. self.ui.rb_balance.setEnabled(False)
  596. self.ui.rb_balance.setVisible(False)
  597. self.ui.rb_pan.setEnabled(False)
  598. self.ui.rb_pan.setVisible(False)
  599. self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
  600. self.reloadAll()
  601. self.fFirstInit = False
  602. # -------------------------------------------------------------
  603. # Set-up connections
  604. self.finished.connect(self.slot_finished)
  605. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  606. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  607. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  608. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  609. self.ui.ch_send_notes.clicked.connect(self.slot_optionChanged)
  610. self.ui.ch_send_program_changes.clicked.connect(self.slot_optionChanged)
  611. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  612. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  613. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  614. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  615. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  616. self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged)
  617. self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged)
  618. self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged)
  619. self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged)
  620. self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged)
  621. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  622. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  623. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  624. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  625. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  626. self.ui.dial_pan.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  627. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  628. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  629. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  630. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  631. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  632. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  633. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  634. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  635. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  636. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  637. host.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  638. host.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  639. host.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  640. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  641. #------------------------------------------------------------------
  642. @pyqtSlot(int, int, int, int)
  643. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  644. if self.fPluginId != pluginId:
  645. return
  646. if self.fControlChannel == channel:
  647. self.ui.keyboard.sendNoteOn(note, False)
  648. playItem = (channel, note)
  649. if playItem not in self.fPlayingNotes:
  650. self.fPlayingNotes.append(playItem)
  651. if len(self.fPlayingNotes) == 1 and self.fParent is not None:
  652. self.fParent.editDialogMidiActivityChanged(self.fPluginId, True)
  653. @pyqtSlot(int, int, int)
  654. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  655. if self.fPluginId != pluginId:
  656. return
  657. if self.fControlChannel == channel:
  658. self.ui.keyboard.sendNoteOff(note, False)
  659. playItem = (channel, note)
  660. if playItem in self.fPlayingNotes:
  661. self.fPlayingNotes.remove(playItem)
  662. if self.fPlayingNotes and self.fParent is not None:
  663. self.fParent.editDialogMidiActivityChanged(self.fPluginId, False)
  664. @pyqtSlot(int)
  665. def slot_handleUpdateCallback(self, pluginId):
  666. if self.fPluginId == pluginId:
  667. self.updateInfo()
  668. @pyqtSlot(int)
  669. def slot_handleReloadInfoCallback(self, pluginId):
  670. if self.fPluginId == pluginId:
  671. self.reloadInfo()
  672. @pyqtSlot(int)
  673. def slot_handleReloadParametersCallback(self, pluginId):
  674. if self.fPluginId == pluginId:
  675. self.reloadParameters()
  676. @pyqtSlot(int)
  677. def slot_handleReloadProgramsCallback(self, pluginId):
  678. if self.fPluginId == pluginId:
  679. self.reloadPrograms()
  680. @pyqtSlot(int)
  681. def slot_handleReloadAllCallback(self, pluginId):
  682. if self.fPluginId == pluginId:
  683. self.reloadAll()
  684. #------------------------------------------------------------------
  685. def updateInfo(self):
  686. # Update current program text
  687. if self.ui.cb_programs.count() > 0:
  688. pIndex = self.ui.cb_programs.currentIndex()
  689. if pIndex >= 0:
  690. pName = self.host.get_program_name(self.fPluginId, pIndex)
  691. #pName = pName[:40] + (pName[40:] and "...")
  692. self.ui.cb_programs.setItemText(pIndex, pName)
  693. # Update current midi program text
  694. if self.ui.cb_midi_programs.count() > 0:
  695. mpIndex = self.ui.cb_midi_programs.currentIndex()
  696. if mpIndex >= 0:
  697. mpData = self.host.get_midi_program_data(self.fPluginId, mpIndex)
  698. mpBank = mpData['bank']
  699. mpProg = mpData['program']
  700. mpName = mpData['name']
  701. #mpName = mpName[:40] + (mpName[40:] and "...")
  702. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  703. # Update all parameter values
  704. for _, paramId, paramWidget in self.fParameterList:
  705. paramWidget.blockSignals(True)
  706. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  707. paramWidget.blockSignals(False)
  708. # and the internal ones too
  709. self.ui.dial_drywet.blockSignals(True)
  710. self.ui.dial_drywet.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_DRYWET))
  711. self.ui.dial_drywet.blockSignals(False)
  712. self.ui.dial_vol.blockSignals(True)
  713. self.ui.dial_vol.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_VOLUME))
  714. self.ui.dial_vol.blockSignals(False)
  715. self.ui.dial_b_left.blockSignals(True)
  716. self.ui.dial_b_left.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_BALANCE_LEFT))
  717. self.ui.dial_b_left.blockSignals(False)
  718. self.ui.dial_b_right.blockSignals(True)
  719. self.ui.dial_b_right.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_BALANCE_RIGHT))
  720. self.ui.dial_b_right.blockSignals(False)
  721. self.ui.dial_pan.blockSignals(True)
  722. self.ui.dial_pan.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_PANNING))
  723. self.ui.dial_pan.blockSignals(False)
  724. self.fControlChannel = round(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_CTRL_CHANNEL))
  725. self.ui.sb_ctrl_channel.blockSignals(True)
  726. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  727. self.ui.sb_ctrl_channel.blockSignals(False)
  728. self.ui.keyboard.allNotesOff()
  729. self._updateCtrlPrograms()
  730. self.fParametersToUpdate = []
  731. #------------------------------------------------------------------
  732. def reloadAll(self):
  733. self.fPluginInfo = self.host.get_plugin_info(self.fPluginId)
  734. self.reloadInfo()
  735. self.reloadParameters()
  736. self.reloadPrograms()
  737. if self.fPluginInfo['type'] == PLUGIN_LV2:
  738. self.ui.b_save_state.setEnabled(False)
  739. if not self.ui.scrollArea.isEnabled():
  740. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  741. #------------------------------------------------------------------
  742. def reloadInfo(self):
  743. realPluginName = self.host.get_real_plugin_name(self.fPluginId)
  744. #audioCountInfo = self.host.get_audio_port_count_info(self.fPluginId)
  745. midiCountInfo = self.host.get_midi_port_count_info(self.fPluginId)
  746. #paramCountInfo = self.host.get_parameter_count_info(self.fPluginId)
  747. pluginHints = self.fPluginInfo['hints']
  748. self.ui.le_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  749. self.ui.label_name.setEnabled(bool(realPluginName))
  750. self.ui.le_name.setEnabled(bool(realPluginName))
  751. self.ui.le_name.setText(realPluginName)
  752. self.ui.le_name.setToolTip(realPluginName)
  753. self.ui.label_label.setEnabled(bool(self.fPluginInfo['label']))
  754. self.ui.le_label.setEnabled(bool(self.fPluginInfo['label']))
  755. self.ui.le_label.setText(self.fPluginInfo['label'])
  756. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  757. self.ui.label_maker.setEnabled(bool(self.fPluginInfo['maker']))
  758. self.ui.le_maker.setEnabled(bool(self.fPluginInfo['maker']))
  759. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  760. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  761. self.ui.label_copyright.setEnabled(bool(self.fPluginInfo['copyright']))
  762. self.ui.le_copyright.setEnabled(bool(self.fPluginInfo['copyright']))
  763. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  764. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  765. self.ui.label_unique_id.setEnabled(bool(self.fPluginInfo['uniqueId']))
  766. self.ui.le_unique_id.setEnabled(bool(self.fPluginInfo['uniqueId']))
  767. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  768. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  769. self.ui.label_plugin.setText("\n%s\n" % (self.fPluginInfo['name'] or "(none)"))
  770. self.setWindowTitle(self.fPluginInfo['name'] or "(none)")
  771. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  772. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  773. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  774. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  775. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  776. optsAvailable = self.fPluginInfo['optionsAvailable']
  777. optsEnabled = self.fPluginInfo['optionsEnabled']
  778. self.ui.ch_use_chunks.setEnabled(optsAvailable & PLUGIN_OPTION_USE_CHUNKS)
  779. self.ui.ch_use_chunks.setChecked(optsEnabled & PLUGIN_OPTION_USE_CHUNKS)
  780. self.ui.ch_fixed_buffer.setEnabled(optsAvailable & PLUGIN_OPTION_FIXED_BUFFERS)
  781. self.ui.ch_fixed_buffer.setChecked(optsEnabled & PLUGIN_OPTION_FIXED_BUFFERS)
  782. self.ui.ch_force_stereo.setEnabled(optsAvailable & PLUGIN_OPTION_FORCE_STEREO)
  783. self.ui.ch_force_stereo.setChecked(optsEnabled & PLUGIN_OPTION_FORCE_STEREO)
  784. self.ui.ch_map_program_changes.setEnabled(optsAvailable & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  785. self.ui.ch_map_program_changes.setChecked(optsEnabled & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  786. self.ui.ch_send_notes.setEnabled(optsAvailable & PLUGIN_OPTION_SKIP_SENDING_NOTES)
  787. self.ui.ch_send_notes.setChecked((self.ui.ch_send_notes.isEnabled() and
  788. (optsEnabled & PLUGIN_OPTION_SKIP_SENDING_NOTES) == 0x0))
  789. self.ui.ch_send_control_changes.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  790. self.ui.ch_send_control_changes.setChecked(optsEnabled & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  791. self.ui.ch_send_channel_pressure.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  792. self.ui.ch_send_channel_pressure.setChecked(optsEnabled & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  793. self.ui.ch_send_note_aftertouch.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  794. self.ui.ch_send_note_aftertouch.setChecked(optsEnabled & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  795. self.ui.ch_send_pitchbend.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_PITCHBEND)
  796. self.ui.ch_send_pitchbend.setChecked(optsEnabled & PLUGIN_OPTION_SEND_PITCHBEND)
  797. self.ui.ch_send_all_sound_off.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  798. self.ui.ch_send_all_sound_off.setChecked(optsEnabled & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  799. canSendPrograms = bool((optsAvailable & PLUGIN_OPTION_SEND_PROGRAM_CHANGES) != 0 and
  800. (optsEnabled & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) == 0)
  801. self.ui.ch_send_program_changes.setEnabled(canSendPrograms)
  802. self.ui.ch_send_program_changes.setChecked(optsEnabled & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  803. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] in (PLUGIN_VST2, PLUGIN_SFZ) else 1)
  804. # Show/hide keyboard
  805. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0)
  806. self.ui.scrollArea.setEnabled(showKeyboard)
  807. self.ui.scrollArea.setVisible(showKeyboard)
  808. # Force-update parent for new hints
  809. if self.fParent is not None and not self.fFirstInit:
  810. self.fParent.editDialogPluginHintsChanged(self.fPluginId, pluginHints)
  811. def reloadParameters(self):
  812. # Reset
  813. self.fParameterList = []
  814. self.fParametersToUpdate = []
  815. self.fTabIconTimers = []
  816. # Save current tab state
  817. tabIndex = self.ui.tabWidget.currentIndex()
  818. tabWidget = self.ui.tabWidget.currentWidget()
  819. scrollVal = tabWidget.verticalScrollBar().value() if isinstance(tabWidget, QScrollArea) else None
  820. del tabWidget
  821. # Remove all previous parameters
  822. for _ in range(self.ui.tabWidget.count()-1):
  823. self.ui.tabWidget.widget(1).deleteLater()
  824. self.ui.tabWidget.removeTab(1)
  825. parameterCount = self.host.get_parameter_count(self.fPluginId)
  826. # -----------------------------------------------------------------
  827. if parameterCount <= 0:
  828. return
  829. # -----------------------------------------------------------------
  830. paramInputList = []
  831. paramOutputList = []
  832. paramInputWidth = 0
  833. paramOutputWidth = 0
  834. paramInputListFull = [] # ([params], width)
  835. paramOutputListFull = [] # ([params], width)
  836. for i in range(min(parameterCount, self.host.maxParameters)):
  837. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  838. paramData = self.host.get_parameter_data(self.fPluginId, i)
  839. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  840. paramValue = self.host.get_current_parameter_value(self.fPluginId, i)
  841. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  842. continue
  843. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  844. continue
  845. parameter = {
  846. 'type': paramData['type'],
  847. 'hints': paramData['hints'],
  848. 'name': paramInfo['name'],
  849. 'unit': paramInfo['unit'],
  850. 'scalePoints': [],
  851. 'index': paramData['index'],
  852. 'default': paramRanges['def'],
  853. 'minimum': paramRanges['min'],
  854. 'maximum': paramRanges['max'],
  855. 'step': paramRanges['step'],
  856. 'stepSmall': paramRanges['stepSmall'],
  857. 'stepLarge': paramRanges['stepLarge'],
  858. 'mappedControlIndex': paramData['mappedControlIndex'],
  859. 'mappedMinimum': paramData['mappedMinimum'],
  860. 'mappedMaximum': paramData['mappedMaximum'],
  861. 'midiChannel': paramData['midiChannel']+1,
  862. 'comment': paramInfo['comment'],
  863. 'groupName': paramInfo['groupName'],
  864. 'current': paramValue
  865. }
  866. for j in range(paramInfo['scalePointCount']):
  867. scalePointInfo = self.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  868. parameter['scalePoints'].append({
  869. 'value': scalePointInfo['value'],
  870. 'label': scalePointInfo['label']
  871. })
  872. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  873. # -----------------------------------------------------------------
  874. # Get width values, in packs of 20
  875. if parameter['type'] == PARAMETER_INPUT:
  876. paramInputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])
  877. if paramInputWidthTMP > paramInputWidth:
  878. paramInputWidth = paramInputWidthTMP
  879. paramInputList.append(parameter)
  880. else:
  881. paramOutputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])
  882. if paramOutputWidthTMP > paramOutputWidth:
  883. paramOutputWidth = paramOutputWidthTMP
  884. paramOutputList.append(parameter)
  885. paramInputListFull.append((paramInputList, paramInputWidth))
  886. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  887. # Create parameter tabs + widgets
  888. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  889. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  890. # Restore tab state
  891. if tabIndex < self.ui.tabWidget.count():
  892. self.ui.tabWidget.setCurrentIndex(tabIndex)
  893. if scrollVal is not None:
  894. self.ui.tabWidget.currentWidget().verticalScrollBar().setValue(scrollVal)
  895. def reloadPrograms(self):
  896. # Programs
  897. self.ui.cb_programs.blockSignals(True)
  898. self.ui.cb_programs.clear()
  899. programCount = self.host.get_program_count(self.fPluginId)
  900. if programCount > 0:
  901. self.ui.cb_programs.setEnabled(True)
  902. self.ui.label_programs.setEnabled(True)
  903. for i in range(programCount):
  904. pName = self.host.get_program_name(self.fPluginId, i)
  905. #pName = pName[:40] + (pName[40:] and "...")
  906. self.ui.cb_programs.addItem(pName)
  907. self.ui.cb_programs.setCurrentIndex(self.host.get_current_program_index(self.fPluginId))
  908. else:
  909. self.ui.cb_programs.setEnabled(False)
  910. self.ui.label_programs.setEnabled(False)
  911. self.ui.cb_programs.blockSignals(False)
  912. # MIDI Programs
  913. self.ui.cb_midi_programs.blockSignals(True)
  914. self.ui.cb_midi_programs.clear()
  915. midiProgramCount = self.host.get_midi_program_count(self.fPluginId)
  916. if midiProgramCount > 0:
  917. self.ui.cb_midi_programs.setEnabled(True)
  918. self.ui.label_midi_programs.setEnabled(True)
  919. for i in range(midiProgramCount):
  920. mpData = self.host.get_midi_program_data(self.fPluginId, i)
  921. mpBank = mpData['bank']
  922. mpProg = mpData['program']
  923. mpName = mpData['name']
  924. #mpName = mpName[:40] + (mpName[40:] and "...")
  925. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  926. self.ui.cb_midi_programs.setCurrentIndex(self.host.get_current_midi_program_index(self.fPluginId))
  927. else:
  928. self.ui.cb_midi_programs.setEnabled(False)
  929. self.ui.label_midi_programs.setEnabled(False)
  930. self.ui.cb_midi_programs.blockSignals(False)
  931. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  932. if self.fPluginInfo['type'] == PLUGIN_LV2:
  933. self.ui.b_load_state.setEnabled(programCount > 0)
  934. #------------------------------------------------------------------
  935. def clearNotes(self):
  936. self.fPlayingNotes = []
  937. self.ui.keyboard.allNotesOff()
  938. def noteOn(self, channel, note, velocity):
  939. if self.fControlChannel == channel:
  940. self.ui.keyboard.sendNoteOn(note, False)
  941. def noteOff(self, channel, note):
  942. if self.fControlChannel == channel:
  943. self.ui.keyboard.sendNoteOff(note, False)
  944. #------------------------------------------------------------------
  945. def getHints(self):
  946. return self.fPluginInfo['hints']
  947. def setPluginId(self, idx):
  948. self.fPluginId = idx
  949. def setName(self, name):
  950. self.fPluginInfo['name'] = name
  951. self.ui.label_plugin.setText("\n%s\n" % name)
  952. self.setWindowTitle(name)
  953. #------------------------------------------------------------------
  954. def setParameterValue(self, parameterId, value):
  955. for paramItem in self.fParametersToUpdate:
  956. if paramItem[0] == parameterId:
  957. paramItem[1] = value
  958. break
  959. else:
  960. self.fParametersToUpdate.append([parameterId, value])
  961. def setParameterDefault(self, parameterId, value):
  962. for _, paramId, paramWidget in self.fParameterList:
  963. if paramId == parameterId:
  964. paramWidget.setDefault(value)
  965. break
  966. def setParameterMappedControlIndex(self, parameterId, control):
  967. for _, paramId, paramWidget in self.fParameterList:
  968. if paramId == parameterId:
  969. paramWidget.setMappedControlIndex(control)
  970. break
  971. def setParameterMappedRange(self, parameterId, minimum, maximum):
  972. for _, paramId, paramWidget in self.fParameterList:
  973. if paramId == parameterId:
  974. paramWidget.setMappedRange(minimum, maximum)
  975. break
  976. def setParameterMidiChannel(self, parameterId, channel):
  977. for _, paramId, paramWidget in self.fParameterList:
  978. if paramId == parameterId:
  979. paramWidget.setMidiChannel(channel+1)
  980. break
  981. def setProgram(self, index):
  982. self.ui.cb_programs.blockSignals(True)
  983. self.ui.cb_programs.setCurrentIndex(index)
  984. self.ui.cb_programs.blockSignals(False)
  985. self._updateParameterValues()
  986. def setMidiProgram(self, index):
  987. self.ui.cb_midi_programs.blockSignals(True)
  988. self.ui.cb_midi_programs.setCurrentIndex(index)
  989. self.ui.cb_midi_programs.blockSignals(False)
  990. self._updateParameterValues()
  991. def setOption(self, option, yesNo):
  992. if option == PLUGIN_OPTION_USE_CHUNKS:
  993. widget = self.ui.ch_use_chunks
  994. elif option == PLUGIN_OPTION_FIXED_BUFFERS:
  995. widget = self.ui.ch_fixed_buffer
  996. elif option == PLUGIN_OPTION_FORCE_STEREO:
  997. widget = self.ui.ch_force_stereo
  998. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  999. widget = self.ui.ch_map_program_changes
  1000. elif option == PLUGIN_OPTION_SKIP_SENDING_NOTES:
  1001. widget = self.ui.ch_send_notes
  1002. yesNo = not yesNo
  1003. elif option == PLUGIN_OPTION_SEND_PROGRAM_CHANGES:
  1004. widget = self.ui.ch_send_program_changes
  1005. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  1006. widget = self.ui.ch_send_control_changes
  1007. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  1008. widget = self.ui.ch_send_channel_pressure
  1009. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  1010. widget = self.ui.ch_send_note_aftertouch
  1011. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  1012. widget = self.ui.ch_send_pitchbend
  1013. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  1014. widget = self.ui.ch_send_all_sound_off
  1015. else:
  1016. return
  1017. widget.blockSignals(True)
  1018. widget.setChecked(yesNo)
  1019. widget.blockSignals(False)
  1020. #------------------------------------------------------------------
  1021. def setVisible(self, yesNo):
  1022. if yesNo:
  1023. if not self.fGeometry.isNull():
  1024. self.restoreGeometry(self.fGeometry)
  1025. else:
  1026. self.fGeometry = self.saveGeometry()
  1027. QDialog.setVisible(self, yesNo)
  1028. #------------------------------------------------------------------
  1029. def idleSlow(self):
  1030. # Check Tab icons
  1031. for i in range(len(self.fTabIconTimers)):
  1032. if self.fTabIconTimers[i] == ICON_STATE_ON:
  1033. self.fTabIconTimers[i] = ICON_STATE_WAIT
  1034. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  1035. self.fTabIconTimers[i] = ICON_STATE_OFF
  1036. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  1037. self.fTabIconTimers[i] = ICON_STATE_NULL
  1038. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  1039. # Check parameters needing update
  1040. for index, value in self.fParametersToUpdate:
  1041. if index == PARAMETER_DRYWET:
  1042. self.ui.dial_drywet.blockSignals(True)
  1043. self.ui.dial_drywet.setValue(value)
  1044. self.ui.dial_drywet.blockSignals(False)
  1045. elif index == PARAMETER_VOLUME:
  1046. self.ui.dial_vol.blockSignals(True)
  1047. self.ui.dial_vol.setValue(value)
  1048. self.ui.dial_vol.blockSignals(False)
  1049. elif index == PARAMETER_BALANCE_LEFT:
  1050. self.ui.dial_b_left.blockSignals(True)
  1051. self.ui.dial_b_left.setValue(value)
  1052. self.ui.dial_b_left.blockSignals(False)
  1053. elif index == PARAMETER_BALANCE_RIGHT:
  1054. self.ui.dial_b_right.blockSignals(True)
  1055. self.ui.dial_b_right.setValue(value)
  1056. self.ui.dial_b_right.blockSignals(False)
  1057. elif index == PARAMETER_PANNING:
  1058. self.ui.dial_pan.blockSignals(True)
  1059. self.ui.dial_pan.setValue(value)
  1060. self.ui.dial_pan.blockSignals(False)
  1061. elif index == PARAMETER_CTRL_CHANNEL:
  1062. self.fControlChannel = round(value)
  1063. self.ui.sb_ctrl_channel.blockSignals(True)
  1064. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  1065. self.ui.sb_ctrl_channel.blockSignals(False)
  1066. self.ui.keyboard.allNotesOff()
  1067. self._updateCtrlPrograms()
  1068. elif index >= 0:
  1069. for paramType, paramId, paramWidget in self.fParameterList:
  1070. if paramId != index:
  1071. continue
  1072. # FIXME see below
  1073. if paramType != PARAMETER_INPUT:
  1074. continue
  1075. paramWidget.blockSignals(True)
  1076. paramWidget.setValue(value)
  1077. paramWidget.blockSignals(False)
  1078. #if paramType == PARAMETER_INPUT:
  1079. tabIndex = paramWidget.getTabIndex()
  1080. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  1081. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  1082. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  1083. break
  1084. # Clear all parameters
  1085. self.fParametersToUpdate = []
  1086. # Update parameter outputs | FIXME needed?
  1087. for paramType, paramId, paramWidget in self.fParameterList:
  1088. if paramType != PARAMETER_OUTPUT:
  1089. continue
  1090. paramWidget.blockSignals(True)
  1091. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  1092. paramWidget.blockSignals(False)
  1093. #------------------------------------------------------------------
  1094. @pyqtSlot()
  1095. def slot_stateSave(self):
  1096. if self.fPluginInfo['type'] == PLUGIN_LV2:
  1097. # TODO
  1098. return
  1099. if self.fCurrentStateFilename:
  1100. askTry = QMessageBox.question(self,
  1101. self.tr("Overwrite?"),
  1102. self.tr("Overwrite previously created file?"),
  1103. QMessageBox.Ok|QMessageBox.Cancel)
  1104. if askTry == QMessageBox.Ok:
  1105. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1106. return
  1107. self.fCurrentStateFilename = None
  1108. fileFilter = self.tr("Carla State File (*.carxs)")
  1109. filename, _ = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  1110. # FIXME use ok value, test if it works as expected
  1111. if not filename:
  1112. return
  1113. if not filename.lower().endswith(".carxs"):
  1114. filename += ".carxs"
  1115. self.fCurrentStateFilename = filename
  1116. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1117. @pyqtSlot()
  1118. def slot_stateLoad(self):
  1119. if self.fPluginInfo['type'] == PLUGIN_LV2:
  1120. presetList = []
  1121. for i in range(self.host.get_program_count(self.fPluginId)):
  1122. presetList.append("%03i - %s" % (i+1, self.host.get_program_name(self.fPluginId, i)))
  1123. ret = QInputDialog.getItem(self,
  1124. self.tr("Open LV2 Preset"),
  1125. self.tr("Select an LV2 Preset:"),
  1126. presetList, 0, False)
  1127. if ret[1]:
  1128. index = int(ret[0].split(" - ", 1)[0])-1
  1129. self.host.set_program(self.fPluginId, index)
  1130. self.setMidiProgram(-1)
  1131. return
  1132. fileFilter = self.tr("Carla State File (*.carxs)")
  1133. filename, _ = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  1134. # FIXME use ok value, test if it works as expected
  1135. if not filename:
  1136. return
  1137. self.fCurrentStateFilename = filename
  1138. self.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1139. #------------------------------------------------------------------
  1140. @pyqtSlot(bool)
  1141. def slot_optionChanged(self, clicked):
  1142. sender = self.sender()
  1143. if sender == self.ui.ch_use_chunks:
  1144. option = PLUGIN_OPTION_USE_CHUNKS
  1145. elif sender == self.ui.ch_fixed_buffer:
  1146. option = PLUGIN_OPTION_FIXED_BUFFERS
  1147. elif sender == self.ui.ch_force_stereo:
  1148. option = PLUGIN_OPTION_FORCE_STEREO
  1149. elif sender == self.ui.ch_map_program_changes:
  1150. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  1151. elif sender == self.ui.ch_send_notes:
  1152. option = PLUGIN_OPTION_SKIP_SENDING_NOTES
  1153. clicked = not clicked
  1154. elif sender == self.ui.ch_send_program_changes:
  1155. option = PLUGIN_OPTION_SEND_PROGRAM_CHANGES
  1156. elif sender == self.ui.ch_send_control_changes:
  1157. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  1158. elif sender == self.ui.ch_send_channel_pressure:
  1159. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  1160. elif sender == self.ui.ch_send_note_aftertouch:
  1161. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  1162. elif sender == self.ui.ch_send_pitchbend:
  1163. option = PLUGIN_OPTION_SEND_PITCHBEND
  1164. elif sender == self.ui.ch_send_all_sound_off:
  1165. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  1166. else:
  1167. return
  1168. #--------------------------------------------------------------
  1169. # handle map-program-changes and send-program-changes conflict
  1170. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and clicked:
  1171. self.ui.ch_send_program_changes.setEnabled(False)
  1172. # disable send-program-changes if needed
  1173. if self.ui.ch_send_program_changes.isChecked():
  1174. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, False)
  1175. #--------------------------------------------------------------
  1176. # set option
  1177. self.host.set_option(self.fPluginId, option, clicked)
  1178. #--------------------------------------------------------------
  1179. # handle map-program-changes and send-program-changes conflict
  1180. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and not clicked:
  1181. self.ui.ch_send_program_changes.setEnabled(
  1182. self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  1183. # restore send-program-changes if needed
  1184. if self.ui.ch_send_program_changes.isChecked():
  1185. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, True)
  1186. #------------------------------------------------------------------
  1187. @pyqtSlot(float)
  1188. def slot_dryWetChanged(self, value):
  1189. self.host.set_drywet(self.fPluginId, value)
  1190. if self.fParent is not None:
  1191. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_DRYWET, value)
  1192. @pyqtSlot(float)
  1193. def slot_volumeChanged(self, value):
  1194. self.host.set_volume(self.fPluginId, value)
  1195. if self.fParent is not None:
  1196. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_VOLUME, value)
  1197. @pyqtSlot(float)
  1198. def slot_balanceLeftChanged(self, value):
  1199. self.host.set_balance_left(self.fPluginId, value)
  1200. if self.fParent is not None:
  1201. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_LEFT, value)
  1202. @pyqtSlot(float)
  1203. def slot_balanceRightChanged(self, value):
  1204. self.host.set_balance_right(self.fPluginId, value)
  1205. if self.fParent is not None:
  1206. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_RIGHT, value)
  1207. @pyqtSlot(float)
  1208. def slot_panChanged(self, value):
  1209. self.host.set_panning(self.fPluginId, value)
  1210. if self.fParent is not None:
  1211. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_PANNING, value)
  1212. @pyqtSlot(int)
  1213. def slot_ctrlChannelChanged(self, value):
  1214. self.fControlChannel = value-1
  1215. self.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  1216. self.ui.keyboard.allNotesOff()
  1217. self._updateCtrlPrograms()
  1218. #------------------------------------------------------------------
  1219. @pyqtSlot(int, float)
  1220. def slot_parameterValueChanged(self, parameterId, value):
  1221. self.host.set_parameter_value(self.fPluginId, parameterId, value)
  1222. if self.fParent is not None:
  1223. self.fParent.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  1224. @pyqtSlot(int, int)
  1225. def slot_parameterMappedControlChanged(self, parameterId, control):
  1226. self.host.set_parameter_mapped_control_index(self.fPluginId, parameterId, control)
  1227. @pyqtSlot(int, float, float)
  1228. def slot_parameterMappedRangeChanged(self, parameterId, minimum, maximum):
  1229. self.host.set_parameter_mapped_range(self.fPluginId, parameterId, minimum, maximum)
  1230. @pyqtSlot(int, int)
  1231. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  1232. self.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1233. #------------------------------------------------------------------
  1234. @pyqtSlot(int)
  1235. def slot_programIndexChanged(self, index):
  1236. self.host.set_program(self.fPluginId, index)
  1237. if self.fParent is not None:
  1238. self.fParent.editDialogProgramChanged(self.fPluginId, index)
  1239. self._updateParameterValues()
  1240. @pyqtSlot(int)
  1241. def slot_midiProgramIndexChanged(self, index):
  1242. self.host.set_midi_program(self.fPluginId, index)
  1243. if self.fParent is not None:
  1244. self.fParent.editDialogMidiProgramChanged(self.fPluginId, index)
  1245. self._updateParameterValues()
  1246. #------------------------------------------------------------------
  1247. @pyqtSlot(int)
  1248. def slot_noteOn(self, note):
  1249. if self.fControlChannel >= 0:
  1250. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1251. if self.fParent is not None:
  1252. self.fParent.editDialogNotePressed(self.fPluginId, note)
  1253. @pyqtSlot(int)
  1254. def slot_noteOff(self, note):
  1255. if self.fControlChannel >= 0:
  1256. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1257. if self.fParent is not None:
  1258. self.fParent.editDialogNoteReleased(self.fPluginId, note)
  1259. #------------------------------------------------------------------
  1260. @pyqtSlot()
  1261. def slot_finished(self):
  1262. if self.fParent is not None:
  1263. self.fParent.editDialogVisibilityChanged(self.fPluginId, False)
  1264. #------------------------------------------------------------------
  1265. @pyqtSlot()
  1266. def slot_knobCustomMenu(self):
  1267. sender = self.sender()
  1268. knobName = sender.objectName()
  1269. if knobName == "dial_drywet":
  1270. minimum = 0.0
  1271. maximum = 1.0
  1272. default = 1.0
  1273. label = "Dry/Wet"
  1274. elif knobName == "dial_vol":
  1275. minimum = 0.0
  1276. maximum = 1.27
  1277. default = 1.0
  1278. label = "Volume"
  1279. elif knobName == "dial_b_left":
  1280. minimum = -1.0
  1281. maximum = 1.0
  1282. default = -1.0
  1283. label = "Balance-Left"
  1284. elif knobName == "dial_b_right":
  1285. minimum = -1.0
  1286. maximum = 1.0
  1287. default = 1.0
  1288. label = "Balance-Right"
  1289. elif knobName == "dial_pan":
  1290. minimum = -1.0
  1291. maximum = 1.0
  1292. default = 0.0
  1293. label = "Panning"
  1294. else:
  1295. minimum = 0.0
  1296. maximum = 1.0
  1297. default = 0.5
  1298. label = "Unknown"
  1299. menu = QMenu(self)
  1300. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1301. menu.addSeparator()
  1302. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1303. actCenter = menu.addAction(self.tr("Set to Center"))
  1304. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1305. menu.addSeparator()
  1306. actSet = menu.addAction(self.tr("Set value..."))
  1307. if label not in ("Balance-Left", "Balance-Right", "Panning"):
  1308. menu.removeAction(actCenter)
  1309. actSelected = menu.exec_(QCursor.pos())
  1310. if actSelected == actSet:
  1311. current = minimum + (maximum-minimum)*(float(sender.value())/10000)
  1312. value, ok = QInputDialog.getInt(self,
  1313. self.tr("Set value"),
  1314. label,
  1315. round(current*100.0),
  1316. round(minimum*100.0),
  1317. round(maximum*100.0),
  1318. 1)
  1319. if ok:
  1320. value = float(value)/100.0
  1321. if not ok:
  1322. return
  1323. elif actSelected == actMinimum:
  1324. value = minimum
  1325. elif actSelected == actMaximum:
  1326. value = maximum
  1327. elif actSelected == actReset:
  1328. value = default
  1329. elif actSelected == actCenter:
  1330. value = 0.0
  1331. else:
  1332. return
  1333. sender.setValue(value, True)
  1334. #------------------------------------------------------------------
  1335. @pyqtSlot()
  1336. def slot_channelCustomMenu(self):
  1337. menu = QMenu(self)
  1338. actNone = menu.addAction(self.tr("None"))
  1339. if self.fControlChannel+1 == 0:
  1340. actNone.setCheckable(True)
  1341. actNone.setChecked(True)
  1342. for i in range(1, 16+1):
  1343. action = menu.addAction("%i" % i)
  1344. if self.fControlChannel+1 == i:
  1345. action.setCheckable(True)
  1346. action.setChecked(True)
  1347. actSel = menu.exec_(QCursor.pos())
  1348. if not actSel:
  1349. pass
  1350. elif actSel == actNone:
  1351. self.ui.sb_ctrl_channel.setValue(0)
  1352. elif actSel:
  1353. selChannel = int(actSel.text())
  1354. self.ui.sb_ctrl_channel.setValue(selChannel)
  1355. #------------------------------------------------------------------
  1356. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1357. groupWidgets = {}
  1358. for paramList, width in paramListFull:
  1359. if not paramList:
  1360. break
  1361. tabIndex = self.ui.tabWidget.count()
  1362. scrollArea = QScrollArea(self.ui.tabWidget)
  1363. scrollArea.setWidgetResizable(True)
  1364. scrollArea.setFrameStyle(0)
  1365. palette1 = scrollArea.palette()
  1366. palette1.setColor(QPalette.Background, Qt.transparent)
  1367. scrollArea.setPalette(palette1)
  1368. palette2 = scrollArea.palette()
  1369. palette2.setColor(QPalette.Background, palette2.color(QPalette.Button))
  1370. scrollAreaWidget = QWidget(scrollArea)
  1371. scrollAreaLayout = QVBoxLayout(scrollAreaWidget)
  1372. scrollAreaLayout.setSpacing(3)
  1373. for paramInfo in paramList:
  1374. groupName = paramInfo['groupName']
  1375. if groupName:
  1376. groupSymbol, groupName = groupName.split(":",1)
  1377. groupLayout, groupWidget = groupWidgets.get(groupSymbol, (None, None))
  1378. if groupLayout is None:
  1379. groupWidget = CollapsibleBox(groupName, scrollAreaWidget)
  1380. groupLayout = groupWidget.getContentLayout()
  1381. groupWidget.setPalette(palette2)
  1382. scrollAreaLayout.addWidget(groupWidget)
  1383. groupWidgets[groupSymbol] = (groupLayout, groupWidget)
  1384. else:
  1385. groupLayout = scrollAreaLayout
  1386. groupWidget = scrollAreaWidget
  1387. paramWidget = PluginParameter(groupWidget, self.host, paramInfo, self.fPluginId, tabIndex)
  1388. paramWidget.setLabelWidth(width)
  1389. groupLayout.addWidget(paramWidget)
  1390. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1391. if paramType == PARAMETER_INPUT:
  1392. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1393. paramWidget.mappedControlChanged.connect(self.slot_parameterMappedControlChanged)
  1394. paramWidget.mappedRangeChanged.connect(self.slot_parameterMappedRangeChanged)
  1395. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1396. scrollAreaLayout.addStretch()
  1397. scrollArea.setWidget(scrollAreaWidget)
  1398. self.ui.tabWidget.addTab(scrollArea, tabPageName)
  1399. if paramType == PARAMETER_INPUT:
  1400. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1401. self.fTabIconTimers.append(ICON_STATE_NULL)
  1402. def _updateCtrlPrograms(self):
  1403. self.ui.keyboard.setEnabled(self.fControlChannel >= 0)
  1404. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1405. return
  1406. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2):
  1407. return
  1408. if self.fControlChannel < 0:
  1409. self.ui.cb_programs.setEnabled(False)
  1410. self.ui.cb_midi_programs.setEnabled(False)
  1411. return
  1412. self.ui.cb_programs.setEnabled(True)
  1413. self.ui.cb_midi_programs.setEnabled(True)
  1414. pIndex = self.host.get_current_program_index(self.fPluginId)
  1415. if self.ui.cb_programs.currentIndex() != pIndex:
  1416. self.setProgram(pIndex)
  1417. mpIndex = self.host.get_current_midi_program_index(self.fPluginId)
  1418. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1419. self.setMidiProgram(mpIndex)
  1420. def _updateParameterValues(self):
  1421. for _, paramId, paramWidget in self.fParameterList:
  1422. paramWidget.blockSignals(True)
  1423. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  1424. paramWidget.blockSignals(False)
  1425. #------------------------------------------------------------------
  1426. def testTimer(self):
  1427. self.fIdleTimerId = self.startTimer(50)
  1428. self.SIGTERM.connect(self.testTimerClose)
  1429. gCarla.gui = self
  1430. setUpSignals()
  1431. def testTimerClose(self):
  1432. self.close()
  1433. _app.quit()
  1434. #------------------------------------------------------------------
  1435. def closeEvent(self, event):
  1436. if self.fIdleTimerId != 0:
  1437. self.killTimer(self.fIdleTimerId)
  1438. self.fIdleTimerId = 0
  1439. self.host.engine_close()
  1440. QDialog.closeEvent(self, event)
  1441. def timerEvent(self, event):
  1442. if event.timerId() == self.fIdleTimerId:
  1443. self.host.engine_idle()
  1444. self.idleSlow()
  1445. QDialog.timerEvent(self, event)
  1446. # ------------------------------------------------------------------------------------------------------------
  1447. # Main
  1448. if __name__ == '__main__':
  1449. from carla_app import CarlaApplication
  1450. from carla_host import initHost as _initHost, loadHostSettings as _loadHostSettings
  1451. _app = CarlaApplication()
  1452. _host = _initHost("Widgets", None, False, False, False)
  1453. _loadHostSettings(_host)
  1454. _host.engine_init("JACK", "Carla-Widgets")
  1455. _host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, 0x0)
  1456. _host.set_active(0, True)
  1457. gui1 = CarlaAboutW(None, _host)
  1458. gui1.show()
  1459. gui2 = PluginEdit(None, _host, 0)
  1460. gui2.testTimer()
  1461. gui2.show()
  1462. _app.exit_exec()