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.

carla_shared.py 24KB

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