/[svn]/linuxsampler/trunk/src/common/global_private.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/common/global_private.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3455 - (hide annotations) (download) (as text)
Sun Jan 27 10:07:54 2019 UTC (5 years, 2 months ago) by persson
File MIME type: text/x-c++hdr
File size: 5630 byte(s)
* Fixed some compiler warnings
* Fixed compilation error when cross-compiling to Mac

1 schoenebeck 1424 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 3455 * Copyright (C) 2005 - 2019 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 persson 3455 #if ( GNUC_VERSION_PREREQ(3,3) && ( defined(__i386__) || defined(__x86_64__) || defined(_ARCH_PPC) ) )
55     #define HAVE_GCC_VECTOR_EXTENSIONS 1
56     #endif
57 schoenebeck 1930
58     #if HAVE_GCC_VECTOR_EXTENSIONS
59 senoner 1913 // v4sf is used by some routines that make use of GCC vector extensions (ie AudioChannel.cpp)
60     typedef float v4sf __attribute__ ((vector_size(16)));
61 schoenebeck 1930 #endif
62 senoner 1913
63 schoenebeck 2600 // circumvents a bug in GCC 4.x which causes a sizeof() expression applied
64     // on a class member to throw a compiler error, i.e. with GCC 4.4:
65     // "object missing in reference to 'LinuxSampler::AbstractEngineChannel::ControllerTable'")
66     // or with GCC 4.0:
67     // "invalid use of non-static data member 'LinuxSampler::AbstractEngineChannel::ControllerTable'"
68     #define _MEMBER_SIZEOF(T_Class, Member) sizeof(((T_Class*)NULL)->Member)
69    
70 schoenebeck 1424 /**
71     * Whether a function / method call was successful, or if warnings or even an
72     * error occured.
73     */
74     enum result_type_t {
75     result_type_success,
76     result_type_warning,
77     result_type_error
78     };
79    
80     /**
81     * Used whenever a detailed description of the result of a function / method
82     * call is needed.
83     */
84     struct result_t {
85     result_type_t type; ///< success, warning or error
86     int code; ///< warning or error code
87     String message; ///< detailed warning or error message
88     };
89    
90     template<class T> inline String ToString(T o) {
91     std::stringstream ss;
92     ss << o;
93     return ss.str();
94     }
95    
96 iliev 1832 inline int ToInt(const std::string& s) throw(LinuxSampler::Exception) {
97     int i;
98     std::istringstream iss(s);
99     if(!(iss >> i)) throw LinuxSampler::Exception("Not an integer");
100     return i;
101     }
102    
103 iliev 2012 inline float ToFloat(const std::string& s) throw(LinuxSampler::Exception) {
104     float i;
105     std::istringstream iss(s);
106     if(!(iss >> i)) throw LinuxSampler::Exception("Not a floating-point number");
107     return i;
108     }
109    
110 schoenebeck 2885 inline std::string ltrim(std::string s) {
111     s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
112     return s;
113     }
114    
115     inline std::string rtrim(std::string s) {
116     s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
117     return s;
118     }
119    
120     inline std::string trim(std::string s) {
121     return ltrim(rtrim(s));
122     }
123    
124 schoenebeck 1424 class Runnable {
125     public:
126     virtual ~Runnable() { }
127     virtual void Run() = 0;
128     };
129    
130     extern double GLOBAL_VOLUME;
131 schoenebeck 1800 extern int GLOBAL_MAX_VOICES;
132     extern int GLOBAL_MAX_STREAMS;
133 schoenebeck 1424
134 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)
135     #if defined(__APPLE__)
136     extern bool g_mainThreadCallbackSupported;
137     extern void (*g_mainThreadCallback)(void* info);
138     extern void* g_mainThreadCallbackInfo;
139     extern bool g_fireMainThreadCallback;
140     #endif
141    
142 schoenebeck 1424 // I read with some Linux kernel versions (between 2.4.18 and 2.4.21)
143     // sscanf() might be buggy regarding parsing of hex characters, so ...
144     int hexToNumber(char hex_digit);
145     int hexsToNumber(char hex_digit0, char hex_digit1 = '0');
146    
147     #endif // __LS_GLOBAL_PRIVATE_H__

  ViewVC Help
Powered by ViewVC