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.

737 lines
26KB

  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_DISABLE_CHECKS = "Main/DisableChecks" # bool
  240. CARLA_KEY_MAIN_REFRESH_INTERVAL = "Main/RefreshInterval" # int
  241. CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str
  242. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  243. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  244. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  245. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy" # enum
  246. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  247. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  248. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  249. CARLA_KEY_ENGINE_ = "Engine/AudioDriver" # str
  250. CARLA_KEY_ENGINE_ = "Engine/ProcessMode" # enum
  251. CARLA_KEY_ENGINE_ = "Engine/MaxParameters" # bool
  252. CARLA_KEY_ENGINE_ = "Engine/UIsAlwaysOnTop" # bool
  253. CARLA_KEY_ENGINE_ = "Engine/PreferUiBridges" # bool
  254. CARLA_KEY_ENGINE_ = "Engine/OscUiTimeout" # int
  255. CARLA_KEY_ENGINE_ = "Engine/PreferPluginBridges" # bool
  256. CARLA_KEY_ENGINE_ = "Engine/ForceStereo" # bool
  257. CARLA_KEY_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  258. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  259. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  260. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  261. CARLA_KEY_PATHS_VST = "Paths/VST"
  262. CARLA_KEY_PATHS_AU = "Paths/AU"
  263. CARLA_KEY_PATHS_CSOUND = "Paths/CSOUND"
  264. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  265. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  266. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  267. # ------------------------------------------------------------------------------------------------------------
  268. # Global Carla object
  269. class CarlaObject(object):
  270. __slots__ = [
  271. # Host library object
  272. 'host',
  273. # Host Window
  274. 'gui',
  275. # bool, is controller
  276. 'isControl',
  277. # bool, is running local
  278. 'isLocal',
  279. # bool, is plugin
  280. 'isPlugin',
  281. # current process mode
  282. 'processMode',
  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.processMode = PROCESS_MODE_MULTIPLE_CLIENTS if LINUX else PROCESS_MODE_CONTINUOUS_RACK
  309. Carla.maxParameters = MAX_DEFAULT_PARAMETERS
  310. Carla.discovery_native = ""
  311. Carla.discovery_posix32 = ""
  312. Carla.discovery_posix64 = ""
  313. Carla.discovery_win32 = ""
  314. Carla.discovery_win64 = ""
  315. # ------------------------------------------------------------------------------------------------------------
  316. # Default Plugin Folders (set)
  317. readEnvVars = True
  318. if WINDOWS:
  319. # Check if running Wine. If yes, ignore env vars
  320. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  321. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  322. try:
  323. key = OpenKey(reg, r"SOFTWARE\Wine")
  324. CloseKey(key)
  325. readEnvVars = False
  326. except:
  327. pass
  328. CloseKey(reg)
  329. del reg
  330. if readEnvVars:
  331. Carla.DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  332. Carla.DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  333. Carla.DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  334. Carla.DEFAULT_VST_PATH = os.getenv("VST_PATH", DEFAULT_VST_PATH).split(splitter)
  335. Carla.DEFAULT_AU_PATH = os.getenv("AU_PATH", DEFAULT_AU_PATH).split(splitter)
  336. Carla.DEFAULT_CSOUND_PATH = os.getenv("CSOUND_PATH", DEFAULT_CSOUND_PATH).split(splitter)
  337. Carla.DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  338. Carla.DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  339. Carla.DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  340. else:
  341. Carla.DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  342. Carla.DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  343. Carla.DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  344. Carla.DEFAULT_VST_PATH = DEFAULT_VST_PATH.split(splitter)
  345. Carla.DEFAULT_AU_PATH = DEFAULT_AU_PATH.split(splitter)
  346. Carla.DEFAULT_CSOUND_PATH = DEFAULT_CSOUND_PATH.split(splitter)
  347. Carla.DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  348. Carla.DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  349. Carla.DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  350. # ------------------------------------------------------------------------------------------------------------
  351. # Search for Carla tools
  352. CWD = sys.path[0]
  353. # make it work with cxfreeze
  354. if CWD.endswith("/carla"):
  355. CWD = CWD.rsplit("/carla", 1)[0]
  356. elif CWD.endswith("\\carla.exe"):
  357. CWD = CWD.rsplit("\\carla.exe", 1)[0]
  358. # find tool
  359. def findTool(toolDir, toolName):
  360. if os.path.exists(os.path.join(CWD, toolDir, toolName)):
  361. return os.path.join(CWD, toolDir, toolName)
  362. for p in PATH:
  363. if os.path.exists(os.path.join(p, toolName)):
  364. return os.path.join(p, toolName)
  365. return ""
  366. # ------------------------------------------------------------------------------------------------------------
  367. # Init host
  368. def initHost(appName, libPrefix = None, failError = True):
  369. # -------------------------------------------------------------
  370. # Search for Carla library
  371. libname = "libcarla_"
  372. if Carla.isControl:
  373. libname += "control"
  374. else:
  375. libname += "standalone"
  376. if WINDOWS:
  377. libname += ".dll"
  378. elif MACOS:
  379. libname += ".dylib"
  380. else:
  381. libname += ".so"
  382. if libPrefix is not None:
  383. libfilename = os.path.join(libPrefix, "lib", "carla", libname)
  384. else:
  385. if os.path.exists(os.path.join(CWD, "backend", libname)):
  386. libfilename = os.path.join(CWD, "backend", libname)
  387. #else:
  388. #CARLA_LIB_PATH = os.getenv("CARLA_LIB_PATH")
  389. #if CARLA_LIB_PATH and os.path.exists(CARLA_LIB_PATH):
  390. #CARLA_LIB_PATH = os.path.join(CARLA_LIB_PATH, "..")
  391. #elif WINDOWS:
  392. #CARLA_LIB_PATH = (os.path.join(PROGRAMFILES, "Carla"),)
  393. #elif MACOS:
  394. #CARLA_LIB_PATH = ("/opt/local/lib", "/usr/local/lib/", "/usr/lib")
  395. #else:
  396. #CARLA_LIB_PATH = ("/usr/local/lib/", "/usr/lib")
  397. #for path in CARLA_LIB_PATH:
  398. #if os.path.exists(os.path.join(path, "carla", libname)):
  399. #libfilename = os.path.join(path, "carla", libname)
  400. #break
  401. # -------------------------------------------------------------
  402. # Search for Carla tools
  403. carla_bridge_native = ""
  404. carla_bridge_posix32 = ""
  405. carla_bridge_posix64 = ""
  406. carla_bridge_win32 = ""
  407. carla_bridge_win64 = ""
  408. carla_bridge_lv2_external = ""
  409. carla_bridge_lv2_gtk2 = ""
  410. carla_bridge_lv2_gtk3 = ""
  411. carla_bridge_lv2_qt4 = ""
  412. carla_bridge_lv2_qt5 = ""
  413. carla_bridge_lv2_cocoa = ""
  414. carla_bridge_lv2_windows = ""
  415. carla_bridge_lv2_x11 = ""
  416. carla_bridge_vst_mac = ""
  417. carla_bridge_vst_hwnd = ""
  418. carla_bridge_vst_x11 = ""
  419. # -------------------------------------------------------------
  420. # find windows tools
  421. Carla.discovery_win32 = findTool("discovery", "carla-discovery-win32.exe")
  422. Carla.discovery_win64 = findTool("discovery", "carla-discovery-win64.exe")
  423. carla_bridge_win32 = findTool("bridges", "carla-bridge-win32.exe")
  424. carla_bridge_win64 = findTool("bridges", "carla-bridge-win64.exe")
  425. # -------------------------------------------------------------
  426. # find native and posix tools
  427. if not WINDOWS:
  428. Carla.discovery_native = findTool("discovery", "carla-discovery-native")
  429. Carla.discovery_posix32 = findTool("discovery", "carla-discovery-posix32")
  430. Carla.discovery_posix64 = findTool("discovery", "carla-discovery-posix64")
  431. carla_bridge_native = findTool("bridges", "carla-bridge-native")
  432. carla_bridge_posix32 = findTool("bridges", "carla-bridge-posix32")
  433. carla_bridge_posix64 = findTool("bridges", "carla-bridge-posix64")
  434. # -------------------------------------------------------------
  435. # find generic tools
  436. carla_bridge_lv2_external = findTool("bridges", "carla-bridge-lv2-external")
  437. # -------------------------------------------------------------
  438. # find windows only tools
  439. if WINDOWS:
  440. carla_bridge_lv2_windows = findTool("bridges", "carla-bridge-lv2-windows.exe")
  441. carla_bridge_vst_hwnd = findTool("bridges", "carla-bridge-vst-hwnd.exe")
  442. # -------------------------------------------------------------
  443. # find mac os only tools
  444. elif MACOS:
  445. carla_bridge_lv2_cocoa = findTool("bridges", "carla-bridge-lv2-cocoa")
  446. carla_bridge_vst_mac = findTool("bridges", "carla-bridge-vst-mac")
  447. # -------------------------------------------------------------
  448. # find other tools
  449. else:
  450. carla_bridge_lv2_gtk2 = findTool("bridges", "carla-bridge-lv2-gtk2")
  451. carla_bridge_lv2_gtk3 = findTool("bridges", "carla-bridge-lv2-gtk3")
  452. carla_bridge_lv2_qt4 = findTool("bridges", "carla-bridge-lv2-qt4")
  453. carla_bridge_lv2_qt5 = findTool("bridges", "carla-bridge-lv2-qt5")
  454. carla_bridge_lv2_x11 = findTool("bridges", "carla-bridge-lv2-x11")
  455. carla_bridge_vst_x11 = findTool("bridges", "carla-bridge-vst-x11")
  456. if not libfilename:
  457. if failError:
  458. QMessageBox.critical(None, "Error", "Failed to find the carla library, cannot continue")
  459. sys.exit(1)
  460. return
  461. # -------------------------------------------------------------
  462. # Init now
  463. Carla.host = Host(libfilename)
  464. # -------------------------------------------------------------
  465. # Set internal stuff
  466. Carla.host.set_engine_option(OPTION_PROCESS_NAME, 0, os.path.basename(appName))
  467. NSM_URL = os.getenv("NSM_URL")
  468. if NSM_URL:
  469. Carla.host.nsm_announce(NSM_URL, appName, os.getpid())
  470. # -------------------------------------------------------------
  471. # Set resource path
  472. localResources = os.path.join(libfilename.replace(libname, ""), "..", "modules", "carla_native", "resources")
  473. systemResources = os.path.join(libfilename.replace(libname, ""), "resources")
  474. if os.path.exists(localResources):
  475. Carla.host.set_engine_option(OPTION_PATH_RESOURCES, 0, localResources)
  476. elif os.path.exists(systemResources):
  477. Carla.host.set_engine_option(OPTION_PATH_RESOURCES, 0, systemResources)
  478. # -------------------------------------------------------------
  479. # Set bridge paths
  480. if carla_bridge_native:
  481. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_NATIVE, 0, carla_bridge_native)
  482. if carla_bridge_posix32:
  483. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_POSIX32, 0, carla_bridge_posix32)
  484. if carla_bridge_posix64:
  485. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_POSIX64, 0, carla_bridge_posix64)
  486. if carla_bridge_win32:
  487. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_WIN32, 0, carla_bridge_win32)
  488. if carla_bridge_win64:
  489. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_WIN64, 0, carla_bridge_win64)
  490. if carla_bridge_lv2_external:
  491. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_EXTERNAL, 0, carla_bridge_lv2_external)
  492. if WINDOWS:
  493. if carla_bridge_lv2_windows:
  494. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_WINDOWS, 0, carla_bridge_lv2_windows)
  495. if carla_bridge_vst_hwnd:
  496. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_HWND, 0, carla_bridge_vst_hwnd)
  497. elif MACOS:
  498. if carla_bridge_lv2_cocoa:
  499. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_COCOA, 0, carla_bridge_lv2_cocoa)
  500. if carla_bridge_vst_mac:
  501. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_MAC, 0, carla_bridge_vst_mac)
  502. else:
  503. if carla_bridge_lv2_gtk2:
  504. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_GTK2, 0, carla_bridge_lv2_gtk2)
  505. if carla_bridge_lv2_gtk3:
  506. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_GTK3, 0, carla_bridge_lv2_gtk3)
  507. if carla_bridge_lv2_qt4:
  508. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_QT4, 0, carla_bridge_lv2_qt4)
  509. if carla_bridge_lv2_qt5:
  510. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_QT5, 0, carla_bridge_lv2_qt5)
  511. if carla_bridge_lv2_x11:
  512. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_LV2_X11, 0, carla_bridge_lv2_x11)
  513. if carla_bridge_vst_x11:
  514. Carla.host.set_engine_option(OPTION_PATH_BRIDGE_VST_X11, 0, carla_bridge_vst_x11)
  515. # ------------------------------------------------------------------------------------------------------------
  516. # Convert a ctypes c_char_p into a python string
  517. def cString(value):
  518. if not value:
  519. return ""
  520. if isinstance(value, str):
  521. return value
  522. return value.decode("utf-8", errors="ignore")
  523. # ------------------------------------------------------------------------------------------------------------
  524. # Check if a value is a number (float support)
  525. def isNumber(value):
  526. try:
  527. float(value)
  528. return True
  529. except:
  530. return False
  531. # ------------------------------------------------------------------------------------------------------------
  532. # Convert a value to a list
  533. def toList(value):
  534. if value is None:
  535. return []
  536. elif not isinstance(value, list):
  537. return [value]
  538. else:
  539. return value
  540. # ------------------------------------------------------------------------------------------------------------
  541. # Get Icon from user theme, using our own as backup (Oxygen)
  542. def getIcon(icon, size=16):
  543. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  544. # ------------------------------------------------------------------------------------------------------------
  545. # Signal handler
  546. def signalHandler(sig, frame):
  547. if Carla.gui is None:
  548. return
  549. if sig in (SIGINT, SIGTERM):
  550. Carla.gui.SIGTERM.emit()
  551. elif haveSIGUSR1 and sig == SIGUSR1:
  552. Carla.gui.SIGUSR1.emit()
  553. def setUpSignals():
  554. signal(SIGINT, signalHandler)
  555. signal(SIGTERM, signalHandler)
  556. if not haveSIGUSR1:
  557. return
  558. signal(SIGUSR1, signalHandler)
  559. # ------------------------------------------------------------------------------------------------------------
  560. # QLineEdit and QPushButton combo
  561. def getAndSetPath(self_, currentPath, lineEdit):
  562. newPath = QFileDialog.getExistingDirectory(self_, self_.tr("Set Path"), currentPath, QFileDialog.ShowDirsOnly)
  563. if newPath:
  564. lineEdit.setText(newPath)
  565. return newPath
  566. # ------------------------------------------------------------------------------------------------------------
  567. # Custom MessageBox
  568. def CustomMessageBox(self_, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  569. msgBox = QMessageBox(self_)
  570. msgBox.setIcon(icon)
  571. msgBox.setWindowTitle(title)
  572. msgBox.setText(text)
  573. msgBox.setInformativeText(extraText)
  574. msgBox.setStandardButtons(buttons)
  575. msgBox.setDefaultButton(defButton)
  576. return msgBox.exec_()