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.

577 lines
19KB

  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 not config_UseQt5:
  48. from PyQt4.QtGui import qt_mac_set_menubar_icons
  49. qt_mac_set_menubar_icons(False)
  50. elif WINDOWS:
  51. WINDIR = os.getenv("WINDIR")
  52. # ------------------------------------------------------------------------------------------------------------
  53. # Set Version
  54. VERSION = "1.9.5 (2.0-beta3)"
  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.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. "0x01 Modulation",
  99. "0x02 Breath",
  100. "0x03 (Undefined)",
  101. "0x04 Foot",
  102. "0x05 Portamento",
  103. "0x07 Volume",
  104. "0x08 Balance",
  105. "0x09 (Undefined)",
  106. "0x0A Pan",
  107. "0x0B Expression",
  108. "0x0C FX Control 1",
  109. "0x0D FX Control 2",
  110. "0x0E (Undefined)",
  111. "0x0F (Undefined)",
  112. "0x10 General Purpose 1",
  113. "0x11 General Purpose 2",
  114. "0x12 General Purpose 3",
  115. "0x13 General Purpose 4",
  116. "0x14 (Undefined)",
  117. "0x15 (Undefined)",
  118. "0x16 (Undefined)",
  119. "0x17 (Undefined)",
  120. "0x18 (Undefined)",
  121. "0x19 (Undefined)",
  122. "0x1A (Undefined)",
  123. "0x1B (Undefined)",
  124. "0x1C (Undefined)",
  125. "0x1D (Undefined)",
  126. "0x1E (Undefined)",
  127. "0x1F (Undefined)",
  128. "0x46 Control 1 [Variation]",
  129. "0x47 Control 2 [Timbre]",
  130. "0x48 Control 3 [Release]",
  131. "0x49 Control 4 [Attack]",
  132. "0x4A Control 5 [Brightness]",
  133. "0x4B Control 6 [Decay]",
  134. "0x4C Control 7 [Vib Rate]",
  135. "0x4D Control 8 [Vib Depth]",
  136. "0x4E Control 9 [Vib Delay]",
  137. "0x4F Control 10 [Undefined]",
  138. "0x50 General Purpose 5",
  139. "0x51 General Purpose 6",
  140. "0x52 General Purpose 7",
  141. "0x53 General Purpose 8",
  142. "0x54 Portamento Control",
  143. "0x5B FX 1 Depth [Reverb]",
  144. "0x5C FX 2 Depth [Tremolo]",
  145. "0x5D FX 3 Depth [Chorus]",
  146. "0x5E FX 4 Depth [Detune]",
  147. "0x5F FX 5 Depth [Phaser]"
  148. )
  149. # ------------------------------------------------------------------------------------------------------------
  150. # PatchCanvas defines
  151. CANVAS_ANTIALIASING_SMALL = 1
  152. CANVAS_EYECANDY_SMALL = 1
  153. # ------------------------------------------------------------------------------------------------------------
  154. # Carla Settings keys
  155. CARLA_KEY_MAIN_PROJECT_FOLDER = "Main/ProjectFolder" # str
  156. CARLA_KEY_MAIN_USE_PRO_THEME = "Main/UseProTheme" # bool
  157. CARLA_KEY_MAIN_PRO_THEME_COLOR = "Main/ProThemeColor" # str
  158. CARLA_KEY_MAIN_REFRESH_INTERVAL = "Main/RefreshInterval" # int
  159. CARLA_KEY_MAIN_USE_CUSTOM_SKINS = "Main/UseCustomSkins" # bool
  160. CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str
  161. CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN"
  162. CARLA_KEY_CANVAS_USE_BEZIER_LINES = "Canvas/UseBezierLines" # bool
  163. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS = "Canvas/AutoHideGroups" # bool
  164. CARLA_KEY_CANVAS_EYE_CANDY = "Canvas/EyeCandy" # enum
  165. CARLA_KEY_CANVAS_USE_OPENGL = "Canvas/UseOpenGL" # bool
  166. CARLA_KEY_CANVAS_ANTIALIASING = "Canvas/Antialiasing" # enum
  167. CARLA_KEY_CANVAS_HQ_ANTIALIASING = "Canvas/HQAntialiasing" # bool
  168. CARLA_KEY_ENGINE_DRIVER_PREFIX = "Engine/Driver-"
  169. CARLA_KEY_ENGINE_AUDIO_DRIVER = "Engine/AudioDriver" # str
  170. CARLA_KEY_ENGINE_PROCESS_MODE = "Engine/ProcessMode" # enum
  171. CARLA_KEY_ENGINE_TRANSPORT_MODE = "Engine/TransportMode" # enum
  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_UIS_ALWAYS_ON_TOP = "Engine/UIsAlwaysOnTop" # bool
  176. CARLA_KEY_ENGINE_MAX_PARAMETERS = "Engine/MaxParameters" # int
  177. CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT = "Engine/UiBridgesTimeout" # int
  178. CARLA_KEY_PATHS_LADSPA = "Paths/LADSPA"
  179. CARLA_KEY_PATHS_DSSI = "Paths/DSSI"
  180. CARLA_KEY_PATHS_LV2 = "Paths/LV2"
  181. CARLA_KEY_PATHS_VST = "Paths/VST"
  182. CARLA_KEY_PATHS_VST3 = "Paths/VST3"
  183. CARLA_KEY_PATHS_AU = "Paths/AU"
  184. CARLA_KEY_PATHS_GIG = "Paths/GIG"
  185. CARLA_KEY_PATHS_SF2 = "Paths/SF2"
  186. CARLA_KEY_PATHS_SFZ = "Paths/SFZ"
  187. # if pro theme is on and color is black
  188. CARLA_KEY_CUSTOM_PAINTING = "UseCustomPainting" # bool
  189. # ------------------------------------------------------------------------------------------------------------
  190. # Carla Settings defaults
  191. # Main
  192. CARLA_DEFAULT_MAIN_PROJECT_FOLDER = HOME
  193. CARLA_DEFAULT_MAIN_USE_PRO_THEME = True
  194. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR = "Black"
  195. CARLA_DEFAULT_MAIN_REFRESH_INTERVAL = 20
  196. CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS = True
  197. # Canvas
  198. CARLA_DEFAULT_CANVAS_THEME = "Modern Dark"
  199. CARLA_DEFAULT_CANVAS_SIZE = "3100x2400"
  200. CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
  201. CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
  202. CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES = True
  203. CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS = True
  204. CARLA_DEFAULT_CANVAS_EYE_CANDY = CANVAS_EYECANDY_SMALL
  205. CARLA_DEFAULT_CANVAS_USE_OPENGL = False
  206. CARLA_DEFAULT_CANVAS_ANTIALIASING = CANVAS_ANTIALIASING_SMALL
  207. CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING = False
  208. # Engine
  209. CARLA_DEFAULT_FORCE_STEREO = False
  210. CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES = False
  211. CARLA_DEFAULT_PREFER_UI_BRIDGES = True
  212. CARLA_DEFAULT_UIS_ALWAYS_ON_TOP = True
  213. CARLA_DEFAULT_MAX_PARAMETERS = MAX_DEFAULT_PARAMETERS
  214. CARLA_DEFAULT_UI_BRIDGES_TIMEOUT = 4000
  215. CARLA_DEFAULT_AUDIO_NUM_PERIODS = 2
  216. CARLA_DEFAULT_AUDIO_BUFFER_SIZE = 512
  217. CARLA_DEFAULT_AUDIO_SAMPLE_RATE = 44100
  218. if WINDOWS:
  219. CARLA_DEFAULT_AUDIO_DRIVER = "DirectSound"
  220. elif MACOS:
  221. CARLA_DEFAULT_AUDIO_DRIVER = "CoreAudio"
  222. else:
  223. CARLA_DEFAULT_AUDIO_DRIVER = "JACK"
  224. if LINUX:
  225. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  226. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_JACK
  227. else:
  228. CARLA_DEFAULT_PROCESS_MODE = ENGINE_PROCESS_MODE_CONTINUOUS_RACK
  229. CARLA_DEFAULT_TRANSPORT_MODE = ENGINE_TRANSPORT_MODE_INTERNAL
  230. # ------------------------------------------------------------------------------------------------------------
  231. # Default Plugin Folders (get)
  232. DEFAULT_LADSPA_PATH = ""
  233. DEFAULT_DSSI_PATH = ""
  234. DEFAULT_LV2_PATH = ""
  235. DEFAULT_VST_PATH = ""
  236. DEFAULT_VST3_PATH = ""
  237. DEFAULT_AU_PATH = ""
  238. DEFAULT_GIG_PATH = ""
  239. DEFAULT_SF2_PATH = ""
  240. DEFAULT_SFZ_PATH = ""
  241. if WINDOWS:
  242. splitter = ";"
  243. APPDATA = os.getenv("APPDATA")
  244. PROGRAMFILES = os.getenv("PROGRAMFILES")
  245. PROGRAMFILESx86 = os.getenv("PROGRAMFILES(x86)")
  246. COMMONPROGRAMFILES = os.getenv("COMMONPROGRAMFILES")
  247. COMMONPROGRAMFILESx86 = os.getenv("COMMONPROGRAMFILES(x86)")
  248. # Small integrity tests
  249. if not APPDATA:
  250. qFatal("APPDATA variable not set, cannot continue")
  251. sys.exit(1)
  252. if not PROGRAMFILES:
  253. qFatal("PROGRAMFILES variable not set, cannot continue")
  254. sys.exit(1)
  255. if not COMMONPROGRAMFILES:
  256. qFatal("COMMONPROGRAMFILES variable not set, cannot continue")
  257. sys.exit(1)
  258. DEFAULT_LADSPA_PATH = APPDATA + "\\LADSPA"
  259. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILES + "\\LADSPA"
  260. DEFAULT_DSSI_PATH = APPDATA + "\\DSSI"
  261. DEFAULT_DSSI_PATH += ";" + PROGRAMFILES + "\\DSSI"
  262. DEFAULT_LV2_PATH = APPDATA + "\\LV2"
  263. DEFAULT_LV2_PATH += ";" + COMMONPROGRAMFILES + "\\LV2"
  264. DEFAULT_VST_PATH = PROGRAMFILES + "\\VstPlugins"
  265. DEFAULT_VST_PATH += ";" + PROGRAMFILES + "\\Steinberg\\VstPlugins"
  266. DEFAULT_VST3_PATH = COMMONPROGRAMFILES + "\\VST3"
  267. DEFAULT_GIG_PATH = APPDATA + "\\GIG"
  268. DEFAULT_SF2_PATH = APPDATA + "\\SF2"
  269. DEFAULT_SFZ_PATH = APPDATA + "\\SFZ"
  270. if PROGRAMFILESx86:
  271. DEFAULT_LADSPA_PATH += ";" + PROGRAMFILESx86 + "\\LADSPA"
  272. DEFAULT_DSSI_PATH += ";" + PROGRAMFILESx86 + "\\DSSI"
  273. DEFAULT_VST_PATH += ";" + PROGRAMFILESx86 + "\\VstPlugins"
  274. DEFAULT_VST_PATH += ";" + PROGRAMFILESx86 + "\\Steinberg\\VstPlugins"
  275. if COMMONPROGRAMFILESx86:
  276. DEFAULT_VST3_PATH += COMMONPROGRAMFILESx86 + "\\VST3"
  277. elif HAIKU:
  278. splitter = ":"
  279. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  280. DEFAULT_LADSPA_PATH += ":/boot/common/add-ons/ladspa"
  281. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  282. DEFAULT_DSSI_PATH += ":/boot/common/add-ons/dssi"
  283. DEFAULT_LV2_PATH = HOME + "/.lv2"
  284. DEFAULT_LV2_PATH += ":/boot/common/add-ons/lv2"
  285. DEFAULT_VST_PATH = HOME + "/.vst"
  286. DEFAULT_VST_PATH += ":/boot/common/add-ons/vst"
  287. DEFAULT_VST3_PATH = HOME + "/.vst3"
  288. DEFAULT_VST3_PATH += ":/boot/common/add-ons/vst3"
  289. elif MACOS:
  290. splitter = ":"
  291. DEFAULT_LADSPA_PATH = HOME + "/Library/Audio/Plug-Ins/LADSPA"
  292. DEFAULT_LADSPA_PATH += ":/Library/Audio/Plug-Ins/LADSPA"
  293. DEFAULT_DSSI_PATH = HOME + "/Library/Audio/Plug-Ins/DSSI"
  294. DEFAULT_DSSI_PATH += ":/Library/Audio/Plug-Ins/DSSI"
  295. DEFAULT_LV2_PATH = HOME + "/Library/Audio/Plug-Ins/LV2"
  296. DEFAULT_LV2_PATH += ":/Library/Audio/Plug-Ins/LV2"
  297. DEFAULT_VST_PATH = HOME + "/Library/Audio/Plug-Ins/VST"
  298. DEFAULT_VST_PATH += ":/Library/Audio/Plug-Ins/VST"
  299. DEFAULT_VST3_PATH = HOME + "/Library/Audio/Plug-Ins/VST3"
  300. DEFAULT_VST3_PATH += ":/Library/Audio/Plug-Ins/VST3"
  301. DEFAULT_AU_PATH = HOME + "/Library/Audio/Plug-Ins/Components"
  302. DEFAULT_AU_PATH += ":/Library/Audio/Plug-Ins/Components"
  303. else:
  304. splitter = ":"
  305. DEFAULT_LADSPA_PATH = HOME + "/.ladspa"
  306. DEFAULT_LADSPA_PATH += ":/usr/lib/ladspa"
  307. DEFAULT_LADSPA_PATH += ":/usr/local/lib/ladspa"
  308. DEFAULT_DSSI_PATH = HOME + "/.dssi"
  309. DEFAULT_DSSI_PATH += ":/usr/lib/dssi"
  310. DEFAULT_DSSI_PATH += ":/usr/local/lib/dssi"
  311. DEFAULT_LV2_PATH = HOME + "/.lv2"
  312. DEFAULT_LV2_PATH += ":/usr/lib/lv2"
  313. DEFAULT_LV2_PATH += ":/usr/local/lib/lv2"
  314. DEFAULT_VST_PATH = HOME + "/.vst"
  315. DEFAULT_VST_PATH += ":/usr/lib/vst"
  316. DEFAULT_VST_PATH += ":/usr/local/lib/vst"
  317. DEFAULT_VST3_PATH = HOME + "/.vst3"
  318. DEFAULT_VST3_PATH += ":/usr/lib/vst3"
  319. DEFAULT_VST3_PATH += ":/usr/local/lib/vst3"
  320. DEFAULT_GIG_PATH = HOME + "/.sounds/gig"
  321. DEFAULT_GIG_PATH += ":/usr/share/sounds/gig"
  322. DEFAULT_SF2_PATH = HOME + "/.sounds/sf2"
  323. DEFAULT_SF2_PATH += ":/usr/share/sounds/sf2"
  324. DEFAULT_SFZ_PATH = HOME + "/.sounds/sfz"
  325. DEFAULT_SFZ_PATH += ":/usr/share/sounds/sfz"
  326. if not WINDOWS:
  327. winePrefix = os.getenv("WINEPREFIX")
  328. if not winePrefix:
  329. winePrefix = HOME + "/.wine"
  330. if os.path.exists(winePrefix):
  331. DEFAULT_VST_PATH += ":" + winePrefix + "/drive_c/Program Files/VstPlugins"
  332. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files/Common Files/VST3"
  333. if kIs64bit and os.path.exists(winePrefix + "/drive_c/Program Files (x86)"):
  334. DEFAULT_VST_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/VstPlugins"
  335. DEFAULT_VST3_PATH += ":" + winePrefix + "/drive_c/Program Files (x86)/Common Files/VST3"
  336. del winePrefix
  337. # ------------------------------------------------------------------------------------------------------------
  338. # Default Plugin Folders (set)
  339. readEnvVars = True
  340. if WINDOWS:
  341. # Check if running Wine. If yes, ignore env vars
  342. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  343. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  344. try:
  345. key = OpenKey(reg, r"SOFTWARE\Wine")
  346. CloseKey(key)
  347. readEnvVars = False
  348. except:
  349. pass
  350. CloseKey(reg)
  351. del reg
  352. if readEnvVars:
  353. CARLA_DEFAULT_LADSPA_PATH = os.getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(splitter)
  354. CARLA_DEFAULT_DSSI_PATH = os.getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(splitter)
  355. CARLA_DEFAULT_LV2_PATH = os.getenv("LV2_PATH", DEFAULT_LV2_PATH).split(splitter)
  356. CARLA_DEFAULT_VST_PATH = os.getenv("VST_PATH", DEFAULT_VST_PATH).split(splitter)
  357. CARLA_DEFAULT_VST3_PATH = os.getenv("VST3_PATH", DEFAULT_VST3_PATH).split(splitter)
  358. CARLA_DEFAULT_AU_PATH = os.getenv("AU_PATH", DEFAULT_AU_PATH).split(splitter)
  359. CARLA_DEFAULT_GIG_PATH = os.getenv("GIG_PATH", DEFAULT_GIG_PATH).split(splitter)
  360. CARLA_DEFAULT_SF2_PATH = os.getenv("SF2_PATH", DEFAULT_SF2_PATH).split(splitter)
  361. CARLA_DEFAULT_SFZ_PATH = os.getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(splitter)
  362. else:
  363. CARLA_DEFAULT_LADSPA_PATH = DEFAULT_LADSPA_PATH.split(splitter)
  364. CARLA_DEFAULT_DSSI_PATH = DEFAULT_DSSI_PATH.split(splitter)
  365. CARLA_DEFAULT_LV2_PATH = DEFAULT_LV2_PATH.split(splitter)
  366. CARLA_DEFAULT_VST_PATH = DEFAULT_VST_PATH.split(splitter)
  367. CARLA_DEFAULT_VST3_PATH = DEFAULT_VST3_PATH.split(splitter)
  368. CARLA_DEFAULT_AU_PATH = DEFAULT_AU_PATH.split(splitter)
  369. CARLA_DEFAULT_GIG_PATH = DEFAULT_GIG_PATH.split(splitter)
  370. CARLA_DEFAULT_SF2_PATH = DEFAULT_SF2_PATH.split(splitter)
  371. CARLA_DEFAULT_SFZ_PATH = DEFAULT_SFZ_PATH.split(splitter)
  372. # ------------------------------------------------------------------------------------------------------------
  373. # Default Plugin Folders (cleanup)
  374. del DEFAULT_LADSPA_PATH
  375. del DEFAULT_DSSI_PATH
  376. del DEFAULT_LV2_PATH
  377. del DEFAULT_VST_PATH
  378. del DEFAULT_VST3_PATH
  379. del DEFAULT_AU_PATH
  380. del DEFAULT_GIG_PATH
  381. del DEFAULT_SF2_PATH
  382. del DEFAULT_SFZ_PATH
  383. # ------------------------------------------------------------------------------------------------------------
  384. # Global Carla object
  385. class CarlaObject(object):
  386. __slots__ = [
  387. 'gui' # Host Window
  388. ]
  389. gCarla = CarlaObject()
  390. gCarla.gui = None
  391. # ------------------------------------------------------------------------------------------------------------
  392. # Set CWD
  393. CWD = sys.path[0]
  394. if not CWD:
  395. CWD = os.path.dirname(sys.argv[0])
  396. # make it work with cxfreeze
  397. if os.path.isfile(CWD):
  398. CWD = os.path.dirname(CWD)
  399. # ------------------------------------------------------------------------------------------------------------
  400. # Check if a value is a number (float support)
  401. def isNumber(value):
  402. try:
  403. float(value)
  404. return True
  405. except:
  406. return False
  407. # ------------------------------------------------------------------------------------------------------------
  408. # Convert a value to a list
  409. def toList(value):
  410. if value is None:
  411. return []
  412. elif not isinstance(value, list):
  413. return [value]
  414. else:
  415. return value
  416. # ------------------------------------------------------------------------------------------------------------
  417. # Get Icon from user theme, using our own as backup (Oxygen)
  418. def getIcon(icon, size = 16):
  419. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  420. # ------------------------------------------------------------------------------------------------------------
  421. # Signal handler
  422. # TODO move to carla_host.py or something
  423. def signalHandler(sig, frame):
  424. if gCarla.gui is None:
  425. return
  426. if sig in (SIGINT, SIGTERM):
  427. gCarla.gui.SIGTERM.emit()
  428. elif haveSIGUSR1 and sig == SIGUSR1:
  429. gCarla.gui.SIGUSR1.emit()
  430. def setUpSignals():
  431. signal(SIGINT, signalHandler)
  432. signal(SIGTERM, signalHandler)
  433. if not haveSIGUSR1:
  434. return
  435. signal(SIGUSR1, signalHandler)
  436. # ------------------------------------------------------------------------------------------------------------
  437. # QLineEdit and QPushButton combo
  438. def getAndSetPath(parent, lineEdit):
  439. newPath = QFileDialog.getExistingDirectory(parent, parent.tr("Set Path"), lineEdit.text(), QFileDialog.ShowDirsOnly)
  440. if newPath:
  441. lineEdit.setText(newPath)
  442. return newPath
  443. # ------------------------------------------------------------------------------------------------------------
  444. # Custom MessageBox
  445. def CustomMessageBox(parent, icon, title, text, extraText="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  446. msgBox = QMessageBox(parent)
  447. msgBox.setIcon(icon)
  448. msgBox.setWindowTitle(title)
  449. msgBox.setText(text)
  450. msgBox.setInformativeText(extraText)
  451. msgBox.setStandardButtons(buttons)
  452. msgBox.setDefaultButton(defButton)
  453. return msgBox.exec_()
  454. # ------------------------------------------------------------------------------------------------------------