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.

722 lines
25KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Common Carla code
  4. # Copyright (C) 2011-2017 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. # These will be modified during install
  21. X_LIBDIR_X = None
  22. X_DATADIR_X = None
  23. # ------------------------------------------------------------------------------------------------------------
  24. # Imports (Global)
  25. import os
  26. import sys
  27. if config_UseQt5:
  28. from PyQt5.Qt import PYQT_VERSION_STR
  29. from PyQt5.QtCore import qFatal, qVersion, qWarning, QDir
  30. from PyQt5.QtGui import QIcon
  31. from PyQt5.QtWidgets import QFileDialog, QMessageBox
  32. else:
  33. from PyQt4.Qt import PYQT_VERSION_STR
  34. from PyQt4.QtCore import qFatal, qVersion, qWarning, QDir
  35. from PyQt4.QtGui import QFileDialog, QIcon, QMessageBox
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Import Signal
  38. from signal import signal, SIGINT, SIGTERM
  39. try:
  40. from signal import SIGUSR1
  41. haveSIGUSR1 = True
  42. except:
  43. haveSIGUSR1 = False
  44. # ------------------------------------------------------------------------------------------------------------
  45. # Imports (Custom)
  46. from carla_backend_qt import *
  47. # ------------------------------------------------------------------------------------------------------------
  48. # Platform specific stuff
  49. if WINDOWS:
  50. WINDIR = os.getenv("WINDIR")
  51. # ------------------------------------------------------------------------------------------------------------
  52. # Set Version
  53. VERSION = "1.9.7 (2.0-beta5)"
  54. # ------------------------------------------------------------------------------------------------------------
  55. # Set TMP
  56. envTMP = os.getenv("TMP")
  57. if envTMP is None:
  58. if WINDOWS:
  59. qWarning("TMP variable not set")
  60. TMP = QDir.tempPath()
  61. else:
  62. TMP = envTMP
  63. if not os.path.exists(TMP):
  64. qWarning("TMP does not exist")
  65. TMP = "/"
  66. del envTMP
  67. # ------------------------------------------------------------------------------------------------------------
  68. # Set HOME
  69. envHOME = os.getenv("HOME")
  70. if envHOME is None:
  71. if LINUX or MACOS:
  72. qWarning("HOME variable not set")
  73. HOME = QDir.toNativeSeparators(QDir.homePath())
  74. else:
  75. HOME = envHOME
  76. if not os.path.exists(HOME):
  77. qWarning("HOME does not exist")
  78. HOME = TMP
  79. del envHOME
  80. # ------------------------------------------------------------------------------------------------------------
  81. # Set PATH
  82. envPATH = os.getenv("PATH")
  83. if envPATH is None:
  84. qWarning("PATH variable not set")
  85. if MACOS:
  86. PATH = ("/opt/local/bin", "/usr/local/bin", "/usr/bin", "/bin")
  87. elif WINDOWS:
  88. PATH = (os.path.join(WINDIR, "system32"), WINDIR)
  89. else:
  90. PATH = ("/usr/local/bin", "/usr/bin", "/bin")
  91. else:
  92. PATH = envPATH.split(os.pathsep)
  93. del envPATH
  94. # ------------------------------------------------------------------------------------------------------------
  95. # Static MIDI CC list
  96. MIDI_CC_LIST = (
  97. "0x01 Modulation",
  98. "0x02 Breath",
  99. "0x03 (Undefined)",
  100. "0x04 Foot",
  101. "0x05 Portamento",
  102. "0x07 Volume",
  103. "0x08 Balance",
  104. "0x09 (Undefined)",
  105. "0x0A Pan",
  106. "0x0B Expression",
  107. "0x0C FX Control 1",
  108. "0x0D FX Control 2",
  109. "0x0E (Undefined)",
  110. "0x0F (Undefined)",
  111. "0x10 General Purpose 1",
  112. "0x11 General Purpose 2",
  113. "0x12 General Purpose 3",
  114. "0x13 General Purpose 4",
  115. "0x14 (Undefined)",
  116. "0x15 (Undefined)",
  117. "0x16 (Undefined)",
  118. "0x17 (Undefined)",
  119. "0x18 (Undefined)",
  120. "0x19 (Undefined)",
  121. "0x1A (Undefined)",
  122. "0x1B (Undefined)",
  123. "0x1C (Undefined)",
  124. "0x1D (Undefined)",
  125. "0x1E (Undefined)",
  126. "0x1F (Undefined)",
  127. "0x46 Control 1 [Variation]",
  128. "0x47 Control 2 [Timbre]",
  129. "0x48 Control 3 [Release]",
  130. "0x49 Control 4 [Attack]",
  131. "0x4A Control 5 [Brightness]",
  132. "0x4B Control 6 [Decay]",
  133. "0x4C Control 7 [Vib Rate]",
  134. "0x4D Control 8 [Vib Depth]",
  135. "0x4E Control 9 [Vib Delay]",
  136. "0x4F Control 10 [Undefined]",
  137. "0x50 General Purpose 5",
  138. "0x51 General Purpose 6",
  139. "0x52 General Purpose 7",
  140. "0x53 General Purpose 8",
  141. "0x54 Portamento Control",
  142. "0x5B FX 1 Depth [Reverb]",
  143. "0x5C FX 2 Depth [Tremolo]",
  144. "0x5D FX 3 Depth [Chorus]",
  145. "0x5E FX 4 Depth [Detune]",
  146. "0x5F FX 5 Depth [Phaser]"
  147. )
  148. # ------------------------------------------------------------------------------------------------------------
  149. # PatchCanvas defines
  150. CANVAS_ANTIALIASING_SMALL = 1
  151. CANVAS_EYECANDY_SMALL = 1
  152. # ------------------------------------------------------------------------------------------------------------
  153. # Carla Settings keys
  154. CARLA_KEY_MAIN_PROJECT_FOLDER = "Main/ProjectFolder" # str
  155. CARLA_KEY_MAIN_USE_PRO_THEME = "Main/UseProTheme" # bool
  156. CARLA_KEY_MAIN_PRO_THEME_COLOR = "Main/ProThemeColor" # str
  157. CARLA_KEY_MAIN_REFRESH_INTERVAL = "Main/RefreshInterval" # int
  158. CARLA_KEY_MAIN_USE_CUSTOM_SKINS = "Main/UseCustomSkins" # bool
  159. CARLA_KEY_MAIN_SHOW_LOGS = "Main/ShowLogs" # bool
  160. CARLA_KEY_MAIN_EXPERIMENTAL = "Main/Experimental" # bool
  161. CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str
  162. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  163. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  164. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  165. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS = "Canvas/AutoSelectItems" # bool
  166. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy2" # bool
  167. CARLA_KEY_CANVAS_FANCY_EYE_CANDY = "Canvas/FancyEyeCandy" # bool
  168. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  169. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  170. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  171. CARLA_KEY_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  172. CARLA_KEY_ENGINE_AUDIO_DRIVER = "Engine/AudioDriver" # str
  173. CARLA_KEY_ENGINE_PROCESS_MODE = "Engine/ProcessMode" # enum
  174. CARLA_KEY_ENGINE_TRANSPORT_MODE = "Engine/TransportMode" # enum
  175. CARLA_KEY_ENGINE_FORCE_STEREO = "Engine/ForceStereo" # bool
  176. CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES = "Engine/PreferPluginBridges" # bool
  177. CARLA_KEY_ENGINE_PREFER_UI_BRIDGES = "Engine/PreferUiBridges" # bool
  178. CARLA_KEY_ENGINE_MANAGE_UIS = "Engine/ManageUIs" # bool
  179. CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  180. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  181. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  182. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  183. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  184. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  185. CARLA_KEY_PATHS_VST2 = "Paths/VST2"
  186. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  187. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  188. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  189. CARLA_KEY_WINE_EXECUTABLE = "Wine/Executable" # str
  190. CARLA_KEY_WINE_AUTO_PREFIX = "Wine/AutoPrefix" # bool
  191. CARLA_KEY_WINE_FALLBACK_PREFIX = "Wine/FallbackPrefix" # str
  192. CARLA_KEY_WINE_RT_PRIO_ENABLED = "Wine/RtPrioEnabled" # bool
  193. CARLA_KEY_WINE_BASE_RT_PRIO = "Wine/BaseRtPrio" # int
  194. CARLA_KEY_WINE_SERVER_RT_PRIO = "Wine/ServerRtPrio" # int
  195. CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES = "Experimental/PluginBridges" # bool
  196. CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES = "Experimental/WineBridges" # bool
  197. CARLA_KEY_EXPERIMENTAL_JACK_APPS = "Experimental/JackApplications" # bool
  198. CARLA_KEY_EXPERIMENTAL_EXPORT_LV2 = "Experimental/ExportLV2" # bool
  199. CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR = "Experimental/PreventBadBehaviour" # bool
  200. CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL = "Experimental/LoadLibGlobal" # bool
  201. # if pro theme is on and color is black
  202. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # bool
  203. # ------------------------------------------------------------------------------------------------------------
  204. # Carla Settings defaults
  205. # Main
  206. CARLA_DEFAULT_MAIN_PROJECT_FOLDER = HOME
  207. CARLA_DEFAULT_MAIN_USE_PRO_THEME = True
  208. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR = "Black"
  209. CARLA_DEFAULT_MAIN_REFRESH_INTERVAL = 20
  210. CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS = True
  211. CARLA_DEFAULT_MAIN_SHOW_LOGS = bool(not WINDOWS)
  212. CARLA_DEFAULT_MAIN_EXPERIMENTAL = False
  213. # Canvas
  214. CARLA_DEFAULT_CANVAS_THEME = "Modern Dark"
  215. CARLA_DEFAULT_CANVAS_SIZE = "3100x2400"
  216. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  217. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  218. CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES = True
  219. CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS = True
  220. CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS = False
  221. CARLA_DEFAULT_CANVAS_EYE_CANDY = True
  222. CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY = False
  223. CARLA_DEFAULT_CANVAS_USE_OPENGL = False
  224. CARLA_DEFAULT_CANVAS_ANTIALIASING = CANVAS_ANTIALIASING_SMALL
  225. CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING = False
  226. # Engine
  227. CARLA_DEFAULT_FORCE_STEREO = False
  228. CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES = False
  229. CARLA_DEFAULT_PREFER_UI_BRIDGES = bool(not WINDOWS)
  230. CARLA_DEFAULT_MANAGE_UIS = True
  231. CARLA_DEFAULT_UIS_ALWAYS_ON_TOP = False
  232. CARLA_DEFAULT_MAX_PARAMETERS = MAX_DEFAULT_PARAMETERS
  233. CARLA_DEFAULT_UI_BRIDGES_TIMEOUT = 4000
  234. CARLA_DEFAULT_AUDIO_NUM_PERIODS = 2
  235. CARLA_DEFAULT_AUDIO_BUFFER_SIZE = 512
  236. CARLA_DEFAULT_AUDIO_SAMPLE_RATE = 44100
  237. if WINDOWS:
  238. CARLA_DEFAULT_AUDIO_DRIVER = "DirectSound"
  239. elif MACOS:
  240. CARLA_DEFAULT_AUDIO_DRIVER = "CoreAudio"
  241. else:
  242. CARLA_DEFAULT_AUDIO_DRIVER = "JACK"
  243. if LINUX:
  244. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  245. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_JACK
  246. else:
  247. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_CONTINUOUS_RACK
  248. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_INTERNAL
  249. # Wine
  250. CARLA_DEFAULT_WINE_EXECUTABLE = "wine"
  251. CARLA_DEFAULT_WINE_AUTO_PREFIX = True
  252. CARLA_DEFAULT_WINE_FALLBACK_PREFIX = os.path.expanduser("~/.wine")
  253. CARLA_DEFAULT_WINE_RT_PRIO_ENABLED = True
  254. CARLA_DEFAULT_WINE_BASE_RT_PRIO = 15
  255. CARLA_DEFAULT_WINE_SERVER_RT_PRIO = 10
  256. # Experimental
  257. CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES = False
  258. CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES = False
  259. CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS = False
  260. CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT = False
  261. CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR = False
  262. CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL = False
  263. # ------------------------------------------------------------------------------------------------------------
  264. # Default Plugin Folders (get)
  265. DEFAULT_LADSPA_PATH = ""
  266. DEFAULT_DSSI_PATH = ""
  267. DEFAULT_LV2_PATH = ""
  268. DEFAULT_VST2_PATH = ""
  269. DEFAULT_GIG_PATH = ""
  270. DEFAULT_SF2_PATH = ""
  271. DEFAULT_SFZ_PATH = ""
  272. if WINDOWS:
  273. splitter = ";"
  274. APPDATA = os.getenv("APPDATA")
  275. PROGRAMFILES = os.getenv("PROGRAMFILES")
  276. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  277. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  278. COMMONPROGRAMFILESx86 = os.getenv("COMMONPROGRAMFILES(x86)")
  279. # Small integrity tests
  280. if not APPDATA:
  281. qFatal("APPDATA variable not set, cannot continue")
  282. sys.exit(1)
  283. if not PROGRAMFILES:
  284. qFatal("PROGRAMFILES variable not set, cannot continue")
  285. sys.exit(1)
  286. if not COMMONPROGRAMFILES:
  287. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  288. sys.exit(1)
  289. DEFAULT_LADSPA_PATH = APPDATA + "\\LADSPA"
  290. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILES + "\\LADSPA"
  291. DEFAULT_DSSI_PATH = APPDATA + "\\DSSI"
  292. DEFAULT_DSSI_PATH += ";" + PROGRAMFILES + "\\DSSI"
  293. DEFAULT_LV2_PATH = APPDATA + "\\LV2"
  294. DEFAULT_LV2_PATH += ";" + COMMONPROGRAMFILES + "\\LV2"
  295. DEFAULT_VST2_PATH = PROGRAMFILES + "\\VstPlugins"
  296. DEFAULT_VST2_PATH += ";" + PROGRAMFILES + "\\Steinberg\\VstPlugins"
  297. if kIs64bit:
  298. DEFAULT_VST2_PATH += ";" + COMMONPROGRAMFILES + "\\VST2"
  299. DEFAULT_GIG_PATH = APPDATA + "\\GIG"
  300. DEFAULT_SF2_PATH = APPDATA + "\\SF2"
  301. DEFAULT_SFZ_PATH = APPDATA + "\\SFZ"
  302. if PROGRAMFILESx86:
  303. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILESx86 + "\\LADSPA"
  304. DEFAULT_DSSI_PATH += ";" + PROGRAMFILESx86 + "\\DSSI"
  305. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\VstPlugins"
  306. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\Steinberg\\VstPlugins"
  307. elif HAIKU:
  308. splitter = ":"
  309. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  310. DEFAULT_LADSPA_PATH += ":/boot/common/add-ons/ladspa"
  311. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  312. DEFAULT_DSSI_PATH += ":/boot/common/add-ons/dssi"
  313. DEFAULT_LV2_PATH = HOME + "/.lv2"
  314. DEFAULT_LV2_PATH += ":/boot/common/add-ons/lv2"
  315. DEFAULT_VST2_PATH = HOME + "/.vst"
  316. DEFAULT_VST2_PATH += ":/boot/common/add-ons/vst"
  317. elif MACOS:
  318. splitter = ":"
  319. DEFAULT_LADSPA_PATH = HOME + "/Library/Audio/Plug-Ins/LADSPA"
  320. DEFAULT_LADSPA_PATH += ":/Library/Audio/Plug-Ins/LADSPA"
  321. DEFAULT_DSSI_PATH = HOME + "/Library/Audio/Plug-Ins/DSSI"
  322. DEFAULT_DSSI_PATH += ":/Library/Audio/Plug-Ins/DSSI"
  323. DEFAULT_LV2_PATH = HOME + "/Library/Audio/Plug-Ins/LV2"
  324. DEFAULT_LV2_PATH += ":/Library/Audio/Plug-Ins/LV2"
  325. DEFAULT_VST2_PATH = HOME + "/Library/Audio/Plug-Ins/VST"
  326. DEFAULT_VST2_PATH += ":/Library/Audio/Plug-Ins/VST"
  327. else:
  328. splitter = ":"
  329. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  330. DEFAULT_LADSPA_PATH += ":/usr/lib/ladspa"
  331. DEFAULT_LADSPA_PATH += ":/usr/local/lib/ladspa"
  332. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  333. DEFAULT_DSSI_PATH += ":/usr/lib/dssi"
  334. DEFAULT_DSSI_PATH += ":/usr/local/lib/dssi"
  335. DEFAULT_LV2_PATH = HOME + "/.lv2"
  336. DEFAULT_LV2_PATH += ":/usr/lib/lv2"
  337. DEFAULT_LV2_PATH += ":/usr/local/lib/lv2"
  338. DEFAULT_VST2_PATH = HOME + "/.vst"
  339. DEFAULT_VST2_PATH += ":/usr/lib/vst"
  340. DEFAULT_VST2_PATH += ":/usr/local/lib/vst"
  341. DEFAULT_GIG_PATH = HOME + "/.sounds/gig"
  342. DEFAULT_GIG_PATH += ":/usr/share/sounds/gig"
  343. DEFAULT_SF2_PATH = HOME + "/.sounds/sf2"
  344. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf2"
  345. DEFAULT_SFZ_PATH = HOME + "/.sounds/sfz"
  346. DEFAULT_SFZ_PATH += ":/usr/share/sounds/sfz"
  347. if not WINDOWS:
  348. winePrefix = os.getenv("WINEPREFIX")
  349. if not winePrefix:
  350. winePrefix = HOME + "/.wine"
  351. if os.path.exists(winePrefix):
  352. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files/VstPlugins"
  353. if kIs64bit and os.path.exists(winePrefix + "/drive_c/Program Files (x86)"):
  354. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/VstPlugins"
  355. del winePrefix
  356. # ------------------------------------------------------------------------------------------------------------
  357. # Default Plugin Folders (set)
  358. readEnvVars = True
  359. if WINDOWS:
  360. # Check if running Wine. If yes, ignore env vars
  361. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  362. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  363. try:
  364. key = OpenKey(reg, r"SOFTWARE\Wine")
  365. CloseKey(key)
  366. del key
  367. readEnvVars = False
  368. except:
  369. pass
  370. CloseKey(reg)
  371. del reg
  372. if readEnvVars:
  373. CARLA_DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  374. CARLA_DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  375. CARLA_DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  376. CARLA_DEFAULT_VST2_PATH = os.getenv("VST_PATH", DEFAULT_VST2_PATH).split(splitter)
  377. CARLA_DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  378. CARLA_DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  379. CARLA_DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  380. else:
  381. CARLA_DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  382. CARLA_DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  383. CARLA_DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  384. CARLA_DEFAULT_VST2_PATH = DEFAULT_VST2_PATH.split(splitter)
  385. CARLA_DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  386. CARLA_DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  387. CARLA_DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  388. # ------------------------------------------------------------------------------------------------------------
  389. # Default Plugin Folders (cleanup)
  390. del DEFAULT_LADSPA_PATH
  391. del DEFAULT_DSSI_PATH
  392. del DEFAULT_LV2_PATH
  393. del DEFAULT_VST2_PATH
  394. del DEFAULT_GIG_PATH
  395. del DEFAULT_SF2_PATH
  396. del DEFAULT_SFZ_PATH
  397. # ------------------------------------------------------------------------------------------------------------
  398. # Global Carla object
  399. class CarlaObject(object):
  400. __slots__ = [
  401. 'gui', # Host Window
  402. 'nogui', # Skip UI
  403. 'term', # Terminated by OS signal
  404. 'utils' # Utils object
  405. ]
  406. gCarla = CarlaObject()
  407. gCarla.gui = None
  408. gCarla.nogui = False
  409. gCarla.term = False
  410. gCarla.utils = None
  411. # ------------------------------------------------------------------------------------------------------------
  412. # Set CWD
  413. CWD = sys.path[0]
  414. if not CWD:
  415. CWD = os.path.dirname(sys.argv[0])
  416. # make it work with cxfreeze
  417. if os.path.isfile(CWD):
  418. CWD = os.path.dirname(CWD)
  419. CXFREEZE = True
  420. else:
  421. CXFREEZE = False
  422. # ------------------------------------------------------------------------------------------------------------
  423. # Set DLL_EXTENSION
  424. if WINDOWS:
  425. DLL_EXTENSION = "dll"
  426. elif MACOS:
  427. DLL_EXTENSION = "dylib"
  428. else:
  429. DLL_EXTENSION = "so"
  430. # ------------------------------------------------------------------------------------------------------------
  431. # Check if a value is a number (float support)
  432. def isNumber(value):
  433. try:
  434. float(value)
  435. return True
  436. except:
  437. return False
  438. # ------------------------------------------------------------------------------------------------------------
  439. # Convert a value to a list
  440. def toList(value):
  441. if value is None:
  442. return []
  443. elif not isinstance(value, list):
  444. return [value]
  445. else:
  446. return value
  447. # ------------------------------------------------------------------------------------------------------------
  448. # Get Icon from user theme, using our own as backup (Oxygen)
  449. def getIcon(icon, size = 16):
  450. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  451. # ------------------------------------------------------------------------------------------------------------
  452. # Handle some basic command-line arguments shared between all carla variants
  453. def handleInitialCommandLineArguments(file):
  454. initName = os.path.basename(file) if (file is not None and os.path.dirname(file) in PATH) else sys.argv[0]
  455. libPrefix = None
  456. for arg in sys.argv[1:]:
  457. if arg.startswith("--with-appname="):
  458. initName = os.path.basename(arg.replace("--with-initname=", ""))
  459. elif arg.startswith("--with-libprefix="):
  460. libPrefix = arg.replace("--with-libprefix=", "")
  461. elif arg == "--gdb":
  462. pass
  463. elif arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
  464. gCarla.nogui = True
  465. elif arg in ("-h", "--h", "-help", "--help"):
  466. print("Usage: %s [OPTION]... [FILE|URL]" % initName)
  467. print("")
  468. print(" where FILE can be a Carla project or preset file to be loaded, or URL if using Carla-Control")
  469. print("")
  470. print(" and OPTION can be one or more of the following:")
  471. print("")
  472. print(" --gdb \t Run Carla inside gdb.")
  473. print(" -n,--no-gui \t Run Carla headless, don't show UI.")
  474. print("")
  475. print(" -h,--help \t Print this help text and exit.")
  476. print(" -v,--version\t Print version information and exit.")
  477. print("")
  478. sys.exit(0)
  479. elif arg in ("-v", "--v", "-version", "--version"):
  480. pathBinaries, pathResources = getPaths(libPrefix)
  481. print("Using Carla version %s" % VERSION)
  482. print(" Python version: %s" % sys.version.split(" ",1)[0])
  483. print(" Qt version: %s" % qVersion())
  484. print(" PyQt version: %s" % PYQT_VERSION_STR)
  485. print(" Binary dir: %s" % pathBinaries)
  486. print(" Resources dir: %s" % pathResources)
  487. sys.exit(0)
  488. return (initName, libPrefix)
  489. # ------------------------------------------------------------------------------------------------------------
  490. # Get initial project file (as passed in the command-line parameters)
  491. def getInitialProjectFile(app, skipExistCheck = False):
  492. # FIXME - PyQt mishandles unicode characters, we'll use direct sys.argv for now
  493. # see https://riverbankcomputing.com/pipermail/pyqt/2015-January/035395.html
  494. #args = app.arguments()[1:]
  495. args = sys.argv[1:]
  496. for arg in args:
  497. if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix=") or arg == "--gdb":
  498. continue
  499. if arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
  500. continue
  501. if skipExistCheck or os.path.exists(arg):
  502. return arg
  503. return None
  504. # ------------------------------------------------------------------------------------------------------------
  505. # Get paths (binaries, resources)
  506. def getPaths(libPrefix = None):
  507. CWDl = CWD.lower()
  508. # adjust for special distros
  509. libdir = os.path.basename(os.path.normpath(X_LIBDIR_X)) if X_LIBDIR_X else "lib"
  510. datadir = os.path.basename(os.path.normpath(X_DATADIR_X)) if X_DATADIR_X else "share"
  511. # standalone, installed system-wide linux
  512. if libPrefix is not None:
  513. pathBinaries = os.path.join(libPrefix, libdir, "carla")
  514. pathResources = os.path.join(libPrefix, datadir, "carla", "resources")
  515. # standalone, local source
  516. elif CWDl.endswith("source"):
  517. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "bin"))
  518. pathResources = os.path.join(pathBinaries, "resources")
  519. # plugin
  520. elif CWDl.endswith("resources"):
  521. # installed system-wide linux
  522. if CWDl.endswith("/share/carla/resources"):
  523. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", libdir, "carla"))
  524. pathResources = CWD
  525. # local source
  526. elif CWDl.endswith("native-plugins%sresources" % os.sep):
  527. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "bin"))
  528. pathResources = CWD
  529. # other
  530. else:
  531. pathBinaries = os.path.abspath(os.path.join(CWD, ".."))
  532. pathResources = CWD
  533. # everything else
  534. else:
  535. pathBinaries = CWD
  536. pathResources = os.path.join(pathBinaries, "resources")
  537. return (pathBinaries, pathResources)
  538. # ------------------------------------------------------------------------------------------------------------
  539. # Signal handler
  540. # TODO move to carla_host.py or something
  541. def signalHandler(sig, frame):
  542. if sig in (SIGINT, SIGTERM):
  543. gCarla.term = True
  544. if gCarla.gui is not None:
  545. gCarla.gui.SIGTERM.emit()
  546. elif haveSIGUSR1 and sig == SIGUSR1:
  547. if gCarla.gui is not None:
  548. gCarla.gui.SIGUSR1.emit()
  549. def setUpSignals():
  550. signal(SIGINT, signalHandler)
  551. signal(SIGTERM, signalHandler)
  552. if not haveSIGUSR1:
  553. return
  554. signal(SIGUSR1, signalHandler)
  555. # ------------------------------------------------------------------------------------------------------------
  556. # QLineEdit and QPushButton combo
  557. def getAndSetPath(parent, lineEdit):
  558. newPath = QFileDialog.getExistingDirectory(parent, parent.tr("Set Path"), lineEdit.text(), QFileDialog.ShowDirsOnly)
  559. if newPath:
  560. lineEdit.setText(newPath)
  561. return newPath
  562. # ------------------------------------------------------------------------------------------------------------
  563. # Custom MessageBox
  564. def CustomMessageBox(parent, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  565. msgBox = QMessageBox(parent)
  566. msgBox.setIcon(icon)
  567. msgBox.setWindowTitle(title)
  568. msgBox.setText(text)
  569. msgBox.setInformativeText(extraText)
  570. msgBox.setStandardButtons(buttons)
  571. msgBox.setDefaultButton(defButton)
  572. return msgBox.exec_()
  573. # ------------------------------------------------------------------------------------------------------------