2008-09-18 20:47:49 -04:00
|
|
|
/* This file is part of Evoral.
|
2011-04-06 11:00:16 -04:00
|
|
|
* Copyright (C) 2008 David Robillard <http://drobilla.net>
|
2008-09-18 20:47:49 -04:00
|
|
|
* Copyright (C) 2000-2008 Paul Davis
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* Evoral is free software; you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2008-09-18 20:47:49 -04:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cassert>
|
|
|
|
#include <utility>
|
|
|
|
#include <iostream>
|
2008-12-21 15:36:15 -05:00
|
|
|
#include "evoral/ControlList.hpp"
|
2009-02-19 14:42:25 -05:00
|
|
|
#include "evoral/Curve.hpp"
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
using namespace std;
|
2012-07-13 17:05:45 -04:00
|
|
|
using namespace PBD;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
namespace Evoral {
|
|
|
|
|
|
|
|
inline bool event_time_less_than (ControlEvent* a, ControlEvent* b)
|
|
|
|
{
|
|
|
|
return a->when < b->when;
|
|
|
|
}
|
|
|
|
|
2012-04-05 07:16:04 -04:00
|
|
|
/* this has no units but corresponds to the area of a rectangle
|
|
|
|
computed between three points in the list. If the area is
|
|
|
|
large, it indicates significant non-linearity between the
|
|
|
|
points.
|
|
|
|
|
|
|
|
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 rectangle
|
|
|
|
formed by three of them), we will not include it in the
|
|
|
|
ControlList. a smaller value will exclude less points,
|
|
|
|
a larger value will exclude more points, so it effectively
|
|
|
|
measures the amount of thinning to be done.
|
|
|
|
*/
|
|
|
|
|
|
|
|
double ControlList::_thinning_factor = 20.0;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
ControlList::ControlList (const Parameter& id)
|
2008-09-18 20:47:49 -04:00
|
|
|
: _parameter(id)
|
|
|
|
, _interpolation(Linear)
|
2009-02-19 14:42:25 -05:00
|
|
|
, _curve(0)
|
2009-10-14 12:10:01 -04:00
|
|
|
{
|
2008-09-18 20:47:49 -04:00
|
|
|
_frozen = 0;
|
|
|
|
_changed_when_thawed = false;
|
|
|
|
_min_yval = id.min();
|
|
|
|
_max_yval = id.max();
|
2009-08-23 14:31:34 -04:00
|
|
|
_default_value = 0;
|
2008-09-18 20:47:49 -04:00
|
|
|
_lookup_cache.left = -1;
|
|
|
|
_lookup_cache.range.first = _events.end();
|
|
|
|
_search_cache.left = -1;
|
2010-07-25 19:19:43 -04:00
|
|
|
_search_cache.first = _events.end();
|
2008-09-18 20:47:49 -04:00
|
|
|
_sort_pending = false;
|
2012-07-13 17:05:45 -04:00
|
|
|
new_write_pass = true;
|
2012-07-16 23:10:40 -04:00
|
|
|
_in_write_pass = false;
|
2012-07-13 17:05:45 -04:00
|
|
|
did_write_during_pass = false;
|
|
|
|
insert_position = -1;
|
2012-07-16 23:10:40 -04:00
|
|
|
most_recent_insert_iterator = _events.end();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlList::ControlList (const ControlList& other)
|
|
|
|
: _parameter(other._parameter)
|
|
|
|
, _interpolation(Linear)
|
2009-02-19 14:42:25 -05:00
|
|
|
, _curve(0)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
_frozen = 0;
|
|
|
|
_changed_when_thawed = false;
|
|
|
|
_min_yval = other._min_yval;
|
|
|
|
_max_yval = other._max_yval;
|
|
|
|
_default_value = other._default_value;
|
|
|
|
_lookup_cache.range.first = _events.end();
|
2010-07-25 19:19:43 -04:00
|
|
|
_search_cache.first = _events.end();
|
2008-09-18 20:47:49 -04:00
|
|
|
_sort_pending = false;
|
2012-07-13 17:05:45 -04:00
|
|
|
new_write_pass = true;
|
2012-07-16 23:10:40 -04:00
|
|
|
_in_write_pass = false;
|
2012-07-13 17:05:45 -04:00
|
|
|
did_write_during_pass = false;
|
|
|
|
insert_position = -1;
|
2012-07-16 23:10:40 -04:00
|
|
|
most_recent_insert_iterator = _events.end();
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-05-11 17:30:36 -04:00
|
|
|
copy_events (other);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlList::ControlList (const ControlList& other, double start, double end)
|
|
|
|
: _parameter(other._parameter)
|
|
|
|
, _interpolation(Linear)
|
2009-02-19 14:42:25 -05:00
|
|
|
, _curve(0)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
_frozen = 0;
|
|
|
|
_changed_when_thawed = false;
|
|
|
|
_min_yval = other._min_yval;
|
|
|
|
_max_yval = other._max_yval;
|
|
|
|
_default_value = other._default_value;
|
|
|
|
_lookup_cache.range.first = _events.end();
|
2010-07-25 19:19:43 -04:00
|
|
|
_search_cache.first = _events.end();
|
2008-09-18 20:47:49 -04:00
|
|
|
_sort_pending = false;
|
|
|
|
|
|
|
|
/* now grab the relevant points, and shift them back if necessary */
|
|
|
|
|
|
|
|
boost::shared_ptr<ControlList> section = const_cast<ControlList*>(&other)->copy (start, end);
|
|
|
|
|
|
|
|
if (!section->empty()) {
|
2012-05-11 17:30:36 -04:00
|
|
|
copy_events (*(section.get()));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
new_write_pass = false;
|
2012-07-16 23:10:40 -04:00
|
|
|
_in_write_pass = false;
|
2012-07-13 17:05:45 -04:00
|
|
|
did_write_during_pass = false;
|
|
|
|
insert_position = -1;
|
2012-07-16 23:10:40 -04:00
|
|
|
most_recent_insert_iterator = _events.end();
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlList::~ControlList()
|
|
|
|
{
|
|
|
|
for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
|
|
|
|
delete (*x);
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2009-02-16 14:06:27 -05:00
|
|
|
delete _curve;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<ControlList>
|
|
|
|
ControlList::create(Parameter id)
|
|
|
|
{
|
|
|
|
return boost::shared_ptr<ControlList>(new ControlList(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlList::operator== (const ControlList& other)
|
|
|
|
{
|
|
|
|
return _events == other._events;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlList&
|
|
|
|
ControlList::operator= (const ControlList& other)
|
|
|
|
{
|
|
|
|
if (this != &other) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
_min_yval = other._min_yval;
|
|
|
|
_max_yval = other._max_yval;
|
|
|
|
_default_value = other._default_value;
|
2012-05-11 17:30:36 -04:00
|
|
|
|
|
|
|
copy_events (other);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-05-11 17:30:36 -04:00
|
|
|
void
|
|
|
|
ControlList::copy_events (const ControlList& other)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2012-05-11 17:30:36 -04:00
|
|
|
_events.clear ();
|
|
|
|
for (const_iterator i = other.begin(); i != other.end(); ++i) {
|
|
|
|
_events.push_back (new ControlEvent ((*i)->when, (*i)->value));
|
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2012-05-11 17:30:36 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
2009-02-19 14:42:25 -05:00
|
|
|
void
|
|
|
|
ControlList::create_curve()
|
|
|
|
{
|
|
|
|
_curve = new Curve(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::destroy_curve()
|
|
|
|
{
|
|
|
|
delete _curve;
|
|
|
|
_curve = NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
void
|
|
|
|
ControlList::maybe_signal_changed ()
|
|
|
|
{
|
|
|
|
mark_dirty ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-05-27 08:26:00 -04:00
|
|
|
if (_frozen) {
|
2008-09-18 20:47:49 -04:00
|
|
|
_changed_when_thawed = true;
|
2010-05-27 08:26:00 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::clear ()
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.clear ();
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::x_scale (double factor)
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
_x_scale (factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlList::extend_to (double when)
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
if (_events.empty() || _events.back()->when == when) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
double factor = when / _events.back()->when;
|
|
|
|
_x_scale (factor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
void
|
2010-08-19 17:09:40 -04:00
|
|
|
ControlList::_x_scale (double factor)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
for (iterator i = _events.begin(); i != _events.end(); ++i) {
|
2011-12-31 08:25:29 -05:00
|
|
|
(*i)->when *= factor;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
2011-03-08 07:34:25 -05:00
|
|
|
struct ControlEventTimeComparator {
|
|
|
|
bool operator() (ControlEvent* a, ControlEvent* b) {
|
|
|
|
return a->when < b->when;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-26 17:13:54 -05:00
|
|
|
void
|
|
|
|
ControlList::thin ()
|
|
|
|
{
|
2012-07-13 17:05:45 -04:00
|
|
|
bool changed = false;
|
2011-12-26 17:13:54 -05:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
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) {
|
2011-12-26 17:13:54 -05:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
cur = *i;
|
|
|
|
counter++;
|
2011-12-26 17:13:54 -05:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
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)) +
|
|
|
|
(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;
|
|
|
|
}
|
2011-12-26 17:13:54 -05:00
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
prevprev = prev;
|
|
|
|
prev = cur;
|
|
|
|
pprev = i;
|
2011-12-26 17:13:54 -05:00
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 thin => %2 events\n", this, _events.size()));
|
2011-12-26 17:13:54 -05:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
if (changed) {
|
|
|
|
unlocked_invalidate_insert_iterator ();
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
maybe_signal_changed ();
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::fast_simple_add (double when, double value)
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
/* to be used only for loading pre-sorted data from saved state */
|
|
|
|
_events.insert (_events.end(), new ControlEvent (when, value));
|
|
|
|
assert(_events.back());
|
2012-04-16 12:32:22 -04:00
|
|
|
|
|
|
|
mark_dirty ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-13 17:05:45 -04:00
|
|
|
ControlList::invalidate_insert_iterator ()
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::unlocked_invalidate_insert_iterator ()
|
|
|
|
{
|
2012-07-16 23:10:40 -04:00
|
|
|
most_recent_insert_iterator = _events.end();
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::start_write_pass (double when)
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
new_write_pass = true;
|
|
|
|
did_write_during_pass = false;
|
|
|
|
insert_position = when;
|
2012-07-16 23:10:40 -04:00
|
|
|
|
2012-07-14 11:42:10 -04:00
|
|
|
/* 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).
|
|
|
|
*/
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2012-07-14 11:42:10 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-16 23:10:40 -04:00
|
|
|
ControlList::write_pass_finished (double when)
|
|
|
|
{
|
|
|
|
if (did_write_during_pass) {
|
|
|
|
thin ();
|
|
|
|
did_write_during_pass = false;
|
|
|
|
}
|
|
|
|
new_write_pass = true;
|
|
|
|
_in_write_pass = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::set_in_write_pass (bool yn)
|
|
|
|
{
|
|
|
|
_in_write_pass = yn;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlList::in_write_pass () const
|
|
|
|
{
|
|
|
|
return _in_write_pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::add (double when, double value)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2011-11-22 19:17:31 -05:00
|
|
|
/* this is for making changes from some kind of user interface or
|
|
|
|
control surface (GUI, MIDI, OSC etc)
|
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (!clamp_value (when, value)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-26 20:31:03 -05:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
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())));
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
ControlEvent cp (when, 0.0f);
|
|
|
|
iterator insertion_point;
|
|
|
|
|
2012-07-09 14:32:53 -04:00
|
|
|
if (_events.empty()) {
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
/* as long as the point we're adding is not at zero,
|
|
|
|
* add an "anchor" point there.
|
|
|
|
*/
|
|
|
|
|
2012-07-09 14:32:53 -04:00
|
|
|
if (when > 1) {
|
|
|
|
_events.insert (_events.end(), new ControlEvent (0, _default_value));
|
2012-07-13 17:05:45 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
|
2012-07-09 14:32:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (_in_write_pass && new_write_pass) {
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-14 11:42:10 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 new write pass, insert pos = %2\n", this, insert_position));
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
/* The first addition of a new control event during a
|
|
|
|
* write pass.
|
|
|
|
*
|
|
|
|
* We need to add a new point at insert_position
|
2012-11-14 10:06:41 -05:00
|
|
|
* corresponding to the (existing, implicit) value there.
|
2012-07-13 17:05:45 -04:00
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-14 11:42:10 -04:00
|
|
|
/* the insert_iterator is not set, figure out where
|
|
|
|
* it needs to be.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ControlEvent cp (insert_position, 0.0);
|
2012-07-16 23:10:40 -04:00
|
|
|
most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
|
2012-07-14 11:42:10 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 looked up insert iterator for new write pass\n", this));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
double eval_value = unlocked_eval (insert_position);
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (most_recent_insert_iterator == _events.end()) {
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
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 */
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
} else if ((*most_recent_insert_iterator)->when == when) {
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert iterator at existing point, setting eval-value there %2\n", this, eval_value));
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
/* most_recent_insert_iterator points to a control event
|
2012-07-13 17:05:45 -04:00
|
|
|
already at the insert position, so there is
|
|
|
|
nothing to do.
|
|
|
|
|
|
|
|
... except ...
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
advance most_recent_insert_iterator so that the "real"
|
2012-07-13 17:05:45 -04:00
|
|
|
insert occurs in the right place, since it
|
|
|
|
points to the control event just inserted.
|
|
|
|
*/
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
++most_recent_insert_iterator;
|
2012-07-13 17:05:45 -04:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/* insert a new control event at the right spot
|
|
|
|
*/
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert eval-value %2 just before iterator @ %3\n",
|
|
|
|
this, eval_value, (*most_recent_insert_iterator)->when));
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
most_recent_insert_iterator = _events.insert (most_recent_insert_iterator, new ControlEvent (insert_position, eval_value));
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
/* advance most_recent_insert_iterator so that the "real"
|
2012-07-13 17:05:45 -04:00
|
|
|
* insert occurs in the right place, since it
|
|
|
|
* points to the control event just inserted.
|
|
|
|
*/
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
++most_recent_insert_iterator;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
/* don't do this again till the next write pass */
|
|
|
|
|
|
|
|
new_write_pass = false;
|
|
|
|
did_write_during_pass = true;
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
} else if (most_recent_insert_iterator == _events.end() || when > (*most_recent_insert_iterator)->when) {
|
2012-11-14 10:06:41 -05:00
|
|
|
|
|
|
|
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 (_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;
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
2012-11-14 10:06:41 -05:00
|
|
|
} else if ((*most_recent_insert_iterator)->when >= when) {
|
|
|
|
break;
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
2012-11-14 10:06:41 -05:00
|
|
|
++most_recent_insert_iterator;
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
2012-11-15 11:22:43 -05:00
|
|
|
|
|
|
|
if (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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 10:06:41 -05:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/* not in a write pass: figure out the iterator we should insert in front of */
|
2012-12-08 12:57:47 -05:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("compute MRI for position %1\n", when));
|
2012-11-14 10:06:41 -05:00
|
|
|
ControlEvent cp (when, 0.0f);
|
|
|
|
most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
2012-12-08 12:57:47 -05:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
/* OK, now we're really ready to add a new point
|
|
|
|
*/
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (most_recent_insert_iterator == _events.end()) {
|
2012-07-13 17:05:45 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 appending new point at end\n", this));
|
2012-07-16 23:10:40 -04:00
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
/* check if would just be adding to a straight line,
|
|
|
|
* and don't add another point if so
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!_events.empty()) { // avoid O(N) _events.size() here
|
|
|
|
if (_events.back()->value == value) {
|
|
|
|
EventList::iterator b = _events.end();
|
2012-09-09 16:31:43 -04:00
|
|
|
--b; // final point, which we know exists
|
|
|
|
if (b != _events.begin()) { // step back again, but check first that it is legal
|
|
|
|
--b; // penultimate-point
|
2012-07-16 23:10:40 -04:00
|
|
|
if ((*b)->value == value) {
|
2012-09-09 16:31:43 -04:00
|
|
|
/* there are at least two points with the exact same value ...
|
|
|
|
* straight line - just move the final
|
2012-07-16 23:10:40 -04:00
|
|
|
* point to the new time
|
|
|
|
*/
|
|
|
|
_events.back()->when = when;
|
|
|
|
done = true;
|
2012-11-14 10:06:41 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("final value of %1 moved to %2\n", value, when));
|
2012-07-16 23:10:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
_events.push_back (new ControlEvent (when, value));
|
2012-11-14 10:06:41 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("\tactually appended, size now %1\n", _events.size()));
|
2012-07-16 23:10:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_in_write_pass) {
|
|
|
|
most_recent_insert_iterator = _events.end();
|
|
|
|
--most_recent_insert_iterator;
|
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
} else if ((*most_recent_insert_iterator)->when == when) {
|
|
|
|
|
2012-11-14 10:06:41 -05:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(*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();
|
|
|
|
}
|
2012-07-16 23:10:40 -04:00
|
|
|
|
2012-11-14 10:06:41 -05:00
|
|
|
} else {
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 same time %2, same value value %3\n", this, when, value));
|
|
|
|
}
|
2012-07-16 23:10:40 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
} else {
|
2012-07-16 23:10:40 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert new point at %2 at iterator at %3\n", this, when, (*most_recent_insert_iterator)->when));
|
|
|
|
|
2012-09-17 17:09:12 -04:00
|
|
|
bool done = false;
|
2012-07-16 23:10:40 -04:00
|
|
|
|
|
|
|
/* check if would just be adding to a straight line,
|
|
|
|
* and don't add another point if so
|
2012-07-13 17:05:45 -04:00
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (most_recent_insert_iterator != _events.begin()) {
|
|
|
|
EventList::iterator b = most_recent_insert_iterator;
|
|
|
|
--b; // prior point, which we know exists
|
|
|
|
if ((*b)->value == value) { // same value as the point we plan to insert
|
|
|
|
if (b != _events.begin()) { // step back again, which may not be possible
|
|
|
|
EventList::iterator bb = b;
|
|
|
|
--bb; // next-to-prior-point
|
|
|
|
if ((*bb)->value == value) {
|
|
|
|
/* straight line - just move the prior
|
|
|
|
* point to the new time
|
|
|
|
*/
|
|
|
|
(*b)->when = when;
|
|
|
|
|
|
|
|
if (!_in_write_pass) {
|
|
|
|
most_recent_insert_iterator = b;
|
|
|
|
}
|
|
|
|
|
2012-11-14 10:06:41 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("final value of %1 moved to %2\n", value, when));
|
2012-07-16 23:10:40 -04:00
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 11:22:43 -05:00
|
|
|
|
|
|
|
if (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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (!done) {
|
|
|
|
EventList::iterator x = _events.insert (most_recent_insert_iterator, new ControlEvent (when, value));
|
2012-11-14 10:06:41 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 inserted new value before MRI, size now %2\n", this, _events.size()));
|
2012-07-16 23:10:40 -04:00
|
|
|
|
|
|
|
if (!_in_write_pass) {
|
|
|
|
most_recent_insert_iterator = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::erase (iterator i)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2012-07-16 23:10:40 -04:00
|
|
|
if (most_recent_insert_iterator == i) {
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.erase (i);
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::erase (iterator start, iterator end)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.erase (start, end);
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2010-12-20 08:30:31 -05:00
|
|
|
/** Erase the first event which matches the given time and value */
|
|
|
|
void
|
|
|
|
ControlList::erase (double when, double value)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2010-12-20 08:30:31 -05:00
|
|
|
|
|
|
|
iterator i = begin ();
|
|
|
|
while (i != end() && ((*i)->when != when || (*i)->value != value)) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != end ()) {
|
|
|
|
_events.erase (i);
|
2012-07-16 23:10:40 -04:00
|
|
|
if (most_recent_insert_iterator == i) {
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
|
|
|
}
|
2010-12-20 08:30:31 -05:00
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2010-12-20 08:30:31 -05:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
void
|
|
|
|
ControlList::erase_range (double start, double endt)
|
|
|
|
{
|
|
|
|
bool erased = false;
|
|
|
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-12-16 18:21:01 -05:00
|
|
|
erased = erase_range_internal (start, endt, _events);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
if (erased) {
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (erased) {
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
bool
|
|
|
|
ControlList::erase_range_internal (double start, double endt, EventList & events)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2008-12-16 18:21:01 -05:00
|
|
|
bool erased = false;
|
|
|
|
ControlEvent cp (start, 0.0f);
|
|
|
|
iterator s;
|
|
|
|
iterator e;
|
|
|
|
|
|
|
|
if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
|
|
|
|
cp.when = endt;
|
|
|
|
e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
|
|
|
|
events.erase (s, e);
|
2010-08-20 19:58:49 -04:00
|
|
|
if (s != e) {
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2010-08-20 19:58:49 -04:00
|
|
|
erased = true;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
return erased;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::slide (iterator before, double distance)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
if (before == _events.end()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
while (before != _events.end()) {
|
|
|
|
(*before)->when += distance;
|
|
|
|
++before;
|
|
|
|
}
|
2010-12-07 10:13:04 -05:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
mark_dirty ();
|
2010-12-07 10:13:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::shift (double pos, double frames)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2010-12-07 10:13:04 -05:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
for (iterator i = _events.begin(); i != _events.end(); ++i) {
|
2010-12-07 10:13:04 -05:00
|
|
|
if ((*i)->when >= pos) {
|
|
|
|
(*i)->when += frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_dirty ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::modify (iterator iter, double when, double val)
|
|
|
|
{
|
|
|
|
/* note: we assume higher level logic is in place to avoid this
|
|
|
|
reordering the time-order of control events in the list. ie. all
|
|
|
|
points after *iter are later than when.
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
(*iter)->when = when;
|
|
|
|
(*iter)->value = val;
|
|
|
|
|
2012-04-15 15:28:44 -04:00
|
|
|
if (std::isnan (val)) {
|
2008-09-18 20:47:49 -04:00
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_frozen) {
|
|
|
|
_events.sort (event_time_less_than);
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
|
|
|
_sort_pending = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<ControlList::iterator,ControlList::iterator>
|
|
|
|
ControlList::control_points_adjacent (double xval)
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
iterator i;
|
|
|
|
ControlEvent cp (xval, 0.0f);
|
|
|
|
std::pair<iterator,iterator> ret;
|
|
|
|
|
|
|
|
ret.first = _events.end();
|
|
|
|
ret.second = _events.end();
|
|
|
|
|
|
|
|
for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (ret.first == _events.end()) {
|
|
|
|
if ((*i)->when >= xval) {
|
|
|
|
if (i != _events.begin()) {
|
|
|
|
ret.first = i;
|
|
|
|
--ret.first;
|
|
|
|
} else {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if ((*i)->when > xval) {
|
|
|
|
ret.second = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::freeze ()
|
|
|
|
{
|
|
|
|
_frozen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::thaw ()
|
|
|
|
{
|
|
|
|
assert(_frozen > 0);
|
|
|
|
|
|
|
|
if (--_frozen > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
if (_sort_pending) {
|
|
|
|
_events.sort (event_time_less_than);
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
_sort_pending = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2008-09-18 20:47:49 -04:00
|
|
|
ControlList::mark_dirty () const
|
|
|
|
{
|
|
|
|
_lookup_cache.left = -1;
|
|
|
|
_search_cache.left = -1;
|
2010-07-11 20:41:45 -04:00
|
|
|
|
|
|
|
if (_curve) {
|
2008-09-18 20:47:49 -04:00
|
|
|
_curve->mark_dirty();
|
2010-07-11 20:41:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Dirty (); /* EMIT SIGNAL */
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::truncate_end (double last_coordinate)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
ControlEvent cp (last_coordinate, 0);
|
|
|
|
ControlList::reverse_iterator i;
|
|
|
|
double last_val;
|
|
|
|
|
|
|
|
if (_events.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_coordinate == _events.back()->when) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_coordinate > _events.back()->when) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* extending end:
|
2011-11-22 19:17:31 -05:00
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
iterator foo = _events.begin();
|
|
|
|
bool lessthantwo;
|
|
|
|
|
|
|
|
if (foo == _events.end()) {
|
|
|
|
lessthantwo = true;
|
|
|
|
} else if (++foo == _events.end()) {
|
|
|
|
lessthantwo = true;
|
|
|
|
} else {
|
|
|
|
lessthantwo = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lessthantwo) {
|
|
|
|
/* less than 2 points: add a new point */
|
|
|
|
_events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* more than 2 points: check to see if the last 2 values
|
|
|
|
are equal. if so, just move the position of the
|
|
|
|
last point. otherwise, add a new point.
|
|
|
|
*/
|
|
|
|
|
|
|
|
iterator penultimate = _events.end();
|
|
|
|
--penultimate; /* points at last point */
|
|
|
|
--penultimate; /* points at the penultimate point */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (_events.back()->value == (*penultimate)->value) {
|
|
|
|
_events.back()->when = last_coordinate;
|
|
|
|
} else {
|
|
|
|
_events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* shortening end */
|
|
|
|
|
|
|
|
last_val = unlocked_eval (last_coordinate);
|
|
|
|
last_val = max ((double) _min_yval, last_val);
|
|
|
|
last_val = min ((double) _max_yval, last_val);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
i = _events.rbegin();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* make i point to the last control point */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
++i;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* now go backwards, removing control points that are
|
|
|
|
beyond the new last coordinate.
|
|
|
|
*/
|
|
|
|
|
2008-09-22 13:47:21 -04:00
|
|
|
// FIXME: SLOW! (size() == O(n))
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
uint32_t sz = _events.size();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
while (i != _events.rend() && sz > 2) {
|
|
|
|
ControlList::reverse_iterator tmp;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if ((*i)->when < last_coordinate) {
|
|
|
|
break;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.erase (i.base());
|
|
|
|
--sz;
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.back()->when = last_coordinate;
|
|
|
|
_events.back()->value = last_val;
|
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
|
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::truncate_start (double overall_length)
|
|
|
|
{
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
iterator i;
|
|
|
|
double first_legal_value;
|
|
|
|
double first_legal_coordinate;
|
|
|
|
|
|
|
|
assert(!_events.empty());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (overall_length == _events.back()->when) {
|
|
|
|
/* no change in overall length */
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (overall_length > _events.back()->when) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* growing at front: duplicate first point. shift all others */
|
|
|
|
|
|
|
|
double shift = overall_length - _events.back()->when;
|
|
|
|
uint32_t np;
|
|
|
|
|
|
|
|
for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
|
|
|
|
(*i)->when += shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (np < 2) {
|
|
|
|
|
|
|
|
/* less than 2 points: add a new point */
|
|
|
|
_events.push_front (new ControlEvent (0, _events.front()->value));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* more than 2 points: check to see if the first 2 values
|
|
|
|
are equal. if so, just move the position of the
|
|
|
|
first point. otherwise, add a new point.
|
|
|
|
*/
|
|
|
|
|
|
|
|
iterator second = _events.begin();
|
|
|
|
++second; /* points at the second point */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (_events.front()->value == (*second)->value) {
|
|
|
|
/* first segment is flat, just move start point back to zero */
|
|
|
|
_events.front()->when = 0;
|
|
|
|
} else {
|
|
|
|
/* leave non-flat segment in place, add a new leading point. */
|
|
|
|
_events.push_front (new ControlEvent (0, _events.front()->value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* shrinking at front */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
first_legal_coordinate = _events.back()->when - overall_length;
|
|
|
|
first_legal_value = unlocked_eval (first_legal_coordinate);
|
|
|
|
first_legal_value = max (_min_yval, first_legal_value);
|
|
|
|
first_legal_value = min (_max_yval, first_legal_value);
|
|
|
|
|
|
|
|
/* remove all events earlier than the new "front" */
|
|
|
|
|
|
|
|
i = _events.begin();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
while (i != _events.end() && !_events.empty()) {
|
|
|
|
ControlList::iterator tmp;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if ((*i)->when > first_legal_coordinate) {
|
|
|
|
break;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.erase (i);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
i = tmp;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
/* shift all remaining points left to keep their same
|
|
|
|
relative position
|
|
|
|
*/
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
for (i = _events.begin(); i != _events.end(); ++i) {
|
|
|
|
(*i)->when -= first_legal_coordinate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a new point for the interpolated new value */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
_events.push_front (new ControlEvent (0, first_legal_value));
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
ControlList::unlocked_eval (double x) const
|
|
|
|
{
|
|
|
|
pair<EventList::iterator,EventList::iterator> range;
|
|
|
|
int32_t npoints;
|
|
|
|
double lpos, upos;
|
|
|
|
double lval, uval;
|
|
|
|
double fraction;
|
|
|
|
|
2008-09-22 13:47:21 -04:00
|
|
|
const_iterator length_check_iter = _events.begin();
|
2009-02-01 19:20:18 -05:00
|
|
|
for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
|
|
|
|
if (length_check_iter == _events.end()) {
|
2008-09-22 13:47:21 -04:00
|
|
|
break;
|
2009-02-01 19:20:18 -05:00
|
|
|
}
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
switch (npoints) {
|
|
|
|
case 0:
|
|
|
|
return _default_value;
|
|
|
|
|
|
|
|
case 1:
|
2009-02-01 19:20:18 -05:00
|
|
|
return _events.front()->value;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
case 2:
|
|
|
|
if (x >= _events.back()->when) {
|
|
|
|
return _events.back()->value;
|
2009-10-22 22:49:12 -04:00
|
|
|
} else if (x <= _events.front()->when) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return _events.front()->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpos = _events.front()->when;
|
|
|
|
lval = _events.front()->value;
|
|
|
|
upos = _events.back()->when;
|
|
|
|
uval = _events.back()->value;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-21 05:20:27 -05:00
|
|
|
if (_interpolation == Discrete) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return lval;
|
2009-01-21 05:20:27 -05:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2009-02-01 19:20:18 -05:00
|
|
|
/* linear interpolation betweeen the two points */
|
2008-09-18 20:47:49 -04:00
|
|
|
fraction = (double) (x - lpos) / (double) (upos - lpos);
|
|
|
|
return lval + (fraction * (uval - lval));
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (x >= _events.back()->when) {
|
|
|
|
return _events.back()->value;
|
2009-10-22 22:49:12 -04:00
|
|
|
} else if (x <= _events.front()->when) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return _events.front()->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return multipoint_eval (x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*NOTREACHED*/ /* stupid gcc */
|
2009-02-01 19:20:18 -05:00
|
|
|
return _default_value;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
ControlList::multipoint_eval (double x) const
|
|
|
|
{
|
|
|
|
double upos, lpos;
|
|
|
|
double uval, lval;
|
|
|
|
double fraction;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* "Stepped" lookup (no interpolation) */
|
|
|
|
/* FIXME: no cache. significant? */
|
|
|
|
if (_interpolation == Discrete) {
|
|
|
|
const ControlEvent cp (x, 0);
|
|
|
|
EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
|
|
|
|
|
|
|
|
// shouldn't have made it to multipoint_eval
|
|
|
|
assert(i != _events.end());
|
|
|
|
|
|
|
|
if (i == _events.begin() || (*i)->when == x)
|
|
|
|
return (*i)->value;
|
|
|
|
else
|
|
|
|
return (*(--i))->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only do the range lookup if x is in a different range than last time
|
|
|
|
* this was called (or if the lookup cache has been marked "dirty" (left<0) */
|
|
|
|
if ((_lookup_cache.left < 0) ||
|
2009-10-14 12:10:01 -04:00
|
|
|
((_lookup_cache.left > x) ||
|
|
|
|
(_lookup_cache.range.first == _events.end()) ||
|
2008-09-18 20:47:49 -04:00
|
|
|
((*_lookup_cache.range.second)->when < x))) {
|
|
|
|
|
|
|
|
const ControlEvent cp (x, 0);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
_lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
pair<const_iterator,const_iterator> range = _lookup_cache.range;
|
|
|
|
|
|
|
|
if (range.first == range.second) {
|
|
|
|
|
|
|
|
/* x does not exist within the list as a control point */
|
|
|
|
|
|
|
|
_lookup_cache.left = x;
|
|
|
|
|
|
|
|
if (range.first != _events.begin()) {
|
|
|
|
--range.first;
|
|
|
|
lpos = (*range.first)->when;
|
|
|
|
lval = (*range.first)->value;
|
|
|
|
} else {
|
|
|
|
/* we're before the first point */
|
|
|
|
// return _default_value;
|
|
|
|
return _events.front()->value;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (range.second == _events.end()) {
|
|
|
|
/* we're after the last point */
|
|
|
|
return _events.back()->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
upos = (*range.second)->when;
|
|
|
|
uval = (*range.second)->value;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* linear interpolation betweeen the two points
|
|
|
|
on either side of x
|
|
|
|
*/
|
|
|
|
|
|
|
|
fraction = (double) (x - lpos) / (double) (upos - lpos);
|
|
|
|
return lval + (fraction * (uval - lval));
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
/* x is a control point in the data */
|
|
|
|
_lookup_cache.left = -1;
|
|
|
|
return (*range.first)->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-25 19:19:43 -04:00
|
|
|
ControlList::build_search_cache_if_necessary (double start) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
/* 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) */
|
2010-07-25 19:19:43 -04:00
|
|
|
if (!_events.empty() && ((_search_cache.left < 0) || (_search_cache.left > start))) {
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
const ControlEvent start_point (start, 0);
|
|
|
|
|
|
|
|
//cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
|
|
|
|
// << start << ".." << end << ")" << endl;
|
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
_search_cache.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
|
2008-09-18 20:47:49 -04:00
|
|
|
_search_cache.left = start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
/** Get the earliest event after \a start using the current interpolation style.
|
2008-09-18 20:47:49 -04:00
|
|
|
*
|
|
|
|
* If an event is found, \a x and \a y are set to its coordinates.
|
|
|
|
*
|
|
|
|
* \param inclusive Include events with timestamp exactly equal to \a start
|
|
|
|
* \return true if event is found (and \a x and \a y are valid).
|
|
|
|
*/
|
|
|
|
bool
|
2010-07-25 19:19:43 -04:00
|
|
|
ControlList::rt_safe_earliest_event (double start, double& x, double& y, bool inclusive) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
// FIXME: It would be nice if this was unnecessary..
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm(_lock, Glib::Threads::TRY_LOCK);
|
2008-09-18 20:47:49 -04:00
|
|
|
if (!lm.locked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
return rt_safe_earliest_event_unlocked (start, x, y, inclusive);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
/** Get the earliest event after \a start using the current interpolation style.
|
2008-09-18 20:47:49 -04:00
|
|
|
*
|
|
|
|
* If an event is found, \a x and \a y are set to its coordinates.
|
|
|
|
*
|
|
|
|
* \param inclusive Include events with timestamp exactly equal to \a start
|
|
|
|
* \return true if event is found (and \a x and \a y are valid).
|
|
|
|
*/
|
|
|
|
bool
|
2010-07-25 19:19:43 -04:00
|
|
|
ControlList::rt_safe_earliest_event_unlocked (double start, double& x, double& y, bool inclusive) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2010-07-13 20:58:15 -04:00
|
|
|
if (_interpolation == Discrete) {
|
2010-07-25 19:19:43 -04:00
|
|
|
return rt_safe_earliest_event_discrete_unlocked(start, x, y, inclusive);
|
2010-07-13 20:58:15 -04:00
|
|
|
} else {
|
2010-07-25 19:19:43 -04:00
|
|
|
return rt_safe_earliest_event_linear_unlocked(start, x, y, inclusive);
|
2010-07-13 20:58:15 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
/** Get the earliest event after \a start without interpolation.
|
2008-09-18 20:47:49 -04:00
|
|
|
*
|
|
|
|
* If an event is found, \a x and \a y are set to its coordinates.
|
|
|
|
*
|
|
|
|
* \param inclusive Include events with timestamp exactly equal to \a start
|
|
|
|
* \return true if event is found (and \a x and \a y are valid).
|
|
|
|
*/
|
|
|
|
bool
|
2010-07-25 19:19:43 -04:00
|
|
|
ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double& x, double& y, bool inclusive) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2010-07-25 19:19:43 -04:00
|
|
|
build_search_cache_if_necessary (start);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
if (_search_cache.first != _events.end()) {
|
|
|
|
const ControlEvent* const first = *_search_cache.first;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
const bool past_start = (inclusive ? first->when >= start : first->when > start);
|
|
|
|
|
|
|
|
/* Earliest points is in range, return it */
|
2010-07-25 19:19:43 -04:00
|
|
|
if (past_start) {
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
x = first->when;
|
|
|
|
y = first->value;
|
|
|
|
|
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range) */
|
|
|
|
_search_cache.left = x;
|
2010-07-25 19:19:43 -04:00
|
|
|
++_search_cache.first;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
assert(x >= start);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* No points in range */
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the earliest time the line crosses an integer (Linear interpolation).
|
|
|
|
*
|
|
|
|
* If an event is found, \a x and \a y are set to its coordinates.
|
|
|
|
*
|
|
|
|
* \param inclusive Include events with timestamp exactly equal to \a start
|
|
|
|
* \return true if event is found (and \a x and \a y are valid).
|
|
|
|
*/
|
|
|
|
bool
|
2010-07-25 19:19:43 -04:00
|
|
|
ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, double& y, bool inclusive) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2010-07-25 19:20:31 -04:00
|
|
|
// cout << "earliest_event(start: " << start << ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2008-09-22 13:47:21 -04:00
|
|
|
const_iterator length_check_iter = _events.begin();
|
2010-07-24 12:40:56 -04:00
|
|
|
if (_events.empty()) { // 0 events
|
2008-09-18 20:47:49 -04:00
|
|
|
return false;
|
2011-11-22 19:17:31 -05:00
|
|
|
} else if (_events.end() == ++length_check_iter) { // 1 event
|
2010-07-25 19:19:43 -04:00
|
|
|
return rt_safe_earliest_event_discrete_unlocked (start, x, y, inclusive);
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
// Hack to avoid infinitely repeating the same event
|
2010-07-25 19:19:43 -04:00
|
|
|
build_search_cache_if_necessary (start);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
if (_search_cache.first != _events.end()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
const ControlEvent* first = NULL;
|
|
|
|
const ControlEvent* next = NULL;
|
2008-09-22 22:40:29 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* Step is after first */
|
2010-07-25 19:20:31 -04:00
|
|
|
if (_search_cache.first == _events.begin() || (*_search_cache.first)->when <= start) {
|
2010-07-25 19:19:43 -04:00
|
|
|
first = *_search_cache.first;
|
2010-07-25 19:20:31 -04:00
|
|
|
++_search_cache.first;
|
|
|
|
if (_search_cache.first == _events.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
next = *_search_cache.first;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* Step is before first */
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
2010-07-25 19:19:43 -04:00
|
|
|
const_iterator prev = _search_cache.first;
|
2008-09-18 20:47:49 -04:00
|
|
|
--prev;
|
|
|
|
first = *prev;
|
2010-07-25 19:19:43 -04:00
|
|
|
next = *_search_cache.first;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (inclusive && first->when == start) {
|
|
|
|
x = first->when;
|
|
|
|
y = first->value;
|
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range) */
|
|
|
|
_search_cache.left = x;
|
|
|
|
//++_search_cache.range.first;
|
2009-01-28 04:49:42 -05:00
|
|
|
assert(x >= start);
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-22 22:40:29 -04:00
|
|
|
if (fabs(first->value - next->value) <= 1) {
|
2010-07-25 19:19:43 -04:00
|
|
|
if (next->when > start) {
|
2008-09-18 20:47:49 -04:00
|
|
|
x = next->when;
|
|
|
|
y = next->value;
|
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range) */
|
|
|
|
_search_cache.left = x;
|
|
|
|
//++_search_cache.range.first;
|
2008-12-12 00:21:06 -05:00
|
|
|
assert(inclusive ? x >= start : x > start);
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const double slope = (next->value - first->value) / (double)(next->when - first->when);
|
|
|
|
//cerr << "start y: " << start_y << endl;
|
|
|
|
|
|
|
|
//y = first->value + (slope * fabs(start - first->when));
|
|
|
|
y = first->value;
|
|
|
|
|
|
|
|
if (first->value < next->value) // ramping up
|
|
|
|
y = ceil(y);
|
|
|
|
else // ramping down
|
|
|
|
y = floor(y);
|
|
|
|
|
|
|
|
x = first->when + (y - first->value) / (double)slope;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
while ((inclusive && x < start) || (x <= start && y != next->value)) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (first->value < next->value) // ramping up
|
|
|
|
y += 1.0;
|
|
|
|
else // ramping down
|
|
|
|
y -= 1.0;
|
|
|
|
|
|
|
|
x = first->when + (y - first->value) / (double)slope;
|
|
|
|
}
|
|
|
|
|
2009-10-22 23:57:52 -04:00
|
|
|
/*cerr << first->value << " @ " << first->when << " ... "
|
2011-11-22 19:17:31 -05:00
|
|
|
<< next->value << " @ " << next->when
|
|
|
|
<< " = " << y << " @ " << x << endl;*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
assert( (y >= first->value && y <= next->value)
|
2011-11-22 19:17:31 -05:00
|
|
|
|| (y <= first->value && y >= next->value) );
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
const bool past_start = (inclusive ? x >= start : x > start);
|
2010-07-25 19:19:43 -04:00
|
|
|
if (past_start) {
|
2008-09-18 20:47:49 -04:00
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range) */
|
|
|
|
_search_cache.left = x;
|
2008-09-22 12:28:02 -04:00
|
|
|
assert(inclusive ? x >= start : x > start);
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* No points in the future, so no steps (towards them) in the future */
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-05 09:36:38 -04:00
|
|
|
/** @param start Start position in model coordinates.
|
|
|
|
* @param end End position in model coordinates.
|
|
|
|
* @param op 0 = cut, 1 = copy, 2 = clear.
|
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
boost::shared_ptr<ControlList>
|
|
|
|
ControlList::cut_copy_clear (double start, double end, int op)
|
|
|
|
{
|
|
|
|
boost::shared_ptr<ControlList> nal = create (_parameter);
|
|
|
|
iterator s, e;
|
2011-11-22 19:17:31 -05:00
|
|
|
ControlEvent cp (start, 0.0);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2010-08-19 17:09:40 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* first, determine s & e, two iterators that define the range of points
|
|
|
|
affected by this operation
|
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
|
|
|
|
return nal;
|
|
|
|
}
|
|
|
|
|
2010-04-25 20:22:26 -04:00
|
|
|
/* and the last that is at or after `end' */
|
2008-09-18 20:47:49 -04:00
|
|
|
cp.when = end;
|
|
|
|
e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
|
|
|
|
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* if "start" isn't the location of an existing point,
|
|
|
|
evaluate the curve to get a value for the start. Add a point to
|
|
|
|
both the existing event list, and if its not a "clear" operation,
|
|
|
|
to the copy ("nal") as well.
|
2010-08-19 17:09:40 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
Note that the time positions of the points in each list are different
|
|
|
|
because we want the copy ("nal") to have a zero time reference.
|
|
|
|
*/
|
2010-08-19 17:09:40 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* before we begin any cut/clear operations, get the value of the curve
|
|
|
|
at "end".
|
|
|
|
*/
|
|
|
|
|
|
|
|
double end_value = unlocked_eval (end);
|
2010-08-19 17:09:40 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if ((*s)->when != start) {
|
|
|
|
|
|
|
|
double val = unlocked_eval (start);
|
2010-08-19 17:09:40 -04:00
|
|
|
|
|
|
|
if (op == 0) { // cut
|
|
|
|
if (start > _events.front()->when) {
|
|
|
|
_events.insert (s, (new ControlEvent (start, val)));
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
|
|
|
if (op != 2) { // ! clear
|
|
|
|
nal->_events.push_back (new ControlEvent (0, val));
|
|
|
|
}
|
|
|
|
}
|
2010-08-19 17:09:40 -04:00
|
|
|
|
|
|
|
for (iterator x = s; x != e; ) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
/* adjust new points to be relative to start, which
|
|
|
|
has been set to zero.
|
|
|
|
*/
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
if (op != 2) {
|
|
|
|
nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op != 1) {
|
2010-08-19 17:09:40 -04:00
|
|
|
x = _events.erase (x);
|
|
|
|
} else {
|
2011-11-22 19:17:31 -05:00
|
|
|
++x;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (e == _events.end() || (*e)->when != end) {
|
2010-08-19 17:09:40 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* only add a boundary point if there is a point after "end"
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (op == 0 && (e != _events.end() && end < (*e)->when)) { // cut
|
|
|
|
_events.insert (e, new ControlEvent (end, end_value));
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (op != 2 && (e != _events.end() && end < (*e)->when)) { // cut/copy
|
|
|
|
nal->_events.push_back (new ControlEvent (end - start, end_value));
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2011-11-22 19:17:31 -05:00
|
|
|
mark_dirty ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
if (op != 1) {
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
return nal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<ControlList>
|
|
|
|
ControlList::cut (double start, double end)
|
|
|
|
{
|
|
|
|
return cut_copy_clear (start, end, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<ControlList>
|
|
|
|
ControlList::copy (double start, double end)
|
|
|
|
{
|
|
|
|
return cut_copy_clear (start, end, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::clear (double start, double end)
|
|
|
|
{
|
2010-08-05 09:36:38 -04:00
|
|
|
cut_copy_clear (start, end, 2);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2010-08-05 09:36:38 -04:00
|
|
|
/** @param pos Position in model coordinates */
|
2008-09-18 20:47:49 -04:00
|
|
|
bool
|
2009-07-21 11:55:17 -04:00
|
|
|
ControlList::paste (ControlList& alist, double pos, float /*times*/)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
if (alist._events.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
iterator where;
|
|
|
|
iterator prev;
|
|
|
|
double end = 0;
|
|
|
|
ControlEvent cp (pos, 0.0);
|
|
|
|
|
|
|
|
where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
|
|
|
|
|
|
|
|
for (iterator i = alist.begin();i != alist.end(); ++i) {
|
|
|
|
_events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
|
|
|
|
end = (*i)->when + pos;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* move all points after the insertion along the timeline by
|
2008-09-18 20:47:49 -04:00
|
|
|
the correct amount.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (where != _events.end()) {
|
|
|
|
iterator tmp;
|
|
|
|
if ((*where)->when <= end) {
|
|
|
|
tmp = where;
|
|
|
|
++tmp;
|
|
|
|
_events.erase(where);
|
|
|
|
where = tmp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-20 19:58:49 -04:00
|
|
|
/** Move automation around according to a list of region movements.
|
|
|
|
* @param return true if anything was changed, otherwise false (ie nothing needed changing)
|
|
|
|
*/
|
|
|
|
bool
|
2009-02-01 21:36:05 -05:00
|
|
|
ControlList::move_ranges (const list< RangeMove<double> >& movements)
|
2008-12-16 18:21:01 -05:00
|
|
|
{
|
2009-02-01 21:36:05 -05:00
|
|
|
typedef list< RangeMove<double> > RangeMoveList;
|
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2008-12-16 18:21:01 -05:00
|
|
|
|
|
|
|
/* a copy of the events list before we started moving stuff around */
|
|
|
|
EventList old_events = _events;
|
|
|
|
|
|
|
|
/* clear the source and destination ranges in the new list */
|
2010-08-20 19:58:49 -04:00
|
|
|
bool things_erased = false;
|
2008-12-16 18:21:01 -05:00
|
|
|
for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
|
|
|
|
|
2010-08-20 19:58:49 -04:00
|
|
|
if (erase_range_internal (i->from, i->from + i->length, _events)) {
|
|
|
|
things_erased = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (erase_range_internal (i->to, i->to + i->length, _events)) {
|
|
|
|
things_erased = true;
|
|
|
|
}
|
|
|
|
}
|
2008-12-16 18:21:01 -05:00
|
|
|
|
2010-08-20 19:58:49 -04:00
|
|
|
/* if nothing was erased, there is nothing to do */
|
|
|
|
if (!things_erased) {
|
|
|
|
return false;
|
2008-12-16 18:21:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the events into the new list */
|
|
|
|
for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
|
|
|
|
iterator j = old_events.begin ();
|
2009-02-01 21:36:05 -05:00
|
|
|
const double limit = i->from + i->length;
|
|
|
|
const double dx = i->to - i->from;
|
2008-12-16 18:21:01 -05:00
|
|
|
while (j != old_events.end () && (*j)->when <= limit) {
|
|
|
|
if ((*j)->when >= i->from) {
|
|
|
|
ControlEvent* ev = new ControlEvent (**j);
|
|
|
|
ev->when += dx;
|
|
|
|
_events.push_back (ev);
|
|
|
|
}
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_frozen) {
|
|
|
|
_events.sort (event_time_less_than);
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-12-16 18:21:01 -05:00
|
|
|
} else {
|
|
|
|
_sort_pending = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
2010-08-20 19:58:49 -04:00
|
|
|
return true;
|
2008-12-16 18:21:01 -05:00
|
|
|
}
|
|
|
|
|
2010-07-13 20:58:15 -04:00
|
|
|
void
|
|
|
|
ControlList::set_interpolation (InterpolationStyle s)
|
|
|
|
{
|
|
|
|
if (_interpolation == s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_interpolation = s;
|
|
|
|
InterpolationChanged (s); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
|
2012-04-05 07:16:04 -04:00
|
|
|
void
|
|
|
|
ControlList::set_thinning_factor (double v)
|
|
|
|
{
|
|
|
|
_thinning_factor = v;
|
|
|
|
}
|
|
|
|
|
2012-06-16 13:20:10 -04:00
|
|
|
bool
|
|
|
|
ControlList::operator!= (ControlList const & other) const
|
|
|
|
{
|
|
|
|
if (_events.size() != other._events.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventList::const_iterator i = _events.begin ();
|
|
|
|
EventList::const_iterator j = other._events.begin ();
|
|
|
|
|
|
|
|
while (i != _events.end() && (*i)->when == (*j)->when && (*i)->value == (*j)->value) {
|
|
|
|
++i;
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != _events.end ()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
_parameter != other._parameter ||
|
|
|
|
_interpolation != other._interpolation ||
|
|
|
|
_min_yval != other._min_yval ||
|
|
|
|
_max_yval != other._max_yval ||
|
|
|
|
_default_value != other._default_value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
} // namespace Evoral
|
|
|
|
|