Replace half-baked param metadata with descriptor.
[ardour.git] / libs / evoral / src / ParameterDescriptor.cpp
1 /* This file is part of Evoral.
2  * Copyright (C) 2000-2014 Paul Davis
3  * Author: David Robillard
4  *
5  * Evoral is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 2 of the License, or (at your option) any later
8  * version.
9  *
10  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "evoral/ParameterDescriptor.hpp"
20
21 namespace Evoral {
22
23 ParameterDescriptor::ParameterDescriptor()
24         : key((uint32_t)-1)
25         , datatype(Variant::NOTHING)
26         , unit(NONE)
27         , normal(0)
28         , lower(0)
29         , upper(0)
30         , step(0)
31         , smallstep(0)
32         , largestep(0)
33         , integer_step(false)
34         , toggled(false)
35         , logarithmic(false)
36         , sr_dependent(false)
37         , min_unbound(0)
38         , max_unbound(0)
39         , enumeration(false)
40 {}
41
42 /* Set step, smallstep, and largestep, based on current description */
43 void
44 ParameterDescriptor::update_steps()
45 {
46         if (unit == ParameterDescriptor::MIDI_NOTE) {
47                 step      = smallstep = 1;  // semitone
48                 largestep = 12;             // octave
49         } else if (integer_step) {
50                 const float delta = upper - lower;
51
52                 smallstep = delta / 10000.0f;
53                 step      = delta / 1000.0f;
54                 largestep = delta / 40.0f;
55
56                 smallstep = std::max(1.0, rint(smallstep));
57                 step      = std::max(1.0, rint(step));
58                 largestep = std::max(1.0, rint(largestep));
59         }
60         /* else: leave all others as default '0'
61          * in that case the UI (eg. AutomationController::create)
62          * uses internal_to_interface() to map the value
63          * to an appropriate interface range
64          */
65 }
66
67 }  // namespace Evoral