1 /* 2 * Copyright (C) 2008-2016 David Robillard <d@drobilla.net> 3 * Copyright (C) 2008-2018 Paul Davis <paul@linuxaudiosystems.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef EVORAL_PARAMETER_HPP 21 #define EVORAL_PARAMETER_HPP 22 23 #include <string> 24 #include <map> 25 #include <stdint.h> 26 #include <boost/shared_ptr.hpp> 27 28 #include "evoral/visibility.h" 29 #include "evoral/types.h" 30 31 namespace Evoral { 32 33 /** ID of a [play|record|automate]able parameter. 34 * 35 * A parameter is defined by (type, id, channel). Type is an integer which 36 * can be used in any way by the application (e.g. cast to a custom enum, 37 * map to/from a URI, etc). ID is type specific (e.g. MIDI controller #). 38 * 39 * This class defines a < operator which is a strict weak ordering, so 40 * Parameter may be stored in a std::set, used as a std::map key, etc. 41 */ 42 class LIBEVORAL_API Parameter 43 { 44 public: 45 inline Parameter(ParameterType type, uint8_t channel=0, uint32_t id=0) _type(type)46 : _type(type), _id(id), _channel(channel) 47 {} 48 type()49 inline ParameterType type() const { return _type; } channel()50 inline uint8_t channel() const { return _channel; } id()51 inline uint32_t id() const { return _id; } 52 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) 57 */ 58 inline bool operator==(const Parameter& id) const { 59 return (_type == id._type && _channel == id._channel && _id == id._id ); 60 } 61 62 inline bool operator!=(const Parameter& id) const { 63 return !operator==(id); 64 } 65 66 /** Strict weak ordering 67 * See: http://www.sgi.com/tech/stl/StrictWeakOrdering.html 68 * Sort Parameters first according to type then to channel and lastly to ID. 69 */ 70 inline bool operator<(const Parameter& other) const { 71 if (_type < other._type) { 72 return true; 73 } else if (_type == other._type && _channel < other._channel) { 74 return true; 75 } else if (_type == other._type && _channel == other._channel && _id < other._id ) { 76 return true; 77 } 78 79 return false; 80 } 81 82 inline operator bool() const { return (_type != 0); } 83 84 private: 85 ParameterType _type; 86 uint32_t _id; 87 uint8_t _channel; 88 }; 89 90 } // namespace Evoral 91 92 namespace std { 93 std::ostream& operator<< (std::ostream &str, Evoral::Parameter const &); 94 } 95 96 #endif // EVORAL_PARAMETER_HPP 97 98