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.

288 lines
16KB

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