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