1 /* This file is part of Evoral.
2 * Copyright (C) 2008 David 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
25 #include <boost/shared_ptr.hpp>
27 #include "evoral/visibility.h"
28 #include "evoral/types.hpp"
32 /** ID of a [play|record|automate]able parameter.
34 * A parameter is defined by (type, id, channel). Type is an integer which
35 * can be used in any way by the application (e.g. cast to a custom enum,
36 * map to/from a URI, etc). ID is type specific (e.g. MIDI controller #).
38 * This class defines a < operator which is a strict weak ordering, so
39 * Parameter may be stored in a std::set, used as a std::map key, etc.
41 class LIBEVORAL_API Parameter
44 inline Parameter(ParameterType type, uint8_t channel=0, uint32_t id=0)
45 : _type(type), _id(id), _channel(channel)
48 inline ParameterType type() const { return _type; }
49 inline uint8_t channel() const { return _channel; }
50 inline uint32_t id() const { return _id; }
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 && _channel == id._channel && _id == id._id );
61 inline bool operator!=(const Parameter& id) const {
62 return !operator==(id);
65 /** Strict weak ordering
66 * See: http://www.sgi.com/tech/stl/StrictWeakOrdering.html
67 * Sort Parameters first according to type then to channel and lastly to ID.
69 inline bool operator<(const Parameter& other) const {
70 if (_type < other._type) {
72 } else if (_type == other._type && _channel < other._channel) {
74 } else if (_type == other._type && _channel == other._channel && _id < other._id ) {
81 inline operator bool() const { return (_type != 0); }
92 std::ostream& operator<< (std::ostream &str, Evoral::Parameter const &);
95 #endif // EVORAL_PARAMETER_HPP