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.

910 lines
33KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Common Carla code
  4. # Copyright (C) 2011-2022 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 (Global)
  19. import os
  20. import sys
  21. from math import fmod
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Signal)
  24. from signal import signal, SIGINT, SIGTERM
  25. try:
  26. from signal import SIGUSR1
  27. haveSIGUSR1 = True
  28. except:
  29. haveSIGUSR1 = False
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (PyQt5)
  32. from PyQt5.Qt import PYQT_VERSION_STR
  33. from PyQt5.QtCore import qFatal, QT_VERSION, QT_VERSION_STR, qWarning, QDir, QSettings
  34. from PyQt5.QtGui import QIcon
  35. from PyQt5.QtWidgets import QFileDialog, QMessageBox
  36. # ------------------------------------------------------------------------------------------------------------
  37. # Imports (Custom)
  38. from carla_backend import (
  39. MAX_DEFAULT_PARAMETERS,
  40. ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,
  41. ENGINE_PROCESS_MODE_PATCHBAY,
  42. ENGINE_TRANSPORT_MODE_INTERNAL,
  43. ENGINE_TRANSPORT_MODE_JACK
  44. )
  45. from common import kIs64bit, HAIKU, LINUX, MACOS, WINDOWS, VERSION
  46. # ------------------------------------------------------------------------------------------------------------
  47. # Config
  48. # These will be modified during install
  49. X_LIBDIR_X = None
  50. X_DATADIR_X = None
  51. # ------------------------------------------------------------------------------------------------------------
  52. # Platform specific stuff
  53. if WINDOWS:
  54. WINDIR = os.getenv("WINDIR")
  55. # ------------------------------------------------------------------------------------------------------------
  56. # Set TMP
  57. envTMP = os.getenv("TMP")
  58. if envTMP is None:
  59. if WINDOWS:
  60. qWarning("TMP variable not set")
  61. TMP = QDir.tempPath()
  62. else:
  63. TMP = envTMP
  64. if not os.path.exists(TMP):
  65. qWarning("TMP does not exist")
  66. TMP = "/"
  67. del envTMP
  68. # ------------------------------------------------------------------------------------------------------------
  69. # Set HOME
  70. envHOME = os.getenv("HOME")
  71. if envHOME is None:
  72. if LINUX or MACOS:
  73. qWarning("HOME variable not set")
  74. HOME = QDir.toNativeSeparators(QDir.homePath())
  75. else:
  76. HOME = envHOME
  77. if not os.path.exists(HOME):
  78. qWarning("HOME does not exist")
  79. HOME = TMP
  80. del envHOME
  81. # ------------------------------------------------------------------------------------------------------------
  82. # Set PATH
  83. envPATH = os.getenv("PATH")
  84. if envPATH is None:
  85. qWarning("PATH variable not set")
  86. if MACOS:
  87. PATH = ("/opt/local/bin", "/usr/local/bin", "/usr/bin", "/bin")
  88. elif WINDOWS:
  89. PATH = (os.path.join(WINDIR, "system32"), WINDIR)
  90. else:
  91. PATH = ("/usr/local/bin", "/usr/bin", "/bin")
  92. else:
  93. PATH = envPATH.split(os.pathsep)
  94. del envPATH
  95. # ------------------------------------------------------------------------------------------------------------
  96. # Static MIDI CC list
  97. MIDI_CC_LIST = (
  98. "01 [0x01] Modulation",
  99. "02 [0x02] Breath",
  100. "04 [0x04] Foot",
  101. "05 [0x05] Portamento",
  102. "07 [0x07] Volume",
  103. "08 [0x08] Balance",
  104. "10 [0x0A] Pan",
  105. "11 [0x0B] Expression",
  106. "12 [0x0C] FX Control 1",
  107. "13 [0x0D] FX Control 2",
  108. "16 [0x10] General Purpose 1",
  109. "17 [0x11] General Purpose 2",
  110. "18 [0x12] General Purpose 3",
  111. "19 [0x13] General Purpose 4",
  112. "70 [0x46] Control 1 [Variation]",
  113. "71 [0x47] Control 2 [Timbre]",
  114. "72 [0x48] Control 3 [Release]",
  115. "73 [0x49] Control 4 [Attack]",
  116. "74 [0x4A] Control 5 [Brightness]",
  117. "75 [0x4B] Control 6 [Decay]",
  118. "76 [0x4C] Control 7 [Vib Rate]",
  119. "77 [0x4D] Control 8 [Vib Depth]",
  120. "78 [0x4E] Control 9 [Vib Delay]",
  121. "79 [0x4F] Control 10 [Undefined]",
  122. "80 [0x50] General Purpose 5",
  123. "81 [0x51] General Purpose 6",
  124. "82 [0x52] General Purpose 7",
  125. "83 [0x53] General Purpose 8",
  126. "84 [0x54] Portamento Control",
  127. "91 [0x5B] FX 1 Depth [Reverb]",
  128. "92 [0x5C] FX 2 Depth [Tremolo]",
  129. "93 [0x5D] FX 3 Depth [Chorus]",
  130. "94 [0x5E] FX 4 Depth [Detune]",
  131. "95 [0x5F] FX 5 Depth [Phaser]"
  132. )
  133. MAX_MIDI_CC_LIST_ITEM = 95
  134. # ------------------------------------------------------------------------------------------------------------
  135. # PatchCanvas defines
  136. CANVAS_ANTIALIASING_SMALL = 1
  137. CANVAS_EYECANDY_SMALL = 1
  138. # ------------------------------------------------------------------------------------------------------------
  139. # Carla Settings keys
  140. CARLA_KEY_MAIN_PROJECT_FOLDER = "Main/ProjectFolder" # str
  141. CARLA_KEY_MAIN_USE_PRO_THEME = "Main/UseProTheme" # bool
  142. CARLA_KEY_MAIN_PRO_THEME_COLOR = "Main/ProThemeColor" # str
  143. CARLA_KEY_MAIN_REFRESH_INTERVAL = "Main/RefreshInterval" # int
  144. CARLA_KEY_MAIN_CONFIRM_EXIT = "Main/ConfirmExit" # bool
  145. CARLA_KEY_MAIN_CLASSIC_SKIN = "Main/ClassicSkin" # bool
  146. CARLA_KEY_MAIN_SHOW_LOGS = "Main/ShowLogs" # bool
  147. CARLA_KEY_MAIN_SYSTEM_ICONS = "Main/SystemIcons" # bool
  148. CARLA_KEY_MAIN_EXPERIMENTAL = "Main/Experimental" # bool
  149. CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str
  150. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  151. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  152. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  153. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS = "Canvas/AutoSelectItems" # bool
  154. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy2" # bool
  155. CARLA_KEY_CANVAS_FANCY_EYE_CANDY = "Canvas/FancyEyeCandy" # bool
  156. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  157. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  158. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  159. CARLA_KEY_CANVAS_INLINE_DISPLAYS = "Canvas/InlineDisplays" # bool
  160. CARLA_KEY_CANVAS_FULL_REPAINTS = "Canvas/FullRepaints" # bool
  161. CARLA_KEY_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  162. CARLA_KEY_ENGINE_AUDIO_DRIVER = "Engine/AudioDriver" # str
  163. CARLA_KEY_ENGINE_PROCESS_MODE = "Engine/ProcessMode" # enum
  164. CARLA_KEY_ENGINE_TRANSPORT_MODE = "Engine/TransportMode" # enum
  165. CARLA_KEY_ENGINE_TRANSPORT_EXTRA = "Engine/TransportExtra" # str
  166. CARLA_KEY_ENGINE_FORCE_STEREO = "Engine/ForceStereo" # bool
  167. CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES = "Engine/PreferPluginBridges" # bool
  168. CARLA_KEY_ENGINE_PREFER_UI_BRIDGES = "Engine/PreferUiBridges" # bool
  169. CARLA_KEY_ENGINE_MANAGE_UIS = "Engine/ManageUIs" # bool
  170. CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  171. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  172. CARLA_KEY_ENGINE_RESET_XRUNS = "Engine/ResetXruns" # bool
  173. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  174. CARLA_KEY_OSC_ENABLED = "OSC/Enabled"
  175. CARLA_KEY_OSC_TCP_PORT_ENABLED = "OSC/TCPEnabled"
  176. CARLA_KEY_OSC_TCP_PORT_NUMBER = "OSC/TCPNumber"
  177. CARLA_KEY_OSC_TCP_PORT_RANDOM = "OSC/TCPRandom"
  178. CARLA_KEY_OSC_UDP_PORT_ENABLED = "OSC/UDPEnabled"
  179. CARLA_KEY_OSC_UDP_PORT_NUMBER = "OSC/UDPNumber"
  180. CARLA_KEY_OSC_UDP_PORT_RANDOM = "OSC/UDPRandom"
  181. CARLA_KEY_PATHS_AUDIO = "Paths/Audio"
  182. CARLA_KEY_PATHS_MIDI = "Paths/MIDI"
  183. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  184. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  185. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  186. CARLA_KEY_PATHS_VST2 = "Paths/VST2"
  187. CARLA_KEY_PATHS_VST3 = "Paths/VST3"
  188. CARLA_KEY_PATHS_CLAP = "Paths/CLAP"
  189. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  190. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  191. CARLA_KEY_PATHS_JSFX = "Paths/JSFX"
  192. CARLA_KEY_WINE_EXECUTABLE = "Wine/Executable" # str
  193. CARLA_KEY_WINE_AUTO_PREFIX = "Wine/AutoPrefix" # bool
  194. CARLA_KEY_WINE_FALLBACK_PREFIX = "Wine/FallbackPrefix" # str
  195. CARLA_KEY_WINE_RT_PRIO_ENABLED = "Wine/RtPrioEnabled" # bool
  196. CARLA_KEY_WINE_BASE_RT_PRIO = "Wine/BaseRtPrio" # int
  197. CARLA_KEY_WINE_SERVER_RT_PRIO = "Wine/ServerRtPrio" # int
  198. CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES = "Experimental/PluginBridges" # bool
  199. CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES = "Experimental/WineBridges" # bool
  200. CARLA_KEY_EXPERIMENTAL_JACK_APPS = "Experimental/JackApplications" # bool
  201. CARLA_KEY_EXPERIMENTAL_EXPORT_LV2 = "Experimental/ExportLV2" # bool
  202. CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR = "Experimental/PreventBadBehaviour" # bool
  203. CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL = "Experimental/LoadLibGlobal" # bool
  204. # if pro theme is on and color is black
  205. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # bool
  206. # ------------------------------------------------------------------------------------------------------------
  207. # Carla Settings defaults
  208. # Main
  209. CARLA_DEFAULT_MAIN_PROJECT_FOLDER = HOME
  210. CARLA_DEFAULT_MAIN_USE_PRO_THEME = True
  211. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR = "Black"
  212. CARLA_DEFAULT_MAIN_REFRESH_INTERVAL = 20
  213. CARLA_DEFAULT_MAIN_CONFIRM_EXIT = True
  214. CARLA_DEFAULT_MAIN_CLASSIC_SKIN = False
  215. CARLA_DEFAULT_MAIN_SHOW_LOGS = bool(not WINDOWS)
  216. CARLA_DEFAULT_MAIN_SYSTEM_ICONS = False
  217. CARLA_DEFAULT_MAIN_EXPERIMENTAL = False
  218. # Canvas
  219. CARLA_DEFAULT_CANVAS_THEME = "Modern Dark"
  220. CARLA_DEFAULT_CANVAS_SIZE = "3100x2400"
  221. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  222. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  223. CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES = True
  224. CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS = True
  225. CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS = False
  226. CARLA_DEFAULT_CANVAS_EYE_CANDY = True
  227. CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY = False
  228. CARLA_DEFAULT_CANVAS_USE_OPENGL = False
  229. CARLA_DEFAULT_CANVAS_ANTIALIASING = CANVAS_ANTIALIASING_SMALL
  230. CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING = False
  231. CARLA_DEFAULT_CANVAS_INLINE_DISPLAYS = False
  232. CARLA_DEFAULT_CANVAS_FULL_REPAINTS = False
  233. # Engine
  234. CARLA_DEFAULT_FORCE_STEREO = False
  235. CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES = False
  236. CARLA_DEFAULT_PREFER_UI_BRIDGES = True
  237. CARLA_DEFAULT_MANAGE_UIS = True
  238. CARLA_DEFAULT_UIS_ALWAYS_ON_TOP = False
  239. CARLA_DEFAULT_MAX_PARAMETERS = MAX_DEFAULT_PARAMETERS
  240. CARLA_DEFAULT_RESET_XRUNS = False
  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 = "Windows Audio"
  247. elif MACOS:
  248. CARLA_DEFAULT_AUDIO_DRIVER = "CoreAudio"
  249. elif os.path.exists("/usr/bin/jackd") or os.path.exists("/usr/bin/jackdbus") or os.path.exists("/usr/bin/pw-jack"):
  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 (MACOS or 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_CLAP_PATH = ""
  293. DEFAULT_SF2_PATH = ""
  294. DEFAULT_SFZ_PATH = ""
  295. DEFAULT_JSFX_PATH = ""
  296. if WINDOWS:
  297. splitter = ";"
  298. APPDATA = os.getenv("APPDATA")
  299. LOCALAPPDATA = os.getenv("LOCALAPPDATA", APPDATA)
  300. PROGRAMFILES = os.getenv("PROGRAMFILES")
  301. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  302. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  303. COMMONPROGRAMFILESx86 = os.getenv("COMMONPROGRAMFILES(x86)")
  304. # Small integrity tests
  305. if not APPDATA:
  306. qFatal("APPDATA variable not set, cannot continue")
  307. sys.exit(1)
  308. if not PROGRAMFILES:
  309. qFatal("PROGRAMFILES variable not set, cannot continue")
  310. sys.exit(1)
  311. if not COMMONPROGRAMFILES:
  312. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  313. sys.exit(1)
  314. DEFAULT_LADSPA_PATH = APPDATA + "\\LADSPA"
  315. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILES + "\\LADSPA"
  316. DEFAULT_DSSI_PATH = APPDATA + "\\DSSI"
  317. DEFAULT_DSSI_PATH += ";" + PROGRAMFILES + "\\DSSI"
  318. DEFAULT_LV2_PATH = APPDATA + "\\LV2"
  319. DEFAULT_LV2_PATH += ";" + COMMONPROGRAMFILES + "\\LV2"
  320. DEFAULT_VST2_PATH = PROGRAMFILES + "\\VstPlugins"
  321. DEFAULT_VST2_PATH += ";" + PROGRAMFILES + "\\Steinberg\\VstPlugins"
  322. DEFAULT_JSFX_PATH = APPDATA + "\\REAPER\\Effects"
  323. #DEFAULT_JSFX_PATH += ";" + PROGRAMFILES + "\\REAPER\\InstallData\\Effects"
  324. if kIs64bit:
  325. DEFAULT_VST2_PATH += ";" + COMMONPROGRAMFILES + "\\VST2"
  326. DEFAULT_VST3_PATH = COMMONPROGRAMFILES + "\\VST3"
  327. DEFAULT_VST3_PATH += ";" + LOCALAPPDATA + "\\Programs\\Common\\VST3"
  328. DEFAULT_CLAP_PATH = COMMONPROGRAMFILES + "\\CLAP"
  329. DEFAULT_CLAP_PATH += ";" + LOCALAPPDATA + "\\Programs\\Common\\CLAP"
  330. DEFAULT_SF2_PATH = APPDATA + "\\SF2"
  331. DEFAULT_SFZ_PATH = APPDATA + "\\SFZ"
  332. if PROGRAMFILESx86:
  333. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILESx86 + "\\LADSPA"
  334. DEFAULT_DSSI_PATH += ";" + PROGRAMFILESx86 + "\\DSSI"
  335. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\VstPlugins"
  336. DEFAULT_VST2_PATH += ";" + PROGRAMFILESx86 + "\\Steinberg\\VstPlugins"
  337. #DEFAULT_JSFX_PATH += ";" + PROGRAMFILESx86 + "\\REAPER\\InstallData\\Effects"
  338. if COMMONPROGRAMFILESx86:
  339. DEFAULT_VST3_PATH += COMMONPROGRAMFILESx86 + "\\VST3"
  340. DEFAULT_CLAP_PATH += COMMONPROGRAMFILESx86 + "\\CLAP"
  341. elif HAIKU:
  342. splitter = ":"
  343. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  344. DEFAULT_LADSPA_PATH += ":/system/add-ons/media/ladspaplugins"
  345. DEFAULT_LADSPA_PATH += ":/system/lib/ladspa"
  346. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  347. DEFAULT_DSSI_PATH += ":/system/add-ons/media/dssiplugins"
  348. DEFAULT_DSSI_PATH += ":/system/lib/dssi"
  349. DEFAULT_LV2_PATH = HOME + "/.lv2"
  350. DEFAULT_LV2_PATH += ":/system/add-ons/media/lv2plugins"
  351. DEFAULT_VST2_PATH = HOME + "/.vst"
  352. DEFAULT_VST2_PATH += ":/system/add-ons/media/vstplugins"
  353. DEFAULT_VST3_PATH = HOME + "/.vst3"
  354. DEFAULT_VST3_PATH += ":/system/add-ons/media/vst3plugins"
  355. DEFAULT_CLAP_PATH = HOME + "/.clap"
  356. DEFAULT_CLAP_PATH += ":/system/add-ons/media/clapplugins"
  357. elif MACOS:
  358. splitter = ":"
  359. DEFAULT_LADSPA_PATH = HOME + "/Library/Audio/Plug-Ins/LADSPA"
  360. DEFAULT_LADSPA_PATH += ":/Library/Audio/Plug-Ins/LADSPA"
  361. DEFAULT_DSSI_PATH = HOME + "/Library/Audio/Plug-Ins/DSSI"
  362. DEFAULT_DSSI_PATH += ":/Library/Audio/Plug-Ins/DSSI"
  363. DEFAULT_LV2_PATH = HOME + "/Library/Audio/Plug-Ins/LV2"
  364. DEFAULT_LV2_PATH += ":/Library/Audio/Plug-Ins/LV2"
  365. DEFAULT_VST2_PATH = HOME + "/Library/Audio/Plug-Ins/VST"
  366. DEFAULT_VST2_PATH += ":/Library/Audio/Plug-Ins/VST"
  367. DEFAULT_VST3_PATH = HOME + "/Library/Audio/Plug-Ins/VST3"
  368. DEFAULT_VST3_PATH += ":/Library/Audio/Plug-Ins/VST3"
  369. DEFAULT_CLAP_PATH = HOME + "/Library/Audio/Plug-Ins/CLAP"
  370. DEFAULT_CLAP_PATH += ":/Library/Audio/Plug-Ins/CLAP"
  371. DEFAULT_JSFX_PATH = HOME + "/Library/Application Support/REAPER/Effects"
  372. #DEFAULT_JSFX_PATH += ":/Applications/REAPER.app/Contents/InstallFiles/Effects"
  373. else:
  374. CONFIG_HOME = os.getenv("XDG_CONFIG_HOME", HOME + "/.config")
  375. splitter = ":"
  376. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  377. DEFAULT_LADSPA_PATH += ":/usr/lib/ladspa"
  378. DEFAULT_LADSPA_PATH += ":/usr/local/lib/ladspa"
  379. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  380. DEFAULT_DSSI_PATH += ":/usr/lib/dssi"
  381. DEFAULT_DSSI_PATH += ":/usr/local/lib/dssi"
  382. DEFAULT_LV2_PATH = HOME + "/.lv2"
  383. DEFAULT_LV2_PATH += ":/usr/lib/lv2"
  384. DEFAULT_LV2_PATH += ":/usr/local/lib/lv2"
  385. DEFAULT_VST2_PATH = HOME + "/.vst"
  386. DEFAULT_VST2_PATH += ":/usr/lib/vst"
  387. DEFAULT_VST2_PATH += ":/usr/local/lib/vst"
  388. DEFAULT_VST2_PATH += HOME + "/.lxvst"
  389. DEFAULT_VST2_PATH += ":/usr/lib/lxvst"
  390. DEFAULT_VST2_PATH += ":/usr/local/lib/lxvst"
  391. DEFAULT_VST3_PATH = HOME + "/.vst3"
  392. DEFAULT_VST3_PATH += ":/usr/lib/vst3"
  393. DEFAULT_VST3_PATH += ":/usr/local/lib/vst3"
  394. DEFAULT_CLAP_PATH = HOME + "/.clap"
  395. DEFAULT_CLAP_PATH += ":/usr/lib/clap"
  396. DEFAULT_CLAP_PATH += ":/usr/local/lib/clap"
  397. DEFAULT_SF2_PATH = HOME + "/.sounds/sf2"
  398. DEFAULT_SF2_PATH += ":" + HOME + "/.sounds/sf3"
  399. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf2"
  400. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf3"
  401. DEFAULT_SF2_PATH += ":/usr/share/soundfonts"
  402. DEFAULT_SFZ_PATH = HOME + "/.sounds/sfz"
  403. DEFAULT_SFZ_PATH += ":/usr/share/sounds/sfz"
  404. DEFAULT_JSFX_PATH = CONFIG_HOME + "/REAPER/Effects"
  405. #DEFAULT_JSFX_PATH += ":" + "/opt/REAPER/InstallData/Effects"
  406. if not WINDOWS:
  407. winePrefix = os.getenv("WINEPREFIX")
  408. if not winePrefix:
  409. winePrefix = HOME + "/.wine"
  410. if os.path.exists(winePrefix):
  411. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files/VstPlugins"
  412. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files/Common Files/VST3"
  413. DEFAULT_CLAP_PATH += ":" + winePrefix + "/drive_c/Program Files/Common Files/CLAP"
  414. if kIs64bit and os.path.exists(winePrefix + "/drive_c/Program Files (x86)"):
  415. DEFAULT_VST2_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/VstPlugins"
  416. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/VST3"
  417. DEFAULT_CLAP_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/CLAP"
  418. del winePrefix
  419. # ------------------------------------------------------------------------------------------------------------
  420. # Default Plugin Folders (set)
  421. readEnvVars = True
  422. if WINDOWS:
  423. # Check if running Wine. If yes, ignore env vars
  424. # pylint: disable=import-error
  425. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  426. # pylint: enable=import-error
  427. _reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  428. try:
  429. _key = OpenKey(_reg, r"SOFTWARE\Wine")
  430. CloseKey(_key)
  431. del _key
  432. readEnvVars = False
  433. except:
  434. pass
  435. CloseKey(_reg)
  436. del _reg
  437. if readEnvVars:
  438. CARLA_DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  439. CARLA_DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  440. CARLA_DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  441. CARLA_DEFAULT_VST2_PATH = os.getenv("VST_PATH", DEFAULT_VST2_PATH).split(splitter)
  442. CARLA_DEFAULT_VST3_PATH = os.getenv("VST3_PATH", DEFAULT_VST3_PATH).split(splitter)
  443. CARLA_DEFAULT_CLAP_PATH = os.getenv("CLAP_PATH", DEFAULT_CLAP_PATH).split(splitter)
  444. CARLA_DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  445. CARLA_DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  446. CARLA_DEFAULT_JSFX_PATH = os.getenv("JSFX_PATH", DEFAULT_JSFX_PATH).split(splitter)
  447. else:
  448. CARLA_DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  449. CARLA_DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  450. CARLA_DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  451. CARLA_DEFAULT_VST2_PATH = DEFAULT_VST2_PATH.split(splitter)
  452. CARLA_DEFAULT_VST3_PATH = DEFAULT_VST3_PATH.split(splitter)
  453. CARLA_DEFAULT_CLAP_PATH = DEFAULT_CLAP_PATH.split(splitter)
  454. CARLA_DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  455. CARLA_DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  456. CARLA_DEFAULT_JSFX_PATH = DEFAULT_JSFX_PATH.split(splitter)
  457. # ------------------------------------------------------------------------------------------------------------
  458. # Default Plugin Folders (cleanup)
  459. del DEFAULT_LADSPA_PATH
  460. del DEFAULT_DSSI_PATH
  461. del DEFAULT_LV2_PATH
  462. del DEFAULT_VST2_PATH
  463. del DEFAULT_VST3_PATH
  464. del DEFAULT_CLAP_PATH
  465. del DEFAULT_SF2_PATH
  466. del DEFAULT_SFZ_PATH
  467. # ------------------------------------------------------------------------------------------------------------
  468. # Global Carla object
  469. class CarlaObject():
  470. def __init__(self):
  471. self.cnprefix = "" # Client name prefix
  472. self.gui = None # Host Window
  473. self.nogui = False # Skip UI
  474. self.term = False # Terminated by OS signal
  475. self.felib = None # Frontend lib object
  476. self.utils = None # Utils object
  477. gCarla = CarlaObject()
  478. # ------------------------------------------------------------------------------------------------------------
  479. # Set CWD
  480. CWD = sys.path[0]
  481. if not CWD:
  482. CWD = os.path.dirname(sys.argv[0])
  483. # make it work with cxfreeze
  484. if os.path.isfile(CWD):
  485. CWD = os.path.dirname(CWD)
  486. if CWD.endswith("/lib"):
  487. CWD = CWD.rsplit("/lib",1)[0]
  488. CXFREEZE = True
  489. if not WINDOWS:
  490. os.environ['CARLA_MAGIC_FILE'] = os.path.join(CWD, "magic.mgc")
  491. else:
  492. CXFREEZE = False
  493. # ------------------------------------------------------------------------------------------------------------
  494. # Set DLL_EXTENSION
  495. if WINDOWS:
  496. DLL_EXTENSION = "dll"
  497. elif MACOS:
  498. DLL_EXTENSION = "dylib"
  499. else:
  500. DLL_EXTENSION = "so"
  501. # ------------------------------------------------------------------------------------------------------------
  502. # Find decimal points for a parameter, using step and stepSmall
  503. def countDecimalPoints(step, stepSmall):
  504. if stepSmall >= 1.0:
  505. return 0
  506. if step >= 1.0:
  507. return 2
  508. count = 0
  509. value = fmod(abs(step), 1)
  510. while 0.0001 < value < 0.999 and count < 6:
  511. value = fmod(value*10, 1)
  512. count += 1
  513. return count
  514. # ------------------------------------------------------------------------------------------------------------
  515. # Check if a value is a number (float support)
  516. def isNumber(value):
  517. try:
  518. float(value)
  519. return True
  520. except:
  521. return False
  522. # ------------------------------------------------------------------------------------------------------------
  523. # Convert a value to a list
  524. def toList(value):
  525. if value is None:
  526. return []
  527. if not isinstance(value, list):
  528. return [value]
  529. return value
  530. # ------------------------------------------------------------------------------------------------------------
  531. # Get Icon from user theme, using our own as backup (Oxygen)
  532. def getIcon(icon, size, qrcformat):
  533. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.%s" % (size, size, icon, qrcformat)))
  534. # ------------------------------------------------------------------------------------------------------------
  535. # Handle some basic command-line arguments shared between all carla variants
  536. def handleInitialCommandLineArguments(file):
  537. initName = os.path.basename(file) if (file is not None and os.path.dirname(file) in PATH) else sys.argv[0]
  538. libPrefix = None
  539. readPrefixNext = False
  540. for arg in sys.argv[1:]:
  541. if arg.startswith("--with-appname="):
  542. initName = os.path.basename(arg.replace("--with-appname=", ""))
  543. elif arg.startswith("--with-libprefix="):
  544. libPrefix = arg.replace("--with-libprefix=", "")
  545. elif arg.startswith("--osc-gui="):
  546. gCarla.nogui = int(arg.replace("--osc-gui=", ""))
  547. elif arg.startswith("--cnprefix="):
  548. gCarla.cnprefix = arg.replace("--cnprefix=", "")
  549. elif arg == "--cnprefix":
  550. readPrefixNext = True
  551. elif arg == "--gdb":
  552. pass
  553. elif arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui"):
  554. gCarla.nogui = True
  555. elif MACOS and arg.startswith("-psn_"):
  556. pass
  557. elif arg in ("-h", "--h", "-help", "--help"):
  558. print("Usage: %s [OPTION]... [FILE|URL]" % initName)
  559. print("")
  560. print(" where FILE can be a Carla project or preset file to be loaded, or URL if using Carla-Control")
  561. print("")
  562. print(" and OPTION can be one or more of the following:")
  563. print("")
  564. print(" --cnprefix\t Set a prefix for client names in multi-client mode.")
  565. if isinstance(gCarla.nogui, bool):
  566. if X_LIBDIR_X is not None:
  567. print(" --gdb \t Run Carla inside gdb.")
  568. print(" -n,--no-gui \t Run Carla headless, don't show UI.")
  569. print("")
  570. print(" -h,--help \t Print this help text and exit.")
  571. print(" -v,--version \t Print version information and exit.")
  572. print("")
  573. if not isinstance(gCarla.nogui, bool):
  574. print("NOTE: when using %s the FILE is only valid the first time the backend is started" % initName)
  575. sys.exit(1)
  576. sys.exit(0)
  577. elif arg in ("-v", "--v", "-version", "--version"):
  578. pathBinaries, pathResources = getPaths(libPrefix)
  579. print("Using Carla version %s" % VERSION)
  580. print(" Python version: %s" % sys.version.split(" ",1)[0])
  581. print(" Qt version: %s" % QT_VERSION_STR)
  582. print(" PyQt version: %s" % PYQT_VERSION_STR)
  583. print(" Binary dir: %s" % pathBinaries)
  584. print(" Resources dir: %s" % pathResources)
  585. sys.exit(1 if gCarla.nogui else 0)
  586. elif readPrefixNext:
  587. readPrefixNext = False
  588. gCarla.cnprefix = arg
  589. if gCarla.nogui and not isinstance(gCarla.nogui, bool):
  590. if os.fork():
  591. # pylint: disable=protected-access
  592. os._exit(0)
  593. # pylint: enable=protected-access
  594. else:
  595. os.setsid()
  596. return (initName, libPrefix)
  597. # ------------------------------------------------------------------------------------------------------------
  598. # Get initial project file (as passed in the command-line parameters)
  599. def getInitialProjectFile(skipExistCheck = False):
  600. # NOTE: PyQt mishandles unicode characters, we directly use sys.argv instead of qApp->arguments()
  601. # see https://riverbankcomputing.com/pipermail/pyqt/2015-January/035395.html
  602. args = sys.argv[1:]
  603. readPrefixNext = False
  604. for arg in args:
  605. if readPrefixNext:
  606. readPrefixNext = False
  607. continue
  608. if arg.startswith("--cnprefix="):
  609. continue
  610. if arg.startswith("--osc-gui="):
  611. continue
  612. if arg.startswith("--with-appname="):
  613. continue
  614. if arg.startswith("--with-libprefix="):
  615. continue
  616. if arg == "--cnprefix":
  617. readPrefixNext = True
  618. continue
  619. if arg in ("-n", "--n", "-no-gui", "--no-gui", "-nogui", "--nogui", "--gdb"):
  620. continue
  621. if MACOS and arg.startswith("-psn_"):
  622. continue
  623. arg = os.path.expanduser(arg)
  624. if skipExistCheck or os.path.exists(arg):
  625. return arg
  626. return None
  627. # ------------------------------------------------------------------------------------------------------------
  628. # Get paths (binaries, resources)
  629. def getPaths(libPrefix = None):
  630. CWDl = CWD.lower()
  631. # adjust for special distros
  632. libdir = os.path.basename(os.path.normpath(X_LIBDIR_X)) if X_LIBDIR_X else "lib"
  633. datadir = os.path.basename(os.path.normpath(X_DATADIR_X)) if X_DATADIR_X else "share"
  634. # standalone, installed system-wide linux
  635. if libPrefix is not None:
  636. pathBinaries = os.path.join(libPrefix, libdir, "carla")
  637. pathResources = os.path.join(libPrefix, datadir, "carla", "resources")
  638. # standalone, local source
  639. elif CWDl.endswith("frontend"):
  640. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "bin"))
  641. pathResources = os.path.join(pathBinaries, "resources")
  642. # plugin
  643. elif CWDl.endswith("resources"):
  644. # installed system-wide linux
  645. if CWDl.endswith("/share/carla/resources"):
  646. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", libdir, "carla"))
  647. pathResources = CWD
  648. # local source
  649. elif CWDl.endswith("native-plugins%sresources" % os.sep):
  650. pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "bin"))
  651. pathResources = CWD
  652. # other
  653. else:
  654. pathBinaries = os.path.abspath(os.path.join(CWD, ".."))
  655. pathResources = CWD
  656. # everything else
  657. else:
  658. pathBinaries = CWD
  659. pathResources = os.path.join(pathBinaries, "resources")
  660. return (pathBinaries, pathResources)
  661. # ------------------------------------------------------------------------------------------------------------
  662. # Signal handler
  663. # TODO move to carla_host.py or something
  664. def signalHandler(sig, frame):
  665. if sig in (SIGINT, SIGTERM):
  666. gCarla.term = True
  667. if gCarla.gui is not None:
  668. gCarla.gui.SIGTERM.emit()
  669. elif haveSIGUSR1 and sig == SIGUSR1:
  670. if gCarla.gui is not None:
  671. gCarla.gui.SIGUSR1.emit()
  672. def setUpSignals():
  673. signal(SIGINT, signalHandler)
  674. signal(SIGTERM, signalHandler)
  675. if not haveSIGUSR1:
  676. return
  677. signal(SIGUSR1, signalHandler)
  678. # ------------------------------------------------------------------------------------------------------------
  679. # QLineEdit and QPushButton combo
  680. def getAndSetPath(parent, lineEdit):
  681. newPath = QFileDialog.getExistingDirectory(parent, parent.tr("Set Path"), lineEdit.text(), QFileDialog.ShowDirsOnly)
  682. if newPath:
  683. lineEdit.setText(newPath)
  684. return newPath
  685. # ------------------------------------------------------------------------------------------------------------
  686. # Backwards-compatible horizontalAdvance/width call, depending on Qt version
  687. def fontMetricsHorizontalAdvance(fontMetrics, string):
  688. if QT_VERSION >= 0x50b00:
  689. return fontMetrics.horizontalAdvance(string)
  690. return fontMetrics.width(string)
  691. # ------------------------------------------------------------------------------------------------------------
  692. # Custom QMessageBox which resizes itself to fit text
  693. class QMessageBoxWithBetterWidth(QMessageBox):
  694. def __init__(self, parent):
  695. QMessageBox.__init__(self, parent)
  696. def showEvent(self, event):
  697. fontMetrics = self.fontMetrics()
  698. lines = self.text().strip().split("\n") + self.informativeText().strip().split("\n")
  699. if lines:
  700. width = 0
  701. for line in lines:
  702. width = max(fontMetricsHorizontalAdvance(fontMetrics, line), width)
  703. self.layout().setColumnMinimumWidth(2, width + 12)
  704. QMessageBox.showEvent(self, event)
  705. # ------------------------------------------------------------------------------------------------------------
  706. # Custom MessageBox
  707. # pylint: disable=too-many-arguments
  708. def CustomMessageBox(parent, icon, title, text,
  709. extraText="",
  710. buttons=QMessageBox.Yes|QMessageBox.No,
  711. defButton=QMessageBox.No):
  712. msgBox = QMessageBoxWithBetterWidth(parent)
  713. msgBox.setIcon(icon)
  714. msgBox.setWindowTitle(title)
  715. msgBox.setText(text)
  716. msgBox.setInformativeText(extraText)
  717. msgBox.setStandardButtons(buttons)
  718. msgBox.setDefaultButton(defButton)
  719. return msgBox.exec_()
  720. # pylint: enable=too-many-arguments
  721. # ------------------------------------------------------------------------------------------------------------