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.

685 lines
22KB

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