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

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  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_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_AUTOMATABLE,
  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-2022 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. if MACOS:
  189. self.ui.l_au.setText(self.tr("Using JUCE host"))
  190. else:
  191. self.ui.line_vst3.hide()
  192. self.ui.l_au.hide()
  193. self.ui.lid_au.hide()
  194. # 3rd tab is usually longer than the 1st
  195. # adjust appropriately
  196. self.ui.tabWidget.setCurrentIndex(2)
  197. self.adjustSize()
  198. self.ui.tabWidget.setCurrentIndex(0)
  199. self.setFixedSize(self.size())
  200. flags = self.windowFlags()
  201. flags &= ~Qt.WindowContextHelpButtonHint
  202. if WINDOWS:
  203. flags |= Qt.MSWindowsFixedSizeDialogHint
  204. self.setWindowFlags(flags)
  205. if MACOS:
  206. self.setWindowModality(Qt.WindowModal)
  207. # ------------------------------------------------------------------------------------------------------------
  208. # JUCE About dialog
  209. class JuceAboutW(QDialog):
  210. def __init__(self, parent):
  211. QDialog.__init__(self, parent)
  212. self.ui = ui_carla_about_juce.Ui_JuceAboutW()
  213. self.ui.setupUi(self)
  214. self.ui.l_text2.setText(self.tr("This program uses JUCE version %s." % gCarla.utils.get_juce_version()))
  215. self.adjustSize()
  216. self.setFixedSize(self.size())
  217. flags = self.windowFlags()
  218. flags &= ~Qt.WindowContextHelpButtonHint
  219. if WINDOWS:
  220. flags |= Qt.MSWindowsFixedSizeDialogHint
  221. self.setWindowFlags(flags)
  222. if MACOS:
  223. self.setWindowModality(Qt.WindowModal)
  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_AUTOMATABLE:
  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. flags = self.windowFlags()
  600. flags &= ~Qt.WindowContextHelpButtonHint
  601. self.setWindowFlags(flags)
  602. self.reloadAll()
  603. self.fFirstInit = False
  604. # -------------------------------------------------------------
  605. # Set-up connections
  606. self.finished.connect(self.slot_finished)
  607. self.ui.ch_fixed_buffer.clicked.connect(self.slot_optionChanged)
  608. self.ui.ch_force_stereo.clicked.connect(self.slot_optionChanged)
  609. self.ui.ch_map_program_changes.clicked.connect(self.slot_optionChanged)
  610. self.ui.ch_use_chunks.clicked.connect(self.slot_optionChanged)
  611. self.ui.ch_send_notes.clicked.connect(self.slot_optionChanged)
  612. self.ui.ch_send_program_changes.clicked.connect(self.slot_optionChanged)
  613. self.ui.ch_send_control_changes.clicked.connect(self.slot_optionChanged)
  614. self.ui.ch_send_channel_pressure.clicked.connect(self.slot_optionChanged)
  615. self.ui.ch_send_note_aftertouch.clicked.connect(self.slot_optionChanged)
  616. self.ui.ch_send_pitchbend.clicked.connect(self.slot_optionChanged)
  617. self.ui.ch_send_all_sound_off.clicked.connect(self.slot_optionChanged)
  618. self.ui.dial_drywet.realValueChanged.connect(self.slot_dryWetChanged)
  619. self.ui.dial_vol.realValueChanged.connect(self.slot_volumeChanged)
  620. self.ui.dial_b_left.realValueChanged.connect(self.slot_balanceLeftChanged)
  621. self.ui.dial_b_right.realValueChanged.connect(self.slot_balanceRightChanged)
  622. self.ui.dial_pan.realValueChanged.connect(self.slot_panChanged)
  623. self.ui.sb_ctrl_channel.valueChanged.connect(self.slot_ctrlChannelChanged)
  624. self.ui.dial_drywet.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  625. self.ui.dial_vol.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  626. self.ui.dial_b_left.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  627. self.ui.dial_b_right.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  628. self.ui.dial_pan.customContextMenuRequested.connect(self.slot_knobCustomMenu)
  629. self.ui.sb_ctrl_channel.customContextMenuRequested.connect(self.slot_channelCustomMenu)
  630. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  631. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  632. self.ui.cb_programs.currentIndexChanged.connect(self.slot_programIndexChanged)
  633. self.ui.cb_midi_programs.currentIndexChanged.connect(self.slot_midiProgramIndexChanged)
  634. self.ui.b_save_state.clicked.connect(self.slot_stateSave)
  635. self.ui.b_load_state.clicked.connect(self.slot_stateLoad)
  636. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  637. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  638. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  639. host.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  640. host.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  641. host.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  642. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  643. #------------------------------------------------------------------
  644. @pyqtSlot(int, int, int, int)
  645. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  646. if self.fPluginId != pluginId:
  647. return
  648. if self.fControlChannel == channel:
  649. self.ui.keyboard.sendNoteOn(note, False)
  650. playItem = (channel, note)
  651. if playItem not in self.fPlayingNotes:
  652. self.fPlayingNotes.append(playItem)
  653. if len(self.fPlayingNotes) == 1 and self.fParent is not None:
  654. self.fParent.editDialogMidiActivityChanged(self.fPluginId, True)
  655. @pyqtSlot(int, int, int)
  656. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  657. if self.fPluginId != pluginId:
  658. return
  659. if self.fControlChannel == channel:
  660. self.ui.keyboard.sendNoteOff(note, False)
  661. playItem = (channel, note)
  662. if playItem in self.fPlayingNotes:
  663. self.fPlayingNotes.remove(playItem)
  664. if self.fPlayingNotes and self.fParent is not None:
  665. self.fParent.editDialogMidiActivityChanged(self.fPluginId, False)
  666. @pyqtSlot(int)
  667. def slot_handleUpdateCallback(self, pluginId):
  668. if self.fPluginId == pluginId:
  669. self.updateInfo()
  670. @pyqtSlot(int)
  671. def slot_handleReloadInfoCallback(self, pluginId):
  672. if self.fPluginId == pluginId:
  673. self.reloadInfo()
  674. @pyqtSlot(int)
  675. def slot_handleReloadParametersCallback(self, pluginId):
  676. if self.fPluginId == pluginId:
  677. self.reloadParameters()
  678. @pyqtSlot(int)
  679. def slot_handleReloadProgramsCallback(self, pluginId):
  680. if self.fPluginId == pluginId:
  681. self.reloadPrograms()
  682. @pyqtSlot(int)
  683. def slot_handleReloadAllCallback(self, pluginId):
  684. if self.fPluginId == pluginId:
  685. self.reloadAll()
  686. #------------------------------------------------------------------
  687. def updateInfo(self):
  688. # Update current program text
  689. if self.ui.cb_programs.count() > 0:
  690. pIndex = self.ui.cb_programs.currentIndex()
  691. if pIndex >= 0:
  692. pName = self.host.get_program_name(self.fPluginId, pIndex)
  693. #pName = pName[:40] + (pName[40:] and "...")
  694. self.ui.cb_programs.setItemText(pIndex, pName)
  695. # Update current midi program text
  696. if self.ui.cb_midi_programs.count() > 0:
  697. mpIndex = self.ui.cb_midi_programs.currentIndex()
  698. if mpIndex >= 0:
  699. mpData = self.host.get_midi_program_data(self.fPluginId, mpIndex)
  700. mpBank = mpData['bank']
  701. mpProg = mpData['program']
  702. mpName = mpData['name']
  703. #mpName = mpName[:40] + (mpName[40:] and "...")
  704. self.ui.cb_midi_programs.setItemText(mpIndex, "%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  705. # Update all parameter values
  706. for _, paramId, paramWidget in self.fParameterList:
  707. paramWidget.blockSignals(True)
  708. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  709. paramWidget.blockSignals(False)
  710. # and the internal ones too
  711. self.ui.dial_drywet.blockSignals(True)
  712. self.ui.dial_drywet.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_DRYWET))
  713. self.ui.dial_drywet.blockSignals(False)
  714. self.ui.dial_vol.blockSignals(True)
  715. self.ui.dial_vol.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_VOLUME))
  716. self.ui.dial_vol.blockSignals(False)
  717. self.ui.dial_b_left.blockSignals(True)
  718. self.ui.dial_b_left.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_BALANCE_LEFT))
  719. self.ui.dial_b_left.blockSignals(False)
  720. self.ui.dial_b_right.blockSignals(True)
  721. self.ui.dial_b_right.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_BALANCE_RIGHT))
  722. self.ui.dial_b_right.blockSignals(False)
  723. self.ui.dial_pan.blockSignals(True)
  724. self.ui.dial_pan.setValue(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_PANNING))
  725. self.ui.dial_pan.blockSignals(False)
  726. self.fControlChannel = round(self.host.get_internal_parameter_value(self.fPluginId, PARAMETER_CTRL_CHANNEL))
  727. self.ui.sb_ctrl_channel.blockSignals(True)
  728. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  729. self.ui.sb_ctrl_channel.blockSignals(False)
  730. self.ui.keyboard.allNotesOff()
  731. self._updateCtrlPrograms()
  732. self.fParametersToUpdate = []
  733. #------------------------------------------------------------------
  734. def reloadAll(self):
  735. self.fPluginInfo = self.host.get_plugin_info(self.fPluginId)
  736. self.reloadInfo()
  737. self.reloadParameters()
  738. self.reloadPrograms()
  739. if self.fPluginInfo['type'] == PLUGIN_LV2:
  740. self.ui.b_save_state.setEnabled(False)
  741. if not self.ui.scrollArea.isEnabled():
  742. self.resize(self.width(), self.height()-self.ui.scrollArea.height())
  743. #------------------------------------------------------------------
  744. def reloadInfo(self):
  745. realPluginName = self.host.get_real_plugin_name(self.fPluginId)
  746. #audioCountInfo = self.host.get_audio_port_count_info(self.fPluginId)
  747. midiCountInfo = self.host.get_midi_port_count_info(self.fPluginId)
  748. #paramCountInfo = self.host.get_parameter_count_info(self.fPluginId)
  749. pluginHints = self.fPluginInfo['hints']
  750. self.ui.le_type.setText(getPluginTypeAsString(self.fPluginInfo['type']))
  751. self.ui.label_name.setEnabled(bool(realPluginName))
  752. self.ui.le_name.setEnabled(bool(realPluginName))
  753. self.ui.le_name.setText(realPluginName)
  754. self.ui.le_name.setToolTip(realPluginName)
  755. self.ui.label_label.setEnabled(bool(self.fPluginInfo['label']))
  756. self.ui.le_label.setEnabled(bool(self.fPluginInfo['label']))
  757. self.ui.le_label.setText(self.fPluginInfo['label'])
  758. self.ui.le_label.setToolTip(self.fPluginInfo['label'])
  759. self.ui.label_maker.setEnabled(bool(self.fPluginInfo['maker']))
  760. self.ui.le_maker.setEnabled(bool(self.fPluginInfo['maker']))
  761. self.ui.le_maker.setText(self.fPluginInfo['maker'])
  762. self.ui.le_maker.setToolTip(self.fPluginInfo['maker'])
  763. self.ui.label_copyright.setEnabled(bool(self.fPluginInfo['copyright']))
  764. self.ui.le_copyright.setEnabled(bool(self.fPluginInfo['copyright']))
  765. self.ui.le_copyright.setText(self.fPluginInfo['copyright'])
  766. self.ui.le_copyright.setToolTip(self.fPluginInfo['copyright'])
  767. self.ui.label_unique_id.setEnabled(bool(self.fPluginInfo['uniqueId']))
  768. self.ui.le_unique_id.setEnabled(bool(self.fPluginInfo['uniqueId']))
  769. self.ui.le_unique_id.setText(str(self.fPluginInfo['uniqueId']))
  770. self.ui.le_unique_id.setToolTip(str(self.fPluginInfo['uniqueId']))
  771. self.ui.label_plugin.setText("\n%s\n" % (self.fPluginInfo['name'] or "(none)"))
  772. self.setWindowTitle(self.fPluginInfo['name'] or "(none)")
  773. self.ui.dial_drywet.setEnabled(pluginHints & PLUGIN_CAN_DRYWET)
  774. self.ui.dial_vol.setEnabled(pluginHints & PLUGIN_CAN_VOLUME)
  775. self.ui.dial_b_left.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  776. self.ui.dial_b_right.setEnabled(pluginHints & PLUGIN_CAN_BALANCE)
  777. self.ui.dial_pan.setEnabled(pluginHints & PLUGIN_CAN_PANNING)
  778. optsAvailable = self.fPluginInfo['optionsAvailable']
  779. optsEnabled = self.fPluginInfo['optionsEnabled']
  780. self.ui.ch_use_chunks.setEnabled(optsAvailable & PLUGIN_OPTION_USE_CHUNKS)
  781. self.ui.ch_use_chunks.setChecked(optsEnabled & PLUGIN_OPTION_USE_CHUNKS)
  782. self.ui.ch_fixed_buffer.setEnabled(optsAvailable & PLUGIN_OPTION_FIXED_BUFFERS)
  783. self.ui.ch_fixed_buffer.setChecked(optsEnabled & PLUGIN_OPTION_FIXED_BUFFERS)
  784. self.ui.ch_force_stereo.setEnabled(optsAvailable & PLUGIN_OPTION_FORCE_STEREO)
  785. self.ui.ch_force_stereo.setChecked(optsEnabled & PLUGIN_OPTION_FORCE_STEREO)
  786. self.ui.ch_map_program_changes.setEnabled(optsAvailable & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  787. self.ui.ch_map_program_changes.setChecked(optsEnabled & PLUGIN_OPTION_MAP_PROGRAM_CHANGES)
  788. self.ui.ch_send_notes.setEnabled(optsAvailable & PLUGIN_OPTION_SKIP_SENDING_NOTES)
  789. self.ui.ch_send_notes.setChecked((self.ui.ch_send_notes.isEnabled() and
  790. (optsEnabled & PLUGIN_OPTION_SKIP_SENDING_NOTES) == 0x0))
  791. self.ui.ch_send_control_changes.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  792. self.ui.ch_send_control_changes.setChecked(optsEnabled & PLUGIN_OPTION_SEND_CONTROL_CHANGES)
  793. self.ui.ch_send_channel_pressure.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  794. self.ui.ch_send_channel_pressure.setChecked(optsEnabled & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE)
  795. self.ui.ch_send_note_aftertouch.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  796. self.ui.ch_send_note_aftertouch.setChecked(optsEnabled & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH)
  797. self.ui.ch_send_pitchbend.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_PITCHBEND)
  798. self.ui.ch_send_pitchbend.setChecked(optsEnabled & PLUGIN_OPTION_SEND_PITCHBEND)
  799. self.ui.ch_send_all_sound_off.setEnabled(optsAvailable & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  800. self.ui.ch_send_all_sound_off.setChecked(optsEnabled & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  801. canSendPrograms = bool((optsAvailable & PLUGIN_OPTION_SEND_PROGRAM_CHANGES) != 0 and
  802. (optsEnabled & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) == 0)
  803. self.ui.ch_send_program_changes.setEnabled(canSendPrograms)
  804. self.ui.ch_send_program_changes.setChecked(optsEnabled & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  805. self.ui.sw_programs.setCurrentIndex(0 if self.fPluginInfo['type'] in (PLUGIN_VST2, PLUGIN_SFZ) else 1)
  806. # Show/hide keyboard
  807. showKeyboard = (self.fPluginInfo['category'] == PLUGIN_CATEGORY_SYNTH or midiCountInfo['ins'] > 0)
  808. self.ui.scrollArea.setEnabled(showKeyboard)
  809. self.ui.scrollArea.setVisible(showKeyboard)
  810. # Force-update parent for new hints
  811. if self.fParent is not None and not self.fFirstInit:
  812. self.fParent.editDialogPluginHintsChanged(self.fPluginId, pluginHints)
  813. def reloadParameters(self):
  814. # Reset
  815. self.fParameterList = []
  816. self.fParametersToUpdate = []
  817. self.fTabIconTimers = []
  818. # Save current tab state
  819. tabIndex = self.ui.tabWidget.currentIndex()
  820. tabWidget = self.ui.tabWidget.currentWidget()
  821. scrollVal = tabWidget.verticalScrollBar().value() if isinstance(tabWidget, QScrollArea) else None
  822. del tabWidget
  823. # Remove all previous parameters
  824. for _ in range(self.ui.tabWidget.count()-1):
  825. self.ui.tabWidget.widget(1).deleteLater()
  826. self.ui.tabWidget.removeTab(1)
  827. parameterCount = self.host.get_parameter_count(self.fPluginId)
  828. # -----------------------------------------------------------------
  829. if parameterCount <= 0:
  830. return
  831. # -----------------------------------------------------------------
  832. paramInputList = []
  833. paramOutputList = []
  834. paramInputWidth = 0
  835. paramOutputWidth = 0
  836. unusedParameters = 0
  837. paramInputListFull = [] # ([params], width)
  838. paramOutputListFull = [] # ([params], width)
  839. for i in range(parameterCount):
  840. if i - unusedParameters == self.host.maxParameters:
  841. break
  842. paramData = self.host.get_parameter_data(self.fPluginId, i)
  843. if paramData['type'] not in (PARAMETER_INPUT, PARAMETER_OUTPUT):
  844. unusedParameters += 1
  845. continue
  846. if (paramData['hints'] & PARAMETER_IS_ENABLED) == 0:
  847. unusedParameters += 1
  848. continue
  849. paramInfo = self.host.get_parameter_info(self.fPluginId, i)
  850. paramRanges = self.host.get_parameter_ranges(self.fPluginId, i)
  851. paramValue = self.host.get_current_parameter_value(self.fPluginId, i)
  852. parameter = {
  853. 'type': paramData['type'],
  854. 'hints': paramData['hints'],
  855. 'name': paramInfo['name'],
  856. 'unit': paramInfo['unit'],
  857. 'scalePoints': [],
  858. 'index': paramData['index'],
  859. 'default': paramRanges['def'],
  860. 'minimum': paramRanges['min'],
  861. 'maximum': paramRanges['max'],
  862. 'step': paramRanges['step'],
  863. 'stepSmall': paramRanges['stepSmall'],
  864. 'stepLarge': paramRanges['stepLarge'],
  865. 'mappedControlIndex': paramData['mappedControlIndex'],
  866. 'mappedMinimum': paramData['mappedMinimum'],
  867. 'mappedMaximum': paramData['mappedMaximum'],
  868. 'midiChannel': paramData['midiChannel']+1,
  869. 'comment': paramInfo['comment'],
  870. 'groupName': paramInfo['groupName'],
  871. 'current': paramValue
  872. }
  873. for j in range(paramInfo['scalePointCount']):
  874. scalePointInfo = self.host.get_parameter_scalepoint_info(self.fPluginId, i, j)
  875. parameter['scalePoints'].append({
  876. 'value': scalePointInfo['value'],
  877. 'label': scalePointInfo['label']
  878. })
  879. #parameter['name'] = parameter['name'][:30] + (parameter['name'][30:] and "...")
  880. # -----------------------------------------------------------------
  881. # Get width values, in packs of 20
  882. if parameter['type'] == PARAMETER_INPUT:
  883. paramInputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])
  884. if paramInputWidthTMP > paramInputWidth:
  885. paramInputWidth = paramInputWidthTMP
  886. paramInputList.append(parameter)
  887. else:
  888. paramOutputWidthTMP = fontMetricsHorizontalAdvance(self.fontMetrics(), parameter['name'])
  889. if paramOutputWidthTMP > paramOutputWidth:
  890. paramOutputWidth = paramOutputWidthTMP
  891. paramOutputList.append(parameter)
  892. paramInputListFull.append((paramInputList, paramInputWidth))
  893. paramOutputListFull.append((paramOutputList, paramOutputWidth))
  894. # Create parameter tabs + widgets
  895. self._createParameterWidgets(PARAMETER_INPUT, paramInputListFull, self.tr("Parameters"))
  896. self._createParameterWidgets(PARAMETER_OUTPUT, paramOutputListFull, self.tr("Outputs"))
  897. # Restore tab state
  898. if tabIndex < self.ui.tabWidget.count():
  899. self.ui.tabWidget.setCurrentIndex(tabIndex)
  900. if scrollVal is not None:
  901. self.ui.tabWidget.currentWidget().verticalScrollBar().setValue(scrollVal)
  902. def reloadPrograms(self):
  903. # Programs
  904. self.ui.cb_programs.blockSignals(True)
  905. self.ui.cb_programs.clear()
  906. programCount = self.host.get_program_count(self.fPluginId)
  907. if programCount > 0:
  908. self.ui.cb_programs.setEnabled(True)
  909. self.ui.label_programs.setEnabled(True)
  910. for i in range(programCount):
  911. pName = self.host.get_program_name(self.fPluginId, i)
  912. #pName = pName[:40] + (pName[40:] and "...")
  913. self.ui.cb_programs.addItem(pName)
  914. self.ui.cb_programs.setCurrentIndex(self.host.get_current_program_index(self.fPluginId))
  915. else:
  916. self.ui.cb_programs.setEnabled(False)
  917. self.ui.label_programs.setEnabled(False)
  918. self.ui.cb_programs.blockSignals(False)
  919. # MIDI Programs
  920. self.ui.cb_midi_programs.blockSignals(True)
  921. self.ui.cb_midi_programs.clear()
  922. midiProgramCount = self.host.get_midi_program_count(self.fPluginId)
  923. if midiProgramCount > 0:
  924. self.ui.cb_midi_programs.setEnabled(True)
  925. self.ui.label_midi_programs.setEnabled(True)
  926. for i in range(midiProgramCount):
  927. mpData = self.host.get_midi_program_data(self.fPluginId, i)
  928. mpBank = mpData['bank']
  929. mpProg = mpData['program']
  930. mpName = mpData['name']
  931. #mpName = mpName[:40] + (mpName[40:] and "...")
  932. self.ui.cb_midi_programs.addItem("%03i:%03i - %s" % (mpBank+1, mpProg+1, mpName))
  933. self.ui.cb_midi_programs.setCurrentIndex(self.host.get_current_midi_program_index(self.fPluginId))
  934. else:
  935. self.ui.cb_midi_programs.setEnabled(False)
  936. self.ui.label_midi_programs.setEnabled(False)
  937. self.ui.cb_midi_programs.blockSignals(False)
  938. self.ui.sw_programs.setEnabled(programCount > 0 or midiProgramCount > 0)
  939. if self.fPluginInfo['type'] == PLUGIN_LV2:
  940. self.ui.b_load_state.setEnabled(programCount > 0)
  941. #------------------------------------------------------------------
  942. def clearNotes(self):
  943. self.fPlayingNotes = []
  944. self.ui.keyboard.allNotesOff()
  945. def noteOn(self, channel, note, velocity):
  946. if self.fControlChannel == channel:
  947. self.ui.keyboard.sendNoteOn(note, False)
  948. def noteOff(self, channel, note):
  949. if self.fControlChannel == channel:
  950. self.ui.keyboard.sendNoteOff(note, False)
  951. #------------------------------------------------------------------
  952. def getHints(self):
  953. return self.fPluginInfo['hints']
  954. def setPluginId(self, idx):
  955. self.fPluginId = idx
  956. def setName(self, name):
  957. self.fPluginInfo['name'] = name
  958. self.ui.label_plugin.setText("\n%s\n" % name)
  959. self.setWindowTitle(name)
  960. #------------------------------------------------------------------
  961. def setParameterValue(self, parameterId, value):
  962. for paramItem in self.fParametersToUpdate:
  963. if paramItem[0] == parameterId:
  964. paramItem[1] = value
  965. break
  966. else:
  967. self.fParametersToUpdate.append([parameterId, value])
  968. def setParameterDefault(self, parameterId, value):
  969. for _, paramId, paramWidget in self.fParameterList:
  970. if paramId == parameterId:
  971. paramWidget.setDefault(value)
  972. break
  973. def setParameterMappedControlIndex(self, parameterId, control):
  974. for _, paramId, paramWidget in self.fParameterList:
  975. if paramId == parameterId:
  976. paramWidget.setMappedControlIndex(control)
  977. break
  978. def setParameterMappedRange(self, parameterId, minimum, maximum):
  979. for _, paramId, paramWidget in self.fParameterList:
  980. if paramId == parameterId:
  981. paramWidget.setMappedRange(minimum, maximum)
  982. break
  983. def setParameterMidiChannel(self, parameterId, channel):
  984. for _, paramId, paramWidget in self.fParameterList:
  985. if paramId == parameterId:
  986. paramWidget.setMidiChannel(channel+1)
  987. break
  988. def setProgram(self, index):
  989. self.ui.cb_programs.blockSignals(True)
  990. self.ui.cb_programs.setCurrentIndex(index)
  991. self.ui.cb_programs.blockSignals(False)
  992. self._updateParameterValues()
  993. def setMidiProgram(self, index):
  994. self.ui.cb_midi_programs.blockSignals(True)
  995. self.ui.cb_midi_programs.setCurrentIndex(index)
  996. self.ui.cb_midi_programs.blockSignals(False)
  997. self._updateParameterValues()
  998. def setOption(self, option, yesNo):
  999. if option == PLUGIN_OPTION_USE_CHUNKS:
  1000. widget = self.ui.ch_use_chunks
  1001. elif option == PLUGIN_OPTION_FIXED_BUFFERS:
  1002. widget = self.ui.ch_fixed_buffer
  1003. elif option == PLUGIN_OPTION_FORCE_STEREO:
  1004. widget = self.ui.ch_force_stereo
  1005. elif option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  1006. widget = self.ui.ch_map_program_changes
  1007. elif option == PLUGIN_OPTION_SKIP_SENDING_NOTES:
  1008. widget = self.ui.ch_send_notes
  1009. yesNo = not yesNo
  1010. elif option == PLUGIN_OPTION_SEND_PROGRAM_CHANGES:
  1011. widget = self.ui.ch_send_program_changes
  1012. elif option == PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  1013. widget = self.ui.ch_send_control_changes
  1014. elif option == PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  1015. widget = self.ui.ch_send_channel_pressure
  1016. elif option == PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  1017. widget = self.ui.ch_send_note_aftertouch
  1018. elif option == PLUGIN_OPTION_SEND_PITCHBEND:
  1019. widget = self.ui.ch_send_pitchbend
  1020. elif option == PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  1021. widget = self.ui.ch_send_all_sound_off
  1022. else:
  1023. return
  1024. widget.blockSignals(True)
  1025. widget.setChecked(yesNo)
  1026. widget.blockSignals(False)
  1027. #------------------------------------------------------------------
  1028. def setVisible(self, yesNo):
  1029. if yesNo:
  1030. if not self.fGeometry.isNull():
  1031. self.restoreGeometry(self.fGeometry)
  1032. else:
  1033. self.fGeometry = self.saveGeometry()
  1034. QDialog.setVisible(self, yesNo)
  1035. if MACOS and yesNo:
  1036. parent = self.parent()
  1037. if parent is None:
  1038. return
  1039. gCarla.utils.cocoa_set_transient_window_for(self.windowHandle().winId(), parent.windowHandle().winId())
  1040. #------------------------------------------------------------------
  1041. def idleSlow(self):
  1042. # Check Tab icons
  1043. for i in range(len(self.fTabIconTimers)):
  1044. if self.fTabIconTimers[i] == ICON_STATE_ON:
  1045. self.fTabIconTimers[i] = ICON_STATE_WAIT
  1046. elif self.fTabIconTimers[i] == ICON_STATE_WAIT:
  1047. self.fTabIconTimers[i] = ICON_STATE_OFF
  1048. elif self.fTabIconTimers[i] == ICON_STATE_OFF:
  1049. self.fTabIconTimers[i] = ICON_STATE_NULL
  1050. self.ui.tabWidget.setTabIcon(i+1, self.fTabIconOff)
  1051. # Check parameters needing update
  1052. for index, value in self.fParametersToUpdate:
  1053. if index == PARAMETER_DRYWET:
  1054. self.ui.dial_drywet.blockSignals(True)
  1055. self.ui.dial_drywet.setValue(value)
  1056. self.ui.dial_drywet.blockSignals(False)
  1057. elif index == PARAMETER_VOLUME:
  1058. self.ui.dial_vol.blockSignals(True)
  1059. self.ui.dial_vol.setValue(value)
  1060. self.ui.dial_vol.blockSignals(False)
  1061. elif index == PARAMETER_BALANCE_LEFT:
  1062. self.ui.dial_b_left.blockSignals(True)
  1063. self.ui.dial_b_left.setValue(value)
  1064. self.ui.dial_b_left.blockSignals(False)
  1065. elif index == PARAMETER_BALANCE_RIGHT:
  1066. self.ui.dial_b_right.blockSignals(True)
  1067. self.ui.dial_b_right.setValue(value)
  1068. self.ui.dial_b_right.blockSignals(False)
  1069. elif index == PARAMETER_PANNING:
  1070. self.ui.dial_pan.blockSignals(True)
  1071. self.ui.dial_pan.setValue(value)
  1072. self.ui.dial_pan.blockSignals(False)
  1073. elif index == PARAMETER_CTRL_CHANNEL:
  1074. self.fControlChannel = round(value)
  1075. self.ui.sb_ctrl_channel.blockSignals(True)
  1076. self.ui.sb_ctrl_channel.setValue(self.fControlChannel+1)
  1077. self.ui.sb_ctrl_channel.blockSignals(False)
  1078. self.ui.keyboard.allNotesOff()
  1079. self._updateCtrlPrograms()
  1080. elif index >= 0:
  1081. for paramType, paramId, paramWidget in self.fParameterList:
  1082. if paramId != index:
  1083. continue
  1084. # FIXME see below
  1085. if paramType != PARAMETER_INPUT:
  1086. continue
  1087. paramWidget.blockSignals(True)
  1088. paramWidget.setValue(value)
  1089. paramWidget.blockSignals(False)
  1090. #if paramType == PARAMETER_INPUT:
  1091. tabIndex = paramWidget.getTabIndex()
  1092. if self.fTabIconTimers[tabIndex-1] == ICON_STATE_NULL:
  1093. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOn)
  1094. self.fTabIconTimers[tabIndex-1] = ICON_STATE_ON
  1095. break
  1096. # Clear all parameters
  1097. self.fParametersToUpdate = []
  1098. # Update parameter outputs | FIXME needed?
  1099. for paramType, paramId, paramWidget in self.fParameterList:
  1100. if paramType != PARAMETER_OUTPUT:
  1101. continue
  1102. paramWidget.blockSignals(True)
  1103. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  1104. paramWidget.blockSignals(False)
  1105. #------------------------------------------------------------------
  1106. @pyqtSlot()
  1107. def slot_stateSave(self):
  1108. if self.fPluginInfo['type'] == PLUGIN_LV2:
  1109. # TODO
  1110. return
  1111. if self.fCurrentStateFilename:
  1112. askTry = QMessageBox.question(self,
  1113. self.tr("Overwrite?"),
  1114. self.tr("Overwrite previously created file?"),
  1115. QMessageBox.Ok|QMessageBox.Cancel)
  1116. if askTry == QMessageBox.Ok:
  1117. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1118. return
  1119. self.fCurrentStateFilename = None
  1120. fileFilter = self.tr("Carla State File (*.carxs)")
  1121. filename, _ = QFileDialog.getSaveFileName(self, self.tr("Save Plugin State File"), filter=fileFilter)
  1122. # FIXME use ok value, test if it works as expected
  1123. if not filename:
  1124. return
  1125. if not filename.lower().endswith(".carxs"):
  1126. filename += ".carxs"
  1127. self.fCurrentStateFilename = filename
  1128. self.host.save_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1129. @pyqtSlot()
  1130. def slot_stateLoad(self):
  1131. if self.fPluginInfo['type'] == PLUGIN_LV2:
  1132. presetList = []
  1133. for i in range(self.host.get_program_count(self.fPluginId)):
  1134. presetList.append("%03i - %s" % (i+1, self.host.get_program_name(self.fPluginId, i)))
  1135. ret = QInputDialog.getItem(self,
  1136. self.tr("Open LV2 Preset"),
  1137. self.tr("Select an LV2 Preset:"),
  1138. presetList, 0, False)
  1139. if ret[1]:
  1140. index = int(ret[0].split(" - ", 1)[0])-1
  1141. self.host.set_program(self.fPluginId, index)
  1142. self.setMidiProgram(-1)
  1143. return
  1144. fileFilter = self.tr("Carla State File (*.carxs)")
  1145. filename, _ = QFileDialog.getOpenFileName(self, self.tr("Open Plugin State File"), filter=fileFilter)
  1146. # FIXME use ok value, test if it works as expected
  1147. if not filename:
  1148. return
  1149. self.fCurrentStateFilename = filename
  1150. self.host.load_plugin_state(self.fPluginId, self.fCurrentStateFilename)
  1151. #------------------------------------------------------------------
  1152. @pyqtSlot(bool)
  1153. def slot_optionChanged(self, clicked):
  1154. sender = self.sender()
  1155. if sender == self.ui.ch_use_chunks:
  1156. option = PLUGIN_OPTION_USE_CHUNKS
  1157. elif sender == self.ui.ch_fixed_buffer:
  1158. option = PLUGIN_OPTION_FIXED_BUFFERS
  1159. elif sender == self.ui.ch_force_stereo:
  1160. option = PLUGIN_OPTION_FORCE_STEREO
  1161. elif sender == self.ui.ch_map_program_changes:
  1162. option = PLUGIN_OPTION_MAP_PROGRAM_CHANGES
  1163. elif sender == self.ui.ch_send_notes:
  1164. option = PLUGIN_OPTION_SKIP_SENDING_NOTES
  1165. clicked = not clicked
  1166. elif sender == self.ui.ch_send_program_changes:
  1167. option = PLUGIN_OPTION_SEND_PROGRAM_CHANGES
  1168. elif sender == self.ui.ch_send_control_changes:
  1169. option = PLUGIN_OPTION_SEND_CONTROL_CHANGES
  1170. elif sender == self.ui.ch_send_channel_pressure:
  1171. option = PLUGIN_OPTION_SEND_CHANNEL_PRESSURE
  1172. elif sender == self.ui.ch_send_note_aftertouch:
  1173. option = PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH
  1174. elif sender == self.ui.ch_send_pitchbend:
  1175. option = PLUGIN_OPTION_SEND_PITCHBEND
  1176. elif sender == self.ui.ch_send_all_sound_off:
  1177. option = PLUGIN_OPTION_SEND_ALL_SOUND_OFF
  1178. else:
  1179. return
  1180. #--------------------------------------------------------------
  1181. # handle map-program-changes and send-program-changes conflict
  1182. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and clicked:
  1183. self.ui.ch_send_program_changes.setEnabled(False)
  1184. # disable send-program-changes if needed
  1185. if self.ui.ch_send_program_changes.isChecked():
  1186. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, False)
  1187. #--------------------------------------------------------------
  1188. # set option
  1189. self.host.set_option(self.fPluginId, option, clicked)
  1190. #--------------------------------------------------------------
  1191. # handle map-program-changes and send-program-changes conflict
  1192. if option == PLUGIN_OPTION_MAP_PROGRAM_CHANGES and not clicked:
  1193. self.ui.ch_send_program_changes.setEnabled(
  1194. self.fPluginInfo['optionsAvailable'] & PLUGIN_OPTION_SEND_PROGRAM_CHANGES)
  1195. # restore send-program-changes if needed
  1196. if self.ui.ch_send_program_changes.isChecked():
  1197. self.host.set_option(self.fPluginId, PLUGIN_OPTION_SEND_PROGRAM_CHANGES, True)
  1198. #------------------------------------------------------------------
  1199. @pyqtSlot(float)
  1200. def slot_dryWetChanged(self, value):
  1201. self.host.set_drywet(self.fPluginId, value)
  1202. if self.fParent is not None:
  1203. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_DRYWET, value)
  1204. @pyqtSlot(float)
  1205. def slot_volumeChanged(self, value):
  1206. self.host.set_volume(self.fPluginId, value)
  1207. if self.fParent is not None:
  1208. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_VOLUME, value)
  1209. @pyqtSlot(float)
  1210. def slot_balanceLeftChanged(self, value):
  1211. self.host.set_balance_left(self.fPluginId, value)
  1212. if self.fParent is not None:
  1213. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_LEFT, value)
  1214. @pyqtSlot(float)
  1215. def slot_balanceRightChanged(self, value):
  1216. self.host.set_balance_right(self.fPluginId, value)
  1217. if self.fParent is not None:
  1218. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_BALANCE_RIGHT, value)
  1219. @pyqtSlot(float)
  1220. def slot_panChanged(self, value):
  1221. self.host.set_panning(self.fPluginId, value)
  1222. if self.fParent is not None:
  1223. self.fParent.editDialogParameterValueChanged(self.fPluginId, PARAMETER_PANNING, value)
  1224. @pyqtSlot(int)
  1225. def slot_ctrlChannelChanged(self, value):
  1226. self.fControlChannel = value-1
  1227. self.host.set_ctrl_channel(self.fPluginId, self.fControlChannel)
  1228. self.ui.keyboard.allNotesOff()
  1229. self._updateCtrlPrograms()
  1230. #------------------------------------------------------------------
  1231. @pyqtSlot(int, float)
  1232. def slot_parameterValueChanged(self, parameterId, value):
  1233. self.host.set_parameter_value(self.fPluginId, parameterId, value)
  1234. if self.fParent is not None:
  1235. self.fParent.editDialogParameterValueChanged(self.fPluginId, parameterId, value)
  1236. @pyqtSlot(int, int)
  1237. def slot_parameterMappedControlChanged(self, parameterId, control):
  1238. self.host.set_parameter_mapped_control_index(self.fPluginId, parameterId, control)
  1239. @pyqtSlot(int, float, float)
  1240. def slot_parameterMappedRangeChanged(self, parameterId, minimum, maximum):
  1241. self.host.set_parameter_mapped_range(self.fPluginId, parameterId, minimum, maximum)
  1242. @pyqtSlot(int, int)
  1243. def slot_parameterMidiChannelChanged(self, parameterId, channel):
  1244. self.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1)
  1245. #------------------------------------------------------------------
  1246. @pyqtSlot(int)
  1247. def slot_programIndexChanged(self, index):
  1248. self.host.set_program(self.fPluginId, index)
  1249. if self.fParent is not None:
  1250. self.fParent.editDialogProgramChanged(self.fPluginId, index)
  1251. self._updateParameterValues()
  1252. @pyqtSlot(int)
  1253. def slot_midiProgramIndexChanged(self, index):
  1254. self.host.set_midi_program(self.fPluginId, index)
  1255. if self.fParent is not None:
  1256. self.fParent.editDialogMidiProgramChanged(self.fPluginId, index)
  1257. self._updateParameterValues()
  1258. #------------------------------------------------------------------
  1259. @pyqtSlot(int)
  1260. def slot_noteOn(self, note):
  1261. if self.fControlChannel >= 0:
  1262. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 100)
  1263. if self.fParent is not None:
  1264. self.fParent.editDialogNotePressed(self.fPluginId, note)
  1265. @pyqtSlot(int)
  1266. def slot_noteOff(self, note):
  1267. if self.fControlChannel >= 0:
  1268. self.host.send_midi_note(self.fPluginId, self.fControlChannel, note, 0)
  1269. if self.fParent is not None:
  1270. self.fParent.editDialogNoteReleased(self.fPluginId, note)
  1271. #------------------------------------------------------------------
  1272. @pyqtSlot()
  1273. def slot_finished(self):
  1274. if self.fParent is not None:
  1275. self.fParent.editDialogVisibilityChanged(self.fPluginId, False)
  1276. #------------------------------------------------------------------
  1277. @pyqtSlot()
  1278. def slot_knobCustomMenu(self):
  1279. sender = self.sender()
  1280. knobName = sender.objectName()
  1281. if knobName == "dial_drywet":
  1282. minimum = 0.0
  1283. maximum = 1.0
  1284. default = 1.0
  1285. label = "Dry/Wet"
  1286. elif knobName == "dial_vol":
  1287. minimum = 0.0
  1288. maximum = 1.27
  1289. default = 1.0
  1290. label = "Volume"
  1291. elif knobName == "dial_b_left":
  1292. minimum = -1.0
  1293. maximum = 1.0
  1294. default = -1.0
  1295. label = "Balance-Left"
  1296. elif knobName == "dial_b_right":
  1297. minimum = -1.0
  1298. maximum = 1.0
  1299. default = 1.0
  1300. label = "Balance-Right"
  1301. elif knobName == "dial_pan":
  1302. minimum = -1.0
  1303. maximum = 1.0
  1304. default = 0.0
  1305. label = "Panning"
  1306. else:
  1307. minimum = 0.0
  1308. maximum = 1.0
  1309. default = 0.5
  1310. label = "Unknown"
  1311. menu = QMenu(self)
  1312. actReset = menu.addAction(self.tr("Reset (%i%%)" % (default*100)))
  1313. menu.addSeparator()
  1314. actMinimum = menu.addAction(self.tr("Set to Minimum (%i%%)" % (minimum*100)))
  1315. actCenter = menu.addAction(self.tr("Set to Center"))
  1316. actMaximum = menu.addAction(self.tr("Set to Maximum (%i%%)" % (maximum*100)))
  1317. menu.addSeparator()
  1318. actSet = menu.addAction(self.tr("Set value..."))
  1319. if label not in ("Balance-Left", "Balance-Right", "Panning"):
  1320. menu.removeAction(actCenter)
  1321. actSelected = menu.exec_(QCursor.pos())
  1322. if actSelected == actSet:
  1323. current = minimum + (maximum-minimum)*(float(sender.value())/10000)
  1324. value, ok = QInputDialog.getInt(self,
  1325. self.tr("Set value"),
  1326. label,
  1327. round(current*100.0),
  1328. round(minimum*100.0),
  1329. round(maximum*100.0),
  1330. 1)
  1331. if ok:
  1332. value = float(value)/100.0
  1333. if not ok:
  1334. return
  1335. elif actSelected == actMinimum:
  1336. value = minimum
  1337. elif actSelected == actMaximum:
  1338. value = maximum
  1339. elif actSelected == actReset:
  1340. value = default
  1341. elif actSelected == actCenter:
  1342. value = 0.0
  1343. else:
  1344. return
  1345. sender.setValue(value, True)
  1346. #------------------------------------------------------------------
  1347. @pyqtSlot()
  1348. def slot_channelCustomMenu(self):
  1349. menu = QMenu(self)
  1350. actNone = menu.addAction(self.tr("None"))
  1351. if self.fControlChannel+1 == 0:
  1352. actNone.setCheckable(True)
  1353. actNone.setChecked(True)
  1354. for i in range(1, 16+1):
  1355. action = menu.addAction("%i" % i)
  1356. if self.fControlChannel+1 == i:
  1357. action.setCheckable(True)
  1358. action.setChecked(True)
  1359. actSel = menu.exec_(QCursor.pos())
  1360. if not actSel:
  1361. pass
  1362. elif actSel == actNone:
  1363. self.ui.sb_ctrl_channel.setValue(0)
  1364. elif actSel:
  1365. selChannel = int(actSel.text())
  1366. self.ui.sb_ctrl_channel.setValue(selChannel)
  1367. #------------------------------------------------------------------
  1368. def _createParameterWidgets(self, paramType, paramListFull, tabPageName):
  1369. groupWidgets = {}
  1370. for paramList, width in paramListFull:
  1371. if not paramList:
  1372. break
  1373. tabIndex = self.ui.tabWidget.count()
  1374. scrollArea = QScrollArea(self.ui.tabWidget)
  1375. scrollArea.setWidgetResizable(True)
  1376. scrollArea.setFrameStyle(0)
  1377. palette1 = scrollArea.palette()
  1378. palette1.setColor(QPalette.Background, Qt.transparent)
  1379. scrollArea.setPalette(palette1)
  1380. palette2 = scrollArea.palette()
  1381. palette2.setColor(QPalette.Background, palette2.color(QPalette.Button))
  1382. scrollAreaWidget = QWidget(scrollArea)
  1383. scrollAreaLayout = QVBoxLayout(scrollAreaWidget)
  1384. scrollAreaLayout.setSpacing(3)
  1385. for paramInfo in paramList:
  1386. groupName = paramInfo['groupName']
  1387. if groupName:
  1388. groupSymbol, groupName = groupName.split(":",1)
  1389. groupLayout, groupWidget = groupWidgets.get(groupSymbol, (None, None))
  1390. if groupLayout is None:
  1391. groupWidget = CollapsibleBox(groupName, scrollAreaWidget)
  1392. groupLayout = groupWidget.getContentLayout()
  1393. groupWidget.setPalette(palette2)
  1394. scrollAreaLayout.addWidget(groupWidget)
  1395. groupWidgets[groupSymbol] = (groupLayout, groupWidget)
  1396. else:
  1397. groupLayout = scrollAreaLayout
  1398. groupWidget = scrollAreaWidget
  1399. paramWidget = PluginParameter(groupWidget, self.host, paramInfo, self.fPluginId, tabIndex)
  1400. paramWidget.setLabelWidth(width)
  1401. groupLayout.addWidget(paramWidget)
  1402. self.fParameterList.append((paramType, paramInfo['index'], paramWidget))
  1403. if paramType == PARAMETER_INPUT:
  1404. paramWidget.valueChanged.connect(self.slot_parameterValueChanged)
  1405. paramWidget.mappedControlChanged.connect(self.slot_parameterMappedControlChanged)
  1406. paramWidget.mappedRangeChanged.connect(self.slot_parameterMappedRangeChanged)
  1407. paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged)
  1408. scrollAreaLayout.addStretch()
  1409. scrollArea.setWidget(scrollAreaWidget)
  1410. self.ui.tabWidget.addTab(scrollArea, tabPageName)
  1411. if paramType == PARAMETER_INPUT:
  1412. self.ui.tabWidget.setTabIcon(tabIndex, self.fTabIconOff)
  1413. self.fTabIconTimers.append(ICON_STATE_NULL)
  1414. def _updateCtrlPrograms(self):
  1415. self.ui.keyboard.setEnabled(self.fControlChannel >= 0)
  1416. if self.fPluginInfo['category'] != PLUGIN_CATEGORY_SYNTH:
  1417. return
  1418. if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_SF2):
  1419. return
  1420. if self.fControlChannel < 0:
  1421. self.ui.cb_programs.setEnabled(False)
  1422. self.ui.cb_midi_programs.setEnabled(False)
  1423. return
  1424. self.ui.cb_programs.setEnabled(True)
  1425. self.ui.cb_midi_programs.setEnabled(True)
  1426. pIndex = self.host.get_current_program_index(self.fPluginId)
  1427. if self.ui.cb_programs.currentIndex() != pIndex:
  1428. self.setProgram(pIndex)
  1429. mpIndex = self.host.get_current_midi_program_index(self.fPluginId)
  1430. if self.ui.cb_midi_programs.currentIndex() != mpIndex:
  1431. self.setMidiProgram(mpIndex)
  1432. def _updateParameterValues(self):
  1433. for _, paramId, paramWidget in self.fParameterList:
  1434. paramWidget.blockSignals(True)
  1435. paramWidget.setValue(self.host.get_current_parameter_value(self.fPluginId, paramId))
  1436. paramWidget.blockSignals(False)
  1437. #------------------------------------------------------------------
  1438. def testTimer(self):
  1439. self.fIdleTimerId = self.startTimer(50)
  1440. self.SIGTERM.connect(self.testTimerClose)
  1441. gCarla.gui = self
  1442. setUpSignals()
  1443. def testTimerClose(self):
  1444. self.close()
  1445. _app.quit()
  1446. #------------------------------------------------------------------
  1447. def closeEvent(self, event):
  1448. if self.fIdleTimerId != 0:
  1449. self.killTimer(self.fIdleTimerId)
  1450. self.fIdleTimerId = 0
  1451. self.host.engine_close()
  1452. QDialog.closeEvent(self, event)
  1453. def timerEvent(self, event):
  1454. if event.timerId() == self.fIdleTimerId:
  1455. self.host.engine_idle()
  1456. self.idleSlow()
  1457. QDialog.timerEvent(self, event)
  1458. # ------------------------------------------------------------------------------------------------------------
  1459. # Main
  1460. if __name__ == '__main__':
  1461. from carla_app import CarlaApplication
  1462. from carla_host import initHost as _initHost, loadHostSettings as _loadHostSettings
  1463. _app = CarlaApplication()
  1464. _host = _initHost("Widgets", None, False, False, False)
  1465. _loadHostSettings(_host)
  1466. _host.engine_init("JACK", "Carla-Widgets")
  1467. _host.add_plugin(BINARY_NATIVE, PLUGIN_DSSI, "/usr/lib/dssi/karplong.so", "karplong", "karplong", 0, None, 0x0)
  1468. _host.set_active(0, True)
  1469. gui1 = CarlaAboutW(None, _host)
  1470. gui1.show()
  1471. gui2 = PluginEdit(None, _host, 0)
  1472. gui2.testTimer()
  1473. gui2.show()
  1474. _app.exit_exec()