2 /* This file is part of Evoral.
3 * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
4 * Copyright (C) 2000-2008 Paul Davis
6 * Evoral is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option) any later
11 * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef EVORAL_PARAMETER_HPP
21 #define EVORAL_PARAMETER_HPP
26 #include <boost/shared_ptr.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 channel and lastly to ID.
66 inline bool operator<(const Parameter& other) const {
67 if (_type < other._type) {
69 } else if (_type == other._type && _channel < other._channel) {
71 } else if (_type == other._type && _channel == other._channel && _id < other._id ) {
78 inline operator bool() const { return (_type != 0); }
80 /** Not used in indentity/comparison */
82 Metadata(double low=0.0, double high=1.0, double mid=0.0, bool tog=false)
83 : min(low), max(high), normal(mid), toggled(tog)
91 inline static void set_range(uint32_t type, double min, double max, double normal, bool toggled) {
92 _type_metadata[type] = Metadata(min, max, normal, toggled);
95 inline void set_range(double min, double max, double normal, bool toggled) {
96 _metadata = boost::shared_ptr<Metadata>(new Metadata(min, max, normal, toggled));
99 inline Metadata& metadata() const {
101 return *_metadata.get();
103 return _type_metadata[_type];
106 inline double min() const { return metadata().min; }
107 inline double max() const { return metadata().max; }
108 inline double normal() const { return metadata().normal; }
109 inline double toggled() const { return metadata().toggled; }
112 // Default copy constructor is ok
114 // ID (used in comparison)
119 boost::shared_ptr<Metadata> _metadata;
121 typedef std::map<uint32_t, Metadata> TypeMetadata;
122 static TypeMetadata _type_metadata;
126 } // namespace Evoral
128 #endif // EVORAL_PARAMETER_HPP