1 |
schoenebeck |
1424 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
2885 |
* Copyright (C) 2005 - 2016 Christian Schoenebeck * |
7 |
schoenebeck |
1424 |
* * |
8 |
|
|
* This program is free software; you can redistribute it and/or modify * |
9 |
|
|
* it under the terms of the GNU General Public License as published by * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (at your option) any later version. * |
12 |
|
|
* * |
13 |
|
|
* This program is distributed in the hope that it will be useful, * |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
|
|
* along with this program; if not, write to the Free Software * |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
// All application global declarations, that are not going to be exposed to |
25 |
|
|
// the C++ API are defined here. |
26 |
|
|
|
27 |
|
|
#ifndef __LS_GLOBAL_PRIVATE_H__ |
28 |
|
|
#define __LS_GLOBAL_PRIVATE_H__ |
29 |
|
|
|
30 |
|
|
#include "global.h" |
31 |
iliev |
1832 |
#include "Exception.h" |
32 |
schoenebeck |
1424 |
#include <sstream> |
33 |
schoenebeck |
2885 |
#include <algorithm> |
34 |
|
|
#include <math.h> |
35 |
schoenebeck |
1424 |
|
36 |
|
|
#if HAVE_CONFIG_H |
37 |
|
|
# include <config.h> |
38 |
|
|
#endif |
39 |
|
|
|
40 |
|
|
#if CONFIG_DEBUG_LEVEL > 0 |
41 |
|
|
# define dmsg(debuglevel,x) if (CONFIG_DEBUG_LEVEL >= debuglevel) {printf x; fflush(stdout);} |
42 |
|
|
#else |
43 |
|
|
# define dmsg(debuglevel,x) |
44 |
|
|
#endif // CONFIG_DEBUG_LEVEL > 0 |
45 |
|
|
|
46 |
|
|
#define EMMS __asm__ __volatile__ ("emms" ::: "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7") |
47 |
|
|
|
48 |
|
|
/// defines globally the bit depth of used samples |
49 |
|
|
typedef int16_t sample_t; |
50 |
|
|
|
51 |
senoner |
1913 |
// macro to check for a certain version (or newer) of GCC |
52 |
|
|
#define GNUC_VERSION_PREREQ(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
53 |
schoenebeck |
1930 |
|
54 |
senoner |
1913 |
// macro which checks if GCC vector extensions are avialable |
55 |
|
|
#define HAVE_GCC_VECTOR_EXTENSIONS ( GNUC_VERSION_PREREQ(3,3) && ( defined(__i386__) || defined(__x86_64__) || defined(_ARCH_PPC) ) ) |
56 |
schoenebeck |
1930 |
|
57 |
|
|
#if HAVE_GCC_VECTOR_EXTENSIONS |
58 |
senoner |
1913 |
// v4sf is used by some routines that make use of GCC vector extensions (ie AudioChannel.cpp) |
59 |
|
|
typedef float v4sf __attribute__ ((vector_size(16))); |
60 |
schoenebeck |
1930 |
#endif |
61 |
senoner |
1913 |
|
62 |
schoenebeck |
2600 |
// circumvents a bug in GCC 4.x which causes a sizeof() expression applied |
63 |
|
|
// on a class member to throw a compiler error, i.e. with GCC 4.4: |
64 |
|
|
// "object missing in reference to 'LinuxSampler::AbstractEngineChannel::ControllerTable'") |
65 |
|
|
// or with GCC 4.0: |
66 |
|
|
// "invalid use of non-static data member 'LinuxSampler::AbstractEngineChannel::ControllerTable'" |
67 |
|
|
#define _MEMBER_SIZEOF(T_Class, Member) sizeof(((T_Class*)NULL)->Member) |
68 |
|
|
|
69 |
schoenebeck |
1424 |
/** |
70 |
|
|
* Whether a function / method call was successful, or if warnings or even an |
71 |
|
|
* error occured. |
72 |
|
|
*/ |
73 |
|
|
enum result_type_t { |
74 |
|
|
result_type_success, |
75 |
|
|
result_type_warning, |
76 |
|
|
result_type_error |
77 |
|
|
}; |
78 |
|
|
|
79 |
|
|
/** |
80 |
|
|
* Used whenever a detailed description of the result of a function / method |
81 |
|
|
* call is needed. |
82 |
|
|
*/ |
83 |
|
|
struct result_t { |
84 |
|
|
result_type_t type; ///< success, warning or error |
85 |
|
|
int code; ///< warning or error code |
86 |
|
|
String message; ///< detailed warning or error message |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
|
template<class T> inline String ToString(T o) { |
90 |
|
|
std::stringstream ss; |
91 |
|
|
ss << o; |
92 |
|
|
return ss.str(); |
93 |
|
|
} |
94 |
|
|
|
95 |
iliev |
1832 |
inline int ToInt(const std::string& s) throw(LinuxSampler::Exception) { |
96 |
|
|
int i; |
97 |
|
|
std::istringstream iss(s); |
98 |
|
|
if(!(iss >> i)) throw LinuxSampler::Exception("Not an integer"); |
99 |
|
|
return i; |
100 |
|
|
} |
101 |
|
|
|
102 |
iliev |
2012 |
inline float ToFloat(const std::string& s) throw(LinuxSampler::Exception) { |
103 |
|
|
float i; |
104 |
|
|
std::istringstream iss(s); |
105 |
|
|
if(!(iss >> i)) throw LinuxSampler::Exception("Not a floating-point number"); |
106 |
|
|
return i; |
107 |
|
|
} |
108 |
|
|
|
109 |
schoenebeck |
2885 |
inline std::string ltrim(std::string s) { |
110 |
|
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); |
111 |
|
|
return s; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
inline std::string rtrim(std::string s) { |
115 |
|
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); |
116 |
|
|
return s; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
inline std::string trim(std::string s) { |
120 |
|
|
return ltrim(rtrim(s)); |
121 |
|
|
} |
122 |
|
|
|
123 |
schoenebeck |
1424 |
class Runnable { |
124 |
|
|
public: |
125 |
|
|
virtual ~Runnable() { } |
126 |
|
|
virtual void Run() = 0; |
127 |
|
|
}; |
128 |
|
|
|
129 |
|
|
extern double GLOBAL_VOLUME; |
130 |
schoenebeck |
1800 |
extern int GLOBAL_MAX_VOICES; |
131 |
|
|
extern int GLOBAL_MAX_STREAMS; |
132 |
schoenebeck |
1424 |
|
133 |
schoenebeck |
2473 |
//TODO: (hopefully) just a temporary nasty hack for launching gigedit on the main thread on Mac (see comments in gigedit.cpp for details) |
134 |
|
|
#if defined(__APPLE__) |
135 |
|
|
extern bool g_mainThreadCallbackSupported; |
136 |
|
|
extern void (*g_mainThreadCallback)(void* info); |
137 |
|
|
extern void* g_mainThreadCallbackInfo; |
138 |
|
|
extern bool g_fireMainThreadCallback; |
139 |
|
|
#endif |
140 |
|
|
|
141 |
schoenebeck |
1424 |
// I read with some Linux kernel versions (between 2.4.18 and 2.4.21) |
142 |
|
|
// sscanf() might be buggy regarding parsing of hex characters, so ... |
143 |
|
|
int hexToNumber(char hex_digit); |
144 |
|
|
int hexsToNumber(char hex_digit0, char hex_digit1 = '0'); |
145 |
|
|
|
146 |
|
|
#endif // __LS_GLOBAL_PRIVATE_H__ |