Chris@150: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@150: Chris@150: /* Chris@150: Sonic Visualiser Chris@150: An audio file viewer and annotation editor. Chris@150: Centre for Digital Music, Queen Mary, University of London. Chris@1475: This file copyright 2006-2018 Chris Cannam and QMUL. Chris@150: Chris@150: This program is free software; you can redistribute it and/or Chris@150: modify it under the terms of the GNU General Public License as Chris@150: published by the Free Software Foundation; either version 2 of the Chris@150: License, or (at your option) any later version. See the file Chris@150: COPYING included with this distribution for more information. Chris@150: */ Chris@150: Chris@1475: #ifndef SV_SYSTEM_H Chris@1475: #define SV_SYSTEM_H Chris@150: Chris@687: #include "base/Debug.h" Chris@687: Chris@150: #ifdef _WIN32 Chris@150: Chris@150: #include Chris@150: #include Chris@150: #include Chris@606: #include Chris@150: Chris@150: #define MLOCK(a,b) 1 Chris@150: #define MUNLOCK(a,b) 1 Chris@150: #define MUNLOCK_SAMPLEBLOCK(a) 1 Chris@368: #define MUNLOCKALL() 1 Chris@150: Chris@835: extern void SystemMemoryBarrier(); Chris@835: #define MBARRIER() SystemMemoryBarrier() Chris@835: Chris@150: #define DLOPEN(a,b) LoadLibrary((a).toStdWString().c_str()) Chris@150: #define DLSYM(a,b) GetProcAddress((HINSTANCE)(a),(b)) Chris@223: #define DLCLOSE(a) (!FreeLibrary((HINSTANCE)(a))) Chris@150: #define DLERROR() "" Chris@150: Chris@150: #define PLUGIN_GLOB "*.dll" Chris@223: #define PATH_SEPARATOR ';' Chris@186: Chris@219: // The default Vamp plugin path is obtained from a function in the Chris@219: // Vamp SDK (Vamp::PluginHostAdapter::getPluginPath). Chris@186: Chris@219: // At the time of writing, at least, the vast majority of LADSPA Chris@219: // plugins on Windows hosts will have been put there for use in Chris@219: // Audacity. It's a bit of a shame that Audacity uses its own Program Chris@219: // Files directory for plugins that any host may want to use... maybe Chris@219: // they were just following the example of VSTs, which are usually Chris@219: // found in Steinberg's Program Files directory. Anyway, we can Chris@219: // greatly increase our chances of picking up some LADSPA plugins by Chris@219: // default if we include the Audacity plugin location as well as an Chris@219: // (imho) more sensible place. Chris@219: Chris@223: #define DEFAULT_LADSPA_PATH "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins" Chris@186: #define DEFAULT_DSSI_PATH "%ProgramFiles%\\DSSI Plugins" Chris@150: Chris@150: #define getpid _getpid Chris@150: Chris@1216: #if defined(_MSC_VER) Chris@1216: #include Chris@1216: typedef SSIZE_T ssize_t; Chris@1216: #endif Chris@1216: Chris@1232: #ifdef _MSC_VER Chris@150: extern "C" { Chris@150: void usleep(unsigned long usec); Chris@1232: } Chris@1232: #else Chris@1232: #include Chris@1218: #endif Chris@1218: Chris@1232: extern "C" { Chris@501: int gettimeofday(struct timeval *p, void *tz); Chris@150: } Chris@150: Chris@765: #define ISNAN std::isnan Chris@765: #define ISINF std::isinf Chris@606: Chris@150: #else Chris@150: Chris@150: #include Chris@150: #include Chris@602: #include // for perror Chris@606: #include Chris@1219: #include // sleep + usleep primarily Chris@150: Chris@150: #define MLOCK(a,b) ::mlock((a),(b)) Chris@150: #define MUNLOCK(a,b) (::munlock((a),(b)) ? (::perror("munlock failed"), 0) : 0) Chris@150: #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0); Chris@232: //#define MLOCK(a,b) 1 Chris@232: //#define MUNLOCK(a,b) 1 Chris@232: //#define MUNLOCK_SAMPLEBLOCK(a) 1 Chris@150: Chris@150: #define DLOPEN(a,b) dlopen((a).toStdString().c_str(),(b)) Chris@150: #define DLSYM(a,b) dlsym((a),(b)) Chris@150: #define DLCLOSE(a) dlclose((a)) Chris@150: #define DLERROR() dlerror() Chris@150: Chris@606: #include Chris@606: #define ISNAN std::isnan Chris@606: #define ISINF std::isinf Chris@606: Chris@150: #ifdef __APPLE__ Chris@150: Chris@255: #define PLUGIN_GLOB "*.dylib *.so" Chris@223: #define PATH_SEPARATOR ':' Chris@186: Chris@186: #define DEFAULT_LADSPA_PATH "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA" Chris@186: #define DEFAULT_DSSI_PATH "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI" Chris@150: Chris@368: #define MUNLOCKALL() 1 Chris@368: Chris@835: #include Chris@835: #define MBARRIER() OSMemoryBarrier() Chris@835: Chris@150: #else Chris@150: Chris@606: #ifdef sun Chris@606: #undef MLOCK Chris@606: #undef MUNLOCK Chris@606: #define MLOCK(a,b) ::mlock((char *)a,b) Chris@606: #define MUNLOCK(a,b) ::munlock((char *)a,b) Chris@606: #ifdef __SUNPRO_CC Chris@606: #undef ISNAN Chris@606: #undef ISINF Chris@606: #define ISNAN(x) ((x)!=(x)) Chris@606: #define ISINF(x) 0 Chris@606: #endif Chris@606: #endif Chris@606: Chris@150: #define PLUGIN_GLOB "*.so" Chris@223: #define PATH_SEPARATOR ':' Chris@186: Chris@186: #define DEFAULT_LADSPA_PATH "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa" Chris@186: #define DEFAULT_DSSI_PATH "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi" Chris@150: Chris@368: #define MUNLOCKALL() ::munlockall() Chris@368: Chris@835: #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) Chris@835: #define MBARRIER() __sync_synchronize() Chris@835: #else Chris@835: extern void SystemMemoryBarrier(); Chris@835: #define MBARRIER() SystemMemoryBarrier() Chris@835: #endif Chris@835: Chris@835: #endif /* ! __APPLE__ */ Chris@150: Chris@150: #endif /* ! _WIN32 */ Chris@150: Chris@150: enum ProcessStatus { ProcessRunning, ProcessNotRunning, UnknownProcessStatus }; Chris@150: extern ProcessStatus GetProcessStatus(int pid); Chris@150: Chris@168: // Return a vague approximation to the number of free megabytes of real memory. Chris@1405: // Return -1 if unknown. (Hence signed args.) Note that this could be more than Chris@1405: // is actually addressable, e.g. for a 32-bit process on a 64-bit system. Chris@1038: extern void GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total); Chris@168: Chris@1038: // Return a vague approximation to the number of free megabytes of Chris@1038: // disc space on the partition containing the given path. Return -1 Chris@1038: // if unknown. (Hence signed return type) Chris@1038: extern ssize_t GetDiscSpaceMBAvailable(const char *path); Chris@168: Chris@1818: // Return true if the OS desktop is set to use a dark mode Chris@1818: // theme. Return false if it is set to a light theme or if the theme Chris@1818: // is unknown. Chris@1819: extern bool OSReportsDarkThemeActive(); Chris@1818: Chris@1820: // Return true if the OS desktop reports an accent colour to go with Chris@1820: // the current theme; if so, also return by reference the r, g, and b Chris@1820: // components of the colour (range 0-255). Return false if we can't Chris@1820: // query such a thing. Chris@1820: extern bool OSQueryAccentColour(int &r, int &g, int &b); Chris@1820: Chris@303: extern void StoreStartupLocale(); Chris@303: extern void RestoreStartupLocale(); Chris@303: Chris@150: #include Chris@150: Chris@1059: #ifndef M_PI Chris@1059: #define M_PI 3.14159265358979323846 Chris@1059: #endif Chris@1059: Chris@150: extern double mod(double x, double y); Chris@150: extern float modf(float x, float y); Chris@150: Chris@150: extern double princarg(double a); Chris@150: extern float princargf(float a); Chris@150: Chris@573: #ifdef USE_POW_NO_F Chris@573: #define powf pow Chris@573: #endif Chris@573: Chris@1475: /** Return the value of the given environment variable by reference. Chris@1475: Return true if successfully retrieved, false if unset or on error. Chris@1475: Both the variable name and the returned value are UTF-8 encoded. Chris@1475: */ Chris@1475: extern bool getEnvUtf8(std::string variable, std::string &value); Chris@1475: Chris@1475: /** Set the value of the given environment variable. Chris@1475: Return true if successfully set, false on error. Chris@1475: Both the variable name and the value must be UTF-8 encoded. Chris@1475: */ Chris@1475: extern bool putEnvUtf8(std::string variable, std::string value); Chris@1475: Chris@150: #endif /* ! _SYSTEM_H_ */ Chris@150: Chris@150: