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_shared.py 29KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Common Carla code
  4. # Copyright (C) 2011-2013 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 GPL.txt file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. import os
  20. import platform
  21. import sys
  22. from codecs import open as codecopen
  23. from copy import deepcopy
  24. #from decimal import Decimal
  25. from PyQt4.QtCore import pyqtSlot, qWarning, SIGNAL, SLOT
  26. #pyqtSlot, qFatal, Qt, QSettings, QTimer
  27. from PyQt4.QtGui import QDialog, QWidget
  28. #from PyQt4.QtGui import QColor, QCursor, QFontMetrics, QFrame, QGraphicsScene, QInputDialog, QLinearGradient, QMenu, QPainter, QPainterPath, QVBoxLayout
  29. #from PyQt4.QtXml import QDomDocument
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (Custom)
  32. import ui_carla_about
  33. #import ui_carla_edit
  34. import ui_carla_parameter
  35. #import ui_carla_plugin
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Try Import Signal
  38. try:
  39. from signal import signal, SIGINT, SIGTERM, SIGUSR1, SIGUSR2
  40. haveSignal = True
  41. except:
  42. haveSignal = False
  43. # ------------------------------------------------------------------------------------------------------------
  44. # Set Platform
  45. if sys.platform == "darwin":
  46. from PyQt4.QtGui import qt_mac_set_menubar_icons
  47. qt_mac_set_menubar_icons(False)
  48. HAIKU = False
  49. LINUX = False
  50. MACOS = True
  51. WINDOWS = False
  52. elif "haiku" in sys.platform:
  53. HAIKU = True
  54. LINUX = False
  55. MACOS = False
  56. WINDOWS = False
  57. elif "linux" in sys.platform:
  58. HAIKU = False
  59. LINUX = True
  60. MACOS = False
  61. WINDOWS = False
  62. elif sys.platform in ("win32", "win64", "cygwin"):
  63. WINDIR = os.getenv("WINDIR")
  64. HAIKU = False
  65. LINUX = False
  66. MACOS = False
  67. WINDOWS = True
  68. else:
  69. HAIKU = False
  70. LINUX = False
  71. MACOS = False
  72. WINDOWS = False
  73. # ------------------------------------------------------------------------------------------------------------
  74. # Set Version
  75. VERSION = "0.5.0"
  76. # ------------------------------------------------------------------------------------------------------------
  77. # Set TMP
  78. TMP = os.getenv("TMP")
  79. if TMP is None:
  80. if WINDOWS:
  81. qWarning("TMP variable not set")
  82. TMP = os.path.join(WINDIR, "temp")
  83. else:
  84. TMP = "/tmp"
  85. # ------------------------------------------------------------------------------------------------------------
  86. # Set HOME
  87. HOME = os.getenv("HOME")
  88. if HOME is None:
  89. HOME = os.path.expanduser("~")
  90. if LINUX or MACOS:
  91. qWarning("HOME variable not set")
  92. if not os.path.exists(HOME):
  93. qWarning("HOME does not exist")
  94. HOME = TMP
  95. # ------------------------------------------------------------------------------------------------------------
  96. # Set PATH
  97. PATH = os.getenv("PATH")
  98. if PATH is None:
  99. qWarning("PATH variable not set")
  100. if MACOS:
  101. PATH = ("/opt/local/bin", "/usr/local/bin", "/usr/bin", "/bin")
  102. elif WINDOWS:
  103. PATH = (os.path.join(WINDIR, "system32"), WINDIR)
  104. else:
  105. PATH = ("/usr/local/bin", "/usr/bin", "/bin")
  106. else:
  107. PATH = PATH.split(os.pathsep)
  108. # ------------------------------------------------------------------------------------------------------------
  109. # 64bit check
  110. kIs64bit = bool(platform.architecture()[0] == "64bit" and sys.maxsize > 2**32)
  111. # ------------------------------------------------------------------------------------------------------------
  112. # Convert a ctypes c_char_p into a python string
  113. def cString(value):
  114. if not value:
  115. return ""
  116. if isinstance(value, str):
  117. return value
  118. return value.decode("utf-8", errors="ignore")
  119. # ------------------------------------------------------------------------------------------------------------
  120. # Check if a value is a number (float support)
  121. def isNumber(value):
  122. try:
  123. float(value)
  124. return True
  125. except:
  126. return False
  127. # ------------------------------------------------------------------------------------------------------------
  128. # Unicode open
  129. def uopen(filename, mode="r"):
  130. return codecopen(filename, encoding="utf-8", mode=mode)
  131. # ------------------------------------------------------------------------------------------------
  132. # Backend defines
  133. MAX_DEFAULT_PLUGINS = 99
  134. MAX_RACK_PLUGINS = 16
  135. MAX_PATCHBAY_PLUGINS = 999
  136. MAX_DEFAULT_PARAMETERS = 200
  137. # Plugin Hints
  138. PLUGIN_IS_BRIDGE = 0x001
  139. PLUGIN_IS_RTSAFE = 0x002
  140. PLUGIN_IS_SYNTH = 0x004
  141. PLUGIN_HAS_GUI = 0x010
  142. PLUGIN_USES_CHUNKS = 0x020
  143. PLUGIN_USES_SINGLE_THREAD = 0x040
  144. PLUGIN_CAN_DRYWET = 0x100
  145. PLUGIN_CAN_VOLUME = 0x200
  146. PLUGIN_CAN_BALANCE = 0x400
  147. PLUGIN_CAN_FORCE_STEREO = 0x800
  148. # Parameter Hints
  149. PARAMETER_IS_BOOLEAN = 0x01
  150. PARAMETER_IS_INTEGER = 0x02
  151. PARAMETER_IS_LOGARITHMIC = 0x04
  152. PARAMETER_IS_ENABLED = 0x08
  153. PARAMETER_IS_AUTOMABLE = 0x10
  154. PARAMETER_USES_SAMPLERATE = 0x20
  155. PARAMETER_USES_SCALEPOINTS = 0x40
  156. PARAMETER_USES_CUSTOM_TEXT = 0x80
  157. # FIXME
  158. # Custom Data types
  159. CUSTOM_DATA_INVALID = None
  160. CUSTOM_DATA_CHUNK = "http://kxstudio.sf.net/ns/carla/chunk"
  161. CUSTOM_DATA_STRING = "http://kxstudio.sf.net/ns/carla/string"
  162. # Binary Type
  163. BINARY_NONE = 0
  164. BINARY_POSIX32 = 1
  165. BINARY_POSIX64 = 2
  166. BINARY_WIN32 = 3
  167. BINARY_WIN64 = 4
  168. BINARY_OTHER = 5
  169. # Plugin Type
  170. PLUGIN_NONE = 0
  171. PLUGIN_INTERNAL = 1
  172. PLUGIN_LADSPA = 2
  173. PLUGIN_DSSI = 3
  174. PLUGIN_LV2 = 4
  175. PLUGIN_VST = 5
  176. PLUGIN_GIG = 6
  177. PLUGIN_SF2 = 7
  178. PLUGIN_SFZ = 8
  179. # Plugin Category
  180. PLUGIN_CATEGORY_NONE = 0
  181. PLUGIN_CATEGORY_SYNTH = 1
  182. PLUGIN_CATEGORY_DELAY = 2 # also Reverb
  183. PLUGIN_CATEGORY_EQ = 3
  184. PLUGIN_CATEGORY_FILTER = 4
  185. PLUGIN_CATEGORY_DYNAMICS = 5 # Amplifier, Compressor, Gate
  186. PLUGIN_CATEGORY_MODULATOR = 6 # Chorus, Flanger, Phaser
  187. PLUGIN_CATEGORY_UTILITY = 7 # Analyzer, Converter, Mixer
  188. PLUGIN_CATEGORY_OTHER = 8 # used to check if a plugin has a category
  189. # Parameter Type
  190. PARAMETER_UNKNOWN = 0
  191. PARAMETER_INPUT = 1
  192. PARAMETER_OUTPUT = 2
  193. PARAMETER_LATENCY = 3
  194. PARAMETER_SAMPLE_RATE = 4
  195. PARAMETER_LV2_FREEWHEEL = 5
  196. PARAMETER_LV2_TIME = 6
  197. # Internal Parameters Index
  198. PARAMETER_NULL = -1
  199. PARAMETER_ACTIVE = -2
  200. PARAMETER_DRYWET = -3
  201. PARAMETER_VOLUME = -4
  202. PARAMETER_BALANCE_LEFT = -5
  203. PARAMETER_BALANCE_RIGHT = -6
  204. PARAMETER_PANNING = -7
  205. # Options Type
  206. OPTION_PROCESS_NAME = 0
  207. OPTION_PROCESS_MODE = 1
  208. OPTION_PROCESS_HIGH_PRECISION = 2
  209. OPTION_FORCE_STEREO = 3
  210. OPTION_PREFER_PLUGIN_BRIDGES = 4
  211. OPTION_PREFER_UI_BRIDGES = 5
  212. OPTION_USE_DSSI_VST_CHUNKS = 6
  213. OPTION_MAX_PARAMETERS = 7
  214. OPTION_OSC_UI_TIMEOUT = 8
  215. OPTION_PREFERRED_BUFFER_SIZE = 9
  216. OPTION_PREFERRED_SAMPLE_RATE = 10
  217. OPTION_PATH_BRIDGE_NATIVE = 11
  218. OPTION_PATH_BRIDGE_POSIX32 = 12
  219. OPTION_PATH_BRIDGE_POSIX64 = 13
  220. OPTION_PATH_BRIDGE_WIN32 = 14
  221. OPTION_PATH_BRIDGE_WIN64 = 15
  222. OPTION_PATH_BRIDGE_LV2_GTK2 = 16
  223. OPTION_PATH_BRIDGE_LV2_GTK3 = 17
  224. OPTION_PATH_BRIDGE_LV2_QT4 = 18
  225. OPTION_PATH_BRIDGE_LV2_QT5 = 19
  226. OPTION_PATH_BRIDGE_LV2_COCOA = 20
  227. OPTION_PATH_BRIDGE_LV2_WINDOWS = 21
  228. OPTION_PATH_BRIDGE_LV2_X11 = 22
  229. OPTION_PATH_BRIDGE_VST_COCOA = 23
  230. OPTION_PATH_BRIDGE_VST_HWND = 24
  231. OPTION_PATH_BRIDGE_VST_X11 = 25
  232. # Callback Type
  233. CALLBACK_DEBUG = 0
  234. CALLBACK_PARAMETER_VALUE_CHANGED = 1
  235. CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED = 2
  236. CALLBACK_PARAMETER_MIDI_CC_CHANGED = 3
  237. CALLBACK_PROGRAM_CHANGED = 4
  238. CALLBACK_MIDI_PROGRAM_CHANGED = 5
  239. CALLBACK_NOTE_ON = 6
  240. CALLBACK_NOTE_OFF = 7
  241. CALLBACK_SHOW_GUI = 8
  242. CALLBACK_UPDATE = 9
  243. CALLBACK_RELOAD_INFO = 10
  244. CALLBACK_RELOAD_PARAMETERS = 11
  245. CALLBACK_RELOAD_PROGRAMS = 12
  246. CALLBACK_RELOAD_ALL = 13
  247. CALLBACK_NSM_ANNOUNCE = 14
  248. CALLBACK_NSM_OPEN1 = 15
  249. CALLBACK_NSM_OPEN2 = 16
  250. CALLBACK_NSM_SAVE = 17
  251. CALLBACK_ERROR = 18
  252. CALLBACK_QUIT = 19
  253. # Process Mode Type
  254. PROCESS_MODE_SINGLE_CLIENT = 0
  255. PROCESS_MODE_MULTIPLE_CLIENTS = 1
  256. PROCESS_MODE_CONTINUOUS_RACK = 2
  257. PROCESS_MODE_PATCHBAY = 3
  258. # Set BINARY_NATIVE
  259. if HAIKU or LINUX or MACOS:
  260. BINARY_NATIVE = BINARY_POSIX64 if kIs64bit else BINARY_POSIX32
  261. elif WINDOWS:
  262. BINARY_NATIVE = BINARY_WIN64 if kIs64bit else BINARY_WIN32
  263. else:
  264. BINARY_NATIVE = BINARY_OTHER
  265. # ------------------------------------------------------------------------------------------------------------
  266. # Carla Host object
  267. class CarlaHostObject(object):
  268. __slots__ = [
  269. 'host',
  270. 'gui',
  271. 'isControl',
  272. 'processMode',
  273. 'maxParameters'
  274. ]
  275. Carla = CarlaHostObject()
  276. Carla.host = None
  277. Carla.gui = None
  278. Carla.isControl = False
  279. Carla.processMode = PROCESS_MODE_CONTINUOUS_RACK
  280. Carla.maxParameters = MAX_RACK_PLUGINS
  281. # ------------------------------------------------------------------------------------------------------------
  282. # Carla GUI stuff
  283. ICON_STATE_NULL = 0
  284. ICON_STATE_WAIT = 1
  285. ICON_STATE_OFF = 2
  286. ICON_STATE_ON = 3
  287. PALETTE_COLOR_NONE = 0
  288. PALETTE_COLOR_WHITE = 1
  289. PALETTE_COLOR_RED = 2
  290. PALETTE_COLOR_GREEN = 3
  291. PALETTE_COLOR_BLUE = 4
  292. PALETTE_COLOR_YELLOW = 5
  293. PALETTE_COLOR_ORANGE = 6
  294. PALETTE_COLOR_BROWN = 7
  295. PALETTE_COLOR_PINK = 8
  296. CarlaStateParameter = {
  297. 'index': 0,
  298. 'name': "",
  299. 'symbol': "",
  300. 'value': 0.0,
  301. 'midiChannel': 1,
  302. 'midiCC': -1
  303. }
  304. CarlaStateCustomData = {
  305. 'type': CUSTOM_DATA_INVALID,
  306. 'key': "",
  307. 'value': ""
  308. }
  309. CarlaSaveState = {
  310. 'type': "",
  311. 'name': "",
  312. 'label': "",
  313. 'binary': "",
  314. 'uniqueId': 0,
  315. 'active': False,
  316. 'dryWet': 1.0,
  317. 'volume': 1.0,
  318. 'balanceLeft': -1.0,
  319. 'balanceRight': 1.0,
  320. 'pannning': 0.0,
  321. 'parameterList': [],
  322. 'currentProgramIndex': -1,
  323. 'currentProgramName': "",
  324. 'currentMidiBank': -1,
  325. 'currentMidiProgram': -1,
  326. 'customDataList': [],
  327. 'chunk': None
  328. }
  329. # ------------------------------------------------------------------------------------------------------------
  330. # Static MIDI CC list
  331. MIDI_CC_LIST = (
  332. #"0x00 Bank Select",
  333. "0x01 Modulation",
  334. "0x02 Breath",
  335. "0x03 (Undefined)",
  336. "0x04 Foot",
  337. "0x05 Portamento",
  338. #"0x06 (Data Entry MSB)",
  339. "0x07 Volume",
  340. "0x08 Balance",
  341. "0x09 (Undefined)",
  342. "0x0A Pan",
  343. "0x0B Expression",
  344. "0x0C FX Control 1",
  345. "0x0D FX Control 2",
  346. "0x0E (Undefined)",
  347. "0x0F (Undefined)",
  348. "0x10 General Purpose 1",
  349. "0x11 General Purpose 2",
  350. "0x12 General Purpose 3",
  351. "0x13 General Purpose 4",
  352. "0x14 (Undefined)",
  353. "0x15 (Undefined)",
  354. "0x16 (Undefined)",
  355. "0x17 (Undefined)",
  356. "0x18 (Undefined)",
  357. "0x19 (Undefined)",
  358. "0x1A (Undefined)",
  359. "0x1B (Undefined)",
  360. "0x1C (Undefined)",
  361. "0x1D (Undefined)",
  362. "0x1E (Undefined)",
  363. "0x1F (Undefined)",
  364. #"0x20 *Bank Select",
  365. #"0x21 *Modulation",
  366. #"0x22 *Breath",
  367. #"0x23 *(Undefined)",
  368. #"0x24 *Foot",
  369. #"0x25 *Portamento",
  370. #"0x26 *(Data Entry MSB)",
  371. #"0x27 *Volume",
  372. #"0x28 *Balance",
  373. #"0x29 *(Undefined)",
  374. #"0x2A *Pan",
  375. #"0x2B *Expression",
  376. #"0x2C *FX *Control 1",
  377. #"0x2D *FX *Control 2",
  378. #"0x2E *(Undefined)",
  379. #"0x2F *(Undefined)",
  380. #"0x30 *General Purpose 1",
  381. #"0x31 *General Purpose 2",
  382. #"0x32 *General Purpose 3",
  383. #"0x33 *General Purpose 4",
  384. #"0x34 *(Undefined)",
  385. #"0x35 *(Undefined)",
  386. #"0x36 *(Undefined)",
  387. #"0x37 *(Undefined)",
  388. #"0x38 *(Undefined)",
  389. #"0x39 *(Undefined)",
  390. #"0x3A *(Undefined)",
  391. #"0x3B *(Undefined)",
  392. #"0x3C *(Undefined)",
  393. #"0x3D *(Undefined)",
  394. #"0x3E *(Undefined)",
  395. #"0x3F *(Undefined)",
  396. #"0x40 Damper On/Off", # <63 off, >64 on
  397. #"0x41 Portamento On/Off", # <63 off, >64 on
  398. #"0x42 Sostenuto On/Off", # <63 off, >64 on
  399. #"0x43 Soft Pedal On/Off", # <63 off, >64 on
  400. #"0x44 Legato Footswitch", # <63 Normal, >64 Legato
  401. #"0x45 Hold 2", # <63 off, >64 on
  402. "0x46 Control 1 [Variation]",
  403. "0x47 Control 2 [Timbre]",
  404. "0x48 Control 3 [Release]",
  405. "0x49 Control 4 [Attack]",
  406. "0x4A Control 5 [Brightness]",
  407. "0x4B Control 6 [Decay]",
  408. "0x4C Control 7 [Vib Rate]",
  409. "0x4D Control 8 [Vib Depth]",
  410. "0x4E Control 9 [Vib Delay]",
  411. "0x4F Control 10 [Undefined]",
  412. "0x50 General Purpose 5",
  413. "0x51 General Purpose 6",
  414. "0x52 General Purpose 7",
  415. "0x53 General Purpose 8",
  416. "0x54 Portamento Control",
  417. "0x5B FX 1 Depth [Reverb]",
  418. "0x5C FX 2 Depth [Tremolo]",
  419. "0x5D FX 3 Depth [Chorus]",
  420. "0x5E FX 4 Depth [Detune]",
  421. "0x5F FX 5 Depth [Phaser]"
  422. )
  423. # ------------------------------------------------------------------------------------------------------------
  424. # Carla XML helpers
  425. def getSaveStateDictFromXML(xmlNode):
  426. saveState = deepcopy(CarlaSaveState)
  427. node = xmlNode.firstChild()
  428. while not node.isNull():
  429. # ------------------------------------------------------
  430. # Info
  431. if node.toElement().tagName() == "Info":
  432. xmlInfo = node.toElement().firstChild()
  433. while not xmlInfo.isNull():
  434. tag = xmlInfo.toElement().tagName()
  435. text = xmlInfo.toElement().text().strip()
  436. if tag == "Type":
  437. saveState["type"] = text
  438. elif tag == "Name":
  439. saveState["name"] = xmlSafeString(text, False)
  440. elif tag in ("Label", "URI"):
  441. saveState["label"] = xmlSafeString(text, False)
  442. elif tag == "Binary":
  443. saveState["binary"] = xmlSafeString(text, False)
  444. elif tag == "UniqueID":
  445. if text.isdigit(): saveState["uniqueId"] = int(text)
  446. xmlInfo = xmlInfo.nextSibling()
  447. # ------------------------------------------------------
  448. # Data
  449. elif node.toElement().tagName() == "Data":
  450. xmlData = node.toElement().firstChild()
  451. while not xmlData.isNull():
  452. tag = xmlData.toElement().tagName()
  453. text = xmlData.toElement().text().strip()
  454. # ----------------------------------------------
  455. # Internal Data
  456. if tag == "Active":
  457. saveState['active'] = bool(text == "Yes")
  458. elif tag == "DryWet":
  459. if isNumber(text): saveState["dryWet"] = float(text)
  460. elif tag == "Volume":
  461. if isNumber(text): saveState["volume"] = float(text)
  462. elif tag == "Balance-Left":
  463. if isNumber(text): saveState["balanceLeft"] = float(text)
  464. elif tag == "Balance-Right":
  465. if isNumber(text): saveState["balanceRight"] = float(text)
  466. elif tag == "Panning":
  467. if isNumber(text): saveState["pannning"] = float(text)
  468. # ----------------------------------------------
  469. # Program (current)
  470. elif tag == "CurrentProgramIndex":
  471. if text.isdigit(): saveState["currentProgramIndex"] = int(text)
  472. elif tag == "CurrentProgramName":
  473. saveState["currentProgramName"] = xmlSafeString(text, False)
  474. # ----------------------------------------------
  475. # Midi Program (current)
  476. elif tag == "CurrentMidiBank":
  477. if text.isdigit(): saveState["currentMidiBank"] = int(text)
  478. elif tag == "CurrentMidiProgram":
  479. if text.isdigit(): saveState["currentMidiProgram"] = int(text)
  480. # ----------------------------------------------
  481. # Parameters
  482. elif tag == "Parameter":
  483. stateParameter = deepcopy(CarlaStateParameter)
  484. xmlSubData = xmlData.toElement().firstChild()
  485. while not xmlSubData.isNull():
  486. pTag = xmlSubData.toElement().tagName()
  487. pText = xmlSubData.toElement().text().strip()
  488. if pTag == "Index":
  489. if pText.isdigit(): stateParameter["index"] = int(pText)
  490. elif pTag == "Name":
  491. stateParameter["name"] = xmlSafeString(pText, False)
  492. elif pTag == "Symbol":
  493. stateParameter["symbol"] = xmlSafeString(pText, False)
  494. elif pTag == "Value":
  495. if isNumber(pText): stateParameter["value"] = float(pText)
  496. elif pTag == "MidiChannel":
  497. if pText.isdigit(): stateParameter["midiChannel"] = int(pText)
  498. elif pTag == "MidiCC":
  499. if pText.isdigit(): stateParameter["midiCC"] = int(pText)
  500. xmlSubData = xmlSubData.nextSibling()
  501. saveState["parameterList"].append(stateParameter)
  502. # ----------------------------------------------
  503. # Custom Data
  504. elif tag == "CustomData":
  505. stateCustomData = deepcopy(CarlaStateCustomData)
  506. xmlSubData = xmlData.toElement().firstChild()
  507. while not xmlSubData.isNull():
  508. cTag = xmlSubData.toElement().tagName()
  509. cText = xmlSubData.toElement().text().strip()
  510. if cTag == "Type":
  511. stateCustomData["type"] = xmlSafeString(cText, False)
  512. elif cTag == "Key":
  513. stateCustomData["key"] = xmlSafeString(cText, False)
  514. elif cTag == "Value":
  515. stateCustomData["value"] = xmlSafeString(cText, False)
  516. xmlSubData = xmlSubData.nextSibling()
  517. saveState["customDataList"].append(stateCustomData)
  518. # ----------------------------------------------
  519. # Chunk
  520. elif tag == "Chunk":
  521. saveState["chunk"] = xmlSafeString(text, False)
  522. # ----------------------------------------------
  523. xmlData = xmlData.nextSibling()
  524. # ------------------------------------------------------
  525. node = node.nextSibling()
  526. return saveState
  527. def xmlSafeString(string, toXml):
  528. if toXml:
  529. return string.replace("&", "&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;")
  530. else:
  531. return string.replace("&amp;", "&").replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"")
  532. # ------------------------------------------------------------------------------------------------------------
  533. # Carla About dialog
  534. class CarlaAboutW(QDialog):
  535. def __init__(self, parent):
  536. QDialog.__init__(self, parent)
  537. self.ui = ui_carla_about.Ui_CarlaAboutW()
  538. self.ui.setupUi(self)
  539. if Carla.isControl:
  540. extraInfo = " - <b>%s</b>" % self.tr("OSC Bridge Version")
  541. else:
  542. extraInfo = ""
  543. self.ui.l_about.setText(self.tr(""
  544. "<br>Version %s"
  545. "<br>Carla is a Multi-Plugin Host for JACK%s.<br>"
  546. "<br>Copyright (C) 2011-2013 falkTX<br>"
  547. "" % (VERSION, extraInfo)))
  548. if Carla.isControl:
  549. self.ui.l_extended.hide()
  550. self.ui.tabWidget.removeTab(1)
  551. self.ui.tabWidget.removeTab(1)
  552. else:
  553. self.ui.l_extended.setText(cString(Carla.host.get_extended_license_text()))
  554. self.ui.le_osc_url.setText(cString(Carla.host.get_host_osc_url()) if Carla.host.is_engine_running() else self.tr("(Engine not running)"))
  555. self.ui.l_osc_cmds.setText(
  556. " /set_active <i-value>\n"
  557. " /set_drywet <f-value>\n"
  558. " /set_volume <f-value>\n"
  559. " /set_balance_left <f-value>\n"
  560. " /set_balance_right <f-value>\n"
  561. " /set_panning <f-value>\n"
  562. " /set_parameter_value <i-index> <f-value>\n"
  563. " /set_parameter_midi_cc <i-index> <i-cc>\n"
  564. " /set_parameter_midi_channel <i-index> <i-channel>\n"
  565. " /set_program <i-index>\n"
  566. " /set_midi_program <i-index>\n"
  567. " /note_on <i-note> <i-velo>\n"
  568. " /note_off <i-note>\n"
  569. )
  570. self.ui.l_example.setText("/Carla/2/set_parameter_value 5 1.0")
  571. self.ui.l_example_help.setText("<i>(as in this example, \"2\" is the plugin number and \"5\" the parameter)</i>")
  572. self.ui.l_ladspa.setText(self.tr("Everything! (Including LRDF)"))
  573. self.ui.l_dssi.setText(self.tr("Everything! (Including CustomData/Chunks)"))
  574. self.ui.l_lv2.setText(self.tr("About 95&#37; complete (using custom extensions).<br/>"
  575. "Implemented Feature/Extensions:"
  576. "<ul>"
  577. "<li>http://lv2plug.in/ns/ext/atom</li>"
  578. "<li>http://lv2plug.in/ns/ext/buf-size</li>"
  579. "<li>http://lv2plug.in/ns/ext/data-access</li>"
  580. #"<li>http://lv2plug.in/ns/ext/dynmanifest</li>"
  581. "<li>http://lv2plug.in/ns/ext/event</li>"
  582. "<li>http://lv2plug.in/ns/ext/instance-access</li>"
  583. "<li>http://lv2plug.in/ns/ext/log</li>"
  584. "<li>http://lv2plug.in/ns/ext/midi</li>"
  585. "<li>http://lv2plug.in/ns/ext/options</li>"
  586. #"<li>http://lv2plug.in/ns/ext/parameters</li>"
  587. "<li>http://lv2plug.in/ns/ext/patch</li>"
  588. #"<li>http://lv2plug.in/ns/ext/port-groups</li>"
  589. "<li>http://lv2plug.in/ns/ext/port-props</li>"
  590. #"<li>http://lv2plug.in/ns/ext/presets</li>"
  591. "<li>http://lv2plug.in/ns/ext/state</li>"
  592. "<li>http://lv2plug.in/ns/ext/time</li>"
  593. "<li>http://lv2plug.in/ns/ext/uri-map</li>"
  594. "<li>http://lv2plug.in/ns/ext/urid</li>"
  595. "<li>http://lv2plug.in/ns/ext/worker</li>"
  596. "<li>http://lv2plug.in/ns/extensions/ui</li>"
  597. "<li>http://lv2plug.in/ns/extensions/units</li>"
  598. "<li>http://kxstudio.sf.net/ns/lv2ext/external-ui</li>"
  599. "<li>http://kxstudio.sf.net/ns/lv2ext/programs</li>"
  600. "<li>http://kxstudio.sf.net/ns/lv2ext/rtmempool</li>"
  601. "<li>http://ll-plugins.nongnu.org/lv2/ext/midimap</li>"
  602. "<li>http://ll-plugins.nongnu.org/lv2/ext/miditype</li>"
  603. "</ul>"))
  604. self.ui.l_vst.setText(self.tr("<p>About 85&#37; complete (missing vst bank/presets and some minor stuff)</p>"))
  605. def done(self, r):
  606. QDialog.done(self, r)
  607. self.close()
  608. # ------------------------------------------------------------------------------------------------------------
  609. # Plugin Parameter
  610. class PluginParameter(QWidget):
  611. def __init__(self, parent, pInfo, pluginId, tabIndex):
  612. QWidget.__init__(self, parent)
  613. self.ui = ui_carla_parameter.Ui_PluginParameter()
  614. self.ui.setupUi(self)
  615. pType = pInfo['type']
  616. pHints = pInfo['hints']
  617. self.fMidiCC = -1
  618. self.fMidiChannel = 1
  619. self.fParameterId = pInfo['index']
  620. self.fPluginId = pluginId
  621. self.fTabIndex = tabIndex
  622. self.ui.label.setText(pInfo['name'])
  623. for MIDI_CC in MIDI_CC_LIST:
  624. self.ui.combo.addItem(MIDI_CC)
  625. if pType == PARAMETER_INPUT:
  626. self.ui.widget.setMinimum(pInfo['minimum'])
  627. self.ui.widget.setMaximum(pInfo['maximum'])
  628. self.ui.widget.setDefault(pInfo['default'])
  629. self.ui.widget.setValue(pInfo['current'], False)
  630. self.ui.widget.setLabel(pInfo['unit'])
  631. self.ui.widget.setStep(pInfo['step'])
  632. self.ui.widget.setStepSmall(pInfo['stepSmall'])
  633. self.ui.widget.setStepLarge(pInfo['stepLarge'])
  634. self.ui.widget.setScalePoints(pInfo['scalepoints'], bool(pHints & PARAMETER_USES_SCALEPOINTS))
  635. if not pHints & PARAMETER_IS_ENABLED:
  636. self.ui.widget.setReadOnly(True)
  637. self.ui.combo.setEnabled(False)
  638. self.ui.sb_channel.setEnabled(False)
  639. elif not pHints & PARAMETER_IS_AUTOMABLE:
  640. self.ui.combo.setEnabled(False)
  641. self.ui.sb_channel.setEnabled(False)
  642. elif pType == PARAMETER_OUTPUT:
  643. self.ui.widget.setMinimum(pInfo['minimum'])
  644. self.ui.widget.setMaximum(pInfo['maximum'])
  645. self.ui.widget.setValue(pInfo['current'], False)
  646. self.ui.widget.setLabel(pInfo['unit'])
  647. self.ui.widget.setReadOnly(True)
  648. if not pHints & PARAMETER_IS_AUTOMABLE:
  649. self.ui.combo.setEnabled(False)
  650. self.ui.sb_channel.setEnabled(False)
  651. else:
  652. self.ui.widget.setVisible(False)
  653. self.ui.combo.setVisible(False)
  654. self.ui.sb_channel.setVisible(False)
  655. if pHints & PARAMETER_USES_CUSTOM_TEXT:
  656. self.ui.widget.setTextCallback(self._textCallBack)
  657. self.setMidiCC(pInfo['midiCC'])
  658. self.setMidiChannel(pInfo['midiChannel'])
  659. self.connect(self.ui.widget, SIGNAL("valueChanged(double)"), SLOT("slot_valueChanged(double)"))
  660. self.connect(self.ui.sb_channel, SIGNAL("valueChanged(int)"), SLOT("slot_midiChannelChanged(int)"))
  661. self.connect(self.ui.combo, SIGNAL("currentIndexChanged(int)"), SLOT("slot_midiCcChanged(int)"))
  662. #if force_parameters_style:
  663. #self.widget.force_plastique_style()
  664. self.ui.widget.updateAll()
  665. def setDefault(self, value):
  666. self.ui.widget.setDefault(value)
  667. def setValue(self, value, send=True):
  668. self.ui.widget.setValue(value, send)
  669. def setMidiCC(self, cc):
  670. self.fMidiCC = cc
  671. self._setMidiCcInComboBox(cc)
  672. def setMidiChannel(self, channel):
  673. self.fMidiChannel = channel
  674. self.ui.sb_channel.setValue(channel)
  675. def tabIndex(self):
  676. return self.fTabIndex
  677. @pyqtSlot(float)
  678. def slot_valueChanged(self, value):
  679. self.emit(SIGNAL("valueChanged(int, double)"), self.fParameterId, value)
  680. @pyqtSlot(int)
  681. def slot_midiCcChanged(self, ccIndex):
  682. if ccIndex <= 0:
  683. cc = -1
  684. else:
  685. ccStr = MIDI_CC_LIST[ccIndex - 1].split(" ")[0]
  686. cc = int(ccStr, 16)
  687. if self.fMidiCC != cc:
  688. self.emit(SIGNAL("midiCcChanged(int, int)"), self.fParameterId, cc)
  689. self.fMidiCC = cc
  690. @pyqtSlot(int)
  691. def slot_midiChannelChanged(self, channel):
  692. if self.fMidiChannel != channel:
  693. self.emit(SIGNAL("midiChannelChanged(int, int)"), self.fParameterId, channel)
  694. self.fMidiChannel = channel
  695. def _setMidiCcInComboBox(self, cc):
  696. for i in range(len(MIDI_CC_LIST)):
  697. ccStr = MIDI_CC_LIST[i].split(" ")[0]
  698. if int(ccStr, 16) == cc:
  699. ccIndex = i+1
  700. break
  701. else:
  702. ccIndex = 0
  703. self.ui.combo.setCurrentIndex(ccIndex)
  704. def _textCallBack(self):
  705. return cString(Carla.host.get_parameter_text(self.fPluginId, self.fParameterId))
  706. # ------------------------------------------------------------------------------------------------------------
  707. # TESTING
  708. from PyQt4.QtGui import QApplication
  709. Carla.isControl = True
  710. ptest = {
  711. 'index': 0,
  712. 'name': "",
  713. 'symbol': "",
  714. 'current': 0.1,
  715. 'default': 0.3,
  716. 'minimum': 0.0,
  717. 'maximum': 1.0,
  718. 'midiChannel': 7,
  719. 'midiCC': 2,
  720. 'type': PARAMETER_INPUT,
  721. 'hints': PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE,
  722. 'scalepoints': [],
  723. 'step': 0.01,
  724. 'stepSmall': 0.001,
  725. 'stepLarge': 0.1,
  726. 'unit': "un",
  727. }
  728. app = QApplication(sys.argv)
  729. #gui1 = CarlaAboutW(None)
  730. gui2 = PluginParameter(None, ptest, 0, 0)
  731. #gui1.show()
  732. gui2.show()
  733. app.exec_()