andrewm@0
|
1 /*
|
andrewm@0
|
2 TouchKeys: multi-touch musical keyboard control software
|
andrewm@0
|
3 Copyright (c) 2013 Andrew McPherson
|
andrewm@0
|
4
|
andrewm@0
|
5 This program is free software: you can redistribute it and/or modify
|
andrewm@0
|
6 it under the terms of the GNU General Public License as published by
|
andrewm@0
|
7 the Free Software Foundation, either version 3 of the License, or
|
andrewm@0
|
8 (at your option) any later version.
|
andrewm@0
|
9
|
andrewm@0
|
10 This program is distributed in the hope that it will be useful,
|
andrewm@0
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
andrewm@0
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
andrewm@0
|
13 GNU General Public License for more details.
|
andrewm@0
|
14
|
andrewm@0
|
15 You should have received a copy of the GNU General Public License
|
andrewm@0
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
andrewm@0
|
17
|
andrewm@0
|
18 =====================================================================
|
andrewm@0
|
19
|
andrewm@0
|
20 Types.h: basic types used throughout the program
|
andrewm@0
|
21 */
|
andrewm@0
|
22
|
andrewm@0
|
23 #ifndef KEYCONTROL_TYPES_H
|
andrewm@0
|
24 #define KEYCONTROL_TYPES_H
|
andrewm@0
|
25
|
andrewm@20
|
26 // For Windows, which defines min() and max() macros
|
andrewm@20
|
27 #ifdef max
|
andrewm@20
|
28 #undef max
|
andrewm@20
|
29 #endif
|
andrewm@20
|
30
|
andrewm@0
|
31 #include <limits>
|
andrewm@0
|
32 #include <cstdlib>
|
andrewm@0
|
33 #include <cmath>
|
andrewm@0
|
34 #include <utility>
|
andrewm@0
|
35
|
andrewm@0
|
36 #undef FIXED_POINT_TIME
|
andrewm@0
|
37
|
andrewm@0
|
38 // The following template specializations give the "missing" values for each kind of data that can be used in a Node.
|
andrewm@0
|
39 // If an unknown type is added, its "missing" value is whatever comes back from the default constructor. Generally speaking, new
|
andrewm@0
|
40 // types should be added to this list as they are used
|
andrewm@0
|
41
|
andrewm@0
|
42 template<typename T>
|
andrewm@0
|
43 struct missing_value {
|
andrewm@0
|
44 static const T missing() { return T(); }
|
andrewm@0
|
45 static const bool isMissing(T val) { return val == missing(); }
|
andrewm@0
|
46 };
|
andrewm@0
|
47
|
andrewm@0
|
48 template<> struct missing_value<short> {
|
andrewm@0
|
49 static const short missing() { return std::numeric_limits<short>::max(); }
|
andrewm@0
|
50 static const bool isMissing(short val) { return (val == missing()); }
|
andrewm@0
|
51 };
|
andrewm@0
|
52 template<> struct missing_value<unsigned short> {
|
andrewm@0
|
53 static const unsigned short missing() { return std::numeric_limits<unsigned short>::max(); }
|
andrewm@0
|
54 static const bool isMissing(unsigned short val) { return (val == missing()); }
|
andrewm@0
|
55 };
|
andrewm@0
|
56 template<> struct missing_value<int> {
|
andrewm@0
|
57 static const int missing() { return std::numeric_limits<int>::max(); }
|
andrewm@0
|
58 static const bool isMissing(int val) { return (val == missing()); }
|
andrewm@0
|
59 };
|
andrewm@0
|
60 template<> struct missing_value<unsigned int> {
|
andrewm@0
|
61 static const unsigned int missing() { return std::numeric_limits<unsigned int>::max(); }
|
andrewm@0
|
62 static const bool isMissing(unsigned int val) { return (val == missing()); }
|
andrewm@0
|
63 };
|
andrewm@0
|
64 template<> struct missing_value<long> {
|
andrewm@0
|
65 static const long missing() { return std::numeric_limits<long>::max(); }
|
andrewm@0
|
66 static const bool isMissing(long val) { return (val == missing()); }
|
andrewm@0
|
67 };
|
andrewm@0
|
68 template<> struct missing_value<unsigned long> {
|
andrewm@0
|
69 static const unsigned long missing() { return std::numeric_limits<unsigned long>::max(); }
|
andrewm@0
|
70 static const bool isMissing(unsigned long val) { return (val == missing()); }
|
andrewm@0
|
71 };
|
andrewm@0
|
72 template<> struct missing_value<long long> {
|
andrewm@0
|
73 static const long long missing() { return std::numeric_limits<long long>::max(); }
|
andrewm@0
|
74 static const bool isMissing(long long val) { return (val == missing()); }
|
andrewm@0
|
75 };
|
andrewm@0
|
76 template<> struct missing_value<unsigned long long> {
|
andrewm@0
|
77 static const unsigned long long missing() { return std::numeric_limits<unsigned long long>::max(); }
|
andrewm@0
|
78 static const bool isMissing(unsigned long long val) { return (val == missing()); }
|
andrewm@0
|
79 };
|
andrewm@0
|
80 template<> struct missing_value<float> {
|
andrewm@0
|
81 static const float missing() { return std::numeric_limits<float>::quiet_NaN(); }
|
andrewm@20
|
82 static const bool isMissing(float val) {
|
andrewm@20
|
83 #ifdef _MSC_VER
|
andrewm@20
|
84 return (_isnan(val) != 0);
|
andrewm@20
|
85 #else
|
andrewm@20
|
86 return std::isnan(val);
|
andrewm@20
|
87 #endif
|
andrewm@20
|
88 }
|
andrewm@0
|
89 };
|
andrewm@0
|
90 template<> struct missing_value<double> {
|
andrewm@0
|
91 static const double missing() { return std::numeric_limits<double>::quiet_NaN(); }
|
andrewm@20
|
92 static const bool isMissing(double val) {
|
andrewm@20
|
93 #ifdef _MSC_VER
|
andrewm@20
|
94 return (_isnan(val) != 0);
|
andrewm@20
|
95 #else
|
andrewm@20
|
96 return std::isnan(val);
|
andrewm@20
|
97 #endif
|
andrewm@20
|
98 }
|
andrewm@0
|
99 };
|
andrewm@0
|
100 template<typename T1, typename T2>
|
andrewm@0
|
101 struct missing_value<std::pair<T1,T2> > {
|
andrewm@0
|
102 static const std::pair<T1,T2> missing() { return std::pair<T1,T2>(missing_value<T1>::missing(), missing_value<T2>::missing()); }
|
andrewm@0
|
103 static const bool isMissing(std::pair<T1,T2> val) {
|
andrewm@0
|
104 return missing_value<T1>::isMissing(val.first) && missing_value<T2>::isMissing(val.second);
|
andrewm@0
|
105 }
|
andrewm@0
|
106 };
|
andrewm@0
|
107
|
andrewm@0
|
108
|
andrewm@0
|
109 // Globally-defined types: these types must be shared by all active units
|
andrewm@0
|
110
|
andrewm@0
|
111 #ifdef FIXED_POINT_TIME
|
andrewm@0
|
112 typedef unsigned long long timestamp_type;
|
andrewm@0
|
113 typedef long long timestamp_diff_type;
|
andrewm@0
|
114
|
andrewm@0
|
115 #define timestamp_abs(x) std::llabs(x)
|
andrewm@0
|
116 #define ptime_to_timestamp(x) (x).total_microseconds()
|
andrewm@0
|
117 #define timestamp_to_ptime(x) microseconds(x)
|
andrewm@0
|
118 #define timestamp_to_milliseconds(x) ((x)/1000ULL)
|
andrewm@0
|
119 #define microseconds_to_timestamp(x) (x)
|
andrewm@0
|
120 #define milliseconds_to_timestamp(x) ((x)*1000ULL)
|
andrewm@0
|
121 #define seconds_to_timestamp(x) ((x)*1000000ULL)
|
andrewm@0
|
122
|
andrewm@0
|
123 #else /* Floating point time */
|
andrewm@0
|
124 typedef double timestamp_type;
|
andrewm@0
|
125 typedef double timestamp_diff_type;
|
andrewm@0
|
126
|
andrewm@0
|
127 #define timestamp_abs(x) std::fabs(x)
|
andrewm@0
|
128 #define ptime_to_timestamp(x) ((timestamp_type)(x).total_microseconds()/1000000.0)
|
andrewm@0
|
129 #define timestamp_to_ptime(x) microseconds((x)*1000000.0)
|
andrewm@0
|
130 #define timestamp_to_milliseconds(x) ((x)*1000.0)
|
andrewm@0
|
131 #define microseconds_to_timestamp(x) ((double)(x)/1000000.0)
|
andrewm@0
|
132 #define milliseconds_to_timestamp(x) ((double)(x)/1000.0)
|
andrewm@0
|
133 #define seconds_to_timestamp(x) (x)
|
andrewm@0
|
134
|
andrewm@0
|
135 #endif /* FIXED_POINT_TIME */
|
andrewm@0
|
136
|
andrewm@0
|
137
|
andrewm@0
|
138 #endif /* KEYCONTROL_TYPES_H */ |