X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fevoral%2Fevoral%2FControlList.hpp;h=3d70fbdda48e931613271bea2e24d1ee9721aac3;hb=8a18929d57ef82b1233278668a9efe78fe1c17f0;hp=01e0f8c1fb57a1b514566a2df289ccd6d3f3d97a;hpb=bdde5da89bc9225815fe9a54e4ab39eb63574ac3;p=ardour.git diff --git a/libs/evoral/evoral/ControlList.hpp b/libs/evoral/evoral/ControlList.hpp index 01e0f8c1fb..3d70fbdda4 100644 --- a/libs/evoral/evoral/ControlList.hpp +++ b/libs/evoral/evoral/ControlList.hpp @@ -21,20 +21,29 @@ #include #include +#include + #include #include -#include + +#include + #include "pbd/signals.h" -#include "evoral/types.hpp" + +#include "evoral/visibility.h" +#include "evoral/Range.hpp" #include "evoral/Parameter.hpp" +#include "evoral/ParameterDescriptor.hpp" namespace Evoral { class Curve; +class TypeMap; /** A single event (time-stamped value) for a control */ -struct ControlEvent { +class LIBEVORAL_API ControlEvent { +public: ControlEvent (double w, double v) : when (w), value (v), coeff (0) {} @@ -63,37 +72,29 @@ struct ControlEvent { double* coeff; ///< double[4] allocated by Curve as needed }; - -/** Pool allocator for control lists that does not use a lock - * and allocates 8k blocks of new pointers at a time - */ -typedef boost::fast_pool_allocator< - ControlEvent*, - boost::default_user_allocator_new_delete, - boost::details::pool::null_mutex, - 8192> -ControlEventAllocator; - - /** A list (sequence) of time-stamped values for a control */ -class ControlList +class LIBEVORAL_API ControlList { public: - typedef std::list EventList; + typedef std::list EventList; typedef EventList::iterator iterator; typedef EventList::reverse_iterator reverse_iterator; typedef EventList::const_iterator const_iterator; + typedef EventList::const_reverse_iterator const_reverse_iterator; - ControlList (const Parameter& id); + ControlList (const Parameter& id, const ParameterDescriptor& desc); ControlList (const ControlList&); ControlList (const ControlList&, double start, double end); virtual ~ControlList(); - virtual boost::shared_ptr create(Parameter id); + virtual boost::shared_ptr create(const Parameter& id, const ParameterDescriptor& desc); + + void dump (std::ostream&); ControlList& operator= (const ControlList&); bool operator== (const ControlList&); + void copy_events (const ControlList&); virtual void freeze(); virtual void thaw (); @@ -102,12 +103,15 @@ public: 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(); } + const ParameterDescriptor& descriptor() const { return _desc; } + void set_descriptor(const ParameterDescriptor& d) { _desc = d; } - void reset_default (double val) { - _default_value = val; + EventList::size_type size() const { return _events.size(); } + double length() const { + Glib::Threads::RWLock::ReaderLock lm (_lock); + return _events.empty() ? 0.0 : _events.back()->when; } + bool empty() const { return _events.empty(); } void clear (); void x_scale (double factor); @@ -115,14 +119,22 @@ public: void slide (iterator before, double distance); void shift (double before, double distance); - virtual bool clamp_value (double& /*when*/, double& /*value*/) const { return true; } + void y_transform (boost::function callback); + void list_merge (ControlList const& other, boost::function callback); + + /** add automation events + * @param when absolute time in samples + * @param value parameter value + * @param with_guards if true, add guard-points + * @param with_initial if true, add an initial point if the list is empty + */ + virtual void add (double when, double value, bool with_guards=true, bool with_initial=true); + + virtual bool editor_add (double when, double value, bool with_guard); - void rt_add (double when, double value); - void add (double when, double value); + /* to be used only for loading pre-sorted data from saved state */ void fast_simple_add (double when, double value); - void merge_nascent (double when); - void reset_range (double start, double end); void erase_range (double start, double end); void erase (iterator); void erase (iterator, iterator); @@ -130,29 +142,54 @@ public: bool move_ranges (std::list< RangeMove > const &); void modify (iterator, double, double); - void thin (); + /** Thin the number of events in this list. + * + * The thinning factor corresponds to the area of a triangle computed + * between three points in the list (time-difference * value-difference). + * If the area is large, it indicates significant non-linearity between + * the points. + * + * Time is measured in samples, value is usually normalized to 0..1. + * + * During automation recording we thin the recorded points using this + * value. If a point is sufficiently co-linear with its neighbours (as + * defined by the area of the triangle formed by three of them), we will + * not include it in the list. The larger the value, the more points are + * excluded, so this effectively measures the amount of thinning to be + * done. + * + * @param thinning_factor area-size (default: 20) + */ + void thin (double thinning_factor); boost::shared_ptr cut (double, double); boost::shared_ptr copy (double, double); - void clear (double, double); - - bool paste (ControlList&, double position, float times); - void set_yrange (double min, double max) { - _min_yval = min; - _max_yval = max; - } + /** remove all automation events between the given time range + * @param start start of range (inclusive) in audio samples + * @param end end of range (inclusive) in audio samples + */ + void clear (double start, double end); - double get_max_y() const { return _max_yval; } - double get_min_y() const { return _min_yval; } + bool paste (const ControlList&, double position); - void truncate_end (double length); - void truncate_start (double length); + /** truncate the event list after the given time + * @param last_coordinate last event to include + */ + void truncate_end (double last_coordinate); + /** truncate the event list to the given time + * @param overall_length overall length + */ + void truncate_start (double overall_length); iterator begin() { return _events.begin(); } const_iterator begin() const { return _events.begin(); } iterator end() { return _events.end(); } const_iterator end() const { return _events.end(); } + reverse_iterator rbegin() { return _events.rbegin(); } + const_reverse_iterator rbegin() const { return _events.rbegin(); } + reverse_iterator rend() { return _events.rend(); } + const_reverse_iterator rend() const { return _events.rend(); } ControlEvent* back() { return _events.back(); } const ControlEvent* back() const { return _events.back(); } ControlEvent* front() { return _events.front(); } @@ -161,18 +198,27 @@ public: std::pair control_points_adjacent (double when); template void apply_to_points (T& obj, void (T::*method)(const ControlList&)) { - Glib::Mutex::Lock lm (_lock); + Glib::Threads::RWLock::WriterLock lm (_lock); (obj.*method)(*this); } - double eval (double where) { - Glib::Mutex::Lock lm (_lock); + /** query value at given time (takes a read-lock, not safe while writing automation) + * @param where absolute time in samples + * @returns parameter value + */ + double eval (double where) const { + Glib::Threads::RWLock::ReaderLock lm (_lock); return unlocked_eval (where); } - double rt_safe_eval (double where, bool& ok) { + /** realtime safe version of eval, may fail if read-lock cannot be taken + * @param where absolute time in samples + * @param ok boolean reference if returned value is valid + * @returns parameter value + */ + double rt_safe_eval (double where, bool& ok) const { - Glib::Mutex::Lock lm (_lock, Glib::TRY_LOCK); + Glib::Threads::RWLock::ReaderLock lm (_lock, Glib::Threads::TRY_LOCK); if ((ok = lm.locked())) { return unlocked_eval (where); @@ -200,10 +246,9 @@ public: }; const EventList& events() const { return _events; } - double default_value() const { return _parameter.normal(); } // FIXME: const violations for Curve - Glib::Mutex& lock() const { return _lock; } + Glib::Threads::RWLock& lock() const { return _lock; } LookupCache& lookup_cache() const { return _lookup_cache; } SearchCache& search_cache() const { return _search_cache; } @@ -230,24 +275,47 @@ public: enum InterpolationStyle { Discrete, Linear, - Curved + Curved, // spline, used for x-fades + Logarithmic, + Exponential // fader, gain }; + /** query interpolation style of the automation data + * @returns Interpolation Style + */ InterpolationStyle interpolation() const { return _interpolation; } - void set_interpolation (InterpolationStyle); + + /** query default interpolation for parameter-descriptor */ + virtual InterpolationStyle default_interpolation() const; + + /** set the interpolation style of the automation data. + * + * This will fail when asking for Logarithmic scale and min,max crosses 0 + * or Exponential scale with min != 0. + * + * @param is interpolation style + * @returns true if style change was successful + */ + bool set_interpolation (InterpolationStyle is); virtual bool touching() const { return false; } virtual bool writing() const { return false; } virtual bool touch_enabled() const { return false; } - void write_pass_finished (double when); + void start_write_pass (double when); + void write_pass_finished (double when, double thinning_factor=0.0); + void set_in_write_pass (bool, bool add_point = false, double when = 0.0); + bool in_write_pass () const; + bool in_new_write_pass () { return new_write_pass; } + PBD::Signal0 WritePassStarted; /** Emitted when mark_dirty() is called on this object */ mutable PBD::Signal0 Dirty; /** Emitted when our interpolation style changes */ PBD::Signal1 InterpolationChanged; - static void set_thinning_factor (double d); - static double thinning_factor() { return _thinning_factor; } + bool operator!= (ControlList const &) const; + + void invalidate_insert_iterator (); protected: @@ -259,6 +327,10 @@ protected: boost::shared_ptr cut_copy_clear (double, double, int op); bool erase_range_internal (double start, double end, EventList &); + void maybe_add_insert_guard (double when); + iterator erase_from_iterator_to (iterator iter, double when); + bool maybe_insert_straight_line (double when, double value); + virtual void maybe_signal_changed (); void _x_scale (double factor); @@ -266,32 +338,30 @@ protected: mutable LookupCache _lookup_cache; mutable SearchCache _search_cache; + mutable Glib::Threads::RWLock _lock; + Parameter _parameter; + ParameterDescriptor _desc; InterpolationStyle _interpolation; EventList _events; - mutable Glib::Mutex _lock; int8_t _frozen; bool _changed_when_thawed; - double _min_yval; - double _max_yval; - double _default_value; bool _sort_pending; Curve* _curve; - struct NascentInfo { - EventList events; - double start_time; - double end_time; +private: + iterator most_recent_insert_iterator; + double insert_position; + bool new_write_pass; + bool did_write_during_pass; + bool _in_write_pass; - NascentInfo (double start = -1.0) - : start_time (start) - , end_time (-1.0) - {} - }; + void unlocked_remove_duplicates (); + void unlocked_invalidate_insert_iterator (); + void add_guard_point (double when, double offset); - std::list nascent; - static double _thinning_factor; + bool is_sorted () const; }; } // namespace Evoral