svcore  1.9
System.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _SYSTEM_H_
17 #define _SYSTEM_H_
18 
19 #include "base/Debug.h"
20 
21 #ifdef _WIN32
22 
23 #include <windows.h>
24 #include <malloc.h>
25 #include <process.h>
26 #include <math.h>
27 
28 #define MLOCK(a,b) 1
29 #define MUNLOCK(a,b) 1
30 #define MUNLOCK_SAMPLEBLOCK(a) 1
31 #define MUNLOCKALL() 1
32 
33 extern void SystemMemoryBarrier();
34 #define MBARRIER() SystemMemoryBarrier()
35 
36 #define DLOPEN(a,b) LoadLibrary((a).toStdWString().c_str())
37 #define DLSYM(a,b) GetProcAddress((HINSTANCE)(a),(b))
38 #define DLCLOSE(a) (!FreeLibrary((HINSTANCE)(a)))
39 #define DLERROR() ""
40 
41 #define PLUGIN_GLOB "*.dll"
42 #define PATH_SEPARATOR ';'
43 
44 // The default Vamp plugin path is obtained from a function in the
45 // Vamp SDK (Vamp::PluginHostAdapter::getPluginPath).
46 
47 // At the time of writing, at least, the vast majority of LADSPA
48 // plugins on Windows hosts will have been put there for use in
49 // Audacity. It's a bit of a shame that Audacity uses its own Program
50 // Files directory for plugins that any host may want to use... maybe
51 // they were just following the example of VSTs, which are usually
52 // found in Steinberg's Program Files directory. Anyway, we can
53 // greatly increase our chances of picking up some LADSPA plugins by
54 // default if we include the Audacity plugin location as well as an
55 // (imho) more sensible place.
56 
57 #define DEFAULT_LADSPA_PATH "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins"
58 #define DEFAULT_DSSI_PATH "%ProgramFiles%\\DSSI Plugins"
59 
60 #define getpid _getpid
61 
62 extern "C" {
63 /* usleep is now in mingw
64 void usleep(unsigned long usec);
65 */
66 int gettimeofday(struct timeval *p, void *tz);
67 }
68 
69 #define ISNAN std::isnan
70 #define ISINF std::isinf
71 
72 #else
73 
74 #include <sys/mman.h>
75 #include <dlfcn.h>
76 #include <stdio.h> // for perror
77 #include <cmath>
78 
79 #define MLOCK(a,b) ::mlock((a),(b))
80 #define MUNLOCK(a,b) (::munlock((a),(b)) ? (::perror("munlock failed"), 0) : 0)
81 #define MUNLOCK_SAMPLEBLOCK(a) do { if (!(a).empty()) { const float &b = *(a).begin(); MUNLOCK(&b, (a).capacity() * sizeof(float)); } } while(0);
82 //#define MLOCK(a,b) 1
83 //#define MUNLOCK(a,b) 1
84 //#define MUNLOCK_SAMPLEBLOCK(a) 1
85 
86 #define DLOPEN(a,b) dlopen((a).toStdString().c_str(),(b))
87 #define DLSYM(a,b) dlsym((a),(b))
88 #define DLCLOSE(a) dlclose((a))
89 #define DLERROR() dlerror()
90 
91 #include <cmath>
92 #define ISNAN std::isnan
93 #define ISINF std::isinf
94 
95 #ifdef __APPLE__
96 
97 #define PLUGIN_GLOB "*.dylib *.so"
98 #define PATH_SEPARATOR ':'
99 
100 #define DEFAULT_LADSPA_PATH "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA"
101 #define DEFAULT_DSSI_PATH "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI"
102 
103 #define MUNLOCKALL() 1
104 
105 #include <libkern/OSAtomic.h>
106 #define MBARRIER() OSMemoryBarrier()
107 
108 #else
109 
110 #ifdef sun
111 #undef MLOCK
112 #undef MUNLOCK
113 #define MLOCK(a,b) ::mlock((char *)a,b)
114 #define MUNLOCK(a,b) ::munlock((char *)a,b)
115 #ifdef __SUNPRO_CC
116 #undef ISNAN
117 #undef ISINF
118 #define ISNAN(x) ((x)!=(x))
119 #define ISINF(x) 0
120 #endif
121 #endif
122 
123 #define PLUGIN_GLOB "*.so"
124 #define PATH_SEPARATOR ':'
125 
126 #define DEFAULT_LADSPA_PATH "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa"
127 #define DEFAULT_DSSI_PATH "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi"
128 
129 #define MUNLOCKALL() ::munlockall()
130 
131 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
132 #define MBARRIER() __sync_synchronize()
133 #else
134 extern void SystemMemoryBarrier();
135 #define MBARRIER() SystemMemoryBarrier()
136 #endif
137 
138 #endif /* ! __APPLE__ */
139 
140 #endif /* ! _WIN32 */
141 
143 extern ProcessStatus GetProcessStatus(int pid);
144 
145 // Return a vague approximation to the number of free megabytes of real memory.
146 // Return -1 if unknown.
147 extern void GetRealMemoryMBAvailable(int &available, int &total);
148 
149 // Return a vague approximation to the number of free megabytes of disc space
150 // on the partition containing the given path. Return -1 if unknown.
151 extern int GetDiscSpaceMBAvailable(const char *path);
152 
153 extern void StoreStartupLocale();
154 extern void RestoreStartupLocale();
155 
156 #include <cmath>
157 
158 extern double mod(double x, double y);
159 extern float modf(float x, float y);
160 
161 extern double princarg(double a);
162 extern float princargf(float a);
163 
164 #ifdef USE_POW_NO_F
165 #define powf pow
166 #endif
167 
168 #endif /* ! _SYSTEM_H_ */
169 
170 
float princargf(float a)
Definition: System.cpp:326
ProcessStatus GetProcessStatus(int pid)
Definition: System.cpp:84
void GetRealMemoryMBAvailable(int &available, int &total)
Definition: System.cpp:126
void StoreStartupLocale()
Definition: System.cpp:304
double princarg(double a)
Definition: System.cpp:325
ProcessStatus
Definition: System.h:142
void SystemMemoryBarrier()
Definition: System.cpp:291
int GetDiscSpaceMBAvailable(const char *path)
Definition: System.cpp:247
double mod(double x, double y)
Definition: System.cpp:322
void RestoreStartupLocale()
Definition: System.cpp:313
float modf(float x, float y)
Definition: System.cpp:323