+
+ 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;