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
24 #include <boost/shared_ptr.hpp>
25 #include <boost/format.hpp>
31 /** ID of a [play|record|automate]able parameter.
33 * A parameter is defined by (type, id, channel). Type is an integer which
34 * can be used in any way by the application (e.g. cast to a custom enum,
35 * map to/from a URI, etc). ID is type specific (e.g. MIDI controller #).
37 * This class defines a < operator which is a strict weak ordering, so
38 * Parameter may be stored in a std::set, used as a std::map key, etc.
43 Parameter(uint32_t type, uint8_t channel=0, uint32_t id=0)
44 : _type(type), _id(id), _channel(channel)
47 virtual ~Parameter() {}
49 inline uint32_t type() const { return _type; }
50 inline uint8_t channel() const { return _channel; }
51 inline uint32_t id() const { return _id; }
53 /** Equivalence operator
54 * It is obvious from the definition that this operator
55 * is transitive, as required by stict weak ordering
56 * (see: http://www.sgi.com/tech/stl/StrictWeakOrdering.html)
58 inline bool operator==(const Parameter& id) const {
59 return (_type == id._type && _channel == id._channel && _id == id._id );
62 /** Strict weak ordering
63 * See: http://www.sgi.com/tech/stl/StrictWeakOrdering.html
64 * Sort Parameters first according to type then to id and lastly to channel.
68 * <li>Irreflexivity: f(x, x) is false because of the irreflexivity of \c < in each branch.</li>
69 * <li>Antisymmetry: given x != y, f(x, y) implies !f(y, x) because of the same
70 * property of \c < in each branch and the symmetry of operator==. </li>
71 * <li>Transitivity: let f(x, y) and f(y, z) => f(x, z) be true.
72 * We prove by contradiction, assuming the contrary:
73 * f(x, y) and f(x, z) hold => !f(x, z)
75 * That implies one of the following:
77 * <li> x == z which contradicts the assumption f(x, y) and f(y, x)
78 * because of antisymmetry.
80 * <li> f(z, x) is true. That would imply that one of the ivars (we call it i)
81 * of x is greater than the same ivar in z while all "previous" ivars
82 * are equal. That would imply that also in y all those "previous"
83 * ivars are equal and because if x.i > z.i it is impossible
84 * that there is an y that satisfies x.i < y.i < z.i at the same
85 * time which contradicts the assumption.
87 * Therefore f(x, z) is true (transitivity)
92 inline bool operator<(const Parameter& other) const {
93 if (_type < other._type) {
95 } else if (_type == other._type && _channel < other._channel) {
97 } else if (_type == other._type && _channel == other._channel && _id < other._id ) {
104 inline operator bool() const { return (_type != 0); }
106 /** Not used in indentity/comparison */
108 Metadata(double low=0.0, double high=1.0, double mid=0.0)
109 : min(low), max(high), normal(mid)
116 inline static void set_range(uint32_t type, double min, double max, double normal) {
117 _type_metadata[type] = Metadata(min, max, normal);
120 inline void set_range(double min, double max, double normal) {
121 _metadata = boost::shared_ptr<Metadata>(new Metadata(min, max, normal));
124 inline Metadata& metadata() const {
126 return *_metadata.get();
128 return _type_metadata[_type];
131 inline double min() const { return metadata().min; }
132 inline double max() const { return metadata().max; }
133 inline double normal() const { return metadata().normal; }
136 // Default copy constructor is ok
138 // ID (used in comparison)
143 boost::shared_ptr<Metadata> _metadata;
145 typedef std::map<uint32_t, Metadata> TypeMetadata;
146 static TypeMetadata _type_metadata;
150 } // namespace Evoral
152 #endif // EVORAL_PARAMETER_HPP