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: PianoTypes.h: some useful constants mainly relevant to continuous key angle andrewm@0: */ andrewm@0: andrewm@0: #ifndef KEYCONTROL_PIANO_TYPES_H andrewm@0: #define KEYCONTROL_PIANO_TYPES_H andrewm@0: andrewm@0: #include "../Utility/Types.h" andrewm@0: andrewm@0: #undef FIXED_POINT_PIANO_SAMPLES andrewm@0: andrewm@0: // Data types. Allow for floating-point (more flexible) or fixed-point (faster) arithmetic andrewm@0: // on piano key positions andrewm@0: #ifdef FIXED_POINT_PIANO_SAMPLES andrewm@0: typedef int key_position; andrewm@0: typedef int key_velocity; andrewm@0: #define scale_key_position(x) 4096*(key_position)(x) andrewm@0: #define key_position_to_float(x) ((float)x/4096.0) andrewm@0: #define key_abs(x) abs(x) andrewm@0: #define calculate_key_velocity(dpos, dt) (key_velocity)((65536*dpos)/(key_position)dt) andrewm@0: #define scale_key_velocity(x) (65536/4096)*(key_velocity)(x) // FIXME: TEST THIS! andrewm@0: #else andrewm@0: typedef float key_position; andrewm@0: typedef float key_velocity; andrewm@0: #define scale_key_position(x) (key_position)(x) andrewm@0: #define key_position_to_float(x) (x) andrewm@0: #define key_abs(x) fabsf(x) andrewm@0: #define calculate_key_velocity(dpos, dt) (key_velocity)(dpos/(key_position)dt) andrewm@0: #define scale_key_velocity(x) (key_velocity)(x) andrewm@0: #endif /* FIXED_POINT_PIANO_SAMPLES */ andrewm@0: andrewm@0: #endif /* KEYCONTROL_PIANO_TYPES_H */