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.

635 lines
22KB

  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_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  244. CARLA_KEY_ENGINE_AUDIO_DRIVER = "Engine/AudioDriver" # str
  245. CARLA_KEY_ENGINE_PROCESS_MODE = "Engine/ProcessMode" # enum
  246. CARLA_KEY_ENGINE_TRANSPORT_MODE = "Engine/TransportMode" # enum
  247. CARLA_KEY_ENGINE_FORCE_STEREO = "Engine/ForceStereo" # bool
  248. CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES = "Engine/PreferPluginBridges" # bool
  249. CARLA_KEY_ENGINE_PREFER_UI_BRIDGES = "Engine/PreferUiBridges" # bool
  250. CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  251. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  252. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  253. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  254. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  255. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  256. CARLA_KEY_PATHS_VST = "Paths/VST"
  257. CARLA_KEY_PATHS_AU = "Paths/AU"
  258. CARLA_KEY_PATHS_CSD = "Paths/CSD"
  259. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  260. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  261. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  262. # ------------------------------------------------------------------------------------------------------------
  263. # Global Carla object
  264. class CarlaObject(object):
  265. __slots__ = [
  266. # Host library object
  267. 'host',
  268. # Host Window
  269. 'gui',
  270. # bool, is controller
  271. 'isControl',
  272. # bool, is running local
  273. 'isLocal',
  274. # bool, is plugin
  275. 'isPlugin',
  276. # current buffer size
  277. 'bufferSize',
  278. # current sample rate
  279. 'sampleRate',
  280. # current process mode
  281. 'processMode',
  282. # current transport mode
  283. 'transportMode',
  284. # current max parameters
  285. 'maxParameters',
  286. # discovery tools
  287. 'discovery_native',
  288. 'discovery_posix32',
  289. 'discovery_posix64',
  290. 'discovery_win32',
  291. 'discovery_win64',
  292. # default paths
  293. 'DEFAULT_LADSPA_PATH',
  294. 'DEFAULT_DSSI_PATH',
  295. 'DEFAULT_LV2_PATH',
  296. 'DEFAULT_VST_PATH',
  297. 'DEFAULT_AU_PATH',
  298. 'DEFAULT_CSOUND_PATH',
  299. 'DEFAULT_GIG_PATH',
  300. 'DEFAULT_SF2_PATH',
  301. 'DEFAULT_SFZ_PATH'
  302. ]
  303. Carla = CarlaObject()
  304. Carla.host = None
  305. Carla.gui = None
  306. Carla.isControl = False
  307. Carla.isLocal = True
  308. Carla.isPlugin = False
  309. Carla.bufferSize = 0
  310. Carla.sampleRate = 0.0
  311. Carla.processMode = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS if LINUX else ENGINE_PROCESS_MODE_CONTINUOUS_RACK
  312. Carla.transportMode = ENGINE_TRANSPORT_MODE_JACK if LINUX else ENGINE_TRANSPORT_MODE_INTERNAL
  313. Carla.maxParameters = MAX_DEFAULT_PARAMETERS
  314. Carla.discovery_native = ""
  315. Carla.discovery_posix32 = ""
  316. Carla.discovery_posix64 = ""
  317. Carla.discovery_win32 = ""
  318. Carla.discovery_win64 = ""
  319. # ------------------------------------------------------------------------------------------------------------
  320. # Default Plugin Folders (set)
  321. readEnvVars = True
  322. if WINDOWS:
  323. # Check if running Wine. If yes, ignore env vars
  324. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  325. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  326. try:
  327. key = OpenKey(reg, r"SOFTWARE\Wine")
  328. CloseKey(key)
  329. readEnvVars = False
  330. except:
  331. pass
  332. CloseKey(reg)
  333. del reg
  334. if readEnvVars:
  335. Carla.DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  336. Carla.DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  337. Carla.DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  338. Carla.DEFAULT_VST_PATH = os.getenv("VST_PATH", DEFAULT_VST_PATH).split(splitter)
  339. Carla.DEFAULT_AU_PATH = os.getenv("AU_PATH", DEFAULT_AU_PATH).split(splitter)
  340. Carla.DEFAULT_CSOUND_PATH = os.getenv("CSOUND_PATH", DEFAULT_CSOUND_PATH).split(splitter)
  341. Carla.DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  342. Carla.DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  343. Carla.DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  344. else:
  345. Carla.DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  346. Carla.DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  347. Carla.DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  348. Carla.DEFAULT_VST_PATH = DEFAULT_VST_PATH.split(splitter)
  349. Carla.DEFAULT_AU_PATH = DEFAULT_AU_PATH.split(splitter)
  350. Carla.DEFAULT_CSOUND_PATH = DEFAULT_CSOUND_PATH.split(splitter)
  351. Carla.DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  352. Carla.DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  353. Carla.DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  354. # ------------------------------------------------------------------------------------------------------------
  355. # Search for Carla tools
  356. CWD = sys.path[0]
  357. # make it work with cxfreeze
  358. if CWD.endswith("/carla"):
  359. CWD = CWD.rsplit("/carla", 1)[0]
  360. elif CWD.endswith("\\carla.exe"):
  361. CWD = CWD.rsplit("\\carla.exe", 1)[0]
  362. # find tool
  363. def findTool(toolDir, toolName):
  364. path = os.path.join(CWD, toolDir, toolName)
  365. if os.path.exists(path):
  366. return path
  367. for p in PATH:
  368. path = os.path.join(p, toolName)
  369. if os.path.exists(path):
  370. return path
  371. return ""
  372. # ------------------------------------------------------------------------------------------------------------
  373. # Init host
  374. def initHost(appName, libPrefix = None, failError = True):
  375. # -------------------------------------------------------------
  376. # Set Carla library name
  377. libname = "libcarla_"
  378. if Carla.isControl:
  379. libname += "control2"
  380. else:
  381. libname += "standalone2"
  382. if WINDOWS:
  383. libname += ".dll"
  384. elif MACOS:
  385. libname += ".dylib"
  386. else:
  387. libname += ".so"
  388. # -------------------------------------------------------------
  389. # Search for the Carla library
  390. libfilename = ""
  391. if libPrefix is not None:
  392. libfilename = os.path.join(libPrefix, "lib", "carla", libname)
  393. else:
  394. path = os.path.join(CWD, "backend", libname)
  395. if os.path.exists(path):
  396. libfilename = path
  397. else:
  398. path = os.getenv("CARLA_LIB_PATH")
  399. if path and os.path.exists(path):
  400. CARLA_LIB_PATH = (path,)
  401. elif WINDOWS:
  402. CARLA_LIB_PATH = (os.path.join(PROGRAMFILES, "Carla"),)
  403. elif MACOS:
  404. CARLA_LIB_PATH = ("/opt/local/lib", "/usr/local/lib/", "/usr/lib")
  405. else:
  406. CARLA_LIB_PATH = ("/usr/local/lib/", "/usr/lib")
  407. for libpath in CARLA_LIB_PATH:
  408. path = os.path.join(libpath, "carla", libname)
  409. if os.path.exists(path):
  410. libfilename = path
  411. break
  412. # -------------------------------------------------------------
  413. # find windows tools
  414. Carla.discovery_win32 = findTool("discovery", "carla-discovery-win32.exe")
  415. Carla.discovery_win64 = findTool("discovery", "carla-discovery-win64.exe")
  416. # -------------------------------------------------------------
  417. # find native and posix tools
  418. if not WINDOWS:
  419. Carla.discovery_native = findTool("discovery", "carla-discovery-native")
  420. Carla.discovery_posix32 = findTool("discovery", "carla-discovery-posix32")
  421. Carla.discovery_posix64 = findTool("discovery", "carla-discovery-posix64")
  422. # -------------------------------------------------------------
  423. if not (libfilename or Carla.isPlugin):
  424. if failError:
  425. QMessageBox.critical(None, "Error", "Failed to find the carla library, cannot continue")
  426. sys.exit(1)
  427. return
  428. # -------------------------------------------------------------
  429. # Init host
  430. if Carla.host is None:
  431. Carla.host = Host(libfilename)
  432. # -------------------------------------------------------------
  433. # Set binary path
  434. libfolder = libfilename.replace(libname, "")
  435. localBinaries = os.path.join(libfolder, "..", "bridges")
  436. systemBinaries = os.path.join(libfolder, "bridges")
  437. if os.path.exists(libfolder):
  438. Carla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, libfolder)
  439. elif os.path.exists(localBinaries):
  440. Carla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, localBinaries)
  441. elif os.path.exists(systemBinaries):
  442. Carla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, systemBinaries)
  443. # -------------------------------------------------------------
  444. # Set resource path
  445. localResources = os.path.join(libfolder, "..", "modules", "daz-plugins", "resources")
  446. systemResources = os.path.join(libfolder, "resources")
  447. if os.path.exists(localResources):
  448. Carla.host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, localResources)
  449. elif os.path.exists(systemResources):
  450. Carla.host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, systemResources)
  451. # ------------------------------------------------------------------------------------------------------------
  452. # Check if a value is a number (float support)
  453. def isNumber(value):
  454. try:
  455. float(value)
  456. return True
  457. except:
  458. return False
  459. # ------------------------------------------------------------------------------------------------------------
  460. # Convert a value to a list
  461. def toList(value):
  462. if value is None:
  463. return []
  464. elif not isinstance(value, list):
  465. return [value]
  466. else:
  467. return value
  468. # ------------------------------------------------------------------------------------------------------------
  469. # Get Icon from user theme, using our own as backup (Oxygen)
  470. def getIcon(icon, size=16):
  471. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  472. # ------------------------------------------------------------------------------------------------------------
  473. # Signal handler
  474. def signalHandler(sig, frame):
  475. if Carla.gui is None:
  476. return
  477. if sig in (SIGINT, SIGTERM):
  478. Carla.gui.SIGTERM.emit()
  479. elif haveSIGUSR1 and sig == SIGUSR1:
  480. Carla.gui.SIGUSR1.emit()
  481. def setUpSignals():
  482. signal(SIGINT, signalHandler)
  483. signal(SIGTERM, signalHandler)
  484. if not haveSIGUSR1:
  485. return
  486. signal(SIGUSR1, signalHandler)
  487. # ------------------------------------------------------------------------------------------------------------
  488. # QLineEdit and QPushButton combo
  489. def getAndSetPath(self_, currentPath, lineEdit):
  490. newPath = QFileDialog.getExistingDirectory(self_, self_.tr("Set Path"), currentPath, QFileDialog.ShowDirsOnly)
  491. if newPath:
  492. lineEdit.setText(newPath)
  493. return newPath
  494. # ------------------------------------------------------------------------------------------------------------
  495. # Custom MessageBox
  496. def CustomMessageBox(self_, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  497. msgBox = QMessageBox(self_)
  498. msgBox.setIcon(icon)
  499. msgBox.setWindowTitle(title)
  500. msgBox.setText(text)
  501. msgBox.setInformativeText(extraText)
  502. msgBox.setStandardButtons(buttons)
  503. msgBox.setDefaultButton(defButton)
  504. return msgBox.exec_()