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/>.
21 #include "aubio_priv.h"
22 #include "parameter.h"
24 #define AUBIO_PARAM_MAX_STEPS 2000
25 #define AUBIO_PARAM_MIN_STEPS 1
27 struct _aubio_parameter_t {
38 aubio_parameter_t * new_aubio_parameter (smpl_t min_value, smpl_t max_value, uint_t steps )
40 aubio_parameter_t * param = AUBIO_NEW(aubio_parameter_t);
42 param->min_value = min_value;
43 param->max_value = max_value;
46 param->current_value = param->min_value;
47 param->target_value = param->current_value;
48 param->increment = 0.;
53 uint_t aubio_parameter_set_target_value ( aubio_parameter_t * param, smpl_t value )
55 uint_t err = AUBIO_OK;
56 if (value < param->min_value ) {
57 param->target_value = param->min_value;
59 } else if ( value > param->max_value ) {
60 param->target_value = param->max_value;
63 param->target_value = value;
65 param->increment = ( param->target_value - param->current_value ) / param->steps;
69 uint_t aubio_parameter_set_current_value ( aubio_parameter_t * param, smpl_t value )
71 uint_t err = AUBIO_OK;
72 if (value < param->min_value ) {
73 param->current_value = param->min_value;
75 } else if ( value > param->max_value ) {
76 param->current_value = param->max_value;
79 param->current_value = value;
81 param->target_value = param->current_value;
86 smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * s )
88 return s->current_value;
91 smpl_t aubio_parameter_get_next_value ( aubio_parameter_t * s )
93 if ( ABS(s->current_value - s->target_value) > ABS(s->increment) ) {
94 s->current_value += s->increment;
96 s->current_value = s->target_value;
98 return s->current_value;
101 uint_t aubio_parameter_set_steps ( aubio_parameter_t * param, uint_t steps )
103 if (steps < AUBIO_PARAM_MIN_STEPS || steps > AUBIO_PARAM_MAX_STEPS) {
106 param->steps = steps;
107 param->increment = ( param->target_value - param->current_value ) / param->steps;
111 uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param )
116 uint_t aubio_parameter_set_min_value ( aubio_parameter_t * param, smpl_t min_value )
118 param->min_value = min_value;
122 smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param )
124 return param->min_value;
127 uint_t aubio_parameter_set_max_value ( aubio_parameter_t * param, smpl_t max_value )
129 param->max_value = max_value;
133 smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param )
135 return param->max_value;
138 void del_aubio_parameter ( aubio_parameter_t * param )