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_shared.hpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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_PATHS_JSFX "Paths/JSFX"
  154. #define CARLA_KEY_WINE_EXECUTABLE "Wine/Executable" /* str */
  155. #define CARLA_KEY_WINE_AUTO_PREFIX "Wine/AutoPrefix" /* bool */
  156. #define CARLA_KEY_WINE_FALLBACK_PREFIX "Wine/FallbackPrefix" /* str */
  157. #define CARLA_KEY_WINE_RT_PRIO_ENABLED "Wine/RtPrioEnabled" /* bool */
  158. #define CARLA_KEY_WINE_BASE_RT_PRIO "Wine/BaseRtPrio" /* int */
  159. #define CARLA_KEY_WINE_SERVER_RT_PRIO "Wine/ServerRtPrio" /* int */
  160. #define CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES "Experimental/PluginBridges" /* bool */
  161. #define CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES "Experimental/WineBridges" /* bool */
  162. #define CARLA_KEY_EXPERIMENTAL_JACK_APPS "Experimental/JackApplications" /* bool */
  163. #define CARLA_KEY_EXPERIMENTAL_EXPORT_LV2 "Experimental/ExportLV2" /* bool */
  164. #define CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR "Experimental/PreventBadBehaviour" /* bool */
  165. #define CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL "Experimental/LoadLibGlobal" /* bool */
  166. // if pro theme is on and color is black
  167. #define CARLA_KEY_CUSTOM_PAINTING "UseCustomPainting" /* bool */
  168. //---------------------------------------------------------------------------------------------------------------------
  169. // Carla Settings defaults
  170. // Main
  171. #define CARLA_DEFAULT_MAIN_PROJECT_FOLDER QDir::homePath()
  172. #define CARLA_DEFAULT_MAIN_USE_PRO_THEME true
  173. #define CARLA_DEFAULT_MAIN_PRO_THEME_COLOR "Black"
  174. #define CARLA_DEFAULT_MAIN_REFRESH_INTERVAL 20
  175. #define CARLA_DEFAULT_MAIN_CONFIRM_EXIT true
  176. #ifdef CARLA_OS_WIN
  177. # define CARLA_DEFAULT_MAIN_SHOW_LOGS false
  178. #else
  179. # define CARLA_DEFAULT_MAIN_SHOW_LOGS true
  180. #endif
  181. #define CARLA_DEFAULT_MAIN_EXPERIMENTAL false
  182. // Canvas
  183. #define CARLA_DEFAULT_CANVAS_THEME "Modern Dark"
  184. #define CARLA_DEFAULT_CANVAS_SIZE "3100x2400"
  185. #define CARLA_DEFAULT_CANVAS_SIZE_WIDTH 3100
  186. #define CARLA_DEFAULT_CANVAS_SIZE_HEIGHT 2400
  187. #define CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES true
  188. #define CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS true
  189. #define CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS false
  190. #define CARLA_DEFAULT_CANVAS_EYE_CANDY true
  191. #define CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY false
  192. #define CARLA_DEFAULT_CANVAS_USE_OPENGL false
  193. #define CARLA_DEFAULT_CANVAS_ANTIALIASING CANVAS_ANTIALIASING_SMALL
  194. #define CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING false
  195. #define CARLA_DEFAULT_CANVAS_INLINE_DISPLAYS false
  196. #define CARLA_DEFAULT_CANVAS_FULL_REPAINTS false
  197. // Engine
  198. #define CARLA_DEFAULT_FORCE_STEREO false
  199. #define CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES false
  200. #define CARLA_DEFAULT_PREFER_UI_BRIDGES true
  201. #define CARLA_DEFAULT_MANAGE_UIS true
  202. #define CARLA_DEFAULT_UIS_ALWAYS_ON_TOP false
  203. #define CARLA_DEFAULT_MAX_PARAMETERS MAX_DEFAULT_PARAMETERS
  204. #define CARLA_DEFAULT_RESET_XRUNS false
  205. #define CARLA_DEFAULT_UI_BRIDGES_TIMEOUT 4000
  206. #define CARLA_DEFAULT_AUDIO_BUFFER_SIZE 512
  207. #define CARLA_DEFAULT_AUDIO_SAMPLE_RATE 44100
  208. #define CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER false
  209. #if defined(CARLA_OS_WIN)
  210. # define CARLA_DEFAULT_AUDIO_DRIVER "DirectSound"
  211. #elif defined(CARLA_OS_MAC)
  212. # define CARLA_DEFAULT_AUDIO_DRIVER "CoreAudio"
  213. #else
  214. // if os.path.exists("/usr/bin/jackd") or os.path.exists("/usr/bin/jackdbus"):
  215. # define CARLA_DEFAULT_AUDIO_DRIVER "JACK"
  216. // # define CARLA_DEFAULT_AUDIO_DRIVER "PulseAudio"
  217. #endif
  218. // #if CARLA_DEFAULT_AUDIO_DRIVER == "JACK"
  219. // # define CARLA_DEFAULT_PROCESS_MODE ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS
  220. // # define CARLA_DEFAULT_TRANSPORT_MODE ENGINE_TRANSPORT_MODE_JACK
  221. // #else
  222. # define CARLA_DEFAULT_PROCESS_MODE ENGINE_PROCESS_MODE_PATCHBAY
  223. # define CARLA_DEFAULT_TRANSPORT_MODE ENGINE_TRANSPORT_MODE_INTERNAL
  224. // #endif
  225. // OSC
  226. #ifdef CARLA_OS_WIN
  227. # define CARLA_DEFAULT_OSC_ENABLED false
  228. #else
  229. # define CARLA_DEFAULT_OSC_ENABLED true
  230. #endif
  231. #define CARLA_DEFAULT_OSC_TCP_PORT_ENABLED true
  232. #define CARLA_DEFAULT_OSC_TCP_PORT_NUMBER 22752
  233. #define CARLA_DEFAULT_OSC_TCP_PORT_RANDOM false
  234. #define CARLA_DEFAULT_OSC_UDP_PORT_ENABLED true
  235. #define CARLA_DEFAULT_OSC_UDP_PORT_NUMBER 22752
  236. #define CARLA_DEFAULT_OSC_UDP_PORT_RANDOM false
  237. // Wine
  238. #define CARLA_DEFAULT_WINE_EXECUTABLE "wine"
  239. #define CARLA_DEFAULT_WINE_AUTO_PREFIX true
  240. #define CARLA_DEFAULT_WINE_FALLBACK_PREFIX QDir::homePath() + "/.wine"
  241. #define CARLA_DEFAULT_WINE_RT_PRIO_ENABLED true
  242. #define CARLA_DEFAULT_WINE_BASE_RT_PRIO 15
  243. #define CARLA_DEFAULT_WINE_SERVER_RT_PRIO 10
  244. // Experimental
  245. #define CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES false
  246. #define CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES false
  247. #define CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS false
  248. #define CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT false
  249. #define CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR false
  250. #define CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL false
  251. //---------------------------------------------------------------------------------------------------------------------
  252. // Default File Folders
  253. #define CARLA_DEFAULT_FILE_PATH_AUDIO {}
  254. #define CARLA_DEFAULT_FILE_PATH_MIDI {}
  255. //---------------------------------------------------------------------------------------------------------------------
  256. // Default Plugin Folders (get)
  257. #define DEFAULT_LADSPA_PATH ""
  258. #define DEFAULT_DSSI_PATH ""
  259. #define DEFAULT_LV2_PATH ""
  260. #define DEFAULT_VST2_PATH ""
  261. #define DEFAULT_VST3_PATH ""
  262. #define DEFAULT_SF2_PATH ""
  263. #define DEFAULT_SFZ_PATH ""
  264. #define DEFAULT_JSFX_PATH ""
  265. #ifdef CARLA_OS_WIN
  266. # define CARLA_PATH_SPLITTER ";"
  267. #else
  268. # define CARLA_PATH_SPLITTER ":"
  269. #endif
  270. //---------------------------------------------------------------------------------------------------------------------
  271. // Default Plugin Folders (set)
  272. /*
  273. readEnvVars = True
  274. if WINDOWS:
  275. # Check if running Wine. If yes, ignore env vars
  276. from winreg import ConnectRegistry, OpenKey, CloseKey, HKEY_CURRENT_USER
  277. reg = ConnectRegistry(None, HKEY_CURRENT_USER)
  278. try:
  279. key = OpenKey(reg, r"SOFTWARE\Wine")
  280. CloseKey(key)
  281. del key
  282. readEnvVars = False
  283. except:
  284. pass
  285. CloseKey(reg)
  286. del reg
  287. */
  288. /*
  289. #ifndef CARLA_OS_WIN
  290. # define CARLA_DEFAULT_LADSPA_PATH = std::getenv("LADSPA_PATH", DEFAULT_LADSPA_PATH).split(CARLA_PATH_SPLITTER)
  291. # define CARLA_DEFAULT_DSSI_PATH = std::getenv("DSSI_PATH", DEFAULT_DSSI_PATH).split(CARLA_PATH_SPLITTER)
  292. # define CARLA_DEFAULT_LV2_PATH = std::getenv("LV2_PATH", DEFAULT_LV2_PATH).split(CARLA_PATH_SPLITTER)
  293. # define CARLA_DEFAULT_VST2_PATH = std::getenv("VST_PATH", DEFAULT_VST2_PATH).split(CARLA_PATH_SPLITTER)
  294. # define CARLA_DEFAULT_VST3_PATH = std::getenv("VST3_PATH", DEFAULT_VST3_PATH).split(CARLA_PATH_SPLITTER)
  295. # define CARLA_DEFAULT_SF2_PATH = std::getenv("SF2_PATH", DEFAULT_SF2_PATH).split(CARLA_PATH_SPLITTER)
  296. # define CARLA_DEFAULT_SFZ_PATH = std::getenv("SFZ_PATH", DEFAULT_SFZ_PATH).split(CARLA_PATH_SPLITTER)
  297. # define CARLA_DEFAULT_JSFX_PATH = std::getenv("JSFX_PATH", DEFAULT_JSFX_PATH).split(CARLA_PATH_SPLITTER)
  298. #else
  299. */
  300. # define CARLA_DEFAULT_LADSPA_PATH QString(DEFAULT_LADSPA_PATH).split(CARLA_PATH_SPLITTER)
  301. # define CARLA_DEFAULT_DSSI_PATH QString(DEFAULT_DSSI_PATH).split(CARLA_PATH_SPLITTER)
  302. # define CARLA_DEFAULT_LV2_PATH QString(DEFAULT_LV2_PATH).split(CARLA_PATH_SPLITTER)
  303. # define CARLA_DEFAULT_VST2_PATH QString(DEFAULT_VST2_PATH).split(CARLA_PATH_SPLITTER)
  304. # define CARLA_DEFAULT_VST3_PATH QString(DEFAULT_VST3_PATH).split(CARLA_PATH_SPLITTER)
  305. # define CARLA_DEFAULT_SF2_PATH QString(DEFAULT_SF2_PATH).split(CARLA_PATH_SPLITTER)
  306. # define CARLA_DEFAULT_SFZ_PATH QString(DEFAULT_SFZ_PATH).split(CARLA_PATH_SPLITTER)
  307. # define CARLA_DEFAULT_JSFX_PATH QString(DEFAULT_JSFX_PATH).split(CARLA_PATH_SPLITTER)
  308. /*
  309. #endif
  310. */
  311. //---------------------------------------------------------------------------------------------------------------------
  312. // Global Carla object
  313. struct CarlaObject {
  314. CarlaHost* host;
  315. QWidget* gui;
  316. bool nogui; // Skip UI
  317. bool term; // Terminated by OS signal
  318. CarlaObject() noexcept;
  319. };
  320. extern CarlaObject gCarla;
  321. //---------------------------------------------------------------------------------------------------------------------
  322. // Set DLL_EXTENSION
  323. #if defined(CARLA_OS_WIN)
  324. # define DLL_EXTENSION "dll"
  325. #elif defined(CARLA_OS_MAC)
  326. # define DLL_EXTENSION "dylib"
  327. #else
  328. # define DLL_EXTENSION "so"
  329. #endif
  330. //---------------------------------------------------------------------------------------------------------------------
  331. // Get Icon from user theme, using our own as backup (Oxygen)
  332. QIcon getIcon(QString icon, int size = 16);
  333. //---------------------------------------------------------------------------------------------------------------------
  334. // Handle some basic command-line arguments shared between all carla variants
  335. QString handleInitialCommandLineArguments(const int argc, char* argv[]);
  336. //---------------------------------------------------------------------------------------------------------------------
  337. // Get initial project file (as passed in the command-line parameters)
  338. QString getInitialProjectFile(bool skipExistCheck = false);
  339. //---------------------------------------------------------------------------------------------------------------------
  340. // Get paths (binaries, resources)
  341. bool getPaths(QString& pathBinaries, QString& pathResources);
  342. //---------------------------------------------------------------------------------------------------------------------
  343. // Signal handler
  344. void setUpSignals();
  345. //---------------------------------------------------------------------------------------------------------------------
  346. // QLineEdit and QPushButton combo
  347. QString getAndSetPath(QWidget* parent, QLineEdit* lineEdit);
  348. //---------------------------------------------------------------------------------------------------------------------
  349. // fill up a qlists from a C arrays
  350. void fillQStringListFromStringArray(QStringList& list, const char* const* const stringArray);
  351. void fillQDoubleListFromDoubleArray(QList<double>& list, const double* const doubleArray);
  352. void fillQUIntListFromUIntArray(QList<uint>& list, const uint* const uintArray);
  353. //---------------------------------------------------------------------------------------------------------------------
  354. // Backwards-compatible horizontalAdvance/width call, depending on Qt version
  355. int fontMetricsHorizontalAdvance(const QFontMetrics& fm, const QString& s);
  356. //---------------------------------------------------------------------------------------------------------------------
  357. // Check if a string array contains a string
  358. bool stringArrayContainsString(const char* const* const stringArray, const char* const string) noexcept;
  359. //---------------------------------------------------------------------------------------------------------------------
  360. // Get index of a QList<double> value
  361. int getIndexOfQDoubleListValue(const QList<double>& list, const double value);
  362. //---------------------------------------------------------------------------------------------------------------------
  363. // Check if two QList<double> instances match
  364. bool isQDoubleListEqual(const QList<double>& list1, const QList<double>& list2);
  365. //---------------------------------------------------------------------------------------------------------------------
  366. // Custom QString class with a few extra methods
  367. class QCarlaString : public QString
  368. {
  369. public:
  370. inline QCarlaString()
  371. : QString() {}
  372. inline QCarlaString(const char* const ch)
  373. : QString(ch) {}
  374. inline QCarlaString(const QString& s)
  375. : QString(s) {}
  376. inline bool isNotEmpty() const
  377. {
  378. return !isEmpty();
  379. }
  380. inline QCarlaString& operator=(const char* const ch)
  381. {
  382. return (*this = fromUtf8(ch));
  383. }
  384. };
  385. //---------------------------------------------------------------------------------------------------------------------
  386. // Custom QMessageBox which resizes itself to fit text
  387. class QMessageBoxWithBetterWidth : public QMessageBox
  388. {
  389. public:
  390. inline QMessageBoxWithBetterWidth(QWidget* const parent)
  391. : QMessageBox(parent) {}
  392. protected:
  393. void showEvent(QShowEvent* event);
  394. };
  395. //---------------------------------------------------------------------------------------------------------------------
  396. // Safer QSettings class, which does not throw if type mismatches
  397. class QSafeSettings : public QSettings
  398. {
  399. public:
  400. inline QSafeSettings()
  401. : QSettings() {}
  402. inline QSafeSettings(const QString organizationName, const QString applicationName)
  403. : QSettings(organizationName, applicationName) {}
  404. bool valueBool(const QString key, const bool defaultValue) const;
  405. Qt::CheckState valueCheckState(const QString key, const Qt::CheckState defaultValue) const;
  406. int valueIntPositive(const QString key, const int defaultValue) const;
  407. uint valueUInt(const QString key, const uint defaultValue) const;
  408. double valueDouble(const QString key, const double defaultValue) const;
  409. QString valueString(const QString key, const QString defaultValue) const;
  410. QByteArray valueByteArray(const QString key, const QByteArray defaultValue = QByteArray()) const;
  411. QStringList valueStringList(const QString key, const QStringList defaultValue = QStringList()) const;
  412. };
  413. //---------------------------------------------------------------------------------------------------------------------
  414. // Custom MessageBox
  415. int CustomMessageBox(QWidget* parent, QMessageBox::Icon icon, QString title, QString text,
  416. QString extraText = "",
  417. QMessageBox::StandardButtons buttons = QMessageBox::Yes|QMessageBox::No,
  418. QMessageBox::StandardButton defButton = QMessageBox::No);
  419. //---------------------------------------------------------------------------------------------------------------------
  420. #endif // CARLA_SHARED_HPP_INCLUDED