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_app.py 17KB

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