_changed_when_thawed = false;
_min_yval = id.min();
_max_yval = id.max();
- _default_value = 0;
+ _default_value = id.normal();
_lookup_cache.left = -1;
_lookup_cache.range.first = _events.end();
_search_cache.left = -1;
}
};
-#if 0
-
-void
-ControlList::merge_nascent (double when)
-{
- {
- Glib::Threads::Mutex::Lock lm (_lock);
-
- if (nascent.empty()) {
- return;
- }
-
- bool was_empty = _events.empty();
-
- for (list<NascentInfo*>::iterator n = nascent.begin(); n != nascent.end(); ++n) {
-
- NascentInfo* ninfo = *n;
- EventList& nascent_events (ninfo->events);
- bool need_adjacent_start_clamp;
- bool need_adjacent_end_clamp;
- EventList::iterator at;
-
- if (nascent_events.empty()) {
- delete ninfo;
- continue;
- }
-
- nascent_events.sort (ControlEventTimeComparator ());
-
- if (ninfo->start_time < 0.0) {
- ninfo->start_time = nascent_events.front()->when;
- }
-
- if (ninfo->end_time < 0.0) {
- ninfo->end_time = when;
- }
-
- if (_events.empty()) {
-
- /* add an initial point just before
- the nascent data, unless nascent_events
- contains a point at zero or one
- */
-
- if (ninfo->start_time > 0) {
- nascent_events.insert (nascent_events.begin(), new ControlEvent (ninfo->start_time - 1, _default_value));
- }
-
- /* add closing "clamp" point before we insert */
-
- nascent_events.insert (nascent_events.end(), new ControlEvent (ninfo->end_time + 1, _default_value));
-
- /* insert - front or back doesn't matter since
- * _events is empty
- */
-
- _events.insert (_events.begin(), nascent_events.begin(), nascent_events.end());
-
- } else if (ninfo->end_time < _events.front()->when) {
-
- /* all points in nascent are before the first existing point */
-
- if (ninfo->start_time > (_events.front()->when + 1)) {
- nascent_events.insert (nascent_events.begin(), new ControlEvent (ninfo->start_time - 1, _default_value));
- }
-
- /* add closing "clamp" point before we insert */
-
- nascent_events.insert (nascent_events.end(), new ControlEvent (ninfo->end_time + 1, _default_value));
-
- /* insert at front */
-
- _events.insert (_events.begin(), nascent_events.begin(), nascent_events.end());
-
- /* now add another default control point right
- after the inserted nascent data
- */
-
- } else if (ninfo->start_time > _events.back()->when) {
-
- /* all points in nascent are after the last existing point */
-
- if (ninfo->start_time > (_events.back()->when + 1)) {
- nascent_events.insert (nascent_events.begin(), new ControlEvent (ninfo->start_time - 1, _default_value));
- }
-
- /* add closing "clamp" point before we insert */
-
- nascent_events.insert (nascent_events.end(), new ControlEvent (ninfo->end_time + 1, _default_value));
-
- /* insert */
-
- _events.insert (_events.end(), nascent_events.begin(), nascent_events.end());
-
- } else {
-
- /* find the range that overlaps with nascent events,
- and insert the contents of nascent events.
- */
-
- iterator i;
- iterator range_begin = _events.end();
- iterator range_end = _events.end();
- double end_value = unlocked_eval (ninfo->end_time);
- double start_value = unlocked_eval (ninfo->start_time - 1);
-
- need_adjacent_end_clamp = true;
- need_adjacent_start_clamp = true;
-
- for (i = _events.begin(); i != _events.end(); ++i) {
-
- if ((*i)->when == ninfo->start_time) {
- /* existing point at same time, remove it
- and the consider the next point instead.
- */
- i = _events.erase (i);
-
- if (i == _events.end()) {
- break;
- }
-
- if (range_begin == _events.end()) {
- range_begin = i;
- need_adjacent_start_clamp = false;
- } else {
- need_adjacent_end_clamp = false;
- }
-
- if ((*i)->when > ninfo->end_time) {
- range_end = i;
- break;
- }
-
- } else if ((*i)->when > ninfo->start_time) {
-
- if (range_begin == _events.end()) {
- range_begin = i;
- }
-
- if ((*i)->when > ninfo->end_time) {
- range_end = i;
- break;
- }
- }
- }
-
- /* Now:
- range_begin is the first event on our list after the first nascent event
- range_end is the first event on our list after the last nascent event
-
- range_begin may be equal to _events.end() if the last event on our list
- was at the same time as the first nascent event.
- */
-
- if (range_begin != _events.begin()) {
- /* clamp point before */
- if (need_adjacent_start_clamp) {
- _events.insert (range_begin, new ControlEvent (ninfo->start_time, start_value));
- }
- }
-
- _events.insert (range_begin, nascent_events.begin(), nascent_events.end());
-
- if (range_end != _events.end()) {
- /* clamp point after */
- if (need_adjacent_end_clamp) {
- _events.insert (range_begin, new ControlEvent (ninfo->end_time, end_value));
- }
- }
-
- _events.erase (range_begin, range_end);
- }
-
- delete ninfo;
- }
-
- if (was_empty && !_events.empty()) {
- if (_events.front()->when != 0) {
- _events.insert (_events.begin(), new ControlEvent (0, _default_value));
- }
- }
-
- nascent.clear ();
-
- if (writing()) {
- nascent.push_back (new NascentInfo ());
- }
- }
-
- maybe_signal_changed ();
-}
-#endif
-
void
ControlList::thin ()
{
{
Glib::Threads::Mutex::Lock 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::write_pass_finished (double when)
+ControlList::write_pass_finished (double /*when*/)
{
+ DEBUG_TRACE (DEBUG::ControlList, "write pass finished\n");
+
if (did_write_during_pass) {
thin ();
did_write_during_pass = false;
}
void
-ControlList::set_in_write_pass (bool yn)
-{
+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) {
+ add_guard_point (when);
+ }
+}
+
+void
+ControlList::add_guard_point (double when)
+{
+ ControlEvent cp (when, 0.0);
+ 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 ...
+
+ advance most_recent_insert_iterator so that the "real"
+ 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",
+ 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
+ * 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;
}
bool
}
void
-ControlList::add (double when, double value)
+ControlList::add (double when, double value, bool with_guards)
{
/* this is for making changes from some kind of user interface or
control surface (GUI, MIDI, OSC etc)
return;
}
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 add %2 at %3 w/erase = %4 at end ? %5\n",
- this, value, when, _in_write_pass, (most_recent_insert_iterator == _events.end())));
-
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 add %2 at %3 w/erase = %4 (new ? %6) at end ? %5\n",
+ this, value, when, _in_write_pass, (most_recent_insert_iterator == _events.end()), new_write_pass));
{
Glib::Threads::Mutex::Lock lm (_lock);
ControlEvent cp (when, 0.0f);
* add an "anchor" point there.
*/
- if (when > 1) {
+ 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 (_in_write_pass && new_write_pass) {
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 new write pass, insert pos = %2\n", this, insert_position));
-
- /* The first addition of a new control event during a
- * write pass.
- *
- * We need to add a new point at insert_position
- * corresponding the value there.
- */
+ if (with_guards) {
+ add_guard_point (insert_position);
+ did_write_during_pass = true;
+ }
- /* the insert_iterator is not set, figure out where
- * it needs to be.
- */
+ } else if (most_recent_insert_iterator == _events.end() || when > (*most_recent_insert_iterator)->when) {
- ControlEvent cp (insert_position, 0.0);
- most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 looked up insert iterator for new write pass\n", this));
-
- double eval_value = unlocked_eval (insert_position);
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 %2 erase from existing iterator (@end ? %3)\n",
+ this, (_in_write_pass ? "DO" : "DON'T"),
+ (most_recent_insert_iterator == _events.end())));
- 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 (insert_position, 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 ...
+ if (_in_write_pass) {
+ while (most_recent_insert_iterator != _events.end()) {
+ if ((*most_recent_insert_iterator)->when < when) {
+ if (_in_write_pass) {
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 erase existing @ %2\n", this, (*most_recent_insert_iterator)));
+ delete *most_recent_insert_iterator;
+ most_recent_insert_iterator = _events.erase (most_recent_insert_iterator);
+ continue;
+ }
+ } else if ((*most_recent_insert_iterator)->when >= when) {
+ break;
+ }
+ ++most_recent_insert_iterator;
+ }
- advance most_recent_insert_iterator so that the "real"
- insert occurs in the right place, since it
- points to the control event just inserted.
- */
+ if (with_guards && most_recent_insert_iterator != _events.end()) {
+ if ((*most_recent_insert_iterator)->when - when > 64) {
+ /* next control point is some
+ * distance from where our new
+ * point is going to go - add a
+ * new point to avoid changing
+ * the shape of the line too
+ * much. the insert iterator needs
+ * to point to the 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));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added post-erase guard point @ %2 = %3\n",
+ this, when+1,
+ (*most_recent_insert_iterator)->value));
+ }
+ }
- ++most_recent_insert_iterator;
} else {
+
+ /* not in a write pass: figure out the iterator we should insert in front of */
- /* 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",
- this, eval_value, (*most_recent_insert_iterator)->when));
-
- most_recent_insert_iterator = _events.insert (most_recent_insert_iterator, new ControlEvent (insert_position, eval_value));
-
- /* advance most_recent_insert_iterator so that the "real"
- * insert occurs in the right place, since it
- * points to the control event just inserted.
- */
-
- ++most_recent_insert_iterator;
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("compute MRI for position %1\n", when));
+ ControlEvent cp (when, 0.0f);
+ most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
}
- /* don't do this again till the next write pass */
-
- new_write_pass = false;
- did_write_during_pass = true;
-
- } else if (most_recent_insert_iterator == _events.end() || when > (*most_recent_insert_iterator)->when) {
+ } else {
- /* this is NOT the first point to be added after the
- start of a write pass, and we have a bit of work to
- do figuring out where to add the new point, as well
- as potentially erasing existing data between the
- most recently added point and wherever this one
- will end up.
- */
-
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 need to discover insert iterator (@end ? %2)\n",
- this, (most_recent_insert_iterator == _events.end())));
-
- /* this means that we either *know* we want to insert
- * at the end, or that we don't know where to insert.
- *
- * so ... lets perform some quick checks before we
- * go doing binary search to figure out where to
- * insert.
+ /* not in a write pass, adding a point within existing
+ * data: figure out the iterator we should insert in
+ * front of
*/
+
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("compute(b) MRI for position %1\n", when));
+ ControlEvent cp (when, 0.0f);
+ most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
+ }
- if (_events.back()->when == when) {
-
- /* we need to modify the final point, so
- make most_recent_insert_iterator point to it.
- */
-
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 modify final value\n", this));
-
- most_recent_insert_iterator = _events.end();
- --most_recent_insert_iterator;
-
- } else if (_events.back()->when < when) {
-
- /* the new point is beyond the end of the
- * current list
- */
-
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 plan to append to list\n", this));
-
- if (_in_write_pass) {
- /* remove the final point, because
- we're adding one beyond it.
- */
- delete _events.back();
- _events.pop_back();
- }
-
- /* leaving this here will force an append */
-
- most_recent_insert_iterator = _events.end();
-
- } else {
-
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 erase %2 from existing iterator (@end ? %3\n",
- this, _in_write_pass,
- (most_recent_insert_iterator == _events.end())));
-
- if (_in_write_pass) {
- while (most_recent_insert_iterator != _events.end()) {
- if ((*most_recent_insert_iterator)->when < when) {
- if (_in_write_pass) {
- DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 erase existing @ %2\n", this, (*most_recent_insert_iterator)));
- delete *most_recent_insert_iterator;
- most_recent_insert_iterator = _events.erase (most_recent_insert_iterator);
- continue;
- }
- } else if ((*most_recent_insert_iterator)->when >= when) {
- break;
- }
- ++most_recent_insert_iterator;
- }
- } else {
-
- /* not in a write pass: figure out the iterator we should insert in front of */
-
- ControlEvent cp (when, 0.0f);
- most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
- }
- }
- }
-
/* OK, now we're really ready to add a new point
*/
if (!_events.empty()) { // avoid O(N) _events.size() here
if (_events.back()->value == value) {
EventList::iterator b = _events.end();
- --b; // last point, which we know exists
- if (b != _events.begin()) { // step back again, which may not be possible
- --b; // next-to-last-point
+ --b; // final point, which we know exists
+ if (b != _events.begin()) { // step back again, but check first that it is legal
+ --b; // penultimate-point
if ((*b)->value == value) {
- /* straight line - just move the last
+ /* there are at least two points with the exact same value ...
+ * straight line - just move the final
* point to the new time
*/
_events.back()->when = when;
done = true;
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("final value of %1 moved to %2\n", value, when));
}
}
}
if (!done) {
_events.push_back (new ControlEvent (when, value));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("\tactually appended, size now %1\n", _events.size()));
}
if (!_in_write_pass) {
}
} else if ((*most_recent_insert_iterator)->when == when) {
- 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.
- */
+ if ((*most_recent_insert_iterator)->value != value) {
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 reset existing point to new value %2\n", this, value));
- (*most_recent_insert_iterator)->value = value;
+ /* only one point allowed per time point, so just
+ * reset the value here.
+ */
+
+ (*most_recent_insert_iterator)->value = value;
+
+ /* if we modified the final value, then its as
+ * if we inserted a new point as far as the
+ * next addition, so make sure we know that.
+ */
+
+ if (_in_write_pass && _events.back()->when == when) {
+ most_recent_insert_iterator = _events.end();
+ }
+
+ } else {
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 same time %2, same value value %3\n", this, when, value));
+ }
} 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));
- bool done;
+ bool done = false;
/* check if would just be adding to a straight line,
* and don't add another point if so
most_recent_insert_iterator = b;
}
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("final value of %1 moved to %2\n", value, when));
done = true;
}
}
}
}
-
+
+ if (with_guards && most_recent_insert_iterator != _events.end()) {
+ if ((*most_recent_insert_iterator)->when - when > 64) {
+ /* next control point is some
+ * distance from where our new
+ * point is going to go - add a
+ * new point to avoid changing
+ * the shape of the line too
+ * much. the insert iterator needs
+ * to point to the 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));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added insert-post-erase guard point @ %2 = %3\n",
+ this, when+1,
+ (*most_recent_insert_iterator)->value));
+ }
+ }
+
if (!done) {
EventList::iterator x = _events.insert (most_recent_insert_iterator, new ControlEvent (when, value));
+ DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 inserted new value before MRI, size now %2\n", this, _events.size()));
if (!_in_write_pass) {
most_recent_insert_iterator = x;
(*iter)->when = when;
(*iter)->value = val;
- if (std::isnan (val)) {
+ if (isnan (val)) {
abort ();
}
assert(inclusive ? x >= start : x > start);
return true;
} else {
- return false;
+ if (inclusive) {
+ x = next->when;
+ } else {
+ x = start;
+ }
+ _search_cache.left = x;
+ return true;
}
/* No points in the future, so no steps (towards them) in the future */
);
}
+void
+ControlList::dump (ostream& o)
+{
+ /* NOT LOCKED ... for debugging only */
+
+ for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
+ o << (*x)->value << " @ " << (uint64_t) (*x)->when << endl;
+ }
+}
+
} // namespace Evoral