1 /* This file is part of Evoral.
2 * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
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
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.
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
19 #ifndef EVORAL_PARAMETER_HPP
20 #define EVORAL_PARAMETER_HPP
23 #include <boost/format.hpp>
28 /** ID of a [play|record|automate]able parameter.
30 * A parameter is defined by (type, id, channel). Type is an integer which
31 * can be used in any way by the application (e.g. cast to a custom enum,
32 * map to/from a URI, etc). ID is type specific (e.g. MIDI controller #).
34 * This class defines a < operator which is a strict weak ordering, so
35 * Parameter may be stored in a std::set, used as a std::map key, etc.
40 Parameter(uint32_t type, uint32_t id, int8_t channel=0,
41 double min=0.0f, double max=0.0f, double def=0.0f)
42 : _type(type), _id(id), _channel(channel), _min(min), _max(max), _normal(def)
45 //Parameter(const std::string& str);
47 inline uint32_t type() const { return _type; }
48 inline uint32_t id() const { return _id; }
49 inline uint8_t channel() const { return _channel; }
52 * Equivalence operator
53 * It is obvious from the definition that this operator
54 * is transitive, as required by stict weak ordering
55 * (see: http://www.sgi.com/tech/stl/StrictWeakOrdering.html)
57 inline bool operator==(const Parameter& id) const {
58 return (_type == id._type && _id == id._id && _channel == id._channel);
61 /** Strict weak ordering
62 * See: http://www.sgi.com/tech/stl/StrictWeakOrdering.html
63 * Sort Parameters first according to type then to id and lastly to channel.
67 * <li>Irreflexivity: f(x, x) is false because of the irreflexivity of \c < in each branch.</li>
68 * <li>Antisymmetry: given x != y, f(x, y) implies !f(y, x) because of the same
69 * property of \c < in each branch and the symmetry of operator==. </li>
70 * <li>Transitivity: let f(x, y) and f(y, z) be true.
71 * We prove by contradiction, assuming the contrary (f(x, z) is false).
72 * That would imply exactly one of the following:
74 * <li> x == z which contradicts the assumption f(x, y) and f(y, x)
75 * because of antisymmetry.
77 * <li> f(z, x) is true. That would imply that one of the ivars (we call it i)
78 * of x is greater than the same ivar in z while all "previous" ivars
79 * are equal. That would imply that also in y all those "previous"
80 * ivars are equal and because if x.i > z.i it is impossible
81 * that there is an y that satisfies x.i < y.i < z.i at the same
82 * time which contradicts the assumption.
84 * Therefore f(x, z) is true (transitivity)
89 inline bool operator<(const Parameter& id) const {
90 if (_type < id._type) {
92 } else if (_type == id._type && _id < id._id) {
94 } else if (_id == id._id && _channel < id._channel) {
101 inline operator bool() const { return (_type != 0); }
103 virtual std::string symbol() const {
104 return (boost::format("%1%_c%2%_n%3%\n") % _type % _channel % _id).str();
107 inline void set_range(double min, double max, double normal) {
113 inline const double min() const { return _min; }
114 inline const double max() const { return _max; }
115 inline const double normal() const { return _normal; }
118 // Default copy constructor is ok
120 // ID (used in comparison)
125 // Metadata (not used in comparison)
132 } // namespace Evoral
134 #endif // EVORAL_PARAMETER_HPP