2008-09-18 20:47:49 -04:00
|
|
|
/* This file is part of Evoral.
|
2011-04-06 11:00:16 -04:00
|
|
|
* Copyright (C) 2008 David Robillard <http://drobilla.net>
|
2008-09-18 20:47:49 -04:00
|
|
|
* Copyright (C) 2000-2008 Paul Davis
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* Evoral is free software; you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EVORAL_PARAMETER_HPP
|
|
|
|
#define EVORAL_PARAMETER_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2008-09-19 02:30:49 -04:00
|
|
|
#include <map>
|
2009-07-20 23:23:57 -04:00
|
|
|
#include <stdint.h>
|
2008-09-19 02:30:49 -04:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
namespace Evoral {
|
|
|
|
|
|
|
|
|
|
|
|
/** ID of a [play|record|automate]able parameter.
|
|
|
|
*
|
|
|
|
* A parameter is defined by (type, id, channel). Type is an integer which
|
|
|
|
* can be used in any way by the application (e.g. cast to a custom enum,
|
|
|
|
* map to/from a URI, etc). ID is type specific (e.g. MIDI controller #).
|
|
|
|
*
|
|
|
|
* This class defines a < operator which is a strict weak ordering, so
|
|
|
|
* Parameter may be stored in a std::set, used as a std::map key, etc.
|
|
|
|
*/
|
|
|
|
class Parameter
|
|
|
|
{
|
|
|
|
public:
|
2008-09-29 18:47:40 -04:00
|
|
|
Parameter(uint32_t type, uint8_t channel=0, uint32_t id=0)
|
2008-09-19 02:30:49 -04:00
|
|
|
: _type(type), _id(id), _channel(channel)
|
2008-09-18 20:47:49 -04:00
|
|
|
{}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-19 10:55:46 -04:00
|
|
|
virtual ~Parameter() {}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
inline uint32_t type() const { return _type; }
|
|
|
|
inline uint8_t channel() const { return _channel; }
|
2009-01-21 03:32:23 -05:00
|
|
|
inline uint32_t id() const { return _id; }
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
/** Equivalence operator
|
2008-09-18 20:47:49 -04:00
|
|
|
* It is obvious from the definition that this operator
|
|
|
|
* is transitive, as required by stict weak ordering
|
|
|
|
* (see: http://www.sgi.com/tech/stl/StrictWeakOrdering.html)
|
|
|
|
*/
|
|
|
|
inline bool operator==(const Parameter& id) const {
|
2009-01-21 03:32:23 -05:00
|
|
|
return (_type == id._type && _channel == id._channel && _id == id._id );
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/** Strict weak ordering
|
|
|
|
* See: http://www.sgi.com/tech/stl/StrictWeakOrdering.html
|
2010-07-27 10:09:16 -04:00
|
|
|
* Sort Parameters first according to type then to channel and lastly to ID.
|
2008-09-18 20:47:49 -04:00
|
|
|
*/
|
2009-01-21 03:32:23 -05:00
|
|
|
inline bool operator<(const Parameter& other) const {
|
|
|
|
if (_type < other._type) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
2009-01-21 03:32:23 -05:00
|
|
|
} else if (_type == other._type && _channel < other._channel) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
2009-01-21 03:32:23 -05:00
|
|
|
} else if (_type == other._type && _channel == other._channel && _id < other._id ) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
inline operator bool() const { return (_type != 0); }
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
/** Not used in indentity/comparison */
|
|
|
|
struct Metadata {
|
2010-12-24 17:48:05 -05:00
|
|
|
Metadata(double low=0.0, double high=1.0, double mid=0.0, bool tog=false)
|
|
|
|
: min(low), max(high), normal(mid), toggled(tog)
|
2008-09-19 02:30:49 -04:00
|
|
|
{}
|
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
double normal;
|
2010-12-24 17:48:05 -05:00
|
|
|
bool toggled;
|
2008-09-19 02:30:49 -04:00
|
|
|
};
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-12-24 17:48:05 -05:00
|
|
|
inline static void set_range(uint32_t type, double min, double max, double normal, bool toggled) {
|
2010-08-23 12:31:34 -04:00
|
|
|
_type_metadata[type] = Metadata(min, max, normal, toggled);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-12-24 17:48:05 -05:00
|
|
|
inline void set_range(double min, double max, double normal, bool toggled) {
|
|
|
|
_metadata = boost::shared_ptr<Metadata>(new Metadata(min, max, normal, toggled));
|
2008-09-19 02:30:49 -04:00
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
inline Metadata& metadata() const {
|
|
|
|
if (_metadata)
|
|
|
|
return *_metadata.get();
|
|
|
|
else
|
|
|
|
return _type_metadata[_type];
|
|
|
|
}
|
|
|
|
|
2010-08-23 12:31:34 -04:00
|
|
|
inline double min() const { return metadata().min; }
|
|
|
|
inline double max() const { return metadata().max; }
|
|
|
|
inline double normal() const { return metadata().normal; }
|
|
|
|
inline double toggled() const { return metadata().toggled; }
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Default copy constructor is ok
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
// ID (used in comparison)
|
|
|
|
uint32_t _type;
|
|
|
|
uint32_t _id;
|
|
|
|
uint8_t _channel;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
boost::shared_ptr<Metadata> _metadata;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
typedef std::map<uint32_t, Metadata> TypeMetadata;
|
|
|
|
static TypeMetadata _type_metadata;
|
2008-09-18 20:47:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Evoral
|
|
|
|
|
|
|
|
#endif // EVORAL_PARAMETER_HPP
|
|
|
|
|