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.

508 lines
20KB

  1. /*
  2. * Common Carla code
  3. * Copyright (C) 2011-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. #ifndef CARLA_SHARED_HPP_INCLUDED
  18. #define CARLA_SHARED_HPP_INCLUDED
  19. //---------------------------------------------------------------------------------------------------------------------
  20. // Imports (Global)
  21. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  22. # pragma GCC diagnostic push
  23. # pragma GCC diagnostic ignored "-Wconversion"
  24. # pragma GCC diagnostic ignored "-Weffc++"
  25. # pragma GCC diagnostic ignored "-Wsign-conversion"
  26. #endif
  27. #include <QtCore/QSettings>
  28. #include <QtCore/QStringList>
  29. #include <QtGui/QIcon>
  30. #include <QtWidgets/QMessageBox>
  31. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  32. # pragma GCC diagnostic pop
  33. #endif
  34. //---------------------------------------------------------------------------------------------------------------------
  35. class CarlaHost;
  36. class QFontMetrics;
  37. class QLineEdit;
  38. //---------------------------------------------------------------------------------------------------------------------
  39. // Imports (Custom)
  40. #include "CarlaDefines.h"
  41. //---------------------------------------------------------------------------------------------------------------------
  42. // Static MIDI CC list
  43. /*
  44. static const char* const* const MIDI_CC_LIST = {
  45. "0x01 Modulation",
  46. "0x02 Breath",
  47. "0x03 (Undefined)",
  48. "0x04 Foot",
  49. "0x05 Portamento",
  50. "0x07 Volume",
  51. "0x08 Balance",
  52. "0x09 (Undefined)",
  53. "0x0A Pan",
  54. "0x0B Expression",
  55. "0x0C FX Control 1",
  56. "0x0D FX Control 2",
  57. "0x0E (Undefined)",
  58. "0x0F (Undefined)",
  59. "0x10 General Purpose 1",
  60. "0x11 General Purpose 2",
  61. "0x12 General Purpose 3",
  62. "0x13 General Purpose 4",
  63. "0x14 (Undefined)",
  64. "0x15 (Undefined)",
  65. "0x16 (Undefined)",
  66. "0x17 (Undefined)",
  67. "0x18 (Undefined)",
  68. "0x19 (Undefined)",
  69. "0x1A (Undefined)",
  70. "0x1B (Undefined)",
  71. "0x1C (Undefined)",
  72. "0x1D (Undefined)",
  73. "0x1E (Undefined)",
  74. "0x1F (Undefined)",
  75. "0x46 Control 1 [Variation]",
  76. "0x47 Control 2 [Timbre]",
  77. "0x48 Control 3 [Release]",
  78. "0x49 Control 4 [Attack]",
  79. "0x4A Control 5 [Brightness]",
  80. "0x4B Control 6 [Decay]",
  81. "0x4C Control 7 [Vib Rate]",
  82. "0x4D Control 8 [Vib Depth]",
  83. "0x4E Control 9 [Vib Delay]",
  84. "0x4F Control 10 [Undefined]",
  85. "0x50 General Purpose 5",
  86. "0x51 General Purpose 6",
  87. "0x52 General Purpose 7",
  88. "0x53 General Purpose 8",
  89. "0x54 Portamento Control",
  90. "0x5B FX 1 Depth [Reverb]",
  91. "0x5C FX 2 Depth [Tremolo]",
  92. "0x5D FX 3 Depth [Chorus]",
  93. "0x5E FX 4 Depth [Detune]",
  94. "0x5F FX 5 Depth [Phaser]",
  95. nullptr
  96. };
  97. */
  98. //---------------------------------------------------------------------------------------------------------------------
  99. // PatchCanvas defines
  100. // NOTE: must match Qt::CheckState and PatchCanvas API at the same time
  101. #define CANVAS_ANTIALIASING_SMALL Qt::PartiallyChecked
  102. #define CANVAS_EYECANDY_SMALL Qt::PartiallyChecked
  103. //---------------------------------------------------------------------------------------------------------------------
  104. // Carla Settings keys
  105. #define CARLA_KEY_MAIN_PROJECT_FOLDER "Main/ProjectFolder" /* str */
  106. #define CARLA_KEY_MAIN_USE_PRO_THEME "Main/UseProTheme" /* bool */
  107. #define CARLA_KEY_MAIN_PRO_THEME_COLOR "Main/ProThemeColor" /* str */
  108. #define CARLA_KEY_MAIN_REFRESH_INTERVAL "Main/RefreshInterval" /* int */
  109. #define CARLA_KEY_MAIN_CONFIRM_EXIT "Main/ConfirmExit" /* bool */
  110. #define CARLA_KEY_MAIN_SHOW_LOGS "Main/ShowLogs" /* bool */
  111. #define CARLA_KEY_MAIN_EXPERIMENTAL "Main/Experimental" /* bool */
  112. #define CARLA_KEY_CANVAS_THEME "Canvas/Theme" /* str */
  113. #define CARLA_KEY_CANVAS_SIZE "Canvas/Size" /* str "NxN" */
  114. #define CARLA_KEY_CANVAS_USE_BEZIER_LINES "Canvas/UseBezierLines" /* bool */
  115. #define CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS "Canvas/AutoHideGroups" /* bool */
  116. #define CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS "Canvas/AutoSelectItems" /* bool */
  117. #define CARLA_KEY_CANVAS_EYE_CANDY "Canvas/EyeCandy2" /* bool */
  118. #define CARLA_KEY_CANVAS_FANCY_EYE_CANDY "Canvas/FancyEyeCandy" /* bool */
  119. #define CARLA_KEY_CANVAS_USE_OPENGL "Canvas/UseOpenGL" /* bool */
  120. #define CARLA_KEY_CANVAS_ANTIALIASING "Canvas/Antialiasing" /* enum */
  121. #define CARLA_KEY_CANVAS_HQ_ANTIALIASING "Canvas/HQAntialiasing" /* bool */
  122. #define CARLA_KEY_CANVAS_INLINE_DISPLAYS "Canvas/InlineDisplays" /* bool */
  123. #define CARLA_KEY_CANVAS_FULL_REPAINTS "Canvas/FullRepaints" /* bool */
  124. #define CARLA_KEY_ENGINE_DRIVER_PREFIX "Engine/Driver-"
  125. #define CARLA_KEY_ENGINE_AUDIO_DRIVER "Engine/AudioDriver" /* str */
  126. #define CARLA_KEY_ENGINE_PROCESS_MODE "Engine/ProcessMode" /* enum */
  127. #define CARLA_KEY_ENGINE_TRANSPORT_MODE "Engine/TransportMode" /* enum */
  128. #define CARLA_KEY_ENGINE_TRANSPORT_EXTRA "Engine/TransportExtra" /* str */
  129. #define CARLA_KEY_ENGINE_FORCE_STEREO "Engine/ForceStereo" /* bool */
  130. #define CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES "Engine/PreferPluginBridges" /* bool */
  131. #define CARLA_KEY_ENGINE_PREFER_UI_BRIDGES "Engine/PreferUiBridges" /* bool */
  132. #define CARLA_KEY_ENGINE_MANAGE_UIS "Engine/ManageUIs" /* bool */
  133. #define CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP "Engine/UIsAlwaysOnTop" /* bool */
  134. #define CARLA_KEY_ENGINE_MAX_PARAMETERS "Engine/MaxParameters" /* int */
  135. #define CARLA_KEY_ENGINE_RESET_XRUNS "Engine/ResetXruns" /* bool */
  136. #define CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT "Engine/UiBridgesTimeout" /* int */
  137. #define CARLA_KEY_OSC_ENABLED "OSC/Enabled"
  138. #define CARLA_KEY_OSC_TCP_PORT_ENABLED "OSC/TCPEnabled"
  139. #define CARLA_KEY_OSC_TCP_PORT_NUMBER "OSC/TCPNumber"
  140. #define CARLA_KEY_OSC_TCP_PORT_RANDOM "OSC/TCPRandom"
  141. #define CARLA_KEY_OSC_UDP_PORT_ENABLED "OSC/UDPEnabled"
  142. #define CARLA_KEY_OSC_UDP_PORT_NUMBER "OSC/UDPNumber"
  143. #define CARLA_KEY_OSC_UDP_PORT_RANDOM "OSC/UDPRandom"
  144. #define CARLA_KEY_PATHS_AUDIO "Paths/Audio"
  145. #define CARLA_KEY_PATHS_MIDI "Paths/MIDI"
  146. #define CARLA_KEY_PATHS_LADSPA "Paths/LADSPA"
  147. #define CARLA_KEY_PATHS_DSSI "Paths/DSSI"
  148. #define CARLA_KEY_PATHS_LV2 "Paths/LV2"
  149. #define CARLA_KEY_PATHS_VST2 "Paths/VST2"
  150. #define CARLA_KEY_PATHS_VST3 "Paths/VST3"
  151. #define CARLA_KEY_PATHS_SF2 "Paths/SF2"
  152. #define CARLA_KEY_PATHS_SFZ "Paths/SFZ"
  153. #define CARLA_KEY_WINE_EXECUTABLE "Wine/Executable" /* str */
  154. #define CARLA_KEY_WINE_AUTO_PREFIX "Wine/AutoPrefix" /* bool */
  155. #define CARLA_KEY_WINE_FALLBACK_PREFIX "Wine/FallbackPrefix" /* str */
  156. #define CARLA_KEY_WINE_RT_PRIO_ENABLED "Wine/RtPrioEnabled" /* bool */
  157. #define CARLA_KEY_WINE_BASE_RT_PRIO "Wine/BaseRtPrio" /* int */
  158. #define CARLA_KEY_WINE_SERVER_RT_PRIO "Wine/ServerRtPrio" /* int */
  159. #define CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES "Experimental/PluginBridges" /* bool */
  160. #define CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES "Experimental/WineBridges" /* bool */
  161. #define CARLA_KEY_EXPERIMENTAL_JACK_APPS "Experimental/JackApplications" /* bool */
  162. #define CARLA_KEY_EXPERIMENTAL_EXPORT_LV2 "Experimental/ExportLV2" /* bool */
  163. #define CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR "Experimental/PreventBadBehaviour" /* bool */
  164. #define CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL "Experimental/LoadLibGlobal" /* bool */
  165. // if pro theme is on and color is black
  166. #define CARLA_KEY_CUSTOM_PAINTING "UseCustomPainting" /* bool */
  167. //---------------------------------------------------------------------------------------------------------------------
  168. // Carla Settings defaults
  169. // Main
  170. #define CARLA_DEFAULT_MAIN_PROJECT_FOLDER QDir::homePath()
  171. #define CARLA_DEFAULT_MAIN_USE_PRO_THEME true
  172. #define CARLA_DEFAULT_MAIN_PRO_THEME_COLOR "Black"
  173. #define CARLA_DEFAULT_MAIN_REFRESH_INTERVAL 20
  174. #define CARLA_DEFAULT_MAIN_CONFIRM_EXIT true
  175. #ifdef CARLA_OS_WIN
  176. # define CARLA_DEFAULT_MAIN_SHOW_LOGS false
  177. #else
  178. # define CARLA_DEFAULT_MAIN_SHOW_LOGS true
  179. #endif
  180. #define CARLA_DEFAULT_MAIN_EXPERIMENTAL false
  181. // Canvas
  182. #define CARLA_DEFAULT_CANVAS_THEME "Modern Dark"
  183. #define CARLA_DEFAULT_CANVAS_SIZE "3100x2400"
  184. #define CARLA_DEFAULT_CANVAS_SIZE_WIDTH 3100
  185. #define CARLA_DEFAULT_CANVAS_SIZE_HEIGHT 2400
  186. #define CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES true
  187. #define CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS true
  188. #define CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS false
  189. #define CARLA_DEFAULT_CANVAS_EYE_CANDY true
  190. #define CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY false
  191. #define CARLA_DEFAULT_CANVAS_USE_OPENGL false
  192. #define CARLA_DEFAULT_CANVAS_ANTIALIASING CANVAS_ANTIALIASING_SMALL
  193. #define CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING false
  194. #define CARLA_DEFAULT_CANVAS_INLINE_DISPLAYS false
  195. #define CARLA_DEFAULT_CANVAS_FULL_REPAINTS false
  196. // Engine
  197. #define CARLA_DEFAULT_FORCE_STEREO false
  198. #define CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES false
  199. #define CARLA_DEFAULT_PREFER_UI_BRIDGES true
  200. #define CARLA_DEFAULT_MANAGE_UIS true
  201. #define CARLA_DEFAULT_UIS_ALWAYS_ON_TOP false
  202. #define CARLA_DEFAULT_MAX_PARAMETERS MAX_DEFAULT_PARAMETERS
  203. #define CARLA_DEFAULT_RESET_XRUNS false
  204. #define CARLA_DEFAULT_UI_BRIDGES_TIMEOUT 4000
  205. #define CARLA_DEFAULT_AUDIO_BUFFER_SIZE 512
  206. #define CARLA_DEFAULT_AUDIO_SAMPLE_RATE 44100
  207. #define CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER false
  208. #if defined(CARLA_OS_WIN)
  209. # define CARLA_DEFAULT_AUDIO_DRIVER "DirectSound"
  210. #elif defined(CARLA_OS_MAC)
  211. # define CARLA_DEFAULT_AUDIO_DRIVER "CoreAudio"
  212. #else
  213. // if os.path.exists("/usr/bin/jackd") or os.path.exists("/usr/bin/jackdbus"):
  214. # define CARLA_DEFAULT_AUDIO_DRIVER "JACK"
  215. // # define CARLA_DEFAULT_AUDIO_DRIVER "PulseAudio"
  216. #endif
  217. // #if CARLA_DEFAULT_AUDIO_DRIVER == "JACK"
  218. // # define CARLA_DEFAULT_PROCESS_MODE ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  219. // # define CARLA_DEFAULT_TRANSPORT_MODE ENGINE_TRANSPORT_MODE_JACK
  220. // #else
  221. # define CARLA_DEFAULT_PROCESS_MODE ENGINE_PROCESS_MODE_PATCHBAY
  222. # define CARLA_DEFAULT_TRANSPORT_MODE ENGINE_TRANSPORT_MODE_INTERNAL
  223. // #endif
  224. // OSC
  225. #ifdef CARLA_OS_WIN
  226. # define CARLA_DEFAULT_OSC_ENABLED false
  227. #else
  228. # define CARLA_DEFAULT_OSC_ENABLED true
  229. #endif
  230. #define CARLA_DEFAULT_OSC_TCP_PORT_ENABLED true
  231. #define CARLA_DEFAULT_OSC_TCP_PORT_NUMBER 22752
  232. #define CARLA_DEFAULT_OSC_TCP_PORT_RANDOM false
  233. #define CARLA_DEFAULT_OSC_UDP_PORT_ENABLED true
  234. #define CARLA_DEFAULT_OSC_UDP_PORT_NUMBER 22752
  235. #define CARLA_DEFAULT_OSC_UDP_PORT_RANDOM false
  236. // Wine
  237. #define CARLA_DEFAULT_WINE_EXECUTABLE "wine"
  238. #define CARLA_DEFAULT_WINE_AUTO_PREFIX true
  239. #define CARLA_DEFAULT_WINE_FALLBACK_PREFIX QDir::homePath() + "/.wine"
  240. #define CARLA_DEFAULT_WINE_RT_PRIO_ENABLED true
  241. #define CARLA_DEFAULT_WINE_BASE_RT_PRIO 15
  242. #define CARLA_DEFAULT_WINE_SERVER_RT_PRIO 10
  243. // Experimental
  244. #define CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES false
  245. #define CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES false
  246. #define CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS false
  247. #define CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT false
  248. #define CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR false
  249. #define CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL false
  250. //---------------------------------------------------------------------------------------------------------------------
  251. // Default File Folders
  252. #define CARLA_DEFAULT_FILE_PATH_AUDIO {}
  253. #define CARLA_DEFAULT_FILE_PATH_MIDI {}
  254. //---------------------------------------------------------------------------------------------------------------------
  255. // Default Plugin Folders (get)
  256. #define DEFAULT_LADSPA_PATH ""
  257. #define DEFAULT_DSSI_PATH ""
  258. #define DEFAULT_LV2_PATH ""
  259. #define DEFAULT_VST2_PATH ""
  260. #define DEFAULT_VST3_PATH ""
  261. #define DEFAULT_SF2_PATH ""
  262. #define DEFAULT_SFZ_PATH ""
  263. #ifdef CARLA_OS_WIN
  264. # define CARLA_PATH_SPLITTER ";"
  265. #else
  266. # define CARLA_PATH_SPLITTER ":"
  267. #endif
  268. //---------------------------------------------------------------------------------------------------------------------
  269. // Default Plugin Folders (set)
  270. /*
  271. readEnvVars = True
  272. if WINDOWS:
  273. # Check if running Wine. If yes, ignore env vars
  274. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  275. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  276. try:
  277. key = OpenKey(reg, r"SOFTWARE\Wine")
  278. CloseKey(key)
  279. del key
  280. readEnvVars = False
  281. except:
  282. pass
  283. CloseKey(reg)
  284. del reg
  285. */
  286. /*
  287. #ifndef CARLA_OS_WIN
  288. # define CARLA_DEFAULT_LADSPA_PATH = std::getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(CARLA_PATH_SPLITTER)
  289. # define CARLA_DEFAULT_DSSI_PATH = std::getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(CARLA_PATH_SPLITTER)
  290. # define CARLA_DEFAULT_LV2_PATH = std::getenv("LV2_PATH", DEFAULT_LV2_PATH).split(CARLA_PATH_SPLITTER)
  291. # define CARLA_DEFAULT_VST2_PATH = std::getenv("VST_PATH", DEFAULT_VST2_PATH).split(CARLA_PATH_SPLITTER)
  292. # define CARLA_DEFAULT_VST3_PATH = std::getenv("VST3_PATH", DEFAULT_VST3_PATH).split(CARLA_PATH_SPLITTER)
  293. # define CARLA_DEFAULT_SF2_PATH = std::getenv("SF2_PATH", DEFAULT_SF2_PATH).split(CARLA_PATH_SPLITTER)
  294. # define CARLA_DEFAULT_SFZ_PATH = std::getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(CARLA_PATH_SPLITTER)
  295. #else
  296. */
  297. # define CARLA_DEFAULT_LADSPA_PATH QString(DEFAULT_LADSPA_PATH).split(CARLA_PATH_SPLITTER)
  298. # define CARLA_DEFAULT_DSSI_PATH QString(DEFAULT_DSSI_PATH).split(CARLA_PATH_SPLITTER)
  299. # define CARLA_DEFAULT_LV2_PATH QString(DEFAULT_LV2_PATH).split(CARLA_PATH_SPLITTER)
  300. # define CARLA_DEFAULT_VST2_PATH QString(DEFAULT_VST2_PATH).split(CARLA_PATH_SPLITTER)
  301. # define CARLA_DEFAULT_VST3_PATH QString(DEFAULT_VST3_PATH).split(CARLA_PATH_SPLITTER)
  302. # define CARLA_DEFAULT_SF2_PATH QString(DEFAULT_SF2_PATH).split(CARLA_PATH_SPLITTER)
  303. # define CARLA_DEFAULT_SFZ_PATH QString(DEFAULT_SFZ_PATH).split(CARLA_PATH_SPLITTER)
  304. /*
  305. #endif
  306. */
  307. //---------------------------------------------------------------------------------------------------------------------
  308. // Global Carla object
  309. struct CarlaObject {
  310. CarlaHost* host;
  311. QWidget* gui;
  312. bool nogui; // Skip UI
  313. bool term; // Terminated by OS signal
  314. CarlaObject() noexcept;
  315. };
  316. extern CarlaObject gCarla;
  317. //---------------------------------------------------------------------------------------------------------------------
  318. // Set DLL_EXTENSION
  319. #if defined(CARLA_OS_WIN)
  320. # define DLL_EXTENSION "dll"
  321. #elif defined(CARLA_OS_MAC)
  322. # define DLL_EXTENSION "dylib"
  323. #else
  324. # define DLL_EXTENSION "so"
  325. #endif
  326. //---------------------------------------------------------------------------------------------------------------------
  327. // Get Icon from user theme, using our own as backup (Oxygen)
  328. QIcon getIcon(QString icon, int size = 16);
  329. //---------------------------------------------------------------------------------------------------------------------
  330. // Handle some basic command-line arguments shared between all carla variants
  331. QString handleInitialCommandLineArguments(const int argc, char* argv[]);
  332. //---------------------------------------------------------------------------------------------------------------------
  333. // Get initial project file (as passed in the command-line parameters)
  334. QString getInitialProjectFile(bool skipExistCheck = false);
  335. //---------------------------------------------------------------------------------------------------------------------
  336. // Get paths (binaries, resources)
  337. bool getPaths(QString& pathBinaries, QString& pathResources);
  338. //---------------------------------------------------------------------------------------------------------------------
  339. // Signal handler
  340. void setUpSignals();
  341. //---------------------------------------------------------------------------------------------------------------------
  342. // QLineEdit and QPushButton combo
  343. QString getAndSetPath(QWidget* parent, QLineEdit* lineEdit);
  344. //---------------------------------------------------------------------------------------------------------------------
  345. // fill up a qlists from a C arrays
  346. void fillQStringListFromStringArray(QStringList& list, const char* const* const stringArray);
  347. void fillQDoubleListFromDoubleArray(QList<double>& list, const double* const doubleArray);
  348. void fillQUIntListFromUIntArray(QList<uint>& list, const uint* const uintArray);
  349. //---------------------------------------------------------------------------------------------------------------------
  350. // Backwards-compatible horizontalAdvance/width call, depending on Qt version
  351. int fontMetricsHorizontalAdvance(const QFontMetrics& fm, const QString& s);
  352. //---------------------------------------------------------------------------------------------------------------------
  353. // Check if a string array contains a string
  354. bool stringArrayContainsString(const char* const* const stringArray, const char* const string) noexcept;
  355. //---------------------------------------------------------------------------------------------------------------------
  356. // Get index of a QList<double> value
  357. int getIndexOfQDoubleListValue(const QList<double>& list, const double value);
  358. //---------------------------------------------------------------------------------------------------------------------
  359. // Check if two QList<double> instances match
  360. bool isQDoubleListEqual(const QList<double>& list1, const QList<double>& list2);
  361. //---------------------------------------------------------------------------------------------------------------------
  362. // Custom QString class with a few extra methods
  363. class QCarlaString : public QString
  364. {
  365. public:
  366. inline QCarlaString()
  367. : QString() {}
  368. inline QCarlaString(const char* const ch)
  369. : QString(ch) {}
  370. inline QCarlaString(const QString& s)
  371. : QString(s) {}
  372. inline bool isNotEmpty() const
  373. {
  374. return !isEmpty();
  375. }
  376. inline QCarlaString& operator=(const char* const ch)
  377. {
  378. return (*this = fromUtf8(ch));
  379. }
  380. };
  381. //---------------------------------------------------------------------------------------------------------------------
  382. // Custom QMessageBox which resizes itself to fit text
  383. class QMessageBoxWithBetterWidth : public QMessageBox
  384. {
  385. public:
  386. inline QMessageBoxWithBetterWidth(QWidget* const parent)
  387. : QMessageBox(parent) {}
  388. protected:
  389. void showEvent(QShowEvent* event);
  390. };
  391. //---------------------------------------------------------------------------------------------------------------------
  392. // Safer QSettings class, which does not throw if type mismatches
  393. class QSafeSettings : public QSettings
  394. {
  395. public:
  396. inline QSafeSettings()
  397. : QSettings() {}
  398. inline QSafeSettings(const QString organizationName, const QString applicationName)
  399. : QSettings(organizationName, applicationName) {}
  400. bool valueBool(const QString key, const bool defaultValue) const;
  401. Qt::CheckState valueCheckState(const QString key, const Qt::CheckState defaultValue) const;
  402. int valueIntPositive(const QString key, const int defaultValue) const;
  403. uint valueUInt(const QString key, const uint defaultValue) const;
  404. double valueDouble(const QString key, const double defaultValue) const;
  405. QString valueString(const QString key, const QString defaultValue) const;
  406. QByteArray valueByteArray(const QString key, const QByteArray defaultValue = QByteArray()) const;
  407. QStringList valueStringList(const QString key, const QStringList defaultValue = QStringList()) const;
  408. };
  409. //---------------------------------------------------------------------------------------------------------------------
  410. // Custom MessageBox
  411. int CustomMessageBox(QWidget* parent, QMessageBox::Icon icon, QString title, QString text,
  412. QString extraText = "",
  413. QMessageBox::StandardButtons buttons = QMessageBox::Yes|QMessageBox::No,
  414. QMessageBox::StandardButton defButton = QMessageBox::No);
  415. //---------------------------------------------------------------------------------------------------------------------
  416. #endif // CARLA_SHARED_HPP_INCLUDED