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.

699 lines
24KB

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