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 22KB

11 years ago
11 years ago
11 years ago
11 years ago
11 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
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
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
10 years ago
10 years ago
10 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
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Common Carla code
  4. # Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. import os
  23. import sys
  24. if config_UseQt5:
  25. from PyQt5.Qt import PYQT_VERSION_STR
  26. from PyQt5.QtCore import qFatal, qVersion, qWarning, QDir
  27. from PyQt5.QtGui import QIcon
  28. from PyQt5.QtWidgets import QFileDialog, QMessageBox
  29. else:
  30. from PyQt4.Qt import PYQT_VERSION_STR
  31. from PyQt4.QtCore import qFatal, qVersion, qWarning, QDir
  32. from PyQt4.QtGui import QFileDialog, QIcon, QMessageBox
  33. # ------------------------------------------------------------------------------------------------------------
  34. # Import Signal
  35. from signal import signal, SIGINT, SIGTERM
  36. try:
  37. from signal import SIGUSR1
  38. haveSIGUSR1 = True
  39. except:
  40. haveSIGUSR1 = False
  41. # ------------------------------------------------------------------------------------------------------------
  42. # Imports (Custom)
  43. from carla_backend import *
  44. # ------------------------------------------------------------------------------------------------------------
  45. # Platform specific stuff
  46. if MACOS:
  47. if config_UseQt5:
  48. pass
  49. #from PyQt5.QtGui import qt_mac_set_menubar_icons
  50. else:
  51. from PyQt4.QtGui import qt_mac_set_menubar_icons
  52. qt_mac_set_menubar_icons(False)
  53. elif WINDOWS:
  54. WINDIR = os.getenv("WINDIR")
  55. # ------------------------------------------------------------------------------------------------------------
  56. # Set Version
  57. VERSION = "1.9.4 (2.0-beta2)"
  58. # ------------------------------------------------------------------------------------------------------------
  59. # Set TMP
  60. envTMP = os.getenv("TMP")
  61. if envTMP is None:
  62. if WINDOWS:
  63. qWarning("TMP variable not set")
  64. TMP = QDir.tempPath()
  65. else:
  66. TMP = envTMP
  67. if not os.path.exists(TMP):
  68. qWarning("TMP does not exist")
  69. TMP = "/"
  70. del envTMP
  71. # ------------------------------------------------------------------------------------------------------------
  72. # Set HOME
  73. envHOME = os.getenv("HOME")
  74. if envHOME is None:
  75. if LINUX or MACOS:
  76. qWarning("HOME variable not set")
  77. HOME = QDir.homePath()
  78. else:
  79. HOME = envHOME
  80. if not os.path.exists(HOME):
  81. qWarning("HOME does not exist")
  82. HOME = TMP
  83. del envHOME
  84. # ------------------------------------------------------------------------------------------------------------
  85. # Set PATH
  86. envPATH = os.getenv("PATH")
  87. if envPATH is None:
  88. qWarning("PATH variable not set")
  89. if MACOS:
  90. PATH = ("/opt/local/bin", "/usr/local/bin", "/usr/bin", "/bin")
  91. elif WINDOWS:
  92. PATH = (os.path.join(WINDIR, "system32"), WINDIR)
  93. else:
  94. PATH = ("/usr/local/bin", "/usr/bin", "/bin")
  95. else:
  96. PATH = envPATH.split(os.pathsep)
  97. del envPATH
  98. # ------------------------------------------------------------------------------------------------------------
  99. # Static MIDI CC list
  100. MIDI_CC_LIST = (
  101. "0x01 Modulation",
  102. "0x02 Breath",
  103. "0x03 (Undefined)",
  104. "0x04 Foot",
  105. "0x05 Portamento",
  106. "0x07 Volume",
  107. "0x08 Balance",
  108. "0x09 (Undefined)",
  109. "0x0A Pan",
  110. "0x0B Expression",
  111. "0x0C FX Control 1",
  112. "0x0D FX Control 2",
  113. "0x0E (Undefined)",
  114. "0x0F (Undefined)",
  115. "0x10 General Purpose 1",
  116. "0x11 General Purpose 2",
  117. "0x12 General Purpose 3",
  118. "0x13 General Purpose 4",
  119. "0x14 (Undefined)",
  120. "0x15 (Undefined)",
  121. "0x16 (Undefined)",
  122. "0x17 (Undefined)",
  123. "0x18 (Undefined)",
  124. "0x19 (Undefined)",
  125. "0x1A (Undefined)",
  126. "0x1B (Undefined)",
  127. "0x1C (Undefined)",
  128. "0x1D (Undefined)",
  129. "0x1E (Undefined)",
  130. "0x1F (Undefined)",
  131. "0x46 Control 1 [Variation]",
  132. "0x47 Control 2 [Timbre]",
  133. "0x48 Control 3 [Release]",
  134. "0x49 Control 4 [Attack]",
  135. "0x4A Control 5 [Brightness]",
  136. "0x4B Control 6 [Decay]",
  137. "0x4C Control 7 [Vib Rate]",
  138. "0x4D Control 8 [Vib Depth]",
  139. "0x4E Control 9 [Vib Delay]",
  140. "0x4F Control 10 [Undefined]",
  141. "0x50 General Purpose 5",
  142. "0x51 General Purpose 6",
  143. "0x52 General Purpose 7",
  144. "0x53 General Purpose 8",
  145. "0x54 Portamento Control",
  146. "0x5B FX 1 Depth [Reverb]",
  147. "0x5C FX 2 Depth [Tremolo]",
  148. "0x5D FX 3 Depth [Chorus]",
  149. "0x5E FX 4 Depth [Detune]",
  150. "0x5F FX 5 Depth [Phaser]"
  151. )
  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_CANVAS_THEME = "Canvas/Theme" # str
  159. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  160. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  161. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  162. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy" # enum
  163. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  164. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  165. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  166. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # 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_FORCE_STEREO = "Engine/ForceStereo" # bool
  172. CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES = "Engine/PreferPluginBridges" # bool
  173. CARLA_KEY_ENGINE_PREFER_UI_BRIDGES = "Engine/PreferUiBridges" # bool
  174. CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  175. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  176. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  177. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  178. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  179. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  180. CARLA_KEY_PATHS_VST = "Paths/VST"
  181. CARLA_KEY_PATHS_VST3 = "Paths/VST3"
  182. CARLA_KEY_PATHS_AU = "Paths/AU"
  183. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  184. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  185. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  186. # ------------------------------------------------------------------------------------------------------------
  187. # Global Carla object
  188. class CarlaObject(object):
  189. __slots__ = [
  190. # Host library object
  191. 'host',
  192. # Host Window
  193. 'gui',
  194. # bool, is controller
  195. 'isControl',
  196. # bool, is running local
  197. 'isLocal',
  198. # bool, is plugin
  199. 'isPlugin',
  200. # current buffer size
  201. 'bufferSize',
  202. # current sample rate
  203. 'sampleRate',
  204. # current process mode
  205. 'processMode',
  206. # check if process mode is forced (rack/patchbay)
  207. 'processModeForced',
  208. # current transport mode
  209. 'transportMode',
  210. # current max parameters
  211. 'maxParameters',
  212. # binary dir
  213. 'pathBinaries',
  214. # resources dir
  215. 'pathResources',
  216. # default paths
  217. 'DEFAULT_LADSPA_PATH',
  218. 'DEFAULT_DSSI_PATH',
  219. 'DEFAULT_LV2_PATH',
  220. 'DEFAULT_VST_PATH',
  221. 'DEFAULT_VST3_PATH',
  222. 'DEFAULT_AU_PATH',
  223. 'DEFAULT_GIG_PATH',
  224. 'DEFAULT_SF2_PATH',
  225. 'DEFAULT_SFZ_PATH'
  226. ]
  227. gCarla = CarlaObject()
  228. gCarla.host = None
  229. gCarla.gui = None
  230. gCarla.isControl = False
  231. gCarla.isLocal = True
  232. gCarla.isPlugin = False
  233. gCarla.bufferSize = 0
  234. gCarla.sampleRate = 0.0
  235. gCarla.processMode = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS if LINUX else ENGINE_PROCESS_MODE_CONTINUOUS_RACK
  236. gCarla.processModeForced = False
  237. gCarla.transportMode = ENGINE_TRANSPORT_MODE_JACK if LINUX else ENGINE_TRANSPORT_MODE_INTERNAL
  238. gCarla.maxParameters = MAX_DEFAULT_PARAMETERS
  239. gCarla.pathBinaries = ""
  240. gCarla.pathResources = ""
  241. # ------------------------------------------------------------------------------------------------------------
  242. # Default Plugin Folders (get)
  243. DEFAULT_LADSPA_PATH = ""
  244. DEFAULT_DSSI_PATH = ""
  245. DEFAULT_LV2_PATH = ""
  246. DEFAULT_VST_PATH = ""
  247. DEFAULT_VST3_PATH = ""
  248. DEFAULT_AU_PATH = ""
  249. DEFAULT_GIG_PATH = ""
  250. DEFAULT_SF2_PATH = ""
  251. DEFAULT_SFZ_PATH = ""
  252. if WINDOWS:
  253. splitter = ";"
  254. APPDATA = os.getenv("APPDATA")
  255. PROGRAMFILES = os.getenv("PROGRAMFILES")
  256. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  257. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  258. COMMONPROGRAMFILESx86 = os.getenv("COMMONPROGRAMFILES(x86)")
  259. # Small integrity tests
  260. if not APPDATA:
  261. qFatal("APPDATA variable not set, cannot continue")
  262. sys.exit(1)
  263. if not PROGRAMFILES:
  264. qFatal("PROGRAMFILES variable not set, cannot continue")
  265. sys.exit(1)
  266. if not COMMONPROGRAMFILES:
  267. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  268. sys.exit(1)
  269. DEFAULT_LADSPA_PATH = APPDATA + "\\LADSPA"
  270. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILES + "\\LADSPA"
  271. DEFAULT_DSSI_PATH = APPDATA + "\\DSSI"
  272. DEFAULT_DSSI_PATH += ";" + PROGRAMFILES + "\\DSSI"
  273. DEFAULT_LV2_PATH = APPDATA + "\\LV2"
  274. DEFAULT_LV2_PATH += ";" + COMMONPROGRAMFILES + "\\LV2"
  275. DEFAULT_VST_PATH = PROGRAMFILES + "\\VstPlugins"
  276. DEFAULT_VST_PATH += ";" + PROGRAMFILES + "\\Steinberg\\VstPlugins"
  277. DEFAULT_VST3_PATH = COMMONPROGRAMFILES + "\\VST3"
  278. DEFAULT_GIG_PATH = APPDATA + "\\GIG"
  279. DEFAULT_SF2_PATH = APPDATA + "\\SF2"
  280. DEFAULT_SFZ_PATH = APPDATA + "\\SFZ"
  281. if PROGRAMFILESx86:
  282. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILESx86 + "\\LADSPA"
  283. DEFAULT_DSSI_PATH += ";" + PROGRAMFILESx86 + "\\DSSI"
  284. DEFAULT_VST_PATH += ";" + PROGRAMFILESx86 + "\\VstPlugins"
  285. DEFAULT_VST_PATH += ";" + PROGRAMFILESx86 + "\\Steinberg\\VstPlugins"
  286. if COMMONPROGRAMFILESx86:
  287. DEFAULT_VST3_PATH += COMMONPROGRAMFILESx86 + "\\VST3"
  288. elif HAIKU:
  289. splitter = ":"
  290. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  291. DEFAULT_LADSPA_PATH += ":/boot/common/add-ons/ladspa"
  292. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  293. DEFAULT_DSSI_PATH += ":/boot/common/add-ons/dssi"
  294. DEFAULT_LV2_PATH = HOME + "/.lv2"
  295. DEFAULT_LV2_PATH += ":/boot/common/add-ons/lv2"
  296. DEFAULT_VST_PATH = HOME + "/.vst"
  297. DEFAULT_VST_PATH += ":/boot/common/add-ons/vst"
  298. DEFAULT_VST3_PATH = HOME + "/.vst3"
  299. DEFAULT_VST3_PATH += ":/boot/common/add-ons/vst3"
  300. elif MACOS:
  301. splitter = ":"
  302. DEFAULT_LADSPA_PATH = HOME + "/Library/Audio/Plug-Ins/LADSPA"
  303. DEFAULT_LADSPA_PATH += ":/Library/Audio/Plug-Ins/LADSPA"
  304. DEFAULT_DSSI_PATH = HOME + "/Library/Audio/Plug-Ins/DSSI"
  305. DEFAULT_DSSI_PATH += ":/Library/Audio/Plug-Ins/DSSI"
  306. DEFAULT_LV2_PATH = HOME + "/Library/Audio/Plug-Ins/LV2"
  307. DEFAULT_LV2_PATH += ":/Library/Audio/Plug-Ins/LV2"
  308. DEFAULT_VST_PATH = HOME + "/Library/Audio/Plug-Ins/VST"
  309. DEFAULT_VST_PATH += ":/Library/Audio/Plug-Ins/VST"
  310. DEFAULT_VST3_PATH = HOME + "/Library/Audio/Plug-Ins/VST3"
  311. DEFAULT_VST3_PATH += ":/Library/Audio/Plug-Ins/VST3"
  312. DEFAULT_AU_PATH = HOME + "/Library/Audio/Plug-Ins/Components"
  313. DEFAULT_AU_PATH += ":/Library/Audio/Plug-Ins/Components"
  314. else:
  315. splitter = ":"
  316. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  317. DEFAULT_LADSPA_PATH += ":/usr/lib/ladspa"
  318. DEFAULT_LADSPA_PATH += ":/usr/local/lib/ladspa"
  319. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  320. DEFAULT_DSSI_PATH += ":/usr/lib/dssi"
  321. DEFAULT_DSSI_PATH += ":/usr/local/lib/dssi"
  322. DEFAULT_LV2_PATH = HOME + "/.lv2"
  323. DEFAULT_LV2_PATH += ":/usr/lib/lv2"
  324. DEFAULT_LV2_PATH += ":/usr/local/lib/lv2"
  325. DEFAULT_VST_PATH = HOME + "/.vst"
  326. DEFAULT_VST_PATH += ":/usr/lib/vst"
  327. DEFAULT_VST_PATH += ":/usr/local/lib/vst"
  328. DEFAULT_VST3_PATH = HOME + "/.vst3"
  329. DEFAULT_VST3_PATH += ":/usr/lib/vst3"
  330. DEFAULT_VST3_PATH += ":/usr/local/lib/vst3"
  331. DEFAULT_GIG_PATH = HOME + "/.sounds/gig"
  332. DEFAULT_GIG_PATH += ":/usr/share/sounds/gig"
  333. DEFAULT_SF2_PATH = HOME + "/.sounds/sf2"
  334. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf2"
  335. DEFAULT_SFZ_PATH = HOME + "/.sounds/sfz"
  336. DEFAULT_SFZ_PATH += ":/usr/share/sounds/sfz"
  337. if not WINDOWS:
  338. winePrefix = os.getenv("WINEPREFIX")
  339. if not winePrefix:
  340. winePrefix = HOME + "/.wine"
  341. if os.path.exists(winePrefix):
  342. DEFAULT_VST_PATH += ":" + winePrefix + "/drive_c/Program Files/VstPlugins"
  343. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files/Common Files/VST3"
  344. if kIs64bit and os.path.exists(winePrefix + "/drive_c/Program Files (x86)"):
  345. DEFAULT_VST_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/VstPlugins"
  346. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/VST3"
  347. # ------------------------------------------------------------------------------------------------------------
  348. # Default Plugin Folders (set)
  349. readEnvVars = True
  350. if WINDOWS:
  351. # Check if running Wine. If yes, ignore env vars
  352. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  353. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  354. try:
  355. key = OpenKey(reg, r"SOFTWARE\Wine")
  356. CloseKey(key)
  357. readEnvVars = False
  358. except:
  359. pass
  360. CloseKey(reg)
  361. del reg
  362. if readEnvVars:
  363. gCarla.DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  364. gCarla.DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  365. gCarla.DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  366. gCarla.DEFAULT_VST_PATH = os.getenv("VST_PATH", DEFAULT_VST_PATH).split(splitter)
  367. gCarla.DEFAULT_VST3_PATH = os.getenv("VST3_PATH", DEFAULT_VST3_PATH).split(splitter)
  368. gCarla.DEFAULT_AU_PATH = os.getenv("AU_PATH", DEFAULT_AU_PATH).split(splitter)
  369. gCarla.DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  370. gCarla.DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  371. gCarla.DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  372. else:
  373. gCarla.DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  374. gCarla.DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  375. gCarla.DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  376. gCarla.DEFAULT_VST_PATH = DEFAULT_VST_PATH.split(splitter)
  377. gCarla.DEFAULT_VST3_PATH = DEFAULT_VST3_PATH.split(splitter)
  378. gCarla.DEFAULT_AU_PATH = DEFAULT_AU_PATH.split(splitter)
  379. gCarla.DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  380. gCarla.DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  381. gCarla.DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  382. # ------------------------------------------------------------------------------------------------------------
  383. # Search for Carla tools
  384. CWD = sys.path[0]
  385. # make it work with cxfreeze
  386. if os.path.isfile(CWD):
  387. CWD = os.path.dirname(CWD)
  388. # find tool
  389. def findTool(toolName):
  390. path = os.path.join(CWD, toolName)
  391. if os.path.exists(path):
  392. return path
  393. if gCarla.pathBinaries:
  394. path = os.path.join(gCarla.pathBinaries, toolName)
  395. if os.path.exists(path):
  396. return path
  397. for p in PATH:
  398. path = os.path.join(p, toolName)
  399. if os.path.exists(path):
  400. return path
  401. return ""
  402. # ------------------------------------------------------------------------------------------------------------
  403. # Init host
  404. def initHost(initName, libPrefix = None, failError = True):
  405. # -------------------------------------------------------------
  406. # Set Carla library name
  407. libname = "libcarla_"
  408. if gCarla.isControl:
  409. libname += "control2"
  410. else:
  411. libname += "standalone2"
  412. if WINDOWS:
  413. libname += ".dll"
  414. elif MACOS:
  415. libname += ".dylib"
  416. else:
  417. libname += ".so"
  418. # -------------------------------------------------------------
  419. # Set binary dir
  420. CWDl = CWD.lower()
  421. if libPrefix is not None:
  422. gCarla.pathBinaries = os.path.join(libPrefix, "lib", "carla")
  423. elif CWDl.endswith("resources"):
  424. if CWDl.endswith("native-plugins%sresources" % os.sep):
  425. gCarla.pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "..", "bin"))
  426. elif "carla-native.lv2" in sys.argv[0]:
  427. gCarla.pathBinaries = os.path.abspath(os.path.join(CWD, "..", "..", "..", "lib", "lv2", "carla-native.lv2"))
  428. else:
  429. gCarla.pathBinaries = os.path.abspath(os.path.join(CWD, ".."))
  430. elif CWDl.endswith("source"):
  431. gCarla.pathBinaries = os.path.abspath(os.path.join(CWD, "..", "bin"))
  432. elif CWDl.endswith("bin") or os.path.isfile(sys.path[0]):
  433. gCarla.pathBinaries = CWD
  434. # -------------------------------------------------------------
  435. # Fail if binary dir is not found
  436. if not (gCarla.pathBinaries or gCarla.isPlugin):
  437. if failError:
  438. QMessageBox.critical(None, "Error", "Failed to find the carla library, cannot continue")
  439. sys.exit(1)
  440. return
  441. # -------------------------------------------------------------
  442. # Set resources dir
  443. if libPrefix is not None:
  444. gCarla.pathResources = os.path.join(libPrefix, "share", "carla", "resources")
  445. else:
  446. gCarla.pathResources = os.path.join(gCarla.pathBinaries, "resources")
  447. # -------------------------------------------------------------
  448. # Print info
  449. print("Carla %s started, status:" % VERSION)
  450. print(" Python version: %s" % sys.version.split(" ",1)[0])
  451. print(" Qt version: %s" % qVersion())
  452. print(" PyQt version: %s" % PYQT_VERSION_STR)
  453. print(" Binary dir: %s" % gCarla.pathBinaries)
  454. print(" Resources dir: %s" % gCarla.pathResources)
  455. # -------------------------------------------------------------
  456. # Init host
  457. if gCarla.host is None:
  458. try:
  459. gCarla.host = Host(os.path.join(gCarla.pathBinaries, libname))
  460. except:
  461. print("hmmmm...")
  462. return
  463. if not gCarla.isPlugin:
  464. gCarla.host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, gCarla.pathBinaries)
  465. gCarla.host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, gCarla.pathResources)
  466. if not gCarla.isControl:
  467. gCarla.host.set_engine_option(ENGINE_OPTION_NSM_INIT, os.getpid(), initName)
  468. # ------------------------------------------------------------------------------------------------------------
  469. # Check if a value is a number (float support)
  470. def isNumber(value):
  471. try:
  472. float(value)
  473. return True
  474. except:
  475. return False
  476. # ------------------------------------------------------------------------------------------------------------
  477. # Convert a value to a list
  478. def toList(value):
  479. if value is None:
  480. return []
  481. elif not isinstance(value, list):
  482. return [value]
  483. else:
  484. return value
  485. # ------------------------------------------------------------------------------------------------------------
  486. # Get Icon from user theme, using our own as backup (Oxygen)
  487. def getIcon(icon, size = 16):
  488. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  489. # ------------------------------------------------------------------------------------------------------------
  490. # Signal handler
  491. def signalHandler(sig, frame):
  492. if gCarla.gui is None:
  493. return
  494. if sig in (SIGINT, SIGTERM):
  495. gCarla.gui.SIGTERM.emit()
  496. elif haveSIGUSR1 and sig == SIGUSR1:
  497. gCarla.gui.SIGUSR1.emit()
  498. def setUpSignals():
  499. signal(SIGINT, signalHandler)
  500. signal(SIGTERM, signalHandler)
  501. if not haveSIGUSR1:
  502. return
  503. signal(SIGUSR1, signalHandler)
  504. # ------------------------------------------------------------------------------------------------------------
  505. # QLineEdit and QPushButton combo
  506. def getAndSetPath(parent, currentPath, lineEdit):
  507. newPath = QFileDialog.getExistingDirectory(parent, parent.tr("Set Path"), currentPath, QFileDialog.ShowDirsOnly)
  508. if newPath:
  509. lineEdit.setText(newPath)
  510. return newPath
  511. # ------------------------------------------------------------------------------------------------------------
  512. # Get plugin type as string
  513. def getPluginTypeAsString(ptype):
  514. if ptype == PLUGIN_INTERNAL:
  515. return "Internal"
  516. if ptype == PLUGIN_LADSPA:
  517. return "LADSPA"
  518. if ptype == PLUGIN_DSSI:
  519. return "DSSI"
  520. if ptype == PLUGIN_LV2:
  521. return "LV2"
  522. if ptype == PLUGIN_VST:
  523. return "VST"
  524. if ptype == PLUGIN_VST3:
  525. return "VST3"
  526. if ptype == PLUGIN_AU:
  527. return "AU"
  528. if ptype == PLUGIN_GIG:
  529. return "GIG"
  530. if ptype == PLUGIN_SF2:
  531. return "SF2"
  532. if ptype == PLUGIN_SFZ:
  533. return "SFZ"
  534. return "Unknown"
  535. # ------------------------------------------------------------------------------------------------------------
  536. # Custom MessageBox
  537. def CustomMessageBox(parent, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  538. msgBox = QMessageBox(parent)
  539. msgBox.setIcon(icon)
  540. msgBox.setWindowTitle(title)
  541. msgBox.setText(text)
  542. msgBox.setInformativeText(extraText)
  543. msgBox.setStandardButtons(buttons)
  544. msgBox.setDefaultButton(defButton)
  545. return msgBox.exec_()