1 /**
2 * projectM -- Milkdrop-esque visualisation SDK
3 * Copyright (C)2003-2007 projectM Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * See 'LICENSE.txt' included within this release
19 *
20 */
21 /**
22 * $Id$
23 *
24 * $Log$
25 */
26
27 #ifndef COMMON_HPP
28 #define COMMON_HPP
29 #include <vector>
30 #include <typeinfo>
31 #include <cstdarg>
32 #include <cassert>
33
34 #ifdef _MSC_VER
35 #define strcasecmp(s, t) _strcmpi(s, t)
36 #endif
37
38 #if defined(_MSC_VER ) && !defined(EYETUNE_WINRT)
39 #pragma warning( disable : 4244 4305 4996; once : 4018 )
40 #define WIN32_LEAN_AND_MEAN
41 #define NOMINMAX
42 #include <windows.h>
43 typedef unsigned int uint;
44 #endif
45
46 #ifdef DEBUG
47 //extern FILE *debugFile;
48 #endif
49
50 #ifdef __APPLE__
51 #include <cstdio>
52 extern FILE *fmemopen(void *buf, size_t len, const char *pMode);
53 #endif /** MACOS */
54
55 #include "dlldefs.h"
56
57 #define DEFAULT_FONT_PATH "/home/carm/fonts/courier1.glf"
58 #define MAX_TOKEN_SIZE 512
59 #define MAX_PATH_SIZE 4096
60
61 #define STRING_BUFFER_SIZE 1024*150
62 #define STRING_LINE_SIZE 1024
63
64
65 #ifdef __unix__
66 #include <cstdlib>
67 #define projectM_isnan std::isnan
68 #endif
69
70 #ifdef EMSCRIPTEN
71 #include <cstdlib>
72 #define projectM_isnan isnan
73 #endif
74
75 #ifdef WIN32
76 #define projectM_isnan(x) ((x) != (x))
77 #endif
78
79 #ifdef __APPLE__
80 #define projectM_isnan(x) ((x) != (x))
81 #endif
82
83 #ifdef __unix__
84 #define projectM_fmax fmax
85 #endif
86
87 #ifdef WIN32
88 #define projectM_fmax(x,y) ((x) >= (y) ? (x): (y))
89 #endif
90
91 #ifdef __APPLE__
92 #define projectM_fmax(x,y) ((x) >= (y) ? (x): (y))
93 #endif
94
95 #ifdef __unix__
96 #define projectM_fmin fmin
97 #endif
98
99 #ifdef WIN32
100 #define projectM_fmin(x,y) ((x) <= (y) ? (x): (y))
101 #endif
102
103 #ifdef __APPLE__
104 #define projectM_fmin(x,y) ((x) <= (y) ? (x): (y))
105 #endif
106
107 #ifndef TRUE
108 #define TRUE true
109 #endif
110
111 #ifndef FALSE
112 #define FALSE false
113 #endif
114
115
116 #define MAX_DOUBLE_SIZE 10000000.0
117 #define MIN_DOUBLE_SIZE -10000000.0
118
119 #define MAX_INT_SIZE 10000000
120 #define MIN_INT_SIZE -10000000
121
122 /* default float initial value */
123 #define DEFAULT_DOUBLE_IV 0.0
124
125 /* default float lower bound */
126 #define DEFAULT_DOUBLE_LB MIN_DOUBLE_SIZE
127
128 /* default float upper bound */
129 #define DEFAULT_DOUBLE_UB MAX_DOUBLE_SIZE
130
131 #ifdef WIN32
132 #include <float.h>
133 #define isnan _isnan
134 #endif /** WIN32 */
135
136 /** Per-platform path separators */
137 #define WIN32_PATH_SEPARATOR '\\'
138 #define UNIX_PATH_SEPARATOR '/'
139 #ifdef WIN32
140 #define PATH_SEPARATOR WIN32_PATH_SEPARATOR
141 #else
142 #define PATH_SEPARATOR UNIX_PATH_SEPARATOR
143 #endif /** WIN32 */
144 #include <string>
145 #include <algorithm>
146
147 const unsigned int NUM_Q_VARIABLES(32);
148 const std::string PROJECTM_FILE_EXTENSION("prjm");
149 const std::string MILKDROP_FILE_EXTENSION("milk");
150 const std::string PROJECTM_MODULE_EXTENSION("so");
151
152 template <class TraverseFunctor, class Container>
traverse(Container & container)153 void traverse(Container & container)
154 {
155
156 TraverseFunctor functor;
157
158 for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos)
159 {
160 assert(pos->second);
161 functor(pos->second);
162 }
163
164 }
165
166
167 template <class TraverseFunctor, class Container>
traverseVector(Container & container)168 void traverseVector(Container & container)
169 {
170
171 TraverseFunctor functor;
172
173 for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos)
174 {
175 assert(*pos);
176 functor(*pos);
177 }
178
179 }
180
181 template <class TraverseFunctor, class Container>
traverse(Container & container,TraverseFunctor & functor)182 void traverse(Container & container, TraverseFunctor & functor)
183 {
184
185 for (typename Container::iterator pos = container.begin(); pos != container.end(); ++pos)
186 {
187 assert(pos->second);
188 functor(pos->second);
189 }
190
191 }
192
193 namespace TraverseFunctors
194 {
195 template <class Data>
196 class Delete
197 {
198
199 public:
200
operator ()(Data * data)201 void operator() (Data * data)
202 {
203 assert(data);
204 delete(data);
205 }
206
207 };
208 }
209
210
parseExtension(const std::string & filename)211 inline std::string parseExtension(const std::string & filename) {
212
213 const std::size_t start = filename.find_last_of('.');
214
215 if (start == std::string::npos || start >= (filename.length()-1))
216 return "";
217 std::string ext = filename.substr(start+1, filename.length());
218 std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
219 return ext;
220 }
221
parseFilename(const std::string & filename)222 inline std::string parseFilename(const std::string & filename) {
223
224 const std::size_t start = filename.find_last_of('/');
225
226 if (start == std::string::npos || start >= (filename.length()-1))
227 return "";
228 else
229 return filename.substr(start+1, filename.length());
230 }
231
meanSquaredError(const double & x,const double & y)232 inline double meanSquaredError(const double & x, const double & y) {
233 return (x-y)*(x-y);
234 }
235
236
237 enum PresetRatingType {
238 FIRST_RATING_TYPE = 0,
239 HARD_CUT_RATING_TYPE = FIRST_RATING_TYPE,
240 SOFT_CUT_RATING_TYPE,
241 LAST_RATING_TYPE = SOFT_CUT_RATING_TYPE,
242 TOTAL_RATING_TYPES = SOFT_CUT_RATING_TYPE+1
243 };
244
245
246 typedef std::vector<int> RatingList;
247
248 #endif
249