#include "evoral/Curve.hpp"
#include "evoral/ParameterDescriptor.hpp"
#include "evoral/TypeMap.hpp"
+#include "evoral/types.hpp"
#include "pbd/compose.h"
#include "pbd/debug.h"
for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
delete (*x);
}
+ _events.clear ();
delete _curve;
}
_interpolation = other._interpolation;
_default_value = other._default_value;
-
+
copy_events (other);
}
ControlList::copy_events (const ControlList& other)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
+ for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
+ delete (*x);
+ }
_events.clear ();
for (const_iterator i = other.begin(); i != other.end(); ++i) {
_events.push_back (new ControlEvent ((*i)->when, (*i)->value));
ControlList::clear ()
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
+ for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
+ delete (*x);
+ }
_events.clear ();
unlocked_invalidate_insert_iterator ();
mark_dirty ();
void
ControlList::x_scale (double factor)
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
_x_scale (factor);
}
bool
ControlList::extend_to (double when)
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
if (_events.empty() || _events.back()->when == when) {
return false;
}
bool changed = false;
{
- Glib::Threads::Mutex::Lock lm (_lock);
-
+ Glib::Threads::RWLock::WriterLock lm (_lock);
+
ControlEvent* prevprev = 0;
ControlEvent* cur = 0;
ControlEvent* prev = 0;
iterator pprev;
int counter = 0;
-
+
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 thin from %2 events\n", this, _events.size()));
-
+
for (iterator i = _events.begin(); i != _events.end(); ++i) {
-
+
cur = *i;
counter++;
-
+
if (counter > 2) {
-
+
/* compute the area of the triangle formed by 3 points
*/
-
- double area = fabs ((prevprev->when * (prev->value - cur->value)) +
- (prev->when * (cur->value - prevprev->value)) +
+
+ double area = fabs ((prevprev->when * (prev->value - cur->value)) +
+ (prev->when * (cur->value - prevprev->value)) +
(cur->when * (prevprev->value - prev->value)));
-
+
if (area < thinning_factor) {
iterator tmp = pprev;
-
+
/* pprev will change to current
i is incremented to the next event
as we loop.
*/
-
+
pprev = i;
_events.erase (tmp);
changed = true;
continue;
}
}
-
+
prevprev = prev;
prev = cur;
pprev = i;
}
-
+
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 thin => %2 events\n", this, _events.size()));
if (changed) {
void
ControlList::fast_simple_add (double when, double value)
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
/* to be used only for loading pre-sorted data from saved state */
_events.insert (_events.end(), new ControlEvent (when, value));
- assert(_events.back());
mark_dirty ();
}
void
ControlList::invalidate_insert_iterator ()
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
unlocked_invalidate_insert_iterator ();
}
void
ControlList::start_write_pass (double when)
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
DEBUG_TRACE (DEBUG::ControlList, string_compose ("%1: setup write pass @ %2\n", this, when));
new_write_pass = true;
did_write_during_pass = false;
insert_position = when;
-
+
/* leave the insert iterator invalid, so that we will do the lookup
of where it should be in a "lazy" way - deferring it until
we actually add the first point (which may never happen).
*/
-
+
unlocked_invalidate_insert_iterator ();
}
void
ControlList::set_in_write_pass (bool yn, bool add_point, double when)
-{
+{
DEBUG_TRACE (DEBUG::ControlList, string_compose ("now in write pass @ %1, add point ? %2\n", when, add_point));
-
+
_in_write_pass = yn;
if (yn && add_point) {
most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
double eval_value = unlocked_eval (insert_position);
-
+
if (most_recent_insert_iterator == _events.end()) {
-
+
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert iterator at end, adding eval-value there %2\n", this, eval_value));
_events.push_back (new ControlEvent (when, eval_value));
/* leave insert iterator at the end */
-
+
} else if ((*most_recent_insert_iterator)->when == when) {
-
+
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert iterator at existing point, setting eval-value there %2\n", this, eval_value));
-
+
/* most_recent_insert_iterator points to a control event
already at the insert position, so there is
nothing to do.
-
- ... except ...
-
+
+ ... except ...
+
advance most_recent_insert_iterator so that the "real"
- insert occurs in the right place, since it
+ insert occurs in the right place, since it
points to the control event just inserted.
*/
-
+
++most_recent_insert_iterator;
} else {
-
+
/* insert a new control event at the right spot
*/
-
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert eval-value %2 just before iterator @ %3\n",
+
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert eval-value %2 just before iterator @ %3\n",
this, eval_value, (*most_recent_insert_iterator)->when));
-
+
most_recent_insert_iterator = _events.insert (most_recent_insert_iterator, new ControlEvent (when, eval_value));
-
+
/* advance most_recent_insert_iterator so that the "real"
- * insert occurs in the right place, since it
+ * insert occurs in the right place, since it
* points to the control event just inserted.
*/
-
+
++most_recent_insert_iterator;
}
-
+
/* don't do this again till the next write pass */
-
+
new_write_pass = false;
}
return _in_write_pass;
}
-void
-ControlList::editor_add (double when, double value)
+bool
+ControlList::editor_add (double when, double value, bool with_guard)
{
/* this is for making changes from a graphical line editor
*/
+ ControlEvent cp (when, 0.0f);
+ iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
+
+ if (i != _events.end () && (*i)->when == when) {
+ return false;
+ }
+
if (_events.empty()) {
-
+
/* as long as the point we're adding is not at zero,
* add an "anchor" point there.
*/
if (when >= 1) {
- _events.insert (_events.end(), new ControlEvent (0, _default_value));
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+ _events.insert (_events.end(), new ControlEvent (0, value));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added value %2 at zero\n", this, value));
}
}
- ControlEvent cp (when, 0.0f);
- iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
+ insert_position = when;
+ if (with_guard) {
+ if (when > 64) {
+ add_guard_point (when - 64);
+ }
+ maybe_add_insert_guard (when);
+ }
+
+ /* clamp new value to allowed range */
+
+ value = max (_min_yval, value);
+ value = min (_max_yval, value);
+
+ iterator result;
DEBUG_TRACE (DEBUG::ControlList, string_compose ("editor_add: actually add when= %1 value= %2\n", when, value));
- _events.insert (i, new ControlEvent (when, value));
+ result = _events.insert (i, new ControlEvent (when, value));
- mark_dirty ();
+ if (i == result) {
+ return false;
+ }
+ mark_dirty ();
maybe_signal_changed ();
+ return true;
}
void
new control point so that our insert will happen correctly. */
most_recent_insert_iterator = _events.insert (
most_recent_insert_iterator,
- new ControlEvent (when + 1, (*most_recent_insert_iterator)->value));
+ new ControlEvent (when + 64, (*most_recent_insert_iterator)->value));
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added insert guard point @ %2 = %3\n",
- this, when+1,
+ this, when + 64,
(*most_recent_insert_iterator)->value));
}
}
}
void
-ControlList::add (double when, double value, bool with_guards, bool with_default)
+ControlList::add (double when, double value, bool with_guards, bool with_initial)
{
/* this is for making changes from some kind of user interface or
control surface (GUI, MIDI, OSC etc)
this, value, when, with_guards, _in_write_pass, new_write_pass,
(most_recent_insert_iterator == _events.end())));
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
ControlEvent cp (when, 0.0f);
iterator insertion_point;
- if (_events.empty() && with_default) {
-
+ if (_events.empty() && with_initial) {
+
/* empty: add an "anchor" point if the point we're adding past time 0 */
if (when >= 1) {
- _events.insert (_events.end(), new ControlEvent (0, _default_value));
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+ if (_desc.toggled) {
+ const double opp_val = ((value < 0.5) ? 1.0 : 0.0);
+ _events.insert (_events.end(), new ControlEvent (0, opp_val));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added toggled value %2 at zero\n", this, opp_val));
+
+ } else {
+ _events.insert (_events.end(), new ControlEvent (0, value));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+ }
}
}
}
} else if (!_in_write_pass) {
-
+
/* not in a write pass: figure out the iterator we should insert in front of */
DEBUG_TRACE (DEBUG::ControlList, string_compose ("compute(b) MRI for position %1\n", when));
if (most_recent_insert_iterator == _events.end()) {
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 appending new point at end\n", this));
-
+
const bool done = maybe_insert_straight_line (when, value);
if (!done) {
_events.push_back (new ControlEvent (when, value));
if ((*most_recent_insert_iterator)->value != value) {
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 reset existing point to new value %2\n", this, value));
- /* only one point allowed per time point, so just
- * reset the value here.
+ /* only one point allowed per time point, so add a guard point
+ * before it if needed then reset the value of the point.
*/
-
+
(*most_recent_insert_iterator)->value = value;
/* if we modified the final value, then its as
} else {
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert new point at %2 at iterator at %3\n", this, when, (*most_recent_insert_iterator)->when));
-
- const bool done = maybe_insert_straight_line (when, value);
+ bool done = false;
+ /* check for possible straight line here until maybe_insert_straight_line () handles the insert iterator properly*/
+ if (most_recent_insert_iterator != _events.begin ()) {
+ bool have_point2 = false;
+ --most_recent_insert_iterator;
+ const bool have_point1 = (*most_recent_insert_iterator)->value == value;
+
+ if (most_recent_insert_iterator != _events.begin ()) {
+ --most_recent_insert_iterator;
+ have_point2 = (*most_recent_insert_iterator)->value == value;
+ ++most_recent_insert_iterator;
+ }
+
+ if (have_point1 && have_point2) {
+ (*most_recent_insert_iterator)->when = when;
+ done = true;
+ } else {
+ ++most_recent_insert_iterator;
+ }
+ }
+ //done = maybe_insert_straight_line (when, value) || done;
+ /* if the transport is stopped, add guard points (?) */
+ if (!done && !_in_write_pass && when > 64) {
+ add_guard_point (when - 64);
+ maybe_add_insert_guard (when);
+ }
+
if (with_guards) {
- maybe_add_insert_guard(when);
+ maybe_add_insert_guard (when);
}
if (!done) {
ControlList::erase (iterator i)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
if (most_recent_insert_iterator == i) {
unlocked_invalidate_insert_iterator ();
}
ControlList::erase (iterator start, iterator end)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
_events.erase (start, end);
unlocked_invalidate_insert_iterator ();
mark_dirty ();
ControlList::erase (double when, double value)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
iterator i = begin ();
while (i != end() && ((*i)->when != when || (*i)->value != value)) {
bool erased = false;
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
erased = erase_range_internal (start, endt, _events);
if (erased) {
ControlList::slide (iterator before, double distance)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
if (before == _events.end()) {
return;
ControlList::shift (double pos, double frames)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
for (iterator i = _events.begin(); i != _events.end(); ++i) {
if ((*i)->when >= pos) {
*/
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
(*iter)->when = when;
(*iter)->value = val;
std::pair<ControlList::iterator,ControlList::iterator>
ControlList::control_points_adjacent (double xval)
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::ReaderLock lm (_lock);
iterator i;
ControlEvent cp (xval, 0.0f);
std::pair<iterator,iterator> ret;
}
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
if (_sort_pending) {
_events.sort (event_time_less_than);
ControlList::truncate_end (double last_coordinate)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
ControlEvent cp (last_coordinate, 0);
ControlList::reverse_iterator i;
double last_val;
_events.back()->when = last_coordinate;
_events.back()->value = last_val;
}
-
+
unlocked_invalidate_insert_iterator ();
mark_dirty();
}
ControlList::truncate_start (double overall_length)
{
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
iterator i;
double first_legal_value;
double first_legal_coordinate;
- assert(!_events.empty());
-
- if (overall_length == _events.back()->when) {
+ if (_events.empty()) {
+ /* nothing to truncate */
+ return;
+ } else if (overall_length == _events.back()->when) {
/* no change in overall length */
return;
}
return lval;
}
- /* linear interpolation betweeen the two points */
+ /* linear interpolation between the two points */
fraction = (double) (x - lpos) / (double) (upos - lpos);
return lval + (fraction * (uval - lval));
void
ControlList::build_search_cache_if_necessary (double start) const
{
- /* Only do the range lookup if x is in a different range than last time
- * this was called (or if the search cache has been marked "dirty" (left<0) */
if (_events.empty()) {
+ /* Empty, nothing to cache, move to end. */
_search_cache.first = _events.end();
_search_cache.left = 0;
+ return;
} else if ((_search_cache.left < 0) || (_search_cache.left > start)) {
+ /* Marked dirty (left < 0), or we're too far forward, re-search. */
const ControlEvent start_point (start, 0);
- //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
- // << start << ".." << end << ")" << endl;
-
_search_cache.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
_search_cache.left = start;
}
+
+ /* We now have a search cache that is not too far right, but it may be too
+ far left and need to be advanced. */
+
+ while (_search_cache.first != end() && (*_search_cache.first)->when < start) {
+ ++_search_cache.first;
+ }
+ _search_cache.left = start;
}
/** Get the earliest event after \a start using the current interpolation style.
ControlList::rt_safe_earliest_event (double start, double& x, double& y, bool inclusive) const
{
// FIXME: It would be nice if this was unnecessary..
- Glib::Threads::Mutex::Lock lm(_lock, Glib::Threads::TRY_LOCK);
+ Glib::Threads::RWLock::ReaderLock lm(_lock, Glib::Threads::TRY_LOCK);
if (!lm.locked()) {
return false;
}
const ControlEvent* first = NULL;
const ControlEvent* next = NULL;
- /* Step is after first */
if (_search_cache.first == _events.begin() || (*_search_cache.first)->when <= start) {
+ /* Step is after first */
first = *_search_cache.first;
++_search_cache.first;
if (_search_cache.first == _events.end()) {
}
next = *_search_cache.first;
- /* Step is before first */
} else {
+ /* Step is before first */
const_iterator prev = _search_cache.first;
--prev;
first = *prev;
return true;
}
- /* No points in the future, so no steps (towards them) in the future */
} else {
+ /* No points in the future, so no steps (towards them) in the future */
return false;
}
}
ControlEvent cp (start, 0.0);
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
/* first, determine s & e, two iterators that define the range of points
affected by this operation
}
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
iterator where;
iterator prev;
double end = 0;
where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
for (const_iterator i = alist.begin();i != alist.end(); ++i) {
- _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
+ double value = (*i)->value;
+ if (alist.parameter() != parameter()) {
+ const ParameterDescriptor& src_desc = alist.descriptor();
+
+ // This does not work for logscale and will probably also not do
+ // the right thing for integer_step and sr_dependent parameters.
+ //
+ // TODO various flags from from ARDOUR::ParameterDescriptor
+ // to Evoral::ParameterDescriptor
+
+ value -= src_desc.lower; // translate to 0-relative
+ value /= (src_desc.upper - src_desc.lower); // normalize range
+ value *= (_desc.upper - _desc.lower); // scale to our range
+ value += _desc.lower; // translate to our offset
+ if (_desc.toggled) {
+ value = (value < 0.5) ? 0.0 : 1.0;
+ }
+ }
+ _events.insert (where, new ControlEvent((*i)->when + pos, value));
end = (*i)->when + pos;
}
typedef list< RangeMove<double> > RangeMoveList;
{
- Glib::Threads::Mutex::Lock lm (_lock);
+ Glib::Threads::RWLock::WriterLock lm (_lock);
/* a copy of the events list before we started moving stuff around */
EventList old_events = _events;
if (i != _events.end ()) {
return true;
}
-
+
return (
_parameter != other._parameter ||
_interpolation != other._interpolation ||