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.

706 lines
24KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Common Carla code
  4. # Copyright (C) 2011-2015 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.6 (2.0-beta4)"
  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_CANVAS_THEME = "Canvas/Theme" # str
  160. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  161. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  162. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  163. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS = "Canvas/AutoSelectItems" # bool
  164. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy" # enum
  165. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  166. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  167. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  168. CARLA_KEY_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  169. CARLA_KEY_ENGINE_AUDIO_DRIVER = "Engine/AudioDriver" # str
  170. CARLA_KEY_ENGINE_PROCESS_MODE = "Engine/ProcessMode" # enum
  171. CARLA_KEY_ENGINE_TRANSPORT_MODE = "Engine/TransportMode" # enum
  172. CARLA_KEY_ENGINE_FORCE_STEREO = "Engine/ForceStereo" # bool
  173. CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES = "Engine/PreferPluginBridges" # bool
  174. CARLA_KEY_ENGINE_PREFER_UI_BRIDGES = "Engine/PreferUiBridges" # bool
  175. CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  176. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  177. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  178. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  179. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  180. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  181. CARLA_KEY_PATHS_VST2 = "Paths/VST2"
  182. CARLA_KEY_PATHS_VST3 = "Paths/VST3"
  183. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  184. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  185. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  186. # if pro theme is on and color is black
  187. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # bool
  188. # ------------------------------------------------------------------------------------------------------------
  189. # Carla Settings defaults
  190. # Main
  191. CARLA_DEFAULT_MAIN_PROJECT_FOLDER = HOME
  192. CARLA_DEFAULT_MAIN_USE_PRO_THEME = True
  193. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR = "Black"
  194. CARLA_DEFAULT_MAIN_REFRESH_INTERVAL = 20
  195. CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS = True
  196. # Canvas
  197. CARLA_DEFAULT_CANVAS_THEME = "Modern Dark"
  198. CARLA_DEFAULT_CANVAS_SIZE = "3100x2400"
  199. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  200. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  201. CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES = True
  202. CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS = True
  203. CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS = False
  204. CARLA_DEFAULT_CANVAS_EYE_CANDY = CANVAS_EYECANDY_SMALL
  205. CARLA_DEFAULT_CANVAS_USE_OPENGL = False
  206. CARLA_DEFAULT_CANVAS_ANTIALIASING = CANVAS_ANTIALIASING_SMALL
  207. CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING = False
  208. # Engine
  209. CARLA_DEFAULT_FORCE_STEREO = False
  210. CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES = False
  211. CARLA_DEFAULT_PREFER_UI_BRIDGES = bool(not WINDOWS)
  212. CARLA_DEFAULT_UIS_ALWAYS_ON_TOP = False
  213. CARLA_DEFAULT_MAX_PARAMETERS = MAX_DEFAULT_PARAMETERS
  214. CARLA_DEFAULT_UI_BRIDGES_TIMEOUT = 4000
  215. CARLA_DEFAULT_AUDIO_NUM_PERIODS = 2
  216. CARLA_DEFAULT_AUDIO_BUFFER_SIZE = 512
  217. CARLA_DEFAULT_AUDIO_SAMPLE_RATE = 44100
  218. if WINDOWS:
  219. CARLA_DEFAULT_AUDIO_DRIVER = "DirectSound"
  220. elif MACOS:
  221. CARLA_DEFAULT_AUDIO_DRIVER = "CoreAudio"
  222. else:
  223. CARLA_DEFAULT_AUDIO_DRIVER = "JACK"
  224. if LINUX:
  225. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  226. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_JACK
  227. else:
  228. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_PATCHBAY
  229. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_INTERNAL
  230. # ------------------------------------------------------------------------------------------------------------
  231. # Default Plugin Folders (get)
  232. DEFAULT_LADSPA_PATH = ""
  233. DEFAULT_DSSI_PATH = ""
  234. DEFAULT_LV2_PATH = ""
  235. DEFAULT_VST2_PATH = ""
  236. DEFAULT_VST3_PATH = ""
  237. DEFAULT_GIG_PATH = ""
  238. DEFAULT_SF2_PATH = ""
  239. DEFAULT_SFZ_PATH = ""
  240. if WINDOWS:
  241. splitter = ";"
  242. APPDATA = os.getenv("APPDATA")
  243. PROGRAMFILES = os.getenv("PROGRAMFILES")
  244. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  245. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  246. COMMONPROGRAMFILESx86 = os.getenv("COMMONPROGRAMFILES(x86)")
  247. # Small integrity tests
  248. if not APPDATA:
  249. qFatal("APPDATA variable not set, cannot continue")
  250. sys.exit(1)
  251. if not PROGRAMFILES:
  252. qFatal("PROGRAMFILES variable not set, cannot continue")
  253. sys.exit(1)
  254. if not COMMONPROGRAMFILES:
  255. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  256. sys.exit(1)
  257. DEFAULT_LADSPA_PATH = APPDATA + "\\LADSPA"
  258. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILES + "\\LADSPA"
  259. DEFAULT_DSSI_PATH = APPDATA + "\\DSSI"
  260. DEFAULT_DSSI_PATH += ";" + PROGRAMFILES + "\\DSSI"
  261. DEFAULT_LV2_PATH = APPDATA + "\\LV2"
  262. DEFAULT_LV2_PATH += ";" + COMMONPROGRAMFILES + "\\LV2"
  263. DEFAULT_VST2_PATH = PROGRAMFILES + "\\VstPlugins"
  264. DEFAULT_VST2_PATH += ";" + PROGRAMFILES + "\\Steinberg\\VstPlugins"
  265. if kIs64bit:
  266. DEFAULT_VST2_PATH += ";" + COMMONPROGRAMFILES + "\\VST2"
  267. DEFAULT_VST3_PATH = COMMONPROGRAMFILES + "\\VST3"
  268. DEFAULT_GIG_PATH = APPDATA + "\\GIG"
  269. DEFAULT_SF2_PATH = APPDATA + "\\SF2"
  270. DEFAULT_SFZ_PATH = APPDATA + "\\SFZ"
  271. if PROGRAMFILESx86:
  272. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILESx86 + "\\LADSPA"
  273. DEFAULT_DSSI_PATH += ";" + PROGRAMFILESx86 + "\\DSSI"
  274. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\VstPlugins"
  275. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\Steinberg\\VstPlugins"
  276. if COMMONPROGRAMFILESx86:
  277. DEFAULT_VST3_PATH += COMMONPROGRAMFILESx86 + "\\VST3"
  278. elif HAIKU:
  279. splitter = ":"
  280. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  281. DEFAULT_LADSPA_PATH += ":/boot/common/add-ons/ladspa"
  282. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  283. DEFAULT_DSSI_PATH += ":/boot/common/add-ons/dssi"
  284. DEFAULT_LV2_PATH = HOME + "/.lv2"
  285. DEFAULT_LV2_PATH += ":/boot/common/add-ons/lv2"
  286. DEFAULT_VST2_PATH = HOME + "/.vst"
  287. DEFAULT_VST2_PATH += ":/boot/common/add-ons/vst"
  288. DEFAULT_VST3_PATH = HOME + "/.vst3"
  289. DEFAULT_VST3_PATH += ":/boot/common/add-ons/vst3"
  290. elif MACOS:
  291. splitter = ":"
  292. DEFAULT_LADSPA_PATH = HOME + "/Library/Audio/Plug-Ins/LADSPA"
  293. DEFAULT_LADSPA_PATH += ":/Library/Audio/Plug-Ins/LADSPA"
  294. DEFAULT_DSSI_PATH = HOME + "/Library/Audio/Plug-Ins/DSSI"
  295. DEFAULT_DSSI_PATH += ":/Library/Audio/Plug-Ins/DSSI"
  296. DEFAULT_LV2_PATH = HOME + "/Library/Audio/Plug-Ins/LV2"
  297. DEFAULT_LV2_PATH += ":/Library/Audio/Plug-Ins/LV2"
  298. DEFAULT_VST2_PATH = HOME + "/Library/Audio/Plug-Ins/VST"
  299. DEFAULT_VST2_PATH += ":/Library/Audio/Plug-Ins/VST"
  300. DEFAULT_VST3_PATH = HOME + "/Library/Audio/Plug-Ins/VST3"
  301. DEFAULT_VST3_PATH += ":/Library/Audio/Plug-Ins/VST3"
  302. else:
  303. splitter = ":"
  304. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  305. DEFAULT_LADSPA_PATH += ":/usr/lib/ladspa"
  306. DEFAULT_LADSPA_PATH += ":/usr/local/lib/ladspa"
  307. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  308. DEFAULT_DSSI_PATH += ":/usr/lib/dssi"
  309. DEFAULT_DSSI_PATH += ":/usr/local/lib/dssi"
  310. DEFAULT_LV2_PATH = HOME + "/.lv2"
  311. DEFAULT_LV2_PATH += ":/usr/lib/lv2"
  312. DEFAULT_LV2_PATH += ":/usr/local/lib/lv2"
  313. DEFAULT_VST2_PATH = HOME + "/.vst"
  314. DEFAULT_VST2_PATH += ":/usr/lib/vst"
  315. DEFAULT_VST2_PATH += ":/usr/local/lib/vst"
  316. DEFAULT_VST3_PATH = HOME + "/.vst3"
  317. DEFAULT_VST3_PATH += ":/usr/lib/vst3"
  318. DEFAULT_VST3_PATH += ":/usr/local/lib/vst3"
  319. DEFAULT_GIG_PATH = HOME + "/.sounds/gig"
  320. DEFAULT_GIG_PATH += ":/usr/share/sounds/gig"
  321. DEFAULT_SF2_PATH = HOME + "/.sounds/sf2"
  322. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf2"
  323. DEFAULT_SFZ_PATH = HOME + "/.sounds/sfz"
  324. DEFAULT_SFZ_PATH += ":/usr/share/sounds/sfz"
  325. if not WINDOWS:
  326. winePrefix = os.getenv("WINEPREFIX")
  327. if not winePrefix:
  328. winePrefix = HOME + "/.wine"
  329. if os.path.exists(winePrefix):
  330. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files/VstPlugins"
  331. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files/Common Files/VST3"
  332. if kIs64bit and os.path.exists(winePrefix + "/drive_c/Program Files (x86)"):
  333. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/VstPlugins"
  334. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/VST3"
  335. del winePrefix
  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. del key
  347. readEnvVars = False
  348. except:
  349. pass
  350. CloseKey(reg)
  351. del reg
  352. if readEnvVars:
  353. CARLA_DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  354. CARLA_DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  355. CARLA_DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  356. CARLA_DEFAULT_VST2_PATH = os.getenv("VST_PATH", DEFAULT_VST2_PATH).split(splitter)
  357. CARLA_DEFAULT_VST3_PATH = os.getenv("VST3_PATH", DEFAULT_VST3_PATH).split(splitter)
  358. CARLA_DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  359. CARLA_DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  360. CARLA_DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  361. else:
  362. CARLA_DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  363. CARLA_DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  364. CARLA_DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  365. CARLA_DEFAULT_VST2_PATH = DEFAULT_VST2_PATH.split(splitter)
  366. CARLA_DEFAULT_VST3_PATH = DEFAULT_VST3_PATH.split(splitter)
  367. CARLA_DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  368. CARLA_DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  369. CARLA_DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  370. # ------------------------------------------------------------------------------------------------------------
  371. # Default Plugin Folders (cleanup)
  372. del DEFAULT_LADSPA_PATH
  373. del DEFAULT_DSSI_PATH
  374. del DEFAULT_LV2_PATH
  375. del DEFAULT_VST2_PATH
  376. del DEFAULT_VST3_PATH
  377. del DEFAULT_GIG_PATH
  378. del DEFAULT_SF2_PATH
  379. del DEFAULT_SFZ_PATH
  380. # ------------------------------------------------------------------------------------------------------------
  381. # Global Carla object
  382. class CarlaObject(object):
  383. __slots__ = [
  384. 'gui', # Host Window
  385. 'nogui', # Skip UI
  386. 'term', # Terminated by OS signal
  387. 'utils' # Utils object
  388. ]
  389. gCarla = CarlaObject()
  390. gCarla.gui = None
  391. gCarla.nogui = False
  392. gCarla.term = False
  393. gCarla.utils = None
  394. # ------------------------------------------------------------------------------------------------------------
  395. # Set CWD
  396. CWD = sys.path[0]
  397. if not CWD:
  398. CWD = os.path.dirname(sys.argv[0])
  399. # make it work with cxfreeze
  400. if os.path.isfile(CWD):
  401. CWD = os.path.dirname(CWD)
  402. CXFREEZE = True
  403. else:
  404. CXFREEZE = False
  405. # ------------------------------------------------------------------------------------------------------------
  406. # Set DLL_EXTENSION
  407. if WINDOWS:
  408. DLL_EXTENSION = "dll"
  409. elif MACOS:
  410. DLL_EXTENSION = "dylib"
  411. else:
  412. DLL_EXTENSION = "so"
  413. # ------------------------------------------------------------------------------------------------------------
  414. # Check if a value is a number (float support)
  415. def isNumber(value):
  416. try:
  417. float(value)
  418. return True
  419. except:
  420. return False
  421. # ------------------------------------------------------------------------------------------------------------
  422. # Convert a value to a list
  423. def toList(value):
  424. if value is None:
  425. return []
  426. elif not isinstance(value, list):
  427. return [value]
  428. else:
  429. return value
  430. # ------------------------------------------------------------------------------------------------------------
  431. # Get Icon from user theme, using our own as backup (Oxygen)
  432. def getIcon(icon, size = 16):
  433. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  434. # ------------------------------------------------------------------------------------------------------------
  435. # Handle some basic command-line arguments shared between all carla variants
  436. def handleInitialCommandLineArguments(file):
  437. initName = os.path.basename(file) if (file is not None and os.path.dirname(file) in PATH) else sys.argv[0]
  438. libPrefix = None
  439. for arg in sys.argv[1:]:
  440. if arg.startswith("--with-appname="):
  441. initName = os.path.basename(arg.replace("--with-initname=", ""))
  442. elif arg.startswith("--with-libprefix="):
  443. libPrefix = arg.replace("--with-libprefix=", "")
  444. elif arg == "--gdb":
  445. pass
  446. elif arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
  447. gCarla.nogui = True
  448. elif arg in ("-h", "--h", "-help", "--help"):
  449. print("Usage: %s [OPTION]... [FILE|URL]" % initName)
  450. print("")
  451. print(" where FILE can be a Carla project or preset file to be loaded, or URL if using Carla-Control")
  452. print("")
  453. print(" and OPTION can be one or more of the following:")
  454. print("")
  455. print(" --gdb \t Run Carla inside gdb.")
  456. print(" -n,--no-gui \t Run Carla headless, don't show UI.")
  457. print("")
  458. print(" -h,--help \t Print this help text and exit.")
  459. print(" -v,--version\t Print version information and exit.")
  460. print("")
  461. sys.exit(0)
  462. elif arg in ("-v", "--v", "-version", "--version"):
  463. pathBinaries, pathResources = getPaths(libPrefix)
  464. print("Using Carla version %s" % VERSION)
  465. print(" Python version: %s" % sys.version.split(" ",1)[0])
  466. print(" Qt version: %s" % qVersion())
  467. print(" PyQt version: %s" % PYQT_VERSION_STR)
  468. print(" Binary dir: %s" % pathBinaries)
  469. print(" Resources dir: %s" % pathResources)
  470. sys.exit(0)
  471. return (initName, libPrefix)
  472. # ------------------------------------------------------------------------------------------------------------
  473. # Get initial project file (as passed in the command-line parameters)
  474. def getInitialProjectFile(app, skipExistCheck = False):
  475. # FIXME - PyQt mishandles unicode characters, we'll use direct sys.argv for now
  476. # see https://riverbankcomputing.com/pipermail/pyqt/2015-January/035395.html
  477. #args = app.arguments()[1:]
  478. args = sys.argv[1:]
  479. for arg in args:
  480. if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix=") or arg == "--gdb":
  481. continue
  482. if arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
  483. continue
  484. if skipExistCheck or os.path.exists(arg):
  485. return arg
  486. return None
  487. # ------------------------------------------------------------------------------------------------------------
  488. # Get paths (binaries, resources)
  489. def getPaths(libPrefix = None):
  490. CWDl = CWD.lower()
  491. # adjust for special distros
  492. libdir = os.path.basename(os.path.normpath(X_LIBDIR_X)) if X_LIBDIR_X else "lib"
  493. datadir = os.path.basename(os.path.normpath(X_DATADIR_X)) if X_DATADIR_X else "share"
  494. # standalone, installed system-wide linux
  495. if libPrefix is not None:
  496. pathBinaries = os.path.join(libPrefix, libdir, "carla")
  497. pathResources = os.path.join(libPrefix, datadir, "carla", "resources")
  498. # standalone, local source
  499. elif CWDl.endswith("source"):
  500. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "bin"))
  501. pathResources = os.path.join(pathBinaries, "resources")
  502. # plugin
  503. elif CWDl.endswith("resources"):
  504. # installed system-wide linux
  505. if CWDl.endswith("/share/carla/resources"):
  506. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", libdir, "carla"))
  507. pathResources = CWD
  508. # local source
  509. elif CWDl.endswith("native-plugins%sresources" % os.sep):
  510. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "bin"))
  511. pathResources = CWD
  512. # other
  513. else:
  514. pathBinaries = os.path.abspath(os.path.join(CWD, ".."))
  515. pathResources = CWD
  516. # everything else
  517. else:
  518. pathBinaries = CWD
  519. pathResources = os.path.join(pathBinaries, "resources")
  520. return (pathBinaries, pathResources)
  521. # ------------------------------------------------------------------------------------------------------------
  522. # Signal handler
  523. # TODO move to carla_host.py or something
  524. def signalHandler(sig, frame):
  525. if sig in (SIGINT, SIGTERM):
  526. gCarla.term = True
  527. if gCarla.gui is not None:
  528. gCarla.gui.SIGTERM.emit()
  529. elif haveSIGUSR1 and sig == SIGUSR1:
  530. if gCarla.gui is not None:
  531. gCarla.gui.SIGUSR1.emit()
  532. def setUpSignals():
  533. signal(SIGINT, signalHandler)
  534. signal(SIGTERM, signalHandler)
  535. if not haveSIGUSR1:
  536. return
  537. signal(SIGUSR1, signalHandler)
  538. # ------------------------------------------------------------------------------------------------------------
  539. # QLineEdit and QPushButton combo
  540. def getAndSetPath(parent, lineEdit):
  541. newPath = QFileDialog.getExistingDirectory(parent, parent.tr("Set Path"), lineEdit.text(), QFileDialog.ShowDirsOnly)
  542. if newPath:
  543. lineEdit.setText(newPath)
  544. return newPath
  545. # ------------------------------------------------------------------------------------------------------------
  546. # Custom MessageBox
  547. def CustomMessageBox(parent, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  548. msgBox = QMessageBox(parent)
  549. msgBox.setIcon(icon)
  550. msgBox.setWindowTitle(title)
  551. msgBox.setText(text)
  552. msgBox.setInformativeText(extraText)
  553. msgBox.setStandardButtons(buttons)
  554. msgBox.setDefaultButton(defButton)
  555. return msgBox.exec_()
  556. # ------------------------------------------------------------------------------------------------------------