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

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