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.

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