andrewm@0: /*
andrewm@0: TouchKeys: multi-touch musical keyboard control software
andrewm@0: Copyright (c) 2013 Andrew McPherson
andrewm@0:
andrewm@0: This program is free software: you can redistribute it and/or modify
andrewm@0: it under the terms of the GNU General Public License as published by
andrewm@0: the Free Software Foundation, either version 3 of the License, or
andrewm@0: (at your option) any later version.
andrewm@0:
andrewm@0: This program is distributed in the hope that it will be useful,
andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0: GNU General Public License for more details.
andrewm@0:
andrewm@0: You should have received a copy of the GNU General Public License
andrewm@0: along with this program. If not, see .
andrewm@0:
andrewm@0: =====================================================================
andrewm@0:
andrewm@0: Types.h: basic types used throughout the program
andrewm@0: */
andrewm@0:
andrewm@0: #ifndef KEYCONTROL_TYPES_H
andrewm@0: #define KEYCONTROL_TYPES_H
andrewm@0:
andrewm@20: // For Windows, which defines min() and max() macros
andrewm@20: #ifdef max
andrewm@20: #undef max
andrewm@20: #endif
andrewm@20:
andrewm@0: #include
andrewm@0: #include
andrewm@0: #include
andrewm@0: #include
andrewm@0:
andrewm@0: #undef FIXED_POINT_TIME
andrewm@0:
andrewm@0: // The following template specializations give the "missing" values for each kind of data that can be used in a Node.
andrewm@0: // If an unknown type is added, its "missing" value is whatever comes back from the default constructor. Generally speaking, new
andrewm@0: // types should be added to this list as they are used
andrewm@0:
andrewm@0: template
andrewm@0: struct missing_value {
andrewm@0: static const T missing() { return T(); }
andrewm@0: static const bool isMissing(T val) { return val == missing(); }
andrewm@0: };
andrewm@0:
andrewm@0: template<> struct missing_value {
andrewm@0: static const short missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(short val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const unsigned short missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(unsigned short val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const int missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(int val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const unsigned int missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(unsigned int val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const long missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(long val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const unsigned long missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(unsigned long val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const long long missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(long long val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const unsigned long long missing() { return std::numeric_limits::max(); }
andrewm@0: static const bool isMissing(unsigned long long val) { return (val == missing()); }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const float missing() { return std::numeric_limits::quiet_NaN(); }
andrewm@20: static const bool isMissing(float val) {
andrewm@20: #ifdef _MSC_VER
andrewm@20: return (_isnan(val) != 0);
andrewm@20: #else
andrewm@20: return std::isnan(val);
andrewm@20: #endif
andrewm@20: }
andrewm@0: };
andrewm@0: template<> struct missing_value {
andrewm@0: static const double missing() { return std::numeric_limits::quiet_NaN(); }
andrewm@20: static const bool isMissing(double val) {
andrewm@20: #ifdef _MSC_VER
andrewm@20: return (_isnan(val) != 0);
andrewm@20: #else
andrewm@20: return std::isnan(val);
andrewm@20: #endif
andrewm@20: }
andrewm@0: };
andrewm@0: template
andrewm@0: struct missing_value > {
andrewm@0: static const std::pair missing() { return std::pair(missing_value::missing(), missing_value::missing()); }
andrewm@0: static const bool isMissing(std::pair val) {
andrewm@0: return missing_value::isMissing(val.first) && missing_value::isMissing(val.second);
andrewm@0: }
andrewm@0: };
andrewm@0:
andrewm@0:
andrewm@0: // Globally-defined types: these types must be shared by all active units
andrewm@0:
andrewm@0: #ifdef FIXED_POINT_TIME
andrewm@0: typedef unsigned long long timestamp_type;
andrewm@0: typedef long long timestamp_diff_type;
andrewm@0:
andrewm@0: #define timestamp_abs(x) std::llabs(x)
andrewm@0: #define ptime_to_timestamp(x) (x).total_microseconds()
andrewm@0: #define timestamp_to_ptime(x) microseconds(x)
andrewm@0: #define timestamp_to_milliseconds(x) ((x)/1000ULL)
andrewm@0: #define microseconds_to_timestamp(x) (x)
andrewm@0: #define milliseconds_to_timestamp(x) ((x)*1000ULL)
andrewm@0: #define seconds_to_timestamp(x) ((x)*1000000ULL)
andrewm@0:
andrewm@0: #else /* Floating point time */
andrewm@0: typedef double timestamp_type;
andrewm@0: typedef double timestamp_diff_type;
andrewm@0:
andrewm@0: #define timestamp_abs(x) std::fabs(x)
andrewm@0: #define ptime_to_timestamp(x) ((timestamp_type)(x).total_microseconds()/1000000.0)
andrewm@0: #define timestamp_to_ptime(x) microseconds((x)*1000000.0)
andrewm@0: #define timestamp_to_milliseconds(x) ((x)*1000.0)
andrewm@0: #define microseconds_to_timestamp(x) ((double)(x)/1000000.0)
andrewm@0: #define milliseconds_to_timestamp(x) ((double)(x)/1000.0)
andrewm@0: #define seconds_to_timestamp(x) (x)
andrewm@0:
andrewm@0: #endif /* FIXED_POINT_TIME */
andrewm@0:
andrewm@0:
andrewm@0: #endif /* KEYCONTROL_TYPES_H */