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.cpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Carla application
  3. * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "carla_app.hpp"
  18. //---------------------------------------------------------------------------------------------------------------------
  19. // Imports (Global)
  20. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  21. # pragma GCC diagnostic push
  22. # pragma GCC diagnostic ignored "-Wconversion"
  23. # pragma GCC diagnostic ignored "-Weffc++"
  24. # pragma GCC diagnostic ignored "-Wsign-conversion"
  25. #endif
  26. #include <QtCore/QCoreApplication>
  27. #include <QtCore/QDir>
  28. #include <QtGui/QIcon>
  29. #include <QtGui/QPalette>
  30. #include <QtWidgets/QApplication>
  31. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  32. # pragma GCC diagnostic pop
  33. #endif
  34. //---------------------------------------------------------------------------------------------------------------------
  35. // Imports (Custom)
  36. #include "carla_shared.hpp"
  37. //---------------------------------------------------------------------------------------------------------------------
  38. CarlaApplication::CarlaApplication(const QString appName, int& argc, char* argv[])
  39. : fApp(nullptr)
  40. {
  41. QCarlaString pathBinaries, pathResources;
  42. /*
  43. pathBinaries, pathResources = getPaths(libPrefix)
  44. // Needed for MacOS and Windows
  45. if (os.path.exists(CWD))
  46. QApplication.addLibraryPath(CWD)
  47. // Needed for local wine build
  48. if WINDOWS and CWD.endswith(("frontend", "resources")) and os.getenv("CXFREEZE") is None:
  49. if kIs64bit:
  50. path = "H:\\builds\\msys2-x86_64\\mingw64\\share\\qt5\\plugins"
  51. else:
  52. path = "H:\\builds\\msys2-i686\\mingw32\\share\\qt5\\plugins"
  53. QApplication.addLibraryPath(path)
  54. */
  55. QCarlaString stylesDir;
  56. // Use binary dir as library path
  57. if (QDir(pathBinaries).exists())
  58. {
  59. QApplication::addLibraryPath(pathBinaries);
  60. stylesDir = pathBinaries;
  61. }
  62. // base settings
  63. const QSafeSettings settings("falkTX", appName);
  64. #ifdef CARLA_OS_MAC
  65. const bool useProTheme = true;
  66. #else
  67. const bool useProTheme = settings.valueBool(CARLA_KEY_MAIN_USE_PRO_THEME, CARLA_DEFAULT_MAIN_USE_PRO_THEME);
  68. #endif
  69. if (! useProTheme)
  70. {
  71. createApp(appName, argc, argv);
  72. return;
  73. }
  74. // set style
  75. QApplication::setStyle(stylesDir.isNotEmpty() ? "carla" : "fusion");
  76. // create app
  77. QApplication* const guiApp = createApp(appName, argc, argv);
  78. if (guiApp == nullptr)
  79. return;
  80. guiApp->setStyle(stylesDir.isNotEmpty() ? "carla" : "fusion");
  81. #ifdef MACOS
  82. if (true)
  83. #else
  84. // set palette
  85. const QString proThemeColor(settings.valueString(CARLA_KEY_MAIN_PRO_THEME_COLOR, CARLA_DEFAULT_MAIN_PRO_THEME_COLOR).toLower());
  86. if (proThemeColor == "black")
  87. #endif
  88. {
  89. QPalette palBlack;
  90. palBlack.setColor(QPalette::Disabled, QPalette::Window, QColor(14, 14, 14));
  91. palBlack.setColor(QPalette::Active, QPalette::Window, QColor(17, 17, 17));
  92. palBlack.setColor(QPalette::Inactive, QPalette::Window, QColor(17, 17, 17));
  93. palBlack.setColor(QPalette::Disabled, QPalette::WindowText, QColor(83, 83, 83));
  94. palBlack.setColor(QPalette::Active, QPalette::WindowText, QColor(240, 240, 240));
  95. palBlack.setColor(QPalette::Inactive, QPalette::WindowText, QColor(240, 240, 240));
  96. palBlack.setColor(QPalette::Disabled, QPalette::Base, QColor(6, 6, 6));
  97. palBlack.setColor(QPalette::Active, QPalette::Base, QColor(7, 7, 7));
  98. palBlack.setColor(QPalette::Inactive, QPalette::Base, QColor(7, 7, 7));
  99. palBlack.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(12, 12, 12));
  100. palBlack.setColor(QPalette::Active, QPalette::AlternateBase, QColor(14, 14, 14));
  101. palBlack.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(14, 14, 14));
  102. palBlack.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(4, 4, 4));
  103. palBlack.setColor(QPalette::Active, QPalette::ToolTipBase, QColor(4, 4, 4));
  104. palBlack.setColor(QPalette::Inactive, QPalette::ToolTipBase, QColor(4, 4, 4));
  105. palBlack.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(230, 230, 230));
  106. palBlack.setColor(QPalette::Active, QPalette::ToolTipText, QColor(230, 230, 230));
  107. palBlack.setColor(QPalette::Inactive, QPalette::ToolTipText, QColor(230, 230, 230));
  108. palBlack.setColor(QPalette::Disabled, QPalette::Text, QColor(74, 74, 74));
  109. palBlack.setColor(QPalette::Active, QPalette::Text, QColor(230, 230, 230));
  110. palBlack.setColor(QPalette::Inactive, QPalette::Text, QColor(230, 230, 230));
  111. palBlack.setColor(QPalette::Disabled, QPalette::Button, QColor(24, 24, 24));
  112. palBlack.setColor(QPalette::Active, QPalette::Button, QColor(28, 28, 28));
  113. palBlack.setColor(QPalette::Inactive, QPalette::Button, QColor(28, 28, 28));
  114. palBlack.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(90, 90, 90));
  115. palBlack.setColor(QPalette::Active, QPalette::ButtonText, QColor(240, 240, 240));
  116. palBlack.setColor(QPalette::Inactive, QPalette::ButtonText, QColor(240, 240, 240));
  117. palBlack.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
  118. palBlack.setColor(QPalette::Active, QPalette::BrightText, QColor(255, 255, 255));
  119. palBlack.setColor(QPalette::Inactive, QPalette::BrightText, QColor(255, 255, 255));
  120. palBlack.setColor(QPalette::Disabled, QPalette::Light, QColor(191, 191, 191));
  121. palBlack.setColor(QPalette::Active, QPalette::Light, QColor(191, 191, 191));
  122. palBlack.setColor(QPalette::Inactive, QPalette::Light, QColor(191, 191, 191));
  123. palBlack.setColor(QPalette::Disabled, QPalette::Midlight, QColor(155, 155, 155));
  124. palBlack.setColor(QPalette::Active, QPalette::Midlight, QColor(155, 155, 155));
  125. palBlack.setColor(QPalette::Inactive, QPalette::Midlight, QColor(155, 155, 155));
  126. palBlack.setColor(QPalette::Disabled, QPalette::Dark, QColor(129, 129, 129));
  127. palBlack.setColor(QPalette::Active, QPalette::Dark, QColor(129, 129, 129));
  128. palBlack.setColor(QPalette::Inactive, QPalette::Dark, QColor(129, 129, 129));
  129. palBlack.setColor(QPalette::Disabled, QPalette::Mid, QColor(94, 94, 94));
  130. palBlack.setColor(QPalette::Active, QPalette::Mid, QColor(94, 94, 94));
  131. palBlack.setColor(QPalette::Inactive, QPalette::Mid, QColor(94, 94, 94));
  132. palBlack.setColor(QPalette::Disabled, QPalette::Shadow, QColor(155, 155, 155));
  133. palBlack.setColor(QPalette::Active, QPalette::Shadow, QColor(155, 155, 155));
  134. palBlack.setColor(QPalette::Inactive, QPalette::Shadow, QColor(155, 155, 155));
  135. palBlack.setColor(QPalette::Disabled, QPalette::Highlight, QColor(14, 14, 14));
  136. palBlack.setColor(QPalette::Active, QPalette::Highlight, QColor(60, 60, 60));
  137. palBlack.setColor(QPalette::Inactive, QPalette::Highlight, QColor(34, 34, 34));
  138. palBlack.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(83, 83, 83));
  139. palBlack.setColor(QPalette::Active, QPalette::HighlightedText, QColor(255, 255, 255));
  140. palBlack.setColor(QPalette::Inactive, QPalette::HighlightedText, QColor(240, 240, 240));
  141. palBlack.setColor(QPalette::Disabled, QPalette::Link, QColor(34, 34, 74));
  142. palBlack.setColor(QPalette::Active, QPalette::Link, QColor(100, 100, 230));
  143. palBlack.setColor(QPalette::Inactive, QPalette::Link, QColor(100, 100, 230));
  144. palBlack.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(74, 34, 74));
  145. palBlack.setColor(QPalette::Active, QPalette::LinkVisited, QColor(230, 100, 230));
  146. palBlack.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(230, 100, 230));
  147. guiApp->setPalette(palBlack);
  148. }
  149. else if (proThemeColor == "blue")
  150. {
  151. QPalette palBlue;
  152. palBlue.setColor(QPalette::Disabled, QPalette::Window, QColor(32, 35, 39));
  153. palBlue.setColor(QPalette::Active, QPalette::Window, QColor(37, 40, 45));
  154. palBlue.setColor(QPalette::Inactive, QPalette::Window, QColor(37, 40, 45));
  155. palBlue.setColor(QPalette::Disabled, QPalette::WindowText, QColor(89, 95, 104));
  156. palBlue.setColor(QPalette::Active, QPalette::WindowText, QColor(223, 237, 255));
  157. palBlue.setColor(QPalette::Inactive, QPalette::WindowText, QColor(223, 237, 255));
  158. palBlue.setColor(QPalette::Disabled, QPalette::Base, QColor(48, 53, 60));
  159. palBlue.setColor(QPalette::Active, QPalette::Base, QColor(55, 61, 69));
  160. palBlue.setColor(QPalette::Inactive, QPalette::Base, QColor(55, 61, 69));
  161. palBlue.setColor(QPalette::Disabled, QPalette::AlternateBase, QColor(60, 64, 67));
  162. palBlue.setColor(QPalette::Active, QPalette::AlternateBase, QColor(69, 73, 77));
  163. palBlue.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(69, 73, 77));
  164. palBlue.setColor(QPalette::Disabled, QPalette::ToolTipBase, QColor(182, 193, 208));
  165. palBlue.setColor(QPalette::Active, QPalette::ToolTipBase, QColor(182, 193, 208));
  166. palBlue.setColor(QPalette::Inactive, QPalette::ToolTipBase, QColor(182, 193, 208));
  167. palBlue.setColor(QPalette::Disabled, QPalette::ToolTipText, QColor(42, 44, 48));
  168. palBlue.setColor(QPalette::Active, QPalette::ToolTipText, QColor(42, 44, 48));
  169. palBlue.setColor(QPalette::Inactive, QPalette::ToolTipText, QColor(42, 44, 48));
  170. palBlue.setColor(QPalette::Disabled, QPalette::Text, QColor(96, 103, 113));
  171. palBlue.setColor(QPalette::Active, QPalette::Text, QColor(210, 222, 240));
  172. palBlue.setColor(QPalette::Inactive, QPalette::Text, QColor(210, 222, 240));
  173. palBlue.setColor(QPalette::Disabled, QPalette::Button, QColor(51, 55, 62));
  174. palBlue.setColor(QPalette::Active, QPalette::Button, QColor(59, 63, 71));
  175. palBlue.setColor(QPalette::Inactive, QPalette::Button, QColor(59, 63, 71));
  176. palBlue.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(98, 104, 114));
  177. palBlue.setColor(QPalette::Active, QPalette::ButtonText, QColor(210, 222, 240));
  178. palBlue.setColor(QPalette::Inactive, QPalette::ButtonText, QColor(210, 222, 240));
  179. palBlue.setColor(QPalette::Disabled, QPalette::BrightText, QColor(255, 255, 255));
  180. palBlue.setColor(QPalette::Active, QPalette::BrightText, QColor(255, 255, 255));
  181. palBlue.setColor(QPalette::Inactive, QPalette::BrightText, QColor(255, 255, 255));
  182. palBlue.setColor(QPalette::Disabled, QPalette::Light, QColor(59, 64, 72));
  183. palBlue.setColor(QPalette::Active, QPalette::Light, QColor(63, 68, 76));
  184. palBlue.setColor(QPalette::Inactive, QPalette::Light, QColor(63, 68, 76));
  185. palBlue.setColor(QPalette::Disabled, QPalette::Midlight, QColor(48, 52, 59));
  186. palBlue.setColor(QPalette::Active, QPalette::Midlight, QColor(51, 56, 63));
  187. palBlue.setColor(QPalette::Inactive, QPalette::Midlight, QColor(51, 56, 63));
  188. palBlue.setColor(QPalette::Disabled, QPalette::Dark, QColor(18, 19, 22));
  189. palBlue.setColor(QPalette::Active, QPalette::Dark, QColor(20, 22, 25));
  190. palBlue.setColor(QPalette::Inactive, QPalette::Dark, QColor(20, 22, 25));
  191. palBlue.setColor(QPalette::Disabled, QPalette::Mid, QColor(28, 30, 34));
  192. palBlue.setColor(QPalette::Active, QPalette::Mid, QColor(32, 35, 39));
  193. palBlue.setColor(QPalette::Inactive, QPalette::Mid, QColor(32, 35, 39));
  194. palBlue.setColor(QPalette::Disabled, QPalette::Shadow, QColor(13, 14, 16));
  195. palBlue.setColor(QPalette::Active, QPalette::Shadow, QColor(15, 16, 18));
  196. palBlue.setColor(QPalette::Inactive, QPalette::Shadow, QColor(15, 16, 18));
  197. palBlue.setColor(QPalette::Disabled, QPalette::Highlight, QColor(32, 35, 39));
  198. palBlue.setColor(QPalette::Active, QPalette::Highlight, QColor(14, 14, 17));
  199. palBlue.setColor(QPalette::Inactive, QPalette::Highlight, QColor(27, 28, 33));
  200. palBlue.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(89, 95, 104));
  201. palBlue.setColor(QPalette::Active, QPalette::HighlightedText, QColor(217, 234, 253));
  202. palBlue.setColor(QPalette::Inactive, QPalette::HighlightedText, QColor(223, 237, 255));
  203. palBlue.setColor(QPalette::Disabled, QPalette::Link, QColor(79, 100, 118));
  204. palBlue.setColor(QPalette::Active, QPalette::Link, QColor(156, 212, 255));
  205. palBlue.setColor(QPalette::Inactive, QPalette::Link, QColor(156, 212, 255));
  206. palBlue.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(51, 74, 118));
  207. palBlue.setColor(QPalette::Active, QPalette::LinkVisited, QColor(64, 128, 255));
  208. palBlue.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(64, 128, 255));
  209. guiApp->setPalette(palBlue);
  210. }
  211. }
  212. QApplication* CarlaApplication::createApp(const QString& appName, int& argc, char* argv[])
  213. {
  214. #ifdef CARLA_OS_LINUX
  215. QApplication::setAttribute(Qt::AA_X11InitThreads);
  216. #endif
  217. #ifdef CARLA_OS_MAC
  218. QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
  219. #endif
  220. #if QT_VERSION >= 0x50600
  221. QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  222. QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
  223. #endif
  224. #ifdef CARLA_OS_WIN
  225. static int r_argc = argc + 2;
  226. static char** const r_argv = static_cast<char**>(calloc(sizeof(char*), r_argc));
  227. static char argvExtra1[] = "-platform\0";
  228. static char argvExtra2[] = "windows:fontengine=freetype\0";
  229. for (int i=0; i<argc; ++i)
  230. r_argv[i] = argv[i];
  231. r_argv[argc] = argvExtra1;
  232. r_argv[argc] = argvExtra2;
  233. #else
  234. # define r_argc argc
  235. # define r_argv argv
  236. #endif
  237. fApp = gCarla.nogui ? new QCoreApplication(r_argc, r_argv) : new QApplication(r_argc, r_argv);
  238. fApp->setApplicationName(appName);
  239. fApp->setApplicationVersion(CARLA_VERSION_STRING);
  240. fApp->setOrganizationName("falkTX");
  241. #ifndef CARLA_OS_WIN
  242. # undef r_argc
  243. # undef r_argv
  244. #endif
  245. if (gCarla.nogui)
  246. return nullptr;
  247. QApplication* const guiApp = dynamic_cast<QApplication*>(fApp);
  248. CARLA_SAFE_ASSERT_RETURN(guiApp != nullptr, nullptr);
  249. if (appName.toLower() == "carla-control")
  250. {
  251. #if QT_VERSION >= 0x50700
  252. guiApp->setDesktopFileName("carla-control");
  253. #endif
  254. guiApp->setWindowIcon(QIcon(":/scalable/carla-control.svg"));
  255. }
  256. else
  257. {
  258. #if QT_VERSION >= 0x50700
  259. guiApp->setDesktopFileName("carla");
  260. #endif
  261. guiApp->setWindowIcon(QIcon(":/scalable/carla.svg"));
  262. }
  263. return guiApp;
  264. }
  265. //---------------------------------------------------------------------------------------------------------------------