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.

668 lines
23KB

  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 doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. import os
  20. import sys
  21. from PyQt4.QtCore import qFatal, qWarning
  22. from PyQt4.QtGui import QIcon
  23. from PyQt4.QtGui import QFileDialog, QMessageBox
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Import Signal
  26. from signal import signal, SIGINT, SIGTERM
  27. try:
  28. from signal import SIGUSR1
  29. haveSIGUSR1 = True
  30. except:
  31. haveSIGUSR1 = False
  32. # ------------------------------------------------------------------------------------------------------------
  33. # Imports (Custom)
  34. from carla_backend import *
  35. # ------------------------------------------------------------------------------------------------------------
  36. # Platform specific stuff
  37. if MACOS:
  38. from PyQt4.QtGui import qt_mac_set_menubar_icons
  39. qt_mac_set_menubar_icons(False)
  40. elif WINDOWS:
  41. WINDIR = os.getenv("WINDIR")
  42. # ------------------------------------------------------------------------------------------------------------
  43. # Set Version
  44. VERSION = "1.9.0"
  45. # ------------------------------------------------------------------------------------------------------------
  46. # Set TMP
  47. TMP = os.getenv("TMP")
  48. if TMP is None:
  49. if WINDOWS:
  50. qWarning("TMP variable not set")
  51. TMP = os.path.join(WINDIR, "temp")
  52. else:
  53. TMP = "/tmp"
  54. elif not os.path.exists(TMP):
  55. qWarning("TMP does not exist")
  56. TMP = "/tmp"
  57. # ------------------------------------------------------------------------------------------------------------
  58. # Set HOME
  59. HOME = os.getenv("HOME")
  60. if HOME is None:
  61. HOME = os.path.expanduser("~")
  62. if LINUX or MACOS:
  63. qWarning("HOME variable not set")
  64. if not os.path.exists(HOME):
  65. qWarning("HOME does not exist")
  66. HOME = TMP
  67. # ------------------------------------------------------------------------------------------------------------
  68. # Set PATH
  69. PATH = os.getenv("PATH")
  70. if PATH is None:
  71. qWarning("PATH variable not set")
  72. if MACOS:
  73. PATH = ("/opt/local/bin", "/usr/local/bin", "/usr/bin", "/bin")
  74. elif WINDOWS:
  75. PATH = (os.path.join(WINDIR, "system32"), WINDIR)
  76. else:
  77. PATH = ("/usr/local/bin", "/usr/bin", "/bin")
  78. else:
  79. PATH = PATH.split(os.pathsep)
  80. # ------------------------------------------------------------------------------------------------------------
  81. # Static MIDI CC list
  82. MIDI_CC_LIST = (
  83. "0x01 Modulation",
  84. "0x02 Breath",
  85. "0x03 (Undefined)",
  86. "0x04 Foot",
  87. "0x05 Portamento",
  88. "0x07 Volume",
  89. "0x08 Balance",
  90. "0x09 (Undefined)",
  91. "0x0A Pan",
  92. "0x0B Expression",
  93. "0x0C FX Control 1",
  94. "0x0D FX Control 2",
  95. "0x0E (Undefined)",
  96. "0x0F (Undefined)",
  97. "0x10 General Purpose 1",
  98. "0x11 General Purpose 2",
  99. "0x12 General Purpose 3",
  100. "0x13 General Purpose 4",
  101. "0x14 (Undefined)",
  102. "0x15 (Undefined)",
  103. "0x16 (Undefined)",
  104. "0x17 (Undefined)",
  105. "0x18 (Undefined)",
  106. "0x19 (Undefined)",
  107. "0x1A (Undefined)",
  108. "0x1B (Undefined)",
  109. "0x1C (Undefined)",
  110. "0x1D (Undefined)",
  111. "0x1E (Undefined)",
  112. "0x1F (Undefined)",
  113. "0x46 Control 1 [Variation]",
  114. "0x47 Control 2 [Timbre]",
  115. "0x48 Control 3 [Release]",
  116. "0x49 Control 4 [Attack]",
  117. "0x4A Control 5 [Brightness]",
  118. "0x4B Control 6 [Decay]",
  119. "0x4C Control 7 [Vib Rate]",
  120. "0x4D Control 8 [Vib Depth]",
  121. "0x4E Control 9 [Vib Delay]",
  122. "0x4F Control 10 [Undefined]",
  123. "0x50 General Purpose 5",
  124. "0x51 General Purpose 6",
  125. "0x52 General Purpose 7",
  126. "0x53 General Purpose 8",
  127. "0x54 Portamento Control",
  128. "0x5B FX 1 Depth [Reverb]",
  129. "0x5C FX 2 Depth [Tremolo]",
  130. "0x5D FX 3 Depth [Chorus]",
  131. "0x5E FX 4 Depth [Detune]",
  132. "0x5F FX 5 Depth [Phaser]"
  133. )
  134. # ------------------------------------------------------------------------------------------------------------
  135. # Default Plugin Folders (get)
  136. if WINDOWS:
  137. splitter = ";"
  138. APPDATA = os.getenv("APPDATA")
  139. PROGRAMFILES = os.getenv("PROGRAMFILES")
  140. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  141. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  142. # Small integrity tests
  143. if not APPDATA:
  144. qFatal("APPDATA variable not set, cannot continue")
  145. sys.exit(1)
  146. if not PROGRAMFILES:
  147. qFatal("PROGRAMFILES variable not set, cannot continue")
  148. sys.exit(1)
  149. if not COMMONPROGRAMFILES:
  150. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  151. sys.exit(1)
  152. DEFAULT_LADSPA_PATH = ";".join((os.path.join(APPDATA, "LADSPA"),
  153. os.path.join(PROGRAMFILES, "LADSPA")))
  154. DEFAULT_DSSI_PATH = ";".join((os.path.join(APPDATA, "DSSI"),
  155. os.path.join(PROGRAMFILES, "DSSI")))
  156. DEFAULT_LV2_PATH = ";".join((os.path.join(APPDATA, "LV2"),
  157. os.path.join(COMMONPROGRAMFILES, "LV2")))
  158. DEFAULT_VST_PATH = ";".join((os.path.join(PROGRAMFILES, "VstPlugins"),
  159. os.path.join(PROGRAMFILES, "Steinberg", "VstPlugins")))
  160. DEFAULT_AU_PATH = ""
  161. # TODO
  162. DEFAULT_CSOUND_PATH = ""
  163. DEFAULT_GIG_PATH = ";".join((os.path.join(APPDATA, "GIG"),))
  164. DEFAULT_SF2_PATH = ";".join((os.path.join(APPDATA, "SF2"),))
  165. DEFAULT_SFZ_PATH = ";".join((os.path.join(APPDATA, "SFZ"),))
  166. if PROGRAMFILESx86:
  167. DEFAULT_LADSPA_PATH += ";"+os.path.join(PROGRAMFILESx86, "LADSPA")
  168. DEFAULT_DSSI_PATH += ";"+os.path.join(PROGRAMFILESx86, "DSSI")
  169. DEFAULT_VST_PATH += ";"+os.path.join(PROGRAMFILESx86, "VstPlugins")
  170. DEFAULT_VST_PATH += ";"+os.path.join(PROGRAMFILESx86, "Steinberg", "VstPlugins")
  171. elif HAIKU:
  172. splitter = ":"
  173. DEFAULT_LADSPA_PATH = ":".join((os.path.join(HOME, ".ladspa"),
  174. os.path.join("/", "boot", "common", "add-ons", "ladspa")))
  175. DEFAULT_DSSI_PATH = ":".join((os.path.join(HOME, ".dssi"),
  176. os.path.join("/", "boot", "common", "add-ons", "dssi")))
  177. DEFAULT_LV2_PATH = ":".join((os.path.join(HOME, ".lv2"),
  178. os.path.join("/", "boot", "common", "add-ons", "lv2")))
  179. DEFAULT_VST_PATH = ":".join((os.path.join(HOME, ".vst"),
  180. os.path.join("/", "boot", "common", "add-ons", "vst")))
  181. DEFAULT_AU_PATH = ""
  182. # TODO
  183. DEFAULT_CSOUND_PATH = ""
  184. # TODO
  185. DEFAULT_GIG_PATH = ""
  186. DEFAULT_SF2_PATH = ""
  187. DEFAULT_SFZ_PATH = ""
  188. elif MACOS:
  189. splitter = ":"
  190. DEFAULT_LADSPA_PATH = ":".join((os.path.join(HOME, "Library", "Audio", "Plug-Ins", "LADSPA"),
  191. os.path.join("/", "Library", "Audio", "Plug-Ins", "LADSPA")))
  192. DEFAULT_DSSI_PATH = ":".join((os.path.join(HOME, "Library", "Audio", "Plug-Ins", "DSSI"),
  193. os.path.join("/", "Library", "Audio", "Plug-Ins", "DSSI")))
  194. DEFAULT_LV2_PATH = ":".join((os.path.join(HOME, "Library", "Audio", "Plug-Ins", "LV2"),
  195. os.path.join("/", "Library", "Audio", "Plug-Ins", "LV2")))
  196. DEFAULT_VST_PATH = ":".join((os.path.join(HOME, "Library", "Audio", "Plug-Ins", "VST"),
  197. os.path.join("/", "Library", "Audio", "Plug-Ins", "VST")))
  198. DEFAULT_AU_PATH = ":".join((os.path.join(HOME, "Library", "Audio", "Plug-Ins", "Components"),
  199. os.path.join("/", "Library", "Audio", "Plug-Ins", "Components")))
  200. # TODO
  201. DEFAULT_CSOUND_PATH = ""
  202. # TODO
  203. DEFAULT_GIG_PATH = ""
  204. DEFAULT_SF2_PATH = ""
  205. DEFAULT_SFZ_PATH = ""
  206. else:
  207. splitter = ":"
  208. DEFAULT_LADSPA_PATH = ":".join((os.path.join(HOME, ".ladspa"),
  209. os.path.join("/", "usr", "lib", "ladspa"),
  210. os.path.join("/", "usr", "local", "lib", "ladspa")))
  211. DEFAULT_DSSI_PATH = ":".join((os.path.join(HOME, ".dssi"),
  212. os.path.join("/", "usr", "lib", "dssi"),
  213. os.path.join("/", "usr", "local", "lib", "dssi")))
  214. DEFAULT_LV2_PATH = ":".join((os.path.join(HOME, ".lv2"),
  215. os.path.join("/", "usr", "lib", "lv2"),
  216. os.path.join("/", "usr", "local", "lib", "lv2")))
  217. DEFAULT_VST_PATH = ":".join((os.path.join(HOME, ".vst"),
  218. os.path.join("/", "usr", "lib", "vst"),
  219. os.path.join("/", "usr", "local", "lib", "vst")))
  220. DEFAULT_AU_PATH = ""
  221. # TODO
  222. DEFAULT_CSOUND_PATH = ""
  223. DEFAULT_GIG_PATH = ":".join((os.path.join(HOME, ".sounds", "gig"),
  224. os.path.join("/", "usr", "share", "sounds", "gig")))
  225. DEFAULT_SF2_PATH = ":".join((os.path.join(HOME, ".sounds", "sf2"),
  226. os.path.join("/", "usr", "share", "sounds", "sf2")))
  227. DEFAULT_SFZ_PATH = ":".join((os.path.join(HOME, ".sounds", "sfz"),
  228. os.path.join("/", "usr", "share", "sounds", "sfz")))
  229. # ------------------------------------------------------------------------------------------------------------
  230. # Carla Settings keys
  231. CARLA_KEY_MAIN_PROJECT_FOLDER = "Main/ProjectFolder" # str
  232. CARLA_KEY_MAIN_USE_PRO_THEME = "Main/UseProTheme" # bool
  233. CARLA_KEY_MAIN_PRO_THEME_COLOR = "Main/ProThemeColor" # str
  234. CARLA_KEY_MAIN_REFRESH_INTERVAL = "Main/RefreshInterval" # int
  235. CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str
  236. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  237. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  238. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  239. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy" # enum
  240. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  241. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  242. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  243. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # bool
  244. CARLA_KEY_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  245. CARLA_KEY_ENGINE_AUDIO_DRIVER = "Engine/AudioDriver" # str
  246. CARLA_KEY_ENGINE_PROCESS_MODE = "Engine/ProcessMode" # enum
  247. CARLA_KEY_ENGINE_TRANSPORT_MODE = "Engine/TransportMode" # enum
  248. CARLA_KEY_ENGINE_FORCE_STEREO = "Engine/ForceStereo" # bool
  249. CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES = "Engine/PreferPluginBridges" # bool
  250. CARLA_KEY_ENGINE_PREFER_UI_BRIDGES = "Engine/PreferUiBridges" # bool
  251. CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  252. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  253. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  254. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  255. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  256. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  257. CARLA_KEY_PATHS_VST = "Paths/VST"
  258. CARLA_KEY_PATHS_AU = "Paths/AU"
  259. CARLA_KEY_PATHS_CSD = "Paths/CSD"
  260. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  261. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  262. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  263. # ------------------------------------------------------------------------------------------------------------
  264. # Global Carla object
  265. class CarlaObject(object):
  266. __slots__ = [
  267. # Host library object
  268. 'host',
  269. # Host Window
  270. 'gui',
  271. # bool, is controller
  272. 'isControl',
  273. # bool, is running local
  274. 'isLocal',
  275. # bool, is plugin
  276. 'isPlugin',
  277. # current buffer size
  278. 'bufferSize',
  279. # current sample rate
  280. 'sampleRate',
  281. # current process mode
  282. 'processMode',
  283. # current transport mode
  284. 'transportMode',
  285. # current max parameters
  286. 'maxParameters',
  287. # discovery tools
  288. 'discovery_native',
  289. 'discovery_posix32',
  290. 'discovery_posix64',
  291. 'discovery_win32',
  292. 'discovery_win64',
  293. # default paths
  294. 'DEFAULT_LADSPA_PATH',
  295. 'DEFAULT_DSSI_PATH',
  296. 'DEFAULT_LV2_PATH',
  297. 'DEFAULT_VST_PATH',
  298. 'DEFAULT_AU_PATH',
  299. 'DEFAULT_CSOUND_PATH',
  300. 'DEFAULT_GIG_PATH',
  301. 'DEFAULT_SF2_PATH',
  302. 'DEFAULT_SFZ_PATH'
  303. ]
  304. Carla = CarlaObject()
  305. Carla.host = None
  306. Carla.gui = None
  307. Carla.isControl = False
  308. Carla.isLocal = True
  309. Carla.isPlugin = False
  310. Carla.bufferSize = 0
  311. Carla.sampleRate = 0.0
  312. Carla.processMode = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS if LINUX else ENGINE_PROCESS_MODE_CONTINUOUS_RACK
  313. Carla.transportMode = ENGINE_TRANSPORT_MODE_JACK if LINUX else ENGINE_TRANSPORT_MODE_INTERNAL
  314. Carla.maxParameters = MAX_DEFAULT_PARAMETERS
  315. Carla.discovery_native = ""
  316. Carla.discovery_posix32 = ""
  317. Carla.discovery_posix64 = ""
  318. Carla.discovery_win32 = ""
  319. Carla.discovery_win64 = ""
  320. # ------------------------------------------------------------------------------------------------------------
  321. # Default Plugin Folders (set)
  322. readEnvVars = True
  323. if WINDOWS:
  324. # Check if running Wine. If yes, ignore env vars
  325. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  326. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  327. try:
  328. key = OpenKey(reg, r"SOFTWARE\Wine")
  329. CloseKey(key)
  330. readEnvVars = False
  331. except:
  332. pass
  333. CloseKey(reg)
  334. del reg
  335. if readEnvVars:
  336. Carla.DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  337. Carla.DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  338. Carla.DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  339. Carla.DEFAULT_VST_PATH = os.getenv("VST_PATH", DEFAULT_VST_PATH).split(splitter)
  340. Carla.DEFAULT_AU_PATH = os.getenv("AU_PATH", DEFAULT_AU_PATH).split(splitter)
  341. Carla.DEFAULT_CSOUND_PATH = os.getenv("CSOUND_PATH", DEFAULT_CSOUND_PATH).split(splitter)
  342. Carla.DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  343. Carla.DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  344. Carla.DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  345. else:
  346. Carla.DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  347. Carla.DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  348. Carla.DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  349. Carla.DEFAULT_VST_PATH = DEFAULT_VST_PATH.split(splitter)
  350. Carla.DEFAULT_AU_PATH = DEFAULT_AU_PATH.split(splitter)
  351. Carla.DEFAULT_CSOUND_PATH = DEFAULT_CSOUND_PATH.split(splitter)
  352. Carla.DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  353. Carla.DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  354. Carla.DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  355. # ------------------------------------------------------------------------------------------------------------
  356. # Search for Carla tools
  357. CWD = sys.path[0]
  358. # make it work with cxfreeze
  359. if CWD.endswith("/carla"):
  360. CWD = CWD.rsplit("/carla", 1)[0]
  361. elif CWD.endswith("\\carla.exe"):
  362. CWD = CWD.rsplit("\\carla.exe", 1)[0]
  363. # find tool
  364. def findTool(toolDir, toolName):
  365. path = os.path.join(CWD, toolDir, toolName)
  366. if os.path.exists(path):
  367. return path
  368. for p in PATH:
  369. path = os.path.join(p, toolName)
  370. if os.path.exists(path):
  371. return path
  372. return ""
  373. # ------------------------------------------------------------------------------------------------------------
  374. # Init host
  375. def initHost(appName, libPrefix = None, failError = True):
  376. # -------------------------------------------------------------
  377. # Set Carla library name
  378. libname = "libcarla_"
  379. if Carla.isControl:
  380. libname += "control2"
  381. else:
  382. libname += "standalone2"
  383. if WINDOWS:
  384. libname += ".dll"
  385. elif MACOS:
  386. libname += ".dylib"
  387. else:
  388. libname += ".so"
  389. # -------------------------------------------------------------
  390. # Search for the Carla library
  391. libfilename = ""
  392. if libPrefix is not None:
  393. libfilename = os.path.join(libPrefix, "lib", "carla", libname)
  394. else:
  395. path = os.path.join(CWD, "backend", libname)
  396. if os.path.exists(path):
  397. libfilename = path
  398. else:
  399. path = os.getenv("CARLA_LIB_PATH")
  400. if path and os.path.exists(path):
  401. CARLA_LIB_PATH = (path,)
  402. elif WINDOWS:
  403. CARLA_LIB_PATH = (os.path.join(PROGRAMFILES, "Carla"),)
  404. elif MACOS:
  405. CARLA_LIB_PATH = ("/opt/local/lib", "/usr/local/lib/", "/usr/lib")
  406. else:
  407. CARLA_LIB_PATH = ("/usr/local/lib/", "/usr/lib")
  408. for libpath in CARLA_LIB_PATH:
  409. path = os.path.join(libpath, "carla", libname)
  410. if os.path.exists(path):
  411. libfilename = path
  412. break
  413. # -------------------------------------------------------------
  414. # find windows tools
  415. Carla.discovery_win32 = findTool("discovery", "carla-discovery-win32.exe")
  416. Carla.discovery_win64 = findTool("discovery", "carla-discovery-win64.exe")
  417. # -------------------------------------------------------------
  418. # find native and posix tools
  419. if not WINDOWS:
  420. Carla.discovery_native = findTool("discovery", "carla-discovery-native")
  421. Carla.discovery_posix32 = findTool("discovery", "carla-discovery-posix32")
  422. Carla.discovery_posix64 = findTool("discovery", "carla-discovery-posix64")
  423. # -------------------------------------------------------------
  424. if not (libfilename or Carla.isPlugin):
  425. if failError:
  426. QMessageBox.critical(None, "Error", "Failed to find the carla library, cannot continue")
  427. sys.exit(1)
  428. return
  429. # -------------------------------------------------------------
  430. # Init host
  431. if Carla.host is None:
  432. Carla.host = Host(libfilename)
  433. # -------------------------------------------------------------
  434. # Set binary path
  435. libfolder = libfilename.replace(libname, "")
  436. localBinaries = os.path.join(libfolder, "..", "bridges")
  437. systemBinaries = os.path.join(libfolder, "bridges")
  438. if os.path.exists(libfolder):
  439. Carla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, libfolder)
  440. elif os.path.exists(localBinaries):
  441. Carla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, localBinaries)
  442. elif os.path.exists(systemBinaries):
  443. Carla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, systemBinaries)
  444. # -------------------------------------------------------------
  445. # Set resource path
  446. localResources = os.path.join(libfolder, "..", "modules", "native-plugins", "resources")
  447. systemResources = os.path.join(libfolder, "resources")
  448. if os.path.exists(localResources):
  449. Carla.host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, localResources)
  450. elif os.path.exists(systemResources):
  451. Carla.host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, systemResources)
  452. # ------------------------------------------------------------------------------------------------------------
  453. # Check if a value is a number (float support)
  454. def isNumber(value):
  455. try:
  456. float(value)
  457. return True
  458. except:
  459. return False
  460. # ------------------------------------------------------------------------------------------------------------
  461. # Convert a value to a list
  462. def toList(value):
  463. if value is None:
  464. return []
  465. elif not isinstance(value, list):
  466. return [value]
  467. else:
  468. return value
  469. # ------------------------------------------------------------------------------------------------------------
  470. # Get Icon from user theme, using our own as backup (Oxygen)
  471. def getIcon(icon, size=16):
  472. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  473. # ------------------------------------------------------------------------------------------------------------
  474. # Signal handler
  475. def signalHandler(sig, frame):
  476. if Carla.gui is None:
  477. return
  478. if sig in (SIGINT, SIGTERM):
  479. Carla.gui.SIGTERM.emit()
  480. elif haveSIGUSR1 and sig == SIGUSR1:
  481. Carla.gui.SIGUSR1.emit()
  482. def setUpSignals():
  483. signal(SIGINT, signalHandler)
  484. signal(SIGTERM, signalHandler)
  485. if not haveSIGUSR1:
  486. return
  487. signal(SIGUSR1, signalHandler)
  488. # ------------------------------------------------------------------------------------------------------------
  489. # QLineEdit and QPushButton combo
  490. def getAndSetPath(self_, currentPath, lineEdit):
  491. newPath = QFileDialog.getExistingDirectory(self_, self_.tr("Set Path"), currentPath, QFileDialog.ShowDirsOnly)
  492. if newPath:
  493. lineEdit.setText(newPath)
  494. return newPath
  495. # ------------------------------------------------------------------------------------------------------------
  496. # Get plugin type as string
  497. def getPluginTypeAsString(ptype):
  498. if ptype == PLUGIN_INTERNAL:
  499. return "Internal"
  500. if ptype == PLUGIN_LADSPA:
  501. return "LADSPA"
  502. if ptype == PLUGIN_DSSI:
  503. return "DSSI"
  504. if ptype == PLUGIN_LV2:
  505. return "LV2"
  506. if ptype == PLUGIN_VST:
  507. return "VST"
  508. if ptype == PLUGIN_VST3:
  509. return "VST3"
  510. if ptype == PLUGIN_AU:
  511. return "AU"
  512. if ptype == PLUGIN_JACK:
  513. return "JACK"
  514. if ptype == PLUGIN_REWIRE:
  515. return "ReWire"
  516. if ptype == PLUGIN_FILE_CSD:
  517. return "CSD"
  518. if ptype == PLUGIN_FILE_GIG:
  519. return "GIG"
  520. if ptype == PLUGIN_FILE_SF2:
  521. return "SF2"
  522. if ptype == PLUGIN_FILE_SFZ:
  523. return "SFZ"
  524. return "Unknown"
  525. # ------------------------------------------------------------------------------------------------------------
  526. # Custom MessageBox
  527. def CustomMessageBox(self_, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  528. msgBox = QMessageBox(self_)
  529. msgBox.setIcon(icon)
  530. msgBox.setWindowTitle(title)
  531. msgBox.setText(text)
  532. msgBox.setInformativeText(extraText)
  533. msgBox.setStandardButtons(buttons)
  534. msgBox.setDefaultButton(defButton)
  535. return msgBox.exec_()