diff options
Diffstat (limited to 'libs/evoral')
-rw-r--r-- | libs/evoral/evoral/Control.hpp | 2 | ||||
-rw-r--r-- | libs/evoral/evoral/ControlList.hpp | 6 | ||||
-rw-r--r-- | libs/evoral/evoral/ControlSet.hpp | 6 | ||||
-rw-r--r-- | libs/evoral/evoral/MIDIParameters.hpp | 29 | ||||
-rw-r--r-- | libs/evoral/evoral/Parameter.hpp | 66 | ||||
-rw-r--r-- | libs/evoral/evoral/Sequence.hpp | 2 | ||||
-rw-r--r-- | libs/evoral/src/Control.cpp | 4 | ||||
-rw-r--r-- | libs/evoral/src/ControlList.cpp | 2 | ||||
-rw-r--r-- | libs/evoral/src/ControlSet.cpp | 4 | ||||
-rw-r--r-- | libs/evoral/src/Sequence.cpp | 2 |
10 files changed, 80 insertions, 43 deletions
diff --git a/libs/evoral/evoral/Control.hpp b/libs/evoral/evoral/Control.hpp index ed957522a1..15d50fcdca 100644 --- a/libs/evoral/evoral/Control.hpp +++ b/libs/evoral/evoral/Control.hpp @@ -46,7 +46,7 @@ public: boost::shared_ptr<ControlList> list() { return _list; } boost::shared_ptr<const ControlList> list() const { return _list; } - Parameter parameter() const; + const Parameter& parameter() const; protected: boost::shared_ptr<ControlList> _list; diff --git a/libs/evoral/evoral/ControlList.hpp b/libs/evoral/evoral/ControlList.hpp index c035b6ddcf..45519955c5 100644 --- a/libs/evoral/evoral/ControlList.hpp +++ b/libs/evoral/evoral/ControlList.hpp @@ -83,7 +83,7 @@ public: typedef EventList::reverse_iterator reverse_iterator; typedef EventList::const_iterator const_iterator; - ControlList (Parameter id); + ControlList (const Parameter& id); //ControlList (const XMLNode&, Parameter id); ~ControlList(); @@ -97,8 +97,8 @@ public: void freeze(); void thaw (); - const Parameter& parameter() const { return _parameter; } - void set_parameter(Parameter p) { _parameter = p; } + const Parameter& parameter() const { return _parameter; } + void set_parameter(const Parameter& p) { _parameter = p; } EventList::size_type size() const { return _events.size(); } bool empty() const { return _events.empty(); } diff --git a/libs/evoral/evoral/ControlSet.hpp b/libs/evoral/evoral/ControlSet.hpp index ba6e5e5623..73fa5554e6 100644 --- a/libs/evoral/evoral/ControlSet.hpp +++ b/libs/evoral/evoral/ControlSet.hpp @@ -37,8 +37,8 @@ public: ControlSet(); virtual ~ControlSet() {} - virtual boost::shared_ptr<Control> control(Evoral::Parameter id, bool create_if_missing=false); - virtual boost::shared_ptr<const Control> control(Evoral::Parameter id) const; + virtual boost::shared_ptr<Control> control(const Parameter& id, bool create_if_missing=false); + virtual boost::shared_ptr<const Control> control(const Parameter& id) const; virtual boost::shared_ptr<Control> control_factory(boost::shared_ptr<ControlList> list) const; virtual boost::shared_ptr<ControlList> control_list_factory(const Parameter& param) const; @@ -51,7 +51,7 @@ public: virtual bool find_next_event(nframes_t start, nframes_t end, ControlEvent& ev) const; - virtual float default_parameter_value(Parameter param) { return 1.0f; } + virtual float default_parameter_value(const Parameter& param) { return 1.0f; } virtual void clear(); diff --git a/libs/evoral/evoral/MIDIParameters.hpp b/libs/evoral/evoral/MIDIParameters.hpp index c21a86264d..e2bfdc3fb0 100644 --- a/libs/evoral/evoral/MIDIParameters.hpp +++ b/libs/evoral/evoral/MIDIParameters.hpp @@ -23,29 +23,34 @@ namespace Evoral { namespace MIDI { struct ContinuousController : public Parameter { - ContinuousController(uint32_t cc_type, uint32_t channel, uint32_t controller) - : Parameter(cc_type, controller, channel) { set_range(*this); } - static void set_range(Parameter& p) { p.set_range(0.0, 127.0, 0.0); } + ContinuousController(uint32_t cc_type, uint8_t channel, uint32_t controller) + : Parameter(cc_type, channel, controller) {} }; struct ProgramChange : public Parameter { - ProgramChange(uint32_t pc_type, uint32_t channel) - : Parameter(pc_type, 0, channel) { set_range(*this); } - static void set_range(Parameter& p) { p.set_range(0.0, 127.0, 0.0); } + ProgramChange(uint32_t pc_type, uint8_t channel) : Parameter(pc_type, 0, channel) {} }; struct ChannelAftertouch : public Parameter { - ChannelAftertouch(uint32_t ca_type, uint32_t channel) - : Parameter(ca_type, 0, channel) { set_range(*this); } - static void set_range(Parameter& p) { p.set_range(0.0, 127.0, 0.0); } + ChannelAftertouch(uint32_t ca_type, uint32_t channel) : Parameter(ca_type, 0, channel) {} }; struct PitchBender : public Parameter { - PitchBender(uint32_t pb_type, uint32_t channel) - : Parameter(pb_type, 0, channel) { set_range(*this); } - static void set_range(Parameter& p) { p.set_range(0.0, 16383.0, 8192.0); } + PitchBender(uint32_t pb_type, uint32_t channel) : Parameter(pb_type, 0, channel) {} }; +inline static void controller_range(double& min, double& max, double& normal) { + min = 0.0; + normal = 0.0; + max = 127.0; +} + +inline static void bender_range(double& min, double& max, double& normal) { + min = 0.0; + normal = 8192.0; + max = 16383.0; +} + } // namespace MIDI } // namespace Evoral diff --git a/libs/evoral/evoral/Parameter.hpp b/libs/evoral/evoral/Parameter.hpp index ae405ec039..301a432bd0 100644 --- a/libs/evoral/evoral/Parameter.hpp +++ b/libs/evoral/evoral/Parameter.hpp @@ -20,7 +20,10 @@ #define EVORAL_PARAMETER_HPP #include <string> +#include <map> +#include <boost/shared_ptr.hpp> #include <boost/format.hpp> +#include <iostream> namespace Evoral { @@ -37,19 +40,27 @@ namespace Evoral { class Parameter { public: - Parameter(uint32_t type, uint32_t id, int8_t channel=0, - double min=0.0f, double max=0.0f, double def=0.0f) - : _type(type), _id(id), _channel(channel), _min(min), _max(max), _normal(def) + Parameter(uint32_t type, uint8_t channel, uint32_t id=0) + : _type(type), _id(id), _channel(channel) {} - //Parameter(const std::string& str); + Parameter(const std::string& str) { + int channel; + if (sscanf(str.c_str(), "%d_c%d_n%d", &_type, &channel, &_id) == 3) { + if (channel >= 0 && channel <= 127) { + _channel = channel; + } else { + std::cerr << "WARNING: Channel out of range: " << channel << std::endl; + } + } + std::cerr << "WARNING: Unable to create parameter from string: " << str << std::endl; + } inline uint32_t type() const { return _type; } inline uint32_t id() const { return _id; } inline uint8_t channel() const { return _channel; } - /** - * Equivalence operator + /** Equivalence operator * 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) @@ -101,18 +112,37 @@ public: inline operator bool() const { return (_type != 0); } virtual std::string symbol() const { - return (boost::format("%1%_c%2%_n%3%\n") % _type % _channel % _id).str(); + return (boost::format("%1%_c%2%_n%3%") % _type % (int)_channel % _id).str(); } + + /** Not used in indentity/comparison */ + struct Metadata { + Metadata(double low=0.0, double high=1.0, double mid=0.0) + : min(low), max(high), normal(mid) + {} + double min; + double max; + double normal; + }; - inline void set_range(double min, double max, double normal) { - _min = min; - _max = max; - _normal = normal; + inline static void set_range(uint32_t type, double min, double max, double normal) { + _type_metadata[type] = Metadata(min, max, normal); } - inline const double min() const { return _min; } - inline const double max() const { return _max; } - inline const double normal() const { return _normal; } + inline void set_range(double min, double max, double normal) { + _metadata = boost::shared_ptr<Metadata>(new Metadata(min, max, normal)); + } + + inline Metadata& metadata() const { + if (_metadata) + return *_metadata.get(); + else + return _type_metadata[_type]; + } + + inline const double min() const { return metadata().min; } + inline const double max() const { return metadata().max; } + inline const double normal() const { return metadata().normal; } protected: // Default copy constructor is ok @@ -121,11 +151,11 @@ protected: uint32_t _type; uint32_t _id; uint8_t _channel; + + boost::shared_ptr<Metadata> _metadata; - // Metadata (not used in comparison) - double _min; - double _max; - double _normal; + typedef std::map<uint32_t, Metadata> TypeMetadata; + static TypeMetadata _type_metadata; }; diff --git a/libs/evoral/evoral/Sequence.hpp b/libs/evoral/evoral/Sequence.hpp index 0f1de2a7af..10a61704ed 100644 --- a/libs/evoral/evoral/Sequence.hpp +++ b/libs/evoral/evoral/Sequence.hpp @@ -177,7 +177,7 @@ private: void append_note_on_unlocked(uint8_t chan, double time, uint8_t note, uint8_t velocity); void append_note_off_unlocked(uint8_t chan, double time, uint8_t note); - void append_control_unlocked(Parameter param, double time, double value); + void append_control_unlocked(const Parameter& param, double time, double value); mutable Glib::RWLock _lock; diff --git a/libs/evoral/src/Control.cpp b/libs/evoral/src/Control.cpp index 8efc2a6659..d23f6c3c9a 100644 --- a/libs/evoral/src/Control.cpp +++ b/libs/evoral/src/Control.cpp @@ -22,6 +22,8 @@ namespace Evoral { +Parameter::TypeMetadata Parameter::_type_metadata; + Control::Control(boost::shared_ptr<ControlList> list) : _list(list) , _user_value(list->default_value()) @@ -72,7 +74,7 @@ Control::set_list(boost::shared_ptr<ControlList> list) } -Parameter +const Parameter& Control::parameter() const { return _list->parameter(); diff --git a/libs/evoral/src/ControlList.cpp b/libs/evoral/src/ControlList.cpp index 8f6ea1872f..62c49a97e6 100644 --- a/libs/evoral/src/ControlList.cpp +++ b/libs/evoral/src/ControlList.cpp @@ -33,7 +33,7 @@ inline bool event_time_less_than (ControlEvent* a, ControlEvent* b) } -ControlList::ControlList (Parameter id) +ControlList::ControlList (const Parameter& id) : _parameter(id) , _interpolation(Linear) , _curve(new Curve(*this)) diff --git a/libs/evoral/src/ControlSet.cpp b/libs/evoral/src/ControlSet.cpp index 93a0b0ef25..5aacff598d 100644 --- a/libs/evoral/src/ControlSet.cpp +++ b/libs/evoral/src/ControlSet.cpp @@ -53,7 +53,7 @@ ControlSet::what_has_data (set<Parameter>& s) const * for \a parameter does not exist. */ boost::shared_ptr<Control> -ControlSet::control (Parameter parameter, bool create_if_missing) +ControlSet::control (const Parameter& parameter, bool create_if_missing) { Controls::iterator i = _controls.find(parameter); @@ -73,7 +73,7 @@ ControlSet::control (Parameter parameter, bool create_if_missing) } boost::shared_ptr<const Control> -ControlSet::control (Parameter parameter) const +ControlSet::control (const Parameter& parameter) const { Controls::const_iterator i = _controls.find(parameter); diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index 81502fdb5f..4880b5a04d 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -587,7 +587,7 @@ void Sequence::append_note_off_unlocked(uint8_t chan, double time, } } -void Sequence::append_control_unlocked(Parameter param, double time, double value) +void Sequence::append_control_unlocked(const Parameter& param, double time, double value) { control(param, true)->list()->rt_add(time, value); } |