2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
6 aubio is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 aubio is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with aubio. If not, see <http://www.gnu.org/licenses/>.
22 #include "aubio_priv.h"
23 #include "parameter.h"
25 #define AUBIO_PARAM_MAX_STEPS 2000
26 #define AUBIO_PARAM_MIN_STEPS 1
28 struct _aubio_parameter_t {
39 aubio_parameter_t * new_aubio_parameter (smpl_t min_value, smpl_t max_value, uint_t steps )
41 aubio_parameter_t * param = AUBIO_NEW(aubio_parameter_t);
43 param->min_value = min_value;
44 param->max_value = max_value;
47 param->current_value = param->min_value;
48 param->target_value = param->current_value;
49 param->increment = 0.;
54 uint_t aubio_parameter_set_target_value ( aubio_parameter_t * param, smpl_t value )
56 uint_t err = AUBIO_OK;
57 if (value < param->min_value ) {
58 param->target_value = param->min_value;
60 } else if ( value > param->max_value ) {
61 param->target_value = param->max_value;
64 param->target_value = value;
66 param->increment = ( param->target_value - param->current_value ) / param->steps;
70 uint_t aubio_parameter_set_current_value ( aubio_parameter_t * param, smpl_t value )
72 uint_t err = AUBIO_OK;
73 if (value < param->min_value ) {
74 param->current_value = param->min_value;
76 } else if ( value > param->max_value ) {
77 param->current_value = param->max_value;
80 param->current_value = value;
82 param->target_value = param->current_value;
87 smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * s )
89 return s->current_value;
92 smpl_t aubio_parameter_get_next_value ( aubio_parameter_t * s )
94 if ( ABS(s->current_value - s->target_value) > ABS(s->increment) ) {
95 s->current_value += s->increment;
97 s->current_value = s->target_value;
99 return s->current_value;
102 uint_t aubio_parameter_set_steps ( aubio_parameter_t * param, uint_t steps )
104 if (steps < AUBIO_PARAM_MIN_STEPS || steps > AUBIO_PARAM_MAX_STEPS) {
107 param->steps = steps;
108 param->increment = ( param->target_value - param->current_value ) / param->steps;
112 uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param )
117 uint_t aubio_parameter_set_min_value ( aubio_parameter_t * param, smpl_t min_value )
119 param->min_value = min_value;
123 smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param )
125 return param->min_value;
128 uint_t aubio_parameter_set_max_value ( aubio_parameter_t * param, smpl_t max_value )
130 param->max_value = max_value;
134 smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param )
136 return param->max_value;
139 void del_aubio_parameter ( aubio_parameter_t * param )