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.

628 lines
21KB

  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.Qt import PYQT_VERSION_STR
  26. from PyQt5.QtCore import qFatal, qVersion, qWarning, QDir
  27. from PyQt5.QtGui import QIcon
  28. from PyQt5.QtWidgets import QFileDialog, QMessageBox
  29. else:
  30. from PyQt4.Qt import PYQT_VERSION_STR
  31. from PyQt4.QtCore import qFatal, qVersion, qWarning, QDir
  32. from PyQt4.QtGui import QFileDialog, QIcon, QMessageBox
  33. # ------------------------------------------------------------------------------------------------------------
  34. # Import Signal
  35. from signal import signal, SIGINT, SIGTERM
  36. try:
  37. from signal import SIGUSR1
  38. haveSIGUSR1 = True
  39. except:
  40. haveSIGUSR1 = False
  41. # ------------------------------------------------------------------------------------------------------------
  42. # Imports (Custom)
  43. from carla_backend_qt import *
  44. # ------------------------------------------------------------------------------------------------------------
  45. # Platform specific stuff
  46. if WINDOWS:
  47. WINDIR = os.getenv("WINDIR")
  48. # ------------------------------------------------------------------------------------------------------------
  49. # Set Version
  50. VERSION = "1.9.6 (2.0-beta4)"
  51. # ------------------------------------------------------------------------------------------------------------
  52. # Set TMP
  53. envTMP = os.getenv("TMP")
  54. if envTMP is None:
  55. if WINDOWS:
  56. qWarning("TMP variable not set")
  57. TMP = QDir.tempPath()
  58. else:
  59. TMP = envTMP
  60. if not os.path.exists(TMP):
  61. qWarning("TMP does not exist")
  62. TMP = "/"
  63. del envTMP
  64. # ------------------------------------------------------------------------------------------------------------
  65. # Set HOME
  66. envHOME = os.getenv("HOME")
  67. if envHOME is None:
  68. if LINUX or MACOS:
  69. qWarning("HOME variable not set")
  70. HOME = QDir.toNativeSeparators(QDir.homePath())
  71. else:
  72. HOME = envHOME
  73. if not os.path.exists(HOME):
  74. qWarning("HOME does not exist")
  75. HOME = TMP
  76. del envHOME
  77. # ------------------------------------------------------------------------------------------------------------
  78. # Set PATH
  79. envPATH = os.getenv("PATH")
  80. if envPATH is None:
  81. qWarning("PATH variable not set")
  82. if MACOS:
  83. PATH = ("/opt/local/bin", "/usr/local/bin", "/usr/bin", "/bin")
  84. elif WINDOWS:
  85. PATH = (os.path.join(WINDIR, "system32"), WINDIR)
  86. else:
  87. PATH = ("/usr/local/bin", "/usr/bin", "/bin")
  88. else:
  89. PATH = envPATH.split(os.pathsep)
  90. del envPATH
  91. # ------------------------------------------------------------------------------------------------------------
  92. # Static MIDI CC list
  93. MIDI_CC_LIST = (
  94. "0x01 Modulation",
  95. "0x02 Breath",
  96. "0x03 (Undefined)",
  97. "0x04 Foot",
  98. "0x05 Portamento",
  99. "0x07 Volume",
  100. "0x08 Balance",
  101. "0x09 (Undefined)",
  102. "0x0A Pan",
  103. "0x0B Expression",
  104. "0x0C FX Control 1",
  105. "0x0D FX Control 2",
  106. "0x0E (Undefined)",
  107. "0x0F (Undefined)",
  108. "0x10 General Purpose 1",
  109. "0x11 General Purpose 2",
  110. "0x12 General Purpose 3",
  111. "0x13 General Purpose 4",
  112. "0x14 (Undefined)",
  113. "0x15 (Undefined)",
  114. "0x16 (Undefined)",
  115. "0x17 (Undefined)",
  116. "0x18 (Undefined)",
  117. "0x19 (Undefined)",
  118. "0x1A (Undefined)",
  119. "0x1B (Undefined)",
  120. "0x1C (Undefined)",
  121. "0x1D (Undefined)",
  122. "0x1E (Undefined)",
  123. "0x1F (Undefined)",
  124. "0x46 Control 1 [Variation]",
  125. "0x47 Control 2 [Timbre]",
  126. "0x48 Control 3 [Release]",
  127. "0x49 Control 4 [Attack]",
  128. "0x4A Control 5 [Brightness]",
  129. "0x4B Control 6 [Decay]",
  130. "0x4C Control 7 [Vib Rate]",
  131. "0x4D Control 8 [Vib Depth]",
  132. "0x4E Control 9 [Vib Delay]",
  133. "0x4F Control 10 [Undefined]",
  134. "0x50 General Purpose 5",
  135. "0x51 General Purpose 6",
  136. "0x52 General Purpose 7",
  137. "0x53 General Purpose 8",
  138. "0x54 Portamento Control",
  139. "0x5B FX 1 Depth [Reverb]",
  140. "0x5C FX 2 Depth [Tremolo]",
  141. "0x5D FX 3 Depth [Chorus]",
  142. "0x5E FX 4 Depth [Detune]",
  143. "0x5F FX 5 Depth [Phaser]"
  144. )
  145. # ------------------------------------------------------------------------------------------------------------
  146. # PatchCanvas defines
  147. CANVAS_ANTIALIASING_SMALL = 1
  148. CANVAS_EYECANDY_SMALL = 1
  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_MAIN_USE_CUSTOM_SKINS = "Main/UseCustomSkins" # bool
  156. CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str
  157. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  158. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  159. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  160. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy" # enum
  161. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  162. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  163. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # 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_VST2 = "Paths/VST2"
  178. CARLA_KEY_PATHS_VST3 = "Paths/VST3"
  179. CARLA_KEY_PATHS_AU = "Paths/AU"
  180. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  181. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  182. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  183. # if pro theme is on and color is black
  184. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # bool
  185. # ------------------------------------------------------------------------------------------------------------
  186. # Carla Settings defaults
  187. # Main
  188. CARLA_DEFAULT_MAIN_PROJECT_FOLDER = HOME
  189. CARLA_DEFAULT_MAIN_USE_PRO_THEME = True
  190. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR = "Black"
  191. CARLA_DEFAULT_MAIN_REFRESH_INTERVAL = 20
  192. CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS = True
  193. # Canvas
  194. CARLA_DEFAULT_CANVAS_THEME = "Modern Dark"
  195. CARLA_DEFAULT_CANVAS_SIZE = "3100x2400"
  196. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  197. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  198. CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES = True
  199. CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS = True
  200. CARLA_DEFAULT_CANVAS_EYE_CANDY = CANVAS_EYECANDY_SMALL
  201. CARLA_DEFAULT_CANVAS_USE_OPENGL = False
  202. CARLA_DEFAULT_CANVAS_ANTIALIASING = CANVAS_ANTIALIASING_SMALL
  203. CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING = False
  204. # Engine
  205. CARLA_DEFAULT_FORCE_STEREO = False
  206. CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES = False
  207. CARLA_DEFAULT_PREFER_UI_BRIDGES = True
  208. CARLA_DEFAULT_UIS_ALWAYS_ON_TOP = False
  209. CARLA_DEFAULT_MAX_PARAMETERS = MAX_DEFAULT_PARAMETERS
  210. CARLA_DEFAULT_UI_BRIDGES_TIMEOUT = 4000
  211. CARLA_DEFAULT_AUDIO_NUM_PERIODS = 2
  212. CARLA_DEFAULT_AUDIO_BUFFER_SIZE = 512
  213. CARLA_DEFAULT_AUDIO_SAMPLE_RATE = 44100
  214. if WINDOWS:
  215. CARLA_DEFAULT_AUDIO_DRIVER = "DirectSound"
  216. elif MACOS:
  217. CARLA_DEFAULT_AUDIO_DRIVER = "CoreAudio"
  218. else:
  219. CARLA_DEFAULT_AUDIO_DRIVER = "JACK"
  220. if LINUX:
  221. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  222. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_JACK
  223. else:
  224. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_CONTINUOUS_RACK
  225. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_INTERNAL
  226. # ------------------------------------------------------------------------------------------------------------
  227. # Default Plugin Folders (get)
  228. DEFAULT_LADSPA_PATH = ""
  229. DEFAULT_DSSI_PATH = ""
  230. DEFAULT_LV2_PATH = ""
  231. DEFAULT_VST2_PATH = ""
  232. DEFAULT_VST3_PATH = ""
  233. DEFAULT_AU_PATH = ""
  234. DEFAULT_GIG_PATH = ""
  235. DEFAULT_SF2_PATH = ""
  236. DEFAULT_SFZ_PATH = ""
  237. if WINDOWS:
  238. splitter = ";"
  239. APPDATA = os.getenv("APPDATA")
  240. PROGRAMFILES = os.getenv("PROGRAMFILES")
  241. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  242. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  243. COMMONPROGRAMFILESx86 = os.getenv("COMMONPROGRAMFILES(x86)")
  244. # Small integrity tests
  245. if not APPDATA:
  246. qFatal("APPDATA variable not set, cannot continue")
  247. sys.exit(1)
  248. if not PROGRAMFILES:
  249. qFatal("PROGRAMFILES variable not set, cannot continue")
  250. sys.exit(1)
  251. if not COMMONPROGRAMFILES:
  252. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  253. sys.exit(1)
  254. DEFAULT_LADSPA_PATH = APPDATA + "\\LADSPA"
  255. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILES + "\\LADSPA"
  256. DEFAULT_DSSI_PATH = APPDATA + "\\DSSI"
  257. DEFAULT_DSSI_PATH += ";" + PROGRAMFILES + "\\DSSI"
  258. DEFAULT_LV2_PATH = APPDATA + "\\LV2"
  259. DEFAULT_LV2_PATH += ";" + COMMONPROGRAMFILES + "\\LV2"
  260. DEFAULT_VST2_PATH = PROGRAMFILES + "\\VstPlugins"
  261. DEFAULT_VST2_PATH += ";" + PROGRAMFILES + "\\Steinberg\\VstPlugins"
  262. if kIs64bit:
  263. DEFAULT_VST2_PATH += ";" + COMMONPROGRAMFILES + "\\VST2"
  264. DEFAULT_VST3_PATH = COMMONPROGRAMFILES + "\\VST3"
  265. DEFAULT_GIG_PATH = APPDATA + "\\GIG"
  266. DEFAULT_SF2_PATH = APPDATA + "\\SF2"
  267. DEFAULT_SFZ_PATH = APPDATA + "\\SFZ"
  268. if PROGRAMFILESx86:
  269. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILESx86 + "\\LADSPA"
  270. DEFAULT_DSSI_PATH += ";" + PROGRAMFILESx86 + "\\DSSI"
  271. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\VstPlugins"
  272. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\Steinberg\\VstPlugins"
  273. if COMMONPROGRAMFILESx86:
  274. DEFAULT_VST3_PATH += COMMONPROGRAMFILESx86 + "\\VST3"
  275. elif HAIKU:
  276. splitter = ":"
  277. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  278. DEFAULT_LADSPA_PATH += ":/boot/common/add-ons/ladspa"
  279. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  280. DEFAULT_DSSI_PATH += ":/boot/common/add-ons/dssi"
  281. DEFAULT_LV2_PATH = HOME + "/.lv2"
  282. DEFAULT_LV2_PATH += ":/boot/common/add-ons/lv2"
  283. DEFAULT_VST2_PATH = HOME + "/.vst"
  284. DEFAULT_VST2_PATH += ":/boot/common/add-ons/vst"
  285. DEFAULT_VST3_PATH = HOME + "/.vst3"
  286. DEFAULT_VST3_PATH += ":/boot/common/add-ons/vst3"
  287. elif MACOS:
  288. splitter = ":"
  289. DEFAULT_LADSPA_PATH = HOME + "/Library/Audio/Plug-Ins/LADSPA"
  290. DEFAULT_LADSPA_PATH += ":/Library/Audio/Plug-Ins/LADSPA"
  291. DEFAULT_DSSI_PATH = HOME + "/Library/Audio/Plug-Ins/DSSI"
  292. DEFAULT_DSSI_PATH += ":/Library/Audio/Plug-Ins/DSSI"
  293. DEFAULT_LV2_PATH = HOME + "/Library/Audio/Plug-Ins/LV2"
  294. DEFAULT_LV2_PATH += ":/Library/Audio/Plug-Ins/LV2"
  295. DEFAULT_VST2_PATH = HOME + "/Library/Audio/Plug-Ins/VST"
  296. DEFAULT_VST2_PATH += ":/Library/Audio/Plug-Ins/VST"
  297. DEFAULT_VST3_PATH = HOME + "/Library/Audio/Plug-Ins/VST3"
  298. DEFAULT_VST3_PATH += ":/Library/Audio/Plug-Ins/VST3"
  299. DEFAULT_AU_PATH = HOME + "/Library/Audio/Plug-Ins/Components"
  300. DEFAULT_AU_PATH += ":/Library/Audio/Plug-Ins/Components"
  301. else:
  302. splitter = ":"
  303. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  304. DEFAULT_LADSPA_PATH += ":/usr/lib/ladspa"
  305. DEFAULT_LADSPA_PATH += ":/usr/local/lib/ladspa"
  306. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  307. DEFAULT_DSSI_PATH += ":/usr/lib/dssi"
  308. DEFAULT_DSSI_PATH += ":/usr/local/lib/dssi"
  309. DEFAULT_LV2_PATH = HOME + "/.lv2"
  310. DEFAULT_LV2_PATH += ":/usr/lib/lv2"
  311. DEFAULT_LV2_PATH += ":/usr/local/lib/lv2"
  312. DEFAULT_VST2_PATH = HOME + "/.vst"
  313. DEFAULT_VST2_PATH += ":/usr/lib/vst"
  314. DEFAULT_VST2_PATH += ":/usr/local/lib/vst"
  315. DEFAULT_VST3_PATH = HOME + "/.vst3"
  316. DEFAULT_VST3_PATH += ":/usr/lib/vst3"
  317. DEFAULT_VST3_PATH += ":/usr/local/lib/vst3"
  318. DEFAULT_GIG_PATH = HOME + "/.sounds/gig"
  319. DEFAULT_GIG_PATH += ":/usr/share/sounds/gig"
  320. DEFAULT_SF2_PATH = HOME + "/.sounds/sf2"
  321. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf2"
  322. DEFAULT_SFZ_PATH = HOME + "/.sounds/sfz"
  323. DEFAULT_SFZ_PATH += ":/usr/share/sounds/sfz"
  324. if not WINDOWS:
  325. winePrefix = os.getenv("WINEPREFIX")
  326. if not winePrefix:
  327. winePrefix = HOME + "/.wine"
  328. if os.path.exists(winePrefix):
  329. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files/VstPlugins"
  330. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files/Common Files/VST3"
  331. if kIs64bit and os.path.exists(winePrefix + "/drive_c/Program Files (x86)"):
  332. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/VstPlugins"
  333. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/VST3"
  334. del winePrefix
  335. # ------------------------------------------------------------------------------------------------------------
  336. # Default Plugin Folders (set)
  337. readEnvVars = True
  338. if WINDOWS:
  339. # Check if running Wine. If yes, ignore env vars
  340. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  341. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  342. try:
  343. key = OpenKey(reg, r"SOFTWARE\Wine")
  344. CloseKey(key)
  345. del key
  346. readEnvVars = False
  347. except:
  348. pass
  349. CloseKey(reg)
  350. del reg
  351. if readEnvVars:
  352. CARLA_DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  353. CARLA_DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  354. CARLA_DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  355. CARLA_DEFAULT_VST2_PATH = os.getenv("VST_PATH", DEFAULT_VST2_PATH).split(splitter)
  356. CARLA_DEFAULT_VST3_PATH = os.getenv("VST3_PATH", DEFAULT_VST3_PATH).split(splitter)
  357. CARLA_DEFAULT_AU_PATH = os.getenv("AU_PATH", DEFAULT_AU_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_AU_PATH = DEFAULT_AU_PATH.split(splitter)
  368. CARLA_DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  369. CARLA_DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  370. CARLA_DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  371. # ------------------------------------------------------------------------------------------------------------
  372. # Default Plugin Folders (cleanup)
  373. del DEFAULT_LADSPA_PATH
  374. del DEFAULT_DSSI_PATH
  375. del DEFAULT_LV2_PATH
  376. del DEFAULT_VST2_PATH
  377. del DEFAULT_VST3_PATH
  378. del DEFAULT_AU_PATH
  379. del DEFAULT_GIG_PATH
  380. del DEFAULT_SF2_PATH
  381. del DEFAULT_SFZ_PATH
  382. # ------------------------------------------------------------------------------------------------------------
  383. # Global Carla object
  384. class CarlaObject(object):
  385. __slots__ = [
  386. 'gui', # Host Window
  387. 'utils' # Utils object
  388. ]
  389. gCarla = CarlaObject()
  390. gCarla.gui = None
  391. gCarla.utils = None
  392. # ------------------------------------------------------------------------------------------------------------
  393. # Set CWD
  394. CWD = sys.path[0]
  395. if not CWD:
  396. CWD = os.path.dirname(sys.argv[0])
  397. # make it work with cxfreeze
  398. if os.path.isfile(CWD):
  399. CWD = os.path.dirname(CWD)
  400. # ------------------------------------------------------------------------------------------------------------
  401. # Set DLL_EXTENSION
  402. if WINDOWS:
  403. DLL_EXTENSION = "dll"
  404. elif MACOS:
  405. DLL_EXTENSION = "dylib"
  406. else:
  407. DLL_EXTENSION = "so"
  408. # ------------------------------------------------------------------------------------------------------------
  409. # Check if a value is a number (float support)
  410. def isNumber(value):
  411. try:
  412. float(value)
  413. return True
  414. except:
  415. return False
  416. # ------------------------------------------------------------------------------------------------------------
  417. # Convert a value to a list
  418. def toList(value):
  419. if value is None:
  420. return []
  421. elif not isinstance(value, list):
  422. return [value]
  423. else:
  424. return value
  425. # ------------------------------------------------------------------------------------------------------------
  426. # Get Icon from user theme, using our own as backup (Oxygen)
  427. def getIcon(icon, size = 16):
  428. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  429. # ------------------------------------------------------------------------------------------------------------
  430. # Get paths (binaries, resources)
  431. def getPaths(libPrefix = None):
  432. CWDl = CWD.lower()
  433. # standalone, installed system-wide linux
  434. if libPrefix is not None:
  435. pathBinaries = os.path.join(libPrefix, "lib", "carla")
  436. pathResources = os.path.join(libPrefix, "share", "carla", "resources")
  437. # standalone, local source
  438. elif CWDl.endswith("source"):
  439. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "bin"))
  440. pathResources = os.path.join(pathBinaries, "resources")
  441. # plugin
  442. elif CWDl.endswith("resources"):
  443. # installed system-wide linux
  444. if CWDl.endswith("/share/carla/resources"):
  445. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "lib", "carla"))
  446. pathResources = CWD
  447. # local source
  448. elif CWDl.endswith("native-plugins%sresources" % os.sep):
  449. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "bin"))
  450. pathResources = CWD
  451. # other
  452. else:
  453. pathBinaries = os.path.abspath(os.path.join(CWD, ".."))
  454. pathResources = CWD
  455. # everything else
  456. else:
  457. pathBinaries = CWD
  458. pathResources = os.path.join(pathBinaries, "resources")
  459. return (pathBinaries, pathResources)
  460. # ------------------------------------------------------------------------------------------------------------
  461. # Signal handler
  462. # TODO move to carla_host.py or something
  463. def signalHandler(sig, frame):
  464. if gCarla.gui is None:
  465. return
  466. if sig in (SIGINT, SIGTERM):
  467. gCarla.gui.SIGTERM.emit()
  468. elif haveSIGUSR1 and sig == SIGUSR1:
  469. gCarla.gui.SIGUSR1.emit()
  470. def setUpSignals():
  471. signal(SIGINT, signalHandler)
  472. signal(SIGTERM, signalHandler)
  473. if not haveSIGUSR1:
  474. return
  475. signal(SIGUSR1, signalHandler)
  476. # ------------------------------------------------------------------------------------------------------------
  477. # QLineEdit and QPushButton combo
  478. def getAndSetPath(parent, lineEdit):
  479. newPath = QFileDialog.getExistingDirectory(parent, parent.tr("Set Path"), lineEdit.text(), QFileDialog.ShowDirsOnly)
  480. if newPath:
  481. lineEdit.setText(newPath)
  482. return newPath
  483. # ------------------------------------------------------------------------------------------------------------
  484. # Custom MessageBox
  485. def CustomMessageBox(parent, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  486. msgBox = QMessageBox(parent)
  487. msgBox.setIcon(icon)
  488. msgBox.setWindowTitle(title)
  489. msgBox.setText(text)
  490. msgBox.setInformativeText(extraText)
  491. msgBox.setStandardButtons(buttons)
  492. msgBox.setDefaultButton(defButton)
  493. return msgBox.exec_()
  494. # ------------------------------------------------------------------------------------------------------------