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.

310 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:\\PawPawBuilds\\targets\\win64\\lib\\qt5\\plugins"
  53. else:
  54. path = "H:\\PawPawBuilds\\targets\\win32\\lib\\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. carlastyle1 = os.path.join(pathBinaries, "styles", "carlastyle.dll")
  93. carlastyle2 = os.path.join(pathResources, "styles", "carlastyle.dll")
  94. carlastyle = carlastyle2 if os.path.exists(carlastyle2) else carlastyle1
  95. self._stylelib = CDLL(carlastyle, RTLD_GLOBAL)
  96. self._stylelib.set_qt_app_style.argtypes = None
  97. self._stylelib.set_qt_app_style.restype = None
  98. self._stylelib.set_qt_app_style()
  99. # set palette
  100. proThemeColor = settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, CARLA_DEFAULT_MAIN_PRO_THEME_COLOR, str).lower()
  101. if MACOS or proThemeColor == "black":
  102. self.createPaletteBlack()
  103. elif proThemeColor == "blue":
  104. self.createPaletteBlue()
  105. def createApp(self, appName):
  106. if LINUX:
  107. # AA_X11InitThreads is not available on old PyQt versions
  108. try:
  109. attr = Qt.AA_X11InitThreads
  110. except:
  111. attr = 10
  112. QApplication.setAttribute(attr)
  113. if MACOS:
  114. QApplication.setAttribute(Qt.AA_DontShowIconsInMenus)
  115. if QT_VERSION >= 0x50600:
  116. QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
  117. QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
  118. args = sys.argv[:]
  119. if WINDOWS:
  120. args += ["-platform", "windows:fontengine=freetype"]
  121. self.fApp = QCoreApplication(args) if gCarla.nogui else QApplication(args)
  122. self.fApp.setApplicationName(appName)
  123. self.fApp.setApplicationVersion(VERSION)
  124. self.fApp.setOrganizationName("falkTX")
  125. if self.fAppTranslator is not None:
  126. self.fApp.installTranslator(self.fAppTranslator)
  127. self.fApp.installTranslator(self.fSysTranslator)
  128. if gCarla.nogui:
  129. return
  130. if appName == "Carla2-Control":
  131. if QT_VERSION >= 0x50700:
  132. self.fApp.setDesktopFileName("carla-control")
  133. self.fApp.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  134. else:
  135. if QT_VERSION >= 0x50700:
  136. self.fApp.setDesktopFileName("carla")
  137. self.fApp.setWindowIcon(QIcon(":/scalable/carla.svg"))
  138. def createPaletteBlack(self):
  139. self.fPalBlack = QPalette()
  140. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Window, QColor(14, 14, 14))
  141. self.fPalBlack.setColor(QPalette.Active, QPalette.Window, QColor(17, 17, 17))
  142. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Window, QColor(17, 17, 17))
  143. self.fPalBlack.setColor(QPalette.Disabled, QPalette.WindowText, QColor(83, 83, 83))
  144. self.fPalBlack.setColor(QPalette.Active, QPalette.WindowText, QColor(240, 240, 240))
  145. self.fPalBlack.setColor(QPalette.Inactive, QPalette.WindowText, QColor(240, 240, 240))
  146. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Base, QColor(6, 6, 6))
  147. self.fPalBlack.setColor(QPalette.Active, QPalette.Base, QColor(7, 7, 7))
  148. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Base, QColor(7, 7, 7))
  149. self.fPalBlack.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(12, 12, 12))
  150. self.fPalBlack.setColor(QPalette.Active, QPalette.AlternateBase, QColor(14, 14, 14))
  151. self.fPalBlack.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(14, 14, 14))
  152. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(4, 4, 4))
  153. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(4, 4, 4))
  154. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(4, 4, 4))
  155. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(230, 230, 230))
  156. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipText, QColor(230, 230, 230))
  157. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(230, 230, 230))
  158. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Text, QColor(74, 74, 74))
  159. self.fPalBlack.setColor(QPalette.Active, QPalette.Text, QColor(230, 230, 230))
  160. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Text, QColor(230, 230, 230))
  161. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Button, QColor(24, 24, 24))
  162. self.fPalBlack.setColor(QPalette.Active, QPalette.Button, QColor(28, 28, 28))
  163. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Button, QColor(28, 28, 28))
  164. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(90, 90, 90))
  165. self.fPalBlack.setColor(QPalette.Active, QPalette.ButtonText, QColor(240, 240, 240))
  166. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(240, 240, 240))
  167. self.fPalBlack.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  168. self.fPalBlack.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  169. self.fPalBlack.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  170. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Light, QColor(191, 191, 191))
  171. self.fPalBlack.setColor(QPalette.Active, QPalette.Light, QColor(191, 191, 191))
  172. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Light, QColor(191, 191, 191))
  173. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Midlight, QColor(155, 155, 155))
  174. self.fPalBlack.setColor(QPalette.Active, QPalette.Midlight, QColor(155, 155, 155))
  175. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Midlight, QColor(155, 155, 155))
  176. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Dark, QColor(129, 129, 129))
  177. self.fPalBlack.setColor(QPalette.Active, QPalette.Dark, QColor(129, 129, 129))
  178. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Dark, QColor(129, 129, 129))
  179. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Mid, QColor(94, 94, 94))
  180. self.fPalBlack.setColor(QPalette.Active, QPalette.Mid, QColor(94, 94, 94))
  181. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Mid, QColor(94, 94, 94))
  182. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Shadow, QColor(155, 155, 155))
  183. self.fPalBlack.setColor(QPalette.Active, QPalette.Shadow, QColor(155, 155, 155))
  184. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Shadow, QColor(155, 155, 155))
  185. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Highlight, QColor(14, 14, 14))
  186. self.fPalBlack.setColor(QPalette.Active, QPalette.Highlight, QColor(60, 60, 60))
  187. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Highlight, QColor(34, 34, 34))
  188. self.fPalBlack.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(83, 83, 83))
  189. self.fPalBlack.setColor(QPalette.Active, QPalette.HighlightedText, QColor(255, 255, 255))
  190. self.fPalBlack.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(240, 240, 240))
  191. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Link, QColor(34, 34, 74))
  192. self.fPalBlack.setColor(QPalette.Active, QPalette.Link, QColor(100, 100, 230))
  193. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Link, QColor(100, 100, 230))
  194. self.fPalBlack.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(74, 34, 74))
  195. self.fPalBlack.setColor(QPalette.Active, QPalette.LinkVisited, QColor(230, 100, 230))
  196. self.fPalBlack.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(230, 100, 230))
  197. self.fApp.setPalette(self.fPalBlack)
  198. def createPaletteBlue(self):
  199. self.fPalBlue = QPalette()
  200. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Window, QColor(32, 35, 39))
  201. self.fPalBlue.setColor(QPalette.Active, QPalette.Window, QColor(37, 40, 45))
  202. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Window, QColor(37, 40, 45))
  203. self.fPalBlue.setColor(QPalette.Disabled, QPalette.WindowText, QColor(89, 95, 104))
  204. self.fPalBlue.setColor(QPalette.Active, QPalette.WindowText, QColor(223, 237, 255))
  205. self.fPalBlue.setColor(QPalette.Inactive, QPalette.WindowText, QColor(223, 237, 255))
  206. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Base, QColor(48, 53, 60))
  207. self.fPalBlue.setColor(QPalette.Active, QPalette.Base, QColor(55, 61, 69))
  208. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Base, QColor(55, 61, 69))
  209. self.fPalBlue.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(60, 64, 67))
  210. self.fPalBlue.setColor(QPalette.Active, QPalette.AlternateBase, QColor(69, 73, 77))
  211. self.fPalBlue.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(69, 73, 77))
  212. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(182, 193, 208))
  213. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(182, 193, 208))
  214. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(182, 193, 208))
  215. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(42, 44, 48))
  216. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipText, QColor(42, 44, 48))
  217. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(42, 44, 48))
  218. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Text, QColor(96, 103, 113))
  219. self.fPalBlue.setColor(QPalette.Active, QPalette.Text, QColor(210, 222, 240))
  220. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Text, QColor(210, 222, 240))
  221. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Button, QColor(51, 55, 62))
  222. self.fPalBlue.setColor(QPalette.Active, QPalette.Button, QColor(59, 63, 71))
  223. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Button, QColor(59, 63, 71))
  224. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(98, 104, 114))
  225. self.fPalBlue.setColor(QPalette.Active, QPalette.ButtonText, QColor(210, 222, 240))
  226. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(210, 222, 240))
  227. self.fPalBlue.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  228. self.fPalBlue.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  229. self.fPalBlue.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  230. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Light, QColor(59, 64, 72))
  231. self.fPalBlue.setColor(QPalette.Active, QPalette.Light, QColor(63, 68, 76))
  232. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Light, QColor(63, 68, 76))
  233. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Midlight, QColor(48, 52, 59))
  234. self.fPalBlue.setColor(QPalette.Active, QPalette.Midlight, QColor(51, 56, 63))
  235. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Midlight, QColor(51, 56, 63))
  236. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Dark, QColor(18, 19, 22))
  237. self.fPalBlue.setColor(QPalette.Active, QPalette.Dark, QColor(20, 22, 25))
  238. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Dark, QColor(20, 22, 25))
  239. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Mid, QColor(28, 30, 34))
  240. self.fPalBlue.setColor(QPalette.Active, QPalette.Mid, QColor(32, 35, 39))
  241. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Mid, QColor(32, 35, 39))
  242. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Shadow, QColor(13, 14, 16))
  243. self.fPalBlue.setColor(QPalette.Active, QPalette.Shadow, QColor(15, 16, 18))
  244. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Shadow, QColor(15, 16, 18))
  245. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Highlight, QColor(32, 35, 39))
  246. self.fPalBlue.setColor(QPalette.Active, QPalette.Highlight, QColor(14, 14, 17))
  247. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Highlight, QColor(27, 28, 33))
  248. self.fPalBlue.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(89, 95, 104))
  249. self.fPalBlue.setColor(QPalette.Active, QPalette.HighlightedText, QColor(217, 234, 253))
  250. self.fPalBlue.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(223, 237, 255))
  251. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Link, QColor(79, 100, 118))
  252. self.fPalBlue.setColor(QPalette.Active, QPalette.Link, QColor(156, 212, 255))
  253. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Link, QColor(156, 212, 255))
  254. self.fPalBlue.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(51, 74, 118))
  255. self.fPalBlue.setColor(QPalette.Active, QPalette.LinkVisited, QColor(64, 128, 255))
  256. self.fPalBlue.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(64, 128, 255))
  257. self.fApp.setPalette(self.fPalBlue)
  258. def exec_(self):
  259. return self.fApp.exec_()
  260. def exit_exec(self):
  261. return sys.exit(self.fApp.exec_())
  262. def getApp(self):
  263. return self.fApp
  264. def quit(self):
  265. self.fApp.quit()
  266. # ------------------------------------------------------------------------------------------------------------