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.

308 lines
17KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla application
  4. # Copyright (C) 2013-2020 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. # ------------------------------------------------------------------------------------------------------------
  22. # Imports (ctypes)
  23. from ctypes import CDLL, RTLD_GLOBAL
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Imports (PyQt5)
  26. from PyQt5.QtCore import QT_VERSION, Qt, QCoreApplication, QLibraryInfo, QLocale, QTranslator
  27. from PyQt5.QtGui import QColor, QIcon, QPalette
  28. from PyQt5.QtWidgets import QApplication
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Imports (Custom)
  31. from carla_backend import kIs64bit, LINUX, MACOS, WINDOWS
  32. from carla_shared import (
  33. CARLA_KEY_MAIN_USE_PRO_THEME,
  34. CARLA_KEY_MAIN_PRO_THEME_COLOR,
  35. CARLA_DEFAULT_MAIN_USE_PRO_THEME,
  36. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR,
  37. CWD, VERSION,
  38. getPaths,
  39. QSafeSettings,
  40. gCarla
  41. )
  42. # ------------------------------------------------------------------------------------------------------------
  43. class CarlaApplication():
  44. def __init__(self, appName = "Carla2", libPrefix = None):
  45. pathBinaries, pathResources = getPaths(libPrefix)
  46. # Needed for MacOS and Windows
  47. if os.path.exists(CWD) and (MACOS or WINDOWS):
  48. QApplication.addLibraryPath(CWD)
  49. # Needed for local wine build
  50. if WINDOWS and CWD.endswith(("frontend", "resources")) and os.getenv("CXFREEZE") is None:
  51. if kIs64bit:
  52. path = "H:\\builds\\msys2-x86_64\\mingw64\\share\\qt5\\plugins"
  53. else:
  54. path = "H:\\builds\\msys2-i686\\mingw32\\share\\qt5\\plugins"
  55. QApplication.addLibraryPath(path)
  56. # Use binary dir as library path
  57. if os.path.exists(pathBinaries):
  58. QApplication.addLibraryPath(pathBinaries)
  59. stylesDir = pathBinaries
  60. # If style is not available we can still fake it
  61. else:
  62. stylesDir = ""
  63. # Set up translations
  64. currentLocale = QLocale()
  65. appTranslator = QTranslator()
  66. sysTranslator = None
  67. pathTranslations = os.path.join(pathResources, "translations")
  68. if appTranslator.load(currentLocale, "carla", "_", pathTranslations):
  69. sysTranslator = QTranslator()
  70. pathSysTranslations = pathTranslations
  71. if not sysTranslator.load(currentLocale, "qt", "_", pathSysTranslations):
  72. pathSysTranslations = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
  73. sysTranslator.load(currentLocale, "qt", "_", pathSysTranslations)
  74. else:
  75. appTranslator = None
  76. self.fAppTranslator = appTranslator
  77. self.fSysTranslator = sysTranslator
  78. # base settings
  79. settings = QSafeSettings("falkTX", appName)
  80. useProTheme = MACOS or settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, CARLA_DEFAULT_MAIN_USE_PRO_THEME, bool)
  81. if not useProTheme:
  82. self.createApp(appName)
  83. return
  84. # set style
  85. QApplication.setStyle("carla" if stylesDir else "fusion")
  86. # create app
  87. self.createApp(appName)
  88. if gCarla.nogui:
  89. return
  90. self.fApp.setStyle("carla" if stylesDir else "fusion")
  91. if WINDOWS:
  92. carlastyle = os.path.join(pathBinaries, "styles", "carlastyle.dll")
  93. self._stylelib = CDLL(carlastyle, RTLD_GLOBAL)
  94. self._stylelib.set_qt_app_style.argtypes = None
  95. self._stylelib.set_qt_app_style.restype = None
  96. self._stylelib.set_qt_app_style()
  97. # set palette
  98. proThemeColor = settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, CARLA_DEFAULT_MAIN_PRO_THEME_COLOR, str).lower()
  99. if MACOS or proThemeColor == "black":
  100. self.createPaletteBlack()
  101. elif proThemeColor == "blue":
  102. self.createPaletteBlue()
  103. def createApp(self, appName):
  104. if LINUX:
  105. # AA_X11InitThreads is not available on old PyQt versions
  106. try:
  107. attr = Qt.AA_X11InitThreads
  108. except:
  109. attr = 10
  110. QApplication.setAttribute(attr)
  111. if MACOS:
  112. QApplication.setAttribute(Qt.AA_DontShowIconsInMenus)
  113. if QT_VERSION >= 0x50600:
  114. QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
  115. QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
  116. args = sys.argv[:]
  117. if WINDOWS:
  118. args += ["-platform", "windows:fontengine=freetype"]
  119. self.fApp = QCoreApplication(args) if gCarla.nogui else QApplication(args)
  120. self.fApp.setApplicationName(appName)
  121. self.fApp.setApplicationVersion(VERSION)
  122. self.fApp.setOrganizationName("falkTX")
  123. if self.fAppTranslator is not None:
  124. self.fApp.installTranslator(self.fAppTranslator)
  125. self.fApp.installTranslator(self.fSysTranslator)
  126. if gCarla.nogui:
  127. return
  128. if appName.lower() == "carla-control":
  129. if QT_VERSION >= 0x50700:
  130. self.fApp.setDesktopFileName("carla-control")
  131. self.fApp.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  132. else:
  133. if QT_VERSION >= 0x50700:
  134. self.fApp.setDesktopFileName("carla")
  135. self.fApp.setWindowIcon(QIcon(":/scalable/carla.svg"))
  136. def createPaletteBlack(self):
  137. self.fPalBlack = QPalette()
  138. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Window, QColor(14, 14, 14))
  139. self.fPalBlack.setColor(QPalette.Active, QPalette.Window, QColor(17, 17, 17))
  140. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Window, QColor(17, 17, 17))
  141. self.fPalBlack.setColor(QPalette.Disabled, QPalette.WindowText, QColor(83, 83, 83))
  142. self.fPalBlack.setColor(QPalette.Active, QPalette.WindowText, QColor(240, 240, 240))
  143. self.fPalBlack.setColor(QPalette.Inactive, QPalette.WindowText, QColor(240, 240, 240))
  144. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Base, QColor(6, 6, 6))
  145. self.fPalBlack.setColor(QPalette.Active, QPalette.Base, QColor(7, 7, 7))
  146. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Base, QColor(7, 7, 7))
  147. self.fPalBlack.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(12, 12, 12))
  148. self.fPalBlack.setColor(QPalette.Active, QPalette.AlternateBase, QColor(14, 14, 14))
  149. self.fPalBlack.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(14, 14, 14))
  150. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(4, 4, 4))
  151. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(4, 4, 4))
  152. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(4, 4, 4))
  153. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(230, 230, 230))
  154. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipText, QColor(230, 230, 230))
  155. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(230, 230, 230))
  156. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Text, QColor(74, 74, 74))
  157. self.fPalBlack.setColor(QPalette.Active, QPalette.Text, QColor(230, 230, 230))
  158. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Text, QColor(230, 230, 230))
  159. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Button, QColor(24, 24, 24))
  160. self.fPalBlack.setColor(QPalette.Active, QPalette.Button, QColor(28, 28, 28))
  161. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Button, QColor(28, 28, 28))
  162. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(90, 90, 90))
  163. self.fPalBlack.setColor(QPalette.Active, QPalette.ButtonText, QColor(240, 240, 240))
  164. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(240, 240, 240))
  165. self.fPalBlack.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  166. self.fPalBlack.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  167. self.fPalBlack.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  168. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Light, QColor(191, 191, 191))
  169. self.fPalBlack.setColor(QPalette.Active, QPalette.Light, QColor(191, 191, 191))
  170. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Light, QColor(191, 191, 191))
  171. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Midlight, QColor(155, 155, 155))
  172. self.fPalBlack.setColor(QPalette.Active, QPalette.Midlight, QColor(155, 155, 155))
  173. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Midlight, QColor(155, 155, 155))
  174. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Dark, QColor(129, 129, 129))
  175. self.fPalBlack.setColor(QPalette.Active, QPalette.Dark, QColor(129, 129, 129))
  176. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Dark, QColor(129, 129, 129))
  177. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Mid, QColor(94, 94, 94))
  178. self.fPalBlack.setColor(QPalette.Active, QPalette.Mid, QColor(94, 94, 94))
  179. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Mid, QColor(94, 94, 94))
  180. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Shadow, QColor(155, 155, 155))
  181. self.fPalBlack.setColor(QPalette.Active, QPalette.Shadow, QColor(155, 155, 155))
  182. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Shadow, QColor(155, 155, 155))
  183. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Highlight, QColor(14, 14, 14))
  184. self.fPalBlack.setColor(QPalette.Active, QPalette.Highlight, QColor(60, 60, 60))
  185. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Highlight, QColor(34, 34, 34))
  186. self.fPalBlack.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(83, 83, 83))
  187. self.fPalBlack.setColor(QPalette.Active, QPalette.HighlightedText, QColor(255, 255, 255))
  188. self.fPalBlack.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(240, 240, 240))
  189. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Link, QColor(34, 34, 74))
  190. self.fPalBlack.setColor(QPalette.Active, QPalette.Link, QColor(100, 100, 230))
  191. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Link, QColor(100, 100, 230))
  192. self.fPalBlack.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(74, 34, 74))
  193. self.fPalBlack.setColor(QPalette.Active, QPalette.LinkVisited, QColor(230, 100, 230))
  194. self.fPalBlack.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(230, 100, 230))
  195. self.fApp.setPalette(self.fPalBlack)
  196. def createPaletteBlue(self):
  197. self.fPalBlue = QPalette()
  198. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Window, QColor(32, 35, 39))
  199. self.fPalBlue.setColor(QPalette.Active, QPalette.Window, QColor(37, 40, 45))
  200. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Window, QColor(37, 40, 45))
  201. self.fPalBlue.setColor(QPalette.Disabled, QPalette.WindowText, QColor(89, 95, 104))
  202. self.fPalBlue.setColor(QPalette.Active, QPalette.WindowText, QColor(223, 237, 255))
  203. self.fPalBlue.setColor(QPalette.Inactive, QPalette.WindowText, QColor(223, 237, 255))
  204. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Base, QColor(48, 53, 60))
  205. self.fPalBlue.setColor(QPalette.Active, QPalette.Base, QColor(55, 61, 69))
  206. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Base, QColor(55, 61, 69))
  207. self.fPalBlue.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(60, 64, 67))
  208. self.fPalBlue.setColor(QPalette.Active, QPalette.AlternateBase, QColor(69, 73, 77))
  209. self.fPalBlue.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(69, 73, 77))
  210. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(182, 193, 208))
  211. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(182, 193, 208))
  212. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(182, 193, 208))
  213. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(42, 44, 48))
  214. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipText, QColor(42, 44, 48))
  215. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(42, 44, 48))
  216. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Text, QColor(96, 103, 113))
  217. self.fPalBlue.setColor(QPalette.Active, QPalette.Text, QColor(210, 222, 240))
  218. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Text, QColor(210, 222, 240))
  219. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Button, QColor(51, 55, 62))
  220. self.fPalBlue.setColor(QPalette.Active, QPalette.Button, QColor(59, 63, 71))
  221. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Button, QColor(59, 63, 71))
  222. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(98, 104, 114))
  223. self.fPalBlue.setColor(QPalette.Active, QPalette.ButtonText, QColor(210, 222, 240))
  224. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(210, 222, 240))
  225. self.fPalBlue.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  226. self.fPalBlue.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  227. self.fPalBlue.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  228. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Light, QColor(59, 64, 72))
  229. self.fPalBlue.setColor(QPalette.Active, QPalette.Light, QColor(63, 68, 76))
  230. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Light, QColor(63, 68, 76))
  231. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Midlight, QColor(48, 52, 59))
  232. self.fPalBlue.setColor(QPalette.Active, QPalette.Midlight, QColor(51, 56, 63))
  233. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Midlight, QColor(51, 56, 63))
  234. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Dark, QColor(18, 19, 22))
  235. self.fPalBlue.setColor(QPalette.Active, QPalette.Dark, QColor(20, 22, 25))
  236. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Dark, QColor(20, 22, 25))
  237. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Mid, QColor(28, 30, 34))
  238. self.fPalBlue.setColor(QPalette.Active, QPalette.Mid, QColor(32, 35, 39))
  239. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Mid, QColor(32, 35, 39))
  240. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Shadow, QColor(13, 14, 16))
  241. self.fPalBlue.setColor(QPalette.Active, QPalette.Shadow, QColor(15, 16, 18))
  242. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Shadow, QColor(15, 16, 18))
  243. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Highlight, QColor(32, 35, 39))
  244. self.fPalBlue.setColor(QPalette.Active, QPalette.Highlight, QColor(14, 14, 17))
  245. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Highlight, QColor(27, 28, 33))
  246. self.fPalBlue.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(89, 95, 104))
  247. self.fPalBlue.setColor(QPalette.Active, QPalette.HighlightedText, QColor(217, 234, 253))
  248. self.fPalBlue.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(223, 237, 255))
  249. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Link, QColor(79, 100, 118))
  250. self.fPalBlue.setColor(QPalette.Active, QPalette.Link, QColor(156, 212, 255))
  251. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Link, QColor(156, 212, 255))
  252. self.fPalBlue.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(51, 74, 118))
  253. self.fPalBlue.setColor(QPalette.Active, QPalette.LinkVisited, QColor(64, 128, 255))
  254. self.fPalBlue.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(64, 128, 255))
  255. self.fApp.setPalette(self.fPalBlue)
  256. def exec_(self):
  257. return self.fApp.exec_()
  258. def exit_exec(self):
  259. return sys.exit(self.fApp.exec_())
  260. def getApp(self):
  261. return self.fApp
  262. def quit(self):
  263. self.fApp.quit()
  264. # ------------------------------------------------------------------------------------------------------------