svcore  1.9
System.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _SYSTEM_H_
00017 #define _SYSTEM_H_
00018 
00019 #include "base/Debug.h"
00020 
00021 #ifdef _WIN32
00022 
00023 #include <windows.h>
00024 #include <malloc.h>
00025 #include <process.h>
00026 #include <math.h>
00027 
00028 #define MLOCK(a,b)   1
00029 #define MUNLOCK(a,b) 1
00030 #define MUNLOCK_SAMPLEBLOCK(a) 1
00031 #define MUNLOCKALL() 1
00032 
00033 extern void SystemMemoryBarrier();
00034 #define MBARRIER()   SystemMemoryBarrier()
00035 
00036 #define DLOPEN(a,b)  LoadLibrary((a).toStdWString().c_str())
00037 #define DLSYM(a,b)   GetProcAddress((HINSTANCE)(a),(b))
00038 #define DLCLOSE(a)   (!FreeLibrary((HINSTANCE)(a)))
00039 #define DLERROR()    ""
00040 
00041 #define PLUGIN_GLOB  "*.dll"
00042 #define PATH_SEPARATOR ';'
00043 
00044 // The default Vamp plugin path is obtained from a function in the
00045 // Vamp SDK (Vamp::PluginHostAdapter::getPluginPath).
00046 
00047 // At the time of writing, at least, the vast majority of LADSPA
00048 // plugins on Windows hosts will have been put there for use in
00049 // Audacity.  It's a bit of a shame that Audacity uses its own Program
00050 // Files directory for plugins that any host may want to use... maybe
00051 // they were just following the example of VSTs, which are usually
00052 // found in Steinberg's Program Files directory.  Anyway, we can
00053 // greatly increase our chances of picking up some LADSPA plugins by
00054 // default if we include the Audacity plugin location as well as an
00055 // (imho) more sensible place.
00056 
00057 #define DEFAULT_LADSPA_PATH "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins"
00058 #define DEFAULT_DSSI_PATH   "%ProgramFiles%\\DSSI Plugins"
00059 
00060 #define getpid _getpid
00061 
00062 extern "C" {
00063 /* usleep is now in mingw
00064 void usleep(unsigned long usec);
00065 */
00066 int gettimeofday(struct timeval *p, void *tz);
00067 }
00068 
00069 #define ISNAN std::isnan
00070 #define ISINF std::isinf
00071 
00072 #else
00073 
00074 #include <sys/mman.h>
00075 #include <dlfcn.h>
00076 #include <stdio.h> // for perror
00077 #include <cmath>
00078 
00079 #define MLOCK(a,b)   ::mlock((a),(b))
00080 #define MUNLOCK(a,b) (::munlock((a),(b)) ? (::perror("munlock failed"), 0) : 0)
00081 #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0);
00082 //#define MLOCK(a,b)   1
00083 //#define MUNLOCK(a,b) 1
00084 //#define MUNLOCK_SAMPLEBLOCK(a) 1
00085 
00086 #define DLOPEN(a,b)  dlopen((a).toStdString().c_str(),(b))
00087 #define DLSYM(a,b)   dlsym((a),(b))
00088 #define DLCLOSE(a)   dlclose((a))
00089 #define DLERROR()    dlerror()
00090 
00091 #include <cmath>
00092 #define ISNAN std::isnan
00093 #define ISINF std::isinf
00094 
00095 #ifdef __APPLE__
00096 
00097 #define PLUGIN_GLOB  "*.dylib *.so"
00098 #define PATH_SEPARATOR ':'
00099 
00100 #define DEFAULT_LADSPA_PATH "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA"
00101 #define DEFAULT_DSSI_PATH   "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI"
00102 
00103 #define MUNLOCKALL() 1
00104 
00105 #include <libkern/OSAtomic.h>
00106 #define MBARRIER() OSMemoryBarrier()
00107 
00108 #else 
00109 
00110 #ifdef sun
00111 #undef MLOCK
00112 #undef MUNLOCK
00113 #define MLOCK(a,b) ::mlock((char *)a,b)
00114 #define MUNLOCK(a,b) ::munlock((char *)a,b)
00115 #ifdef __SUNPRO_CC
00116 #undef ISNAN
00117 #undef ISINF
00118 #define ISNAN(x) ((x)!=(x))
00119 #define ISINF(x) 0
00120 #endif
00121 #endif
00122 
00123 #define PLUGIN_GLOB  "*.so"
00124 #define PATH_SEPARATOR ':'
00125 
00126 #define DEFAULT_LADSPA_PATH "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa"
00127 #define DEFAULT_DSSI_PATH "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi"
00128 
00129 #define MUNLOCKALL() ::munlockall()
00130 
00131 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
00132 #define MBARRIER() __sync_synchronize()
00133 #else
00134 extern void SystemMemoryBarrier();
00135 #define MBARRIER() SystemMemoryBarrier()
00136 #endif
00137 
00138 #endif /* ! __APPLE__ */
00139 
00140 #endif /* ! _WIN32 */
00141 
00142 enum ProcessStatus { ProcessRunning, ProcessNotRunning, UnknownProcessStatus };
00143 extern ProcessStatus GetProcessStatus(int pid);
00144 
00145 // Return a vague approximation to the number of free megabytes of real memory.
00146 // Return -1 if unknown.
00147 extern void GetRealMemoryMBAvailable(int &available, int &total);
00148 
00149 // Return a vague approximation to the number of free megabytes of disc space
00150 // on the partition containing the given path.  Return -1 if unknown.
00151 extern int GetDiscSpaceMBAvailable(const char *path);
00152 
00153 extern void StoreStartupLocale();
00154 extern void RestoreStartupLocale();
00155 
00156 #include <cmath>
00157 
00158 extern double mod(double x, double y);
00159 extern float modf(float x, float y);
00160 
00161 extern double princarg(double a);
00162 extern float princargf(float a);
00163 
00164 #ifdef USE_POW_NO_F
00165 #define powf pow
00166 #endif
00167 
00168 #endif /* ! _SYSTEM_H_ */
00169 
00170