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.

791 lines
27KB

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