2019-08-02 23:10:55 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008-2009 Hans Baier <hansfbaier@googlemail.com>
|
|
|
|
* Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2008-2015 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2010-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2014 Ben Loftis <ben@harrisonconsoles.com>
|
|
|
|
* Copyright (C) 2015 Nick Mainsbridge <mainsbridge@gmail.com>
|
2009-10-14 12:10:01 -04:00
|
|
|
*
|
2019-08-02 23:10:55 -04:00
|
|
|
* This program 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
|
|
|
*
|
2019-08-02 23:10:55 -04:00
|
|
|
* This program 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 more 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.,
|
2019-08-02 23:10:55 -04:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-18 20:47:49 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cmath>
|
2014-11-01 13:35:44 -04:00
|
|
|
|
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
// 'std::isnan()' is not available in MSVC.
|
2022-12-03 08:45:09 -05:00
|
|
|
#define isnan_local(val) (bool)_isnan ((double)val)
|
2014-11-01 13:35:44 -04:00
|
|
|
#else
|
|
|
|
#define isnan_local std::isnan
|
|
|
|
#endif
|
|
|
|
|
2023-01-22 21:19:20 -05:00
|
|
|
#define GUARD_POINT_DELTA(foo) ((foo).time_domain () == Temporal::AudioTime ? Temporal::timecnt_t (64) : Temporal::timecnt_t (Beats (0, 1)))
|
2017-07-23 17:52:20 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
#include <cassert>
|
2014-12-01 14:28:03 -05:00
|
|
|
#include <cmath>
|
2008-09-18 20:47:49 -04:00
|
|
|
#include <iostream>
|
2014-12-01 14:28:03 -05:00
|
|
|
#include <utility>
|
|
|
|
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/ControlList.h"
|
|
|
|
#include "evoral/Curve.h"
|
|
|
|
#include "evoral/ParameterDescriptor.h"
|
|
|
|
#include "evoral/TypeMap.h"
|
|
|
|
#include "evoral/types.h"
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
#include "pbd/compose.h"
|
2022-12-03 08:45:09 -05:00
|
|
|
#include "pbd/control_math.h"
|
|
|
|
#include "pbd/debug.h"
|
2020-08-24 16:40:03 -04:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/i18n.h"
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
using namespace std;
|
2012-07-13 17:05:45 -04:00
|
|
|
using namespace PBD;
|
2020-09-20 18:34:58 -04:00
|
|
|
using namespace Temporal;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
namespace Evoral
|
|
|
|
{
|
|
|
|
inline bool
|
|
|
|
event_time_less_than (ControlEvent* a, ControlEvent* b)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
return a->when < b->when;
|
|
|
|
}
|
|
|
|
|
2023-07-21 11:56:42 -04:00
|
|
|
ControlList::ControlList (const Parameter& id, const ParameterDescriptor& desc, TimeDomainProvider const & tds)
|
|
|
|
: TimeDomainProvider (tds)
|
|
|
|
, _parameter (id)
|
2022-12-03 08:45:09 -05:00
|
|
|
, _desc (desc)
|
2017-06-19 09:45:47 -04:00
|
|
|
, _interpolation (default_interpolation ())
|
2022-12-03 08:45:09 -05:00
|
|
|
, _curve (0)
|
|
|
|
{
|
|
|
|
_frozen = 0;
|
|
|
|
_changed_when_thawed = false;
|
2023-07-21 11:56:42 -04:00
|
|
|
_lookup_cache.left = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05:00
|
|
|
_lookup_cache.range.first = _events.end ();
|
|
|
|
_lookup_cache.range.second = _events.end ();
|
2023-07-21 11:56:42 -04:00
|
|
|
_search_cache.left = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05:00
|
|
|
_search_cache.first = _events.end ();
|
|
|
|
_sort_pending = false;
|
|
|
|
new_write_pass = true;
|
|
|
|
_in_write_pass = false;
|
|
|
|
did_write_during_pass = false;
|
2023-07-21 11:56:42 -04:00
|
|
|
insert_position = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = _events.end ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlList::ControlList (const ControlList& other)
|
2023-07-21 11:56:42 -04:00
|
|
|
: TimeDomainProvider (other)
|
|
|
|
, _parameter (other._parameter)
|
2022-12-03 08:45:09 -05:00
|
|
|
, _desc (other._desc)
|
|
|
|
, _interpolation (other._interpolation)
|
|
|
|
, _curve (0)
|
|
|
|
{
|
|
|
|
_frozen = 0;
|
|
|
|
_changed_when_thawed = false;
|
|
|
|
_lookup_cache.range.first = _events.end ();
|
|
|
|
_lookup_cache.range.second = _events.end ();
|
|
|
|
_search_cache.first = _events.end ();
|
|
|
|
_sort_pending = false;
|
|
|
|
new_write_pass = true;
|
|
|
|
_in_write_pass = false;
|
|
|
|
did_write_during_pass = false;
|
2023-07-21 11:56:42 -04:00
|
|
|
insert_position = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = _events.end ();
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2017-06-19 09:45:47 -04:00
|
|
|
// XXX copy_events() emits Dirty, but this is just assignment copy/construction
|
2012-05-11 17:30:36 -04:00
|
|
|
copy_events (other);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::ControlList (const ControlList& other, timepos_t const& start, timepos_t const& end)
|
2023-07-21 11:56:42 -04:00
|
|
|
: TimeDomainProvider (other)
|
|
|
|
, _parameter (other._parameter)
|
2022-12-03 08:45:09 -05:00
|
|
|
, _desc (other._desc)
|
|
|
|
, _interpolation (other._interpolation)
|
|
|
|
, _curve (0)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
_frozen = 0;
|
|
|
|
_changed_when_thawed = false;
|
|
|
|
_lookup_cache.range.first = _events.end ();
|
|
|
|
_lookup_cache.range.second = _events.end ();
|
|
|
|
_search_cache.first = _events.end ();
|
|
|
|
_sort_pending = false;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
/* now grab the relevant points, and shift them back if necessary */
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ControlList> section = const_cast<ControlList*> (&other)->copy (start, end);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (!section->empty ()) {
|
2017-06-19 09:45:47 -04:00
|
|
|
// XXX copy_events() emits Dirty, but this is just assignment copy/construction
|
2022-12-03 08:45:09 -05:00
|
|
|
copy_events (*(section.get ()));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
new_write_pass = true;
|
|
|
|
_in_write_pass = false;
|
|
|
|
did_write_during_pass = false;
|
2023-07-21 11:56:42 -04:00
|
|
|
insert_position = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05: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 ();
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::~ControlList ()
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
for (EventList::iterator x = _events.begin (); x != _events.end (); ++x) {
|
2008-09-18 20:47:49 -04:00
|
|
|
delete (*x);
|
|
|
|
}
|
2016-07-25 11:16:32 -04:00
|
|
|
_events.clear ();
|
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
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ControlList>
|
2023-07-21 11:56:42 -04:00
|
|
|
ControlList::create (const Parameter& id, const ParameterDescriptor& desc, TimeDomainProvider const & tdp)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2023-07-21 11:56:42 -04:00
|
|
|
ControlList* cl (new ControlList (id, desc, tdp));
|
|
|
|
return std::shared_ptr<ControlList> (cl);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlList::operator== (const ControlList& other)
|
|
|
|
{
|
|
|
|
return _events == other._events;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlList&
|
|
|
|
ControlList::operator= (const ControlList& other)
|
|
|
|
{
|
|
|
|
if (this != &other) {
|
2017-07-06 20:34:09 -04:00
|
|
|
/* list should be frozen before assignment */
|
|
|
|
assert (_frozen > 0);
|
2017-06-19 09:45:47 -04:00
|
|
|
_changed_when_thawed = false;
|
2022-12-03 08:45:09 -05:00
|
|
|
_sort_pending = false;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
insert_position = other.insert_position;
|
|
|
|
new_write_pass = true;
|
|
|
|
_in_write_pass = false;
|
2017-06-19 09:45:47 -04:00
|
|
|
did_write_during_pass = false;
|
2023-07-21 11:56:42 -04:00
|
|
|
insert_position = timepos_t::max (time_domain());
|
2014-07-09 14:29:57 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
_parameter = other._parameter;
|
|
|
|
_desc = other._desc;
|
2014-07-09 14:29:57 -04:00
|
|
|
_interpolation = other._interpolation;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
for (EventList::iterator x = _events.begin (); x != _events.end (); ++x) {
|
2016-07-25 11:16:32 -04:00
|
|
|
delete (*x);
|
|
|
|
}
|
2012-05-11 17:30:36 -04:00
|
|
|
_events.clear ();
|
2017-06-19 09:45:47 -04:00
|
|
|
Glib::Threads::RWLock::ReaderLock olm (other._lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
for (const_iterator i = other.begin (); i != other.end (); ++i) {
|
2012-05-11 17:30:36 -04:00
|
|
|
_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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::create_curve ()
|
2009-02-19 14:42:25 -05:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
_curve = new Curve (*this);
|
2009-02-19 14:42:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::destroy_curve ()
|
2009-02-19 14:42:25 -05:00
|
|
|
{
|
|
|
|
delete _curve;
|
|
|
|
_curve = NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-19 09:45:47 -04:00
|
|
|
ControlList::InterpolationStyle
|
|
|
|
ControlList::default_interpolation () const
|
|
|
|
{
|
|
|
|
if (_desc.toggled) {
|
|
|
|
return Discrete;
|
|
|
|
} else if (_desc.logarithmic) {
|
|
|
|
return Logarithmic;
|
|
|
|
}
|
|
|
|
return Linear;
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
void
|
|
|
|
ControlList::maybe_signal_changed ()
|
|
|
|
{
|
2010-05-27 08:26:00 -04:00
|
|
|
if (_frozen) {
|
2008-09-18 20:47:49 -04:00
|
|
|
_changed_when_thawed = true;
|
2020-08-31 01:39:45 -04:00
|
|
|
} else {
|
|
|
|
Dirty (); /* EMIT SIGNAL */
|
2010-05-27 08:26:00 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::clear ()
|
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
for (EventList::iterator x = _events.begin (); x != _events.end (); ++x) {
|
2016-07-25 11:16:32 -04:00
|
|
|
delete (*x);
|
|
|
|
}
|
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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::x_scale (ratio_t const& factor)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
_x_scale (factor);
|
|
|
|
}
|
|
|
|
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::ensure_time_domain (timepos_t const& val) const
|
2022-05-01 19:50:41 -04:00
|
|
|
{
|
2023-07-21 11:56:42 -04:00
|
|
|
TimeDomain td (time_domain());
|
|
|
|
if (val.time_domain () != td) {
|
|
|
|
switch (td) {
|
2022-12-03 08:45:09 -05:00
|
|
|
case Temporal::AudioTime:
|
|
|
|
return timepos_t (val.samples ());
|
|
|
|
break;
|
|
|
|
case Temporal::BeatTime:
|
|
|
|
return timepos_t (val.beats ());
|
|
|
|
break;
|
2022-05-01 19:50:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
bool
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::extend_to (timepos_t const& end)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t actual_end = ensure_time_domain (end);
|
|
|
|
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.empty () || _events.back ()->when == actual_end) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
ratio_t factor (actual_end.val (), _events.back ()->when.val ());
|
2008-09-18 20:47:49 -04:00
|
|
|
_x_scale (factor);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-13 14:57:01 -04:00
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::y_transform (boost::function<double (double)> callback)
|
2017-06-13 14:57:01 -04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
for (iterator i = _events.begin (); i != _events.end (); ++i) {
|
2017-06-13 14:57:01 -04:00
|
|
|
(*i)->value = callback ((*i)->value);
|
|
|
|
}
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
2017-06-13 20:38:32 -04:00
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::list_merge (ControlList const& other, boost::function<double (double, double)> callback)
|
2017-06-13 20:38:32 -04:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
|
|
|
/* First scale existing events, copy into a new list.
|
|
|
|
* The original list is needed later to interpolate
|
|
|
|
* for new events only present in the master list.
|
|
|
|
*/
|
2022-12-03 08:45:09 -05:00
|
|
|
EventList nel;
|
|
|
|
for (iterator i = _events.begin (); i != _events.end (); ++i) {
|
2017-06-13 20:38:32 -04:00
|
|
|
float val = callback ((*i)->value, other.eval ((*i)->when));
|
2022-12-03 08:45:09 -05:00
|
|
|
nel.push_back (new ControlEvent ((*i)->when, val));
|
2017-06-13 20:38:32 -04:00
|
|
|
}
|
|
|
|
/* Now add events which are only present in the master-list. */
|
2022-12-03 08:45:09 -05:00
|
|
|
const EventList& evl (other.events ());
|
|
|
|
for (const_iterator i = evl.begin (); i != evl.end (); ++i) {
|
2017-06-13 20:38:32 -04:00
|
|
|
bool found = false;
|
|
|
|
// TODO: optimize, remember last matching iterator (lists are sorted)
|
2022-12-03 08:45:09 -05:00
|
|
|
for (iterator j = _events.begin (); j != _events.end (); ++j) {
|
2017-06-13 20:38:32 -04:00
|
|
|
if ((*i)->when == (*j)->when) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* skip events that have already been merge in the first pass */
|
|
|
|
if (found) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
float val = callback (unlocked_eval ((*i)->when), (*i)->value);
|
|
|
|
nel.push_back (new ControlEvent ((*i)->when, val));
|
|
|
|
}
|
|
|
|
nel.sort (event_time_less_than);
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (EventList::iterator x = _events.begin (); x != _events.end (); ++x) {
|
2017-06-13 20:38:32 -04:00
|
|
|
delete (*x);
|
|
|
|
}
|
|
|
|
_events.clear ();
|
|
|
|
_events = nel;
|
|
|
|
|
2017-06-21 06:07:12 -04:00
|
|
|
unlocked_remove_duplicates ();
|
2017-06-13 20:38:32 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::_x_scale (ratio_t const& factor)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
for (iterator i = _events.begin (); i != _events.end (); ++i) {
|
2022-05-27 14:46:58 -04:00
|
|
|
(*i)->when = (*i)->when.scale (factor);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
2011-03-08 07:34:25 -05:00
|
|
|
struct ControlEventTimeComparator {
|
2022-12-03 08:45:09 -05:00
|
|
|
bool operator() (ControlEvent* a, ControlEvent* b)
|
|
|
|
{
|
2011-03-08 07:34:25 -05:00
|
|
|
return a->when < b->when;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-26 17:13:54 -05:00
|
|
|
void
|
2014-11-30 22:18:18 -05:00
|
|
|
ControlList::thin (double thinning_factor)
|
2011-12-26 17:13:54 -05:00
|
|
|
{
|
2014-12-01 19:37:05 -05:00
|
|
|
if (thinning_factor == 0.0 || _desc.toggled) {
|
2014-11-30 22:18:18 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-17 18:55:12 -05:00
|
|
|
/* compat. In the past the actual (internal) value was used
|
|
|
|
* to compute the area. For gain the range is 0..2 (exp).
|
|
|
|
* Since we cannot change automation-thinning-factor
|
|
|
|
* in user's existing config, we simply re-normalize
|
|
|
|
* the thinning factor.
|
|
|
|
*/
|
|
|
|
thinning_factor *= .7071;
|
|
|
|
|
2017-07-24 14:54:32 -04:00
|
|
|
assert (is_sorted ());
|
|
|
|
|
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
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
ControlEvent* prevprev = 0;
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlEvent* cur = 0;
|
|
|
|
ControlEvent* prev = 0;
|
|
|
|
iterator pprev;
|
|
|
|
int counter = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 thin from %2 events\n", this, _events.size ()));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (iterator i = _events.begin (); i != _events.end (); ++i) {
|
2012-07-13 17:05:45 -04:00
|
|
|
cur = *i;
|
|
|
|
counter++;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
if (counter > 2) {
|
2022-12-03 08:45:09 -05:00
|
|
|
/* compute the area of the triangle formed by 3 points */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
const double ppw = prevprev->when.samples ();
|
|
|
|
const double pw = prev->when.samples ();
|
|
|
|
const double cw = cur->when.samples ();
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-17 18:55:12 -05:00
|
|
|
const float ppv = _desc.to_interface (prevprev->value);
|
|
|
|
const float cv = _desc.to_interface (cur->value);
|
|
|
|
const float pv = _desc.to_interface (prev->value);
|
|
|
|
|
|
|
|
double area = fabs ((ppw * (pv - cv)) +
|
|
|
|
(pw * (cv - ppv)) +
|
|
|
|
(cw * (ppv - pv)));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-11-30 22:18:18 -05:00
|
|
|
if (area < thinning_factor) {
|
2012-07-13 17:05:45 -04:00
|
|
|
iterator tmp = pprev;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
/* pprev will change to current
|
2022-12-03 08:45:09 -05:00
|
|
|
* i is incremented to the next event
|
|
|
|
* as we loop.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
pprev = i;
|
2022-12-17 18:55:12 -05:00
|
|
|
prev = cur;
|
2012-07-13 17:05:45 -04:00
|
|
|
_events.erase (tmp);
|
|
|
|
changed = true;
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-26 17:13:54 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
prevprev = prev;
|
2022-12-03 08:45:09 -05:00
|
|
|
prev = cur;
|
|
|
|
pprev = i;
|
2011-12-26 17:13:54 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05: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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::fast_simple_add (timepos_t const& time, double value)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
/* to be used only for loading pre-sorted data from saved state */
|
2022-05-01 19:50:41 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.insert (_events.end (), new ControlEvent (ensure_time_domain (time), value));
|
2012-04-16 12:32:22 -04:00
|
|
|
|
|
|
|
mark_dirty ();
|
2017-07-04 14:12:51 -04:00
|
|
|
if (_frozen) {
|
|
|
|
_sort_pending = true;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-13 17:05:45 -04:00
|
|
|
ControlList::invalidate_insert_iterator ()
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::unlocked_invalidate_insert_iterator ()
|
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = _events.end ();
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
|
|
|
|
2017-06-21 06:07:12 -04:00
|
|
|
void
|
|
|
|
ControlList::unlocked_remove_duplicates ()
|
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.size () < 2) {
|
2017-06-21 06:07:12 -04:00
|
|
|
return;
|
|
|
|
}
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator i = _events.begin ();
|
2017-06-21 06:07:12 -04:00
|
|
|
iterator prev = i++;
|
2022-12-03 08:45:09 -05:00
|
|
|
while (i != _events.end ()) {
|
2017-06-21 06:07:12 -04:00
|
|
|
if ((*prev)->when == (*i)->when && (*prev)->value == (*i)->value) {
|
|
|
|
i = _events.erase (i);
|
|
|
|
} else {
|
|
|
|
++prev;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::start_write_pass (timepos_t const& time)
|
2012-07-13 17:05:45 -04:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2014-02-19 12:52:14 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("%1: setup write pass @ %2\n", this, when));
|
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
insert_position = when;
|
2015-10-05 10:17:49 -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).
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-14 11:42:10 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2017-07-27 11:50:27 -04:00
|
|
|
|
|
|
|
/* except if we're already in an active write-pass.
|
|
|
|
*
|
|
|
|
* invalid iterator == end() the iterator is set to the correct
|
|
|
|
* position in ControlList::add IFF (_in_write_pass && new_write_pass)
|
|
|
|
*/
|
|
|
|
if (_in_write_pass && !new_write_pass) {
|
|
|
|
#if 1
|
2023-07-21 11:56:42 -04:00
|
|
|
add_guard_point (when, timecnt_t (time_domain())); // also sets most_recent_insert_iterator
|
2017-07-27 11:50:27 -04:00
|
|
|
#else
|
|
|
|
const ControlEvent cp (when, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2017-07-27 11:50:27 -04:00
|
|
|
#endif
|
|
|
|
}
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::write_pass_finished (timepos_t const& /*when*/, double thinning_factor)
|
2012-07-16 23:10:40 -04:00
|
|
|
{
|
2014-02-19 12:52:14 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, "write pass finished\n");
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (did_write_during_pass) {
|
2014-11-30 22:18:18 -05:00
|
|
|
thin (thinning_factor);
|
2012-07-16 23:10:40 -04:00
|
|
|
did_write_during_pass = false;
|
|
|
|
}
|
|
|
|
new_write_pass = true;
|
|
|
|
_in_write_pass = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-09-20 18:34:58 -04:00
|
|
|
ControlList::set_in_write_pass (bool yn, bool add_point, timepos_t when)
|
2015-10-05 10:17:49 -04:00
|
|
|
{
|
2020-06-11 23:08:40 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("set_in_write_pass: in-write: %1 @ %2 add point? %3\n", yn, when, add_point));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
_in_write_pass = yn;
|
2013-04-02 16:10:51 -04:00
|
|
|
|
|
|
|
if (yn && add_point) {
|
2017-07-23 17:52:20 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2023-07-21 11:56:42 -04:00
|
|
|
add_guard_point (when, timecnt_t (time_domain()));
|
2013-04-02 16:10:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::add_guard_point (timepos_t const& time, timecnt_t const& offset)
|
2013-04-02 16:10:51 -04:00
|
|
|
{
|
2022-05-01 19:50:41 -04:00
|
|
|
/* we do not convert this yet */
|
2023-07-21 11:56:42 -04:00
|
|
|
assert (offset.time_domain () == time_domain());
|
2021-08-30 17:15:14 -04:00
|
|
|
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
// caller needs to hold writer-lock
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (offset.is_negative () && when < offset) {
|
2017-07-23 17:52:20 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (offset.is_negative ()) {
|
2017-07-23 17:52:20 -04:00
|
|
|
/* check if there are points between when + offset .. when */
|
|
|
|
ControlEvent cp (when + offset, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator s;
|
|
|
|
iterator e;
|
|
|
|
if ((s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator)) != _events.end ()) {
|
2017-07-23 17:52:20 -04:00
|
|
|
cp.when = when;
|
2022-12-03 08:45:09 -05:00
|
|
|
e = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2017-07-23 17:52:20 -04:00
|
|
|
if (s != e) {
|
2020-08-24 16:40:03 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 add_guard_point, none added, found event between %2 and %3\n", this, when.earlier (offset), when));
|
2017-07-23 17:52:20 -04:00
|
|
|
return;
|
2022-05-15 11:37:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* check if there are points between when + offset .. when */
|
|
|
|
ControlEvent cp (when + offset, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator s;
|
|
|
|
iterator e;
|
|
|
|
if ((s = upper_bound (_events.begin (), _events.end (), &cp, time_comparator)) != _events.end ()) {
|
2022-05-15 11:37:20 -04:00
|
|
|
cp.when = when;
|
2022-12-03 08:45:09 -05:00
|
|
|
e = upper_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2022-05-15 11:37:20 -04:00
|
|
|
if (s != e) {
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 add_guard_point, none added, found event between %2 and %3\n", this, when.earlier (offset), when));
|
|
|
|
return;
|
2017-07-23 17:52:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 14:54:32 -04:00
|
|
|
/* don't do this again till the next write pass,
|
|
|
|
* unless we're not in a write-pass (transport stopped)
|
|
|
|
*/
|
|
|
|
if (_in_write_pass && new_write_pass) {
|
|
|
|
WritePassStarted (); /* EMIT SIGNAL w/WriteLock */
|
2022-12-17 19:45:04 -05:00
|
|
|
did_write_during_pass = true;
|
2017-07-24 14:54:32 -04:00
|
|
|
new_write_pass = false;
|
|
|
|
}
|
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
when += offset;
|
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
ControlEvent cp (when, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2013-04-02 16:10:51 -04:00
|
|
|
|
2017-07-24 14:54:32 -04:00
|
|
|
double eval_value = unlocked_eval (when);
|
2015-06-07 09:07:56 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (most_recent_insert_iterator == _events.end ()) {
|
2013-04-02 16:10:51 -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 (when, eval_value));
|
|
|
|
/* leave insert iterator at the end */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
} 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));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
/* most_recent_insert_iterator points to a control event
|
|
|
|
already at the insert position, so there is
|
|
|
|
nothing to do.
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 15:11:15 -04:00
|
|
|
... except ...
|
2015-06-07 09:07:56 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
advance most_recent_insert_iterator so that the "real"
|
2015-10-04 15:11:15 -04:00
|
|
|
insert occurs in the right place, since it
|
2013-04-02 16:10:51 -04:00
|
|
|
points to the control event just inserted.
|
|
|
|
*/
|
2015-06-07 09:07:56 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
++most_recent_insert_iterator;
|
|
|
|
} else {
|
2017-07-23 17:52:20 -04:00
|
|
|
/* insert a new control event at the right spot */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 15:11:15 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert eval-value %2 just before iterator @ %3\n",
|
2022-12-03 08:45:09 -05:00
|
|
|
this, eval_value, (*most_recent_insert_iterator)->when));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
most_recent_insert_iterator = _events.insert (most_recent_insert_iterator, new ControlEvent (when, eval_value));
|
2015-06-07 09:07:56 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
/* advance most_recent_insert_iterator so that the "real"
|
2015-10-04 15:11:15 -04:00
|
|
|
* insert occurs in the right place, since it
|
2013-04-02 16:10:51 -04:00
|
|
|
* points to the control event just inserted.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
++most_recent_insert_iterator;
|
|
|
|
}
|
2012-07-16 23:10:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlList::in_write_pass () const
|
|
|
|
{
|
|
|
|
return _in_write_pass;
|
|
|
|
}
|
|
|
|
|
2015-09-13 15:24:28 -04:00
|
|
|
bool
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::editor_add (timepos_t const& time, double value, bool with_guard)
|
2014-08-05 16:42:06 -04:00
|
|
|
{
|
2017-07-23 17:52:20 -04:00
|
|
|
/* this is for making changes from a graphical line editor */
|
|
|
|
{
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2014-08-05 16:42:06 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
ControlEvent cp (when, 0.0f);
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator i = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2015-09-13 15:24:28 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
if (i != _events.end () && (*i)->when == when) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-13 15:24:28 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
/* clamp new value to allowed range */
|
|
|
|
value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, value));
|
2017-06-21 06:08:12 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.empty ()) {
|
2017-07-23 17:52:20 -04:00
|
|
|
/* as long as the point we're adding is not at zero,
|
|
|
|
* add an "anchor" point there.
|
|
|
|
*/
|
2014-08-05 16:42:06 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
if (when >= 1) {
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.insert (_events.end (), new ControlEvent (timepos_t (time_domain()), value));
|
2017-07-23 17:52:20 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added value %2 at zero\n", this, value));
|
|
|
|
}
|
2014-08-05 16:42:06 -04:00
|
|
|
}
|
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
insert_position = when;
|
|
|
|
if (with_guard) {
|
2022-12-03 08:45:09 -05:00
|
|
|
add_guard_point (when, -GUARD_POINT_DELTA (when));
|
2017-07-23 17:52:20 -04:00
|
|
|
maybe_add_insert_guard (when);
|
2022-12-03 08:45:09 -05:00
|
|
|
i = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2015-06-17 20:03:18 -04:00
|
|
|
}
|
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
iterator result;
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("editor_add: actually add when= %1 value= %2\n", when, value));
|
|
|
|
result = _events.insert (i, new ControlEvent (when, value));
|
2014-08-05 16:42:06 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
if (i == result) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-05 16:42:06 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
mark_dirty ();
|
|
|
|
}
|
2014-08-05 16:42:06 -04:00
|
|
|
maybe_signal_changed ();
|
|
|
|
|
2015-09-13 15:24:28 -04:00
|
|
|
return true;
|
2014-08-05 16:42:06 -04:00
|
|
|
}
|
|
|
|
|
2023-07-10 13:20:17 -04:00
|
|
|
bool
|
|
|
|
ControlList::editor_add_ordered (OrderedPoints const & points, bool with_guard)
|
|
|
|
{
|
|
|
|
/* this is for making changes from a graphical line editor */
|
2023-07-10 16:05:27 -04:00
|
|
|
|
|
|
|
/* Note that as the name suggests, @p points must be in time
|
|
|
|
* order. This code does not check for this condition to be satisfied,
|
|
|
|
* but it will break if not honored.
|
|
|
|
*/
|
|
|
|
|
2023-07-10 13:20:17 -04:00
|
|
|
if (points.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
|
|
|
|
|
|
|
Temporal::timepos_t earliest = points.front().when;
|
|
|
|
Temporal::timepos_t latest = points.back().when;
|
|
|
|
|
2023-07-10 16:23:17 -04:00
|
|
|
assert (earliest <= latest);
|
2023-07-10 13:20:17 -04:00
|
|
|
|
2023-07-10 16:05:27 -04:00
|
|
|
timecnt_t distance = earliest.distance (latest);
|
|
|
|
|
2023-07-10 13:20:17 -04:00
|
|
|
(void) erase_range_internal (earliest, latest, _events);
|
|
|
|
|
2023-07-10 16:05:27 -04:00
|
|
|
if (with_guard) {
|
|
|
|
ControlEvent cp (earliest, 0.0);
|
|
|
|
double v = unlocked_eval (earliest);
|
|
|
|
iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
|
|
|
if (s != _events.end ()) {
|
|
|
|
_events.insert (s, new ControlEvent (earliest, v));
|
|
|
|
}
|
|
|
|
}
|
2023-07-10 16:17:10 -04:00
|
|
|
if (with_guard && !distance.is_zero()) {
|
2023-07-10 16:05:27 -04:00
|
|
|
ControlEvent cp (latest, 0.0);
|
|
|
|
double v = unlocked_eval (latest);
|
|
|
|
iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
|
|
|
if (s != _events.end ()) {
|
|
|
|
_events.insert (s, new ControlEvent (latest, v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:20:17 -04:00
|
|
|
/* Get the iterator where we should start insertion */
|
|
|
|
|
2023-07-10 16:05:27 -04:00
|
|
|
timepos_t when = ensure_time_domain (points.front().when);
|
|
|
|
ControlEvent cp (when, 0.0f);
|
|
|
|
iterator i = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
|
|
|
double value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, points.front().value));
|
2023-07-10 13:20:17 -04:00
|
|
|
|
|
|
|
if (i != _events.end () && (*i)->when == when) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-10 16:05:27 -04:00
|
|
|
/* if we are creating the first point in the list, and it will
|
|
|
|
* not be at zero, add an "anchor" point there at zero, with
|
|
|
|
* the same value.
|
|
|
|
*/
|
|
|
|
|
2023-07-21 11:56:42 -04:00
|
|
|
if (_events.empty () && when > timecnt_t (time_domain())) {
|
|
|
|
_events.insert (_events.end (), new ControlEvent (timepos_t (time_domain()), value));
|
2023-07-10 16:05:27 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added value %2 at zero\n", this, value));
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:20:17 -04:00
|
|
|
for (auto const & p : points) {
|
|
|
|
|
2023-07-10 16:05:27 -04:00
|
|
|
/* ensure time domain for point is correct */
|
2023-07-10 13:20:17 -04:00
|
|
|
when = ensure_time_domain (p.when);
|
|
|
|
|
|
|
|
/* clamp new value to allowed range */
|
2023-07-10 16:05:27 -04:00
|
|
|
value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, p.value));
|
2023-07-10 13:20:17 -04:00
|
|
|
|
|
|
|
insert_position = when;
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("editor_add: actually add when= %1 value= %2\n", when, value));
|
2023-07-10 16:05:27 -04:00
|
|
|
_events.insert (i, new ControlEvent (when, value));
|
2023-07-10 13:20:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mark_dirty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-01 18:36:24 -05:00
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::maybe_add_insert_guard (timepos_t const& time)
|
2014-12-01 18:36:24 -05:00
|
|
|
{
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2017-07-23 17:52:20 -04:00
|
|
|
// caller needs to hold writer-lock
|
2022-12-03 08:45:09 -05:00
|
|
|
if (most_recent_insert_iterator != _events.end ()) {
|
|
|
|
if ((*most_recent_insert_iterator)->when.earlier (when) > GUARD_POINT_DELTA (when)) {
|
2014-12-01 18:36:24 -05:00
|
|
|
/* Next control point is some distance from where our new point is
|
|
|
|
going to go, so 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. */
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = _events.insert (most_recent_insert_iterator,
|
|
|
|
new ControlEvent (when + GUARD_POINT_DELTA (when), (*most_recent_insert_iterator)->value));
|
2017-07-23 17:52:20 -04:00
|
|
|
|
2014-12-01 18:36:24 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added insert guard point @ %2 = %3\n",
|
2022-12-03 08:45:09 -05:00
|
|
|
this, when + GUARD_POINT_DELTA (when),
|
2014-12-01 18:36:24 -05:00
|
|
|
(*most_recent_insert_iterator)->value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** If we would just be adding to a straight line, move the previous point instead. */
|
|
|
|
bool
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::maybe_insert_straight_line (timepos_t const& time, double value)
|
2014-12-01 18:36:24 -05:00
|
|
|
{
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
// caller needs to hold writer-lock
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.empty ()) {
|
2014-12-01 18:36:24 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.back ()->value == value) {
|
2014-12-01 18:36:24 -05:00
|
|
|
// Point b at the final point, which we know exists
|
2022-12-03 08:45:09 -05:00
|
|
|
EventList::iterator b = _events.end ();
|
2014-12-01 18:36:24 -05:00
|
|
|
--b;
|
2022-12-03 08:45:09 -05:00
|
|
|
if (b == _events.begin ()) {
|
|
|
|
return false; // No previous point
|
2014-12-01 18:36:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the previous point's value
|
|
|
|
--b;
|
|
|
|
if ((*b)->value == value) {
|
|
|
|
/* At least two points with the exact same value (straight
|
|
|
|
line), just move the final point to the new time. */
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.back ()->when = when;
|
2014-12-01 18:36:24 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("final value of %1 moved to %2\n", value, when));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlList::iterator
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::erase_from_iterator_to (iterator iter, timepos_t const& time)
|
2014-12-01 18:36:24 -05:00
|
|
|
{
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
// caller needs to hold writer-lock
|
2022-12-03 08:45:09 -05:00
|
|
|
while (iter != _events.end ()) {
|
2014-12-01 18:36:24 -05:00
|
|
|
if ((*iter)->when < when) {
|
2014-12-01 19:37:05 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 erase existing @ %2\n", this, (*iter)->when));
|
2014-12-01 18:36:24 -05:00
|
|
|
delete *iter;
|
|
|
|
iter = _events.erase (iter);
|
|
|
|
continue;
|
|
|
|
} else if ((*iter)->when >= when) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2017-06-21 06:08:12 -04:00
|
|
|
/* this is for making changes from some kind of user interface or
|
|
|
|
* control surface (GUI, MIDI, OSC etc)
|
|
|
|
*/
|
2012-07-16 23:10:40 -04:00
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::add (timepos_t const& time, double value, bool with_guards, bool with_initial)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2017-06-21 06:08:12 -04:00
|
|
|
/* clamp new value to allowed range */
|
|
|
|
value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, value));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2014-12-01 19:37:05 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList,
|
|
|
|
string_compose ("@%1 add %2 at %3 guards = %4 write pass = %5 (new? %6) at end? %7\n",
|
|
|
|
this, value, when, with_guards, _in_write_pass, new_write_pass,
|
2022-12-03 08:45:09 -05:00
|
|
|
(most_recent_insert_iterator == _events.end ())));
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlEvent cp (when, 0.0f);
|
|
|
|
iterator insertion_point;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.empty () && with_initial) {
|
2014-12-01 19:37:05 -05:00
|
|
|
/* empty: add an "anchor" point if the point we're adding past time 0 */
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2014-02-19 12:52:14 -05:00
|
|
|
if (when >= 1) {
|
2015-10-03 09:47:52 -04:00
|
|
|
if (_desc.toggled) {
|
2019-11-13 10:53:46 -05:00
|
|
|
const double opp_val = ((value >= 0.5) ? 1.0 : 0.0);
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.insert (_events.end (), new ControlEvent (timepos_t (time_domain()), opp_val));
|
2015-10-04 11:58:03 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added toggled value %2 at zero\n", this, opp_val));
|
2015-10-03 09:47:52 -04:00
|
|
|
|
|
|
|
} else {
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.insert (_events.end (), new ControlEvent (timepos_t (time_domain()), value));
|
2017-06-21 07:40:41 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _desc.normal));
|
2015-10-03 09:47:52 -04:00
|
|
|
}
|
2012-07-09 14:32:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (_in_write_pass && new_write_pass) {
|
2014-12-01 19:37:05 -05:00
|
|
|
/* first write in a write pass: add guard point if requested */
|
|
|
|
|
2014-02-19 12:52:14 -05:00
|
|
|
if (with_guards) {
|
2023-07-21 11:56:42 -04:00
|
|
|
add_guard_point (insert_position, timecnt_t (time_domain()));
|
2014-12-01 19:37:05 -05:00
|
|
|
} else {
|
|
|
|
/* not adding a guard, but we need to set iterator appropriately */
|
|
|
|
const ControlEvent cp (when, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2014-02-19 12:52:14 -05:00
|
|
|
}
|
2017-07-24 14:54:32 -04:00
|
|
|
WritePassStarted (); /* EMIT SIGNAL w/WriteLock */
|
2014-12-01 19:37:05 -05:00
|
|
|
new_write_pass = false;
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2014-12-01 19:37:05 -05:00
|
|
|
} else if (_in_write_pass &&
|
2022-12-03 08:45:09 -05:00
|
|
|
(most_recent_insert_iterator == _events.end () || when > (*most_recent_insert_iterator)->when)) {
|
2014-12-01 19:37:05 -05:00
|
|
|
/* in write pass: erase from most recent insert to now */
|
2012-12-08 12:57:47 -05:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (most_recent_insert_iterator != _events.end ()) {
|
2014-12-01 19:37:05 -05:00
|
|
|
/* advance to avoid deleting the last inserted point itself. */
|
|
|
|
++most_recent_insert_iterator;
|
2012-07-13 17:05:45 -04:00
|
|
|
}
|
2012-12-08 12:57:47 -05:00
|
|
|
|
2014-12-01 19:37:05 -05:00
|
|
|
if (with_guards) {
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = erase_from_iterator_to (most_recent_insert_iterator, when + GUARD_POINT_DELTA (when));
|
2014-12-01 19:37:05 -05:00
|
|
|
maybe_add_insert_guard (when);
|
2017-07-23 17:52:20 -04:00
|
|
|
} else {
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = erase_from_iterator_to (most_recent_insert_iterator, when);
|
2014-12-01 19:37:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!_in_write_pass) {
|
|
|
|
/* 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(b) MRI for position %1\n", when));
|
|
|
|
ControlEvent cp (when, 0.0f);
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2012-12-08 12:57:47 -05:00
|
|
|
}
|
|
|
|
|
2014-12-01 19:37:05 -05:00
|
|
|
/* OK, now we're really ready to add a new point */
|
2012-07-13 17:05:45 -04:00
|
|
|
|
2022-12-03 08:45:09 -05: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));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-12-01 18:36:24 -05:00
|
|
|
const bool done = maybe_insert_straight_line (when, value);
|
2012-07-16 23:10:40 -04:00
|
|
|
if (!done) {
|
|
|
|
_events.push_back (new ControlEvent (when, value));
|
2022-12-03 08:45:09 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("\tactually appended, size now %1\n", _events.size ()));
|
2012-07-16 23:10:40 -04:00
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
most_recent_insert_iterator = _events.end ();
|
2014-12-01 19:37:05 -05:00
|
|
|
--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));
|
|
|
|
|
2015-06-07 09:07:56 -04:00
|
|
|
/* only one point allowed per time point, so add a guard point
|
|
|
|
* before it if needed then reset the value of the point.
|
2012-11-14 10:06:41 -05:00
|
|
|
*/
|
2015-06-07 09:07:56 -04:00
|
|
|
|
2012-11-14 10:06:41 -05:00
|
|
|
(*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.
|
|
|
|
*/
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.back ()->when == when) {
|
|
|
|
most_recent_insert_iterator = _events.end ();
|
2012-11-14 10:06:41 -05:00
|
|
|
}
|
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));
|
2015-06-15 02:35:19 -04:00
|
|
|
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) {
|
2017-07-23 17:52:20 -04:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 no change: move existing at %3 to %2\n", this, when, (*most_recent_insert_iterator)->when));
|
2015-06-15 02:35:19 -04:00
|
|
|
(*most_recent_insert_iterator)->when = when;
|
2022-12-03 08:45:09 -05:00
|
|
|
|
2015-06-15 02:35:19 -04:00
|
|
|
done = true;
|
|
|
|
} else {
|
|
|
|
++most_recent_insert_iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-23 17:52:20 -04:00
|
|
|
/* if the transport is stopped, add guard points */
|
|
|
|
if (!done && !_in_write_pass) {
|
2022-12-03 08:45:09 -05:00
|
|
|
add_guard_point (when, -GUARD_POINT_DELTA (when));
|
2017-07-23 17:52:20 -04:00
|
|
|
maybe_add_insert_guard (when);
|
|
|
|
} else if (with_guards) {
|
2015-06-15 02:35:19 -04:00
|
|
|
maybe_add_insert_guard (when);
|
2012-07-16 23:10:40 -04:00
|
|
|
}
|
2012-11-15 11:22:43 -05:00
|
|
|
|
2012-07-16 23:10:40 -04:00
|
|
|
if (!done) {
|
|
|
|
EventList::iterator x = _events.insert (most_recent_insert_iterator, new ControlEvent (when, value));
|
2022-12-03 08:45:09 -05:00
|
|
|
DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 inserted new value before MRI, size now %2\n", this, _events.size ()));
|
2014-12-01 19:37:05 -05:00
|
|
|
most_recent_insert_iterator = x;
|
2012-07-16 23:10:40 -04:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock 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)
|
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock 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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::erase (timepos_t const& time, double value)
|
2010-12-20 08:30:31 -05:00
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2010-12-20 08:30:31 -05:00
|
|
|
|
|
|
|
iterator i = begin ();
|
2022-12-03 08:45:09 -05:00
|
|
|
while (i != end () && ((*i)->when != when || (*i)->value != value)) {
|
2010-12-20 08:30:31 -05:00
|
|
|
++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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::erase_range (timepos_t const& start, timepos_t const& endt)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
bool erased = false;
|
|
|
|
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (erased) {
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
bool
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::erase_range_internal (timepos_t const& start, timepos_t const& endt, EventList& events)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2020-08-24 16:40:03 -04:00
|
|
|
/* This is where we have to pick the time domain to be used when
|
|
|
|
* defining the control points.
|
|
|
|
*
|
|
|
|
* start/endt retain their values no matter what the time domain is,
|
|
|
|
* but the location of the control point is specified as a single
|
|
|
|
* integer value that represents either samples or beats. The sample
|
|
|
|
* position and beat position, while representing the same position on
|
|
|
|
* the timeline, will be numerically different anywhere (except perhaps
|
|
|
|
* zero).
|
|
|
|
*
|
|
|
|
* eg. start = 1000000 samples == 12.34 beats
|
|
|
|
* cp.when = 100000 if ControlList uses AudioTime
|
2020-09-20 18:34:58 -04:00
|
|
|
* cp.when = 23074 if ControlList uses BeatTime (see Beats::to_ticks())
|
2020-08-24 16:40:03 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
ControlEvent cp (start, 0.0f);
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
bool erased = false;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator s;
|
|
|
|
iterator e;
|
|
|
|
if ((s = lower_bound (events.begin (), events.end (), &cp, time_comparator)) != events.end ()) {
|
2008-12-16 18:21:01 -05:00
|
|
|
cp.when = endt;
|
2022-12-03 08:45:09 -05:00
|
|
|
e = upper_bound (events.begin (), events.end (), &cp, time_comparator);
|
2008-12-16 18:21:01 -05:00
|
|
|
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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::slide (iterator before, timecnt_t const& distance)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (before == _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-09-20 18:34:58 -04:00
|
|
|
timecnt_t wd = distance;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
while (before != _events.end ()) {
|
2020-08-24 16:40:03 -04:00
|
|
|
(*before)->when += wd;
|
2008-09-18 20:47:49 -04:00
|
|
|
++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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::shift (timepos_t const& time, timecnt_t const& distance)
|
2010-12-07 10:13:04 -05:00
|
|
|
{
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t pos = time;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2010-12-07 10:13:04 -05:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
2018-12-21 20:04:17 -05:00
|
|
|
double v0, v1;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (distance.is_negative ()) {
|
2018-12-21 19:09:24 -05:00
|
|
|
/* Route::shift () with negative shift is used
|
|
|
|
* for "remove time". The time [pos.. pos-frames] is removed.
|
|
|
|
* and everyhing after, moved backwards.
|
|
|
|
*/
|
2018-12-21 20:04:17 -05:00
|
|
|
v0 = unlocked_eval (pos);
|
2020-08-24 16:40:03 -04:00
|
|
|
v1 = unlocked_eval (pos.earlier (distance));
|
|
|
|
erase_range_internal (pos, pos.earlier (distance), _events);
|
2018-12-21 20:04:17 -05:00
|
|
|
} else {
|
|
|
|
v0 = v1 = unlocked_eval (pos);
|
2018-12-21 19:09:24 -05:00
|
|
|
}
|
2010-12-07 10:13:04 -05:00
|
|
|
|
2018-12-21 20:04:17 -05:00
|
|
|
bool dst_guard_exists = false;
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (iterator i = _events.begin (); i != _events.end (); ++i) {
|
2018-12-21 20:04:17 -05:00
|
|
|
if ((*i)->when == pos) {
|
|
|
|
dst_guard_exists = true;
|
|
|
|
}
|
2010-12-07 10:13:04 -05:00
|
|
|
if ((*i)->when >= pos) {
|
2020-08-24 16:40:03 -04:00
|
|
|
(*i)->when += distance;
|
2010-12-07 10:13:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 20:04:17 -05:00
|
|
|
/* add guard-points to retain shape, if needed */
|
2022-12-03 08:45:09 -05:00
|
|
|
if (distance.is_positive ()) {
|
2018-12-21 20:04:17 -05:00
|
|
|
ControlEvent cp (pos, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2018-12-21 20:04:17 -05:00
|
|
|
if (s != _events.end ()) {
|
|
|
|
_events.insert (s, new ControlEvent (pos, v0));
|
|
|
|
}
|
2020-08-24 16:40:03 -04:00
|
|
|
pos += distance;
|
2022-12-03 08:45:09 -05:00
|
|
|
} else if (distance.is_negative () && pos > 0) {
|
|
|
|
ControlEvent cp (pos.decrement (), 0.0);
|
|
|
|
iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2018-12-21 20:04:17 -05:00
|
|
|
if (s != _events.end ()) {
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.insert (s, new ControlEvent (pos.decrement (), v0));
|
2018-12-21 20:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dst_guard_exists) {
|
|
|
|
ControlEvent cp (pos, 0.0);
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2018-12-21 20:04:17 -05:00
|
|
|
_events.insert (s, new ControlEvent (pos, s == _events.end () ? v0 : v1));
|
|
|
|
}
|
|
|
|
|
2010-12-07 10:13:04 -05:00
|
|
|
mark_dirty ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::modify (iterator iter, timepos_t const& time, double val)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
/* note: we assume higher level logic is in place to avoid this
|
2017-06-21 06:08:12 -04:00
|
|
|
* reordering the time-order of control events in the list. ie. all
|
|
|
|
* points after *iter are later than when.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* catch possible float/double rounding errors from higher levels */
|
|
|
|
val = std::min ((double)_desc.upper, std::max ((double)_desc.lower, val));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
2022-05-01 19:50:41 -04:00
|
|
|
timepos_t when = ensure_time_domain (time);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
(*iter)->when = when;
|
2008-09-18 20:47:49 -04:00
|
|
|
(*iter)->value = val;
|
2014-11-01 13:35:44 -04:00
|
|
|
if (isnan_local (val)) {
|
2008-09-18 20:47:49 -04:00
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_frozen) {
|
|
|
|
_events.sort (event_time_less_than);
|
2017-06-21 06:07:12 -04:00
|
|
|
unlocked_remove_duplicates ();
|
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 ();
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
std::pair<ControlList::iterator, ControlList::iterator>
|
|
|
|
ControlList::control_points_adjacent (timepos_t const& xtime)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::ReaderLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
timepos_t xval = xtime;
|
|
|
|
ControlEvent cp (xval, 0.0f);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
std::pair<iterator, iterator> ret;
|
|
|
|
ret.first = _events.end ();
|
|
|
|
ret.second = _events.end ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator i;
|
|
|
|
for (i = lower_bound (_events.begin (), _events.end (), &cp, time_comparator); i != _events.end (); ++i) {
|
|
|
|
if (ret.first == _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
if ((*i)->when >= xval) {
|
2022-12-03 08:45:09 -05:00
|
|
|
if (i != _events.begin ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
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 ()
|
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
assert (_frozen > 0);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
if (--_frozen > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
if (_sort_pending) {
|
|
|
|
_events.sort (event_time_less_than);
|
2017-06-21 06:07:12 -04:00
|
|
|
unlocked_remove_duplicates ();
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2008-09-18 20:47:49 -04:00
|
|
|
_sort_pending = false;
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 01:39:45 -04:00
|
|
|
maybe_signal_changed ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2008-09-18 20:47:49 -04:00
|
|
|
ControlList::mark_dirty () const
|
|
|
|
{
|
2023-07-21 11:56:42 -04:00
|
|
|
_lookup_cache.left = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05:00
|
|
|
_lookup_cache.range.first = _events.end ();
|
|
|
|
_lookup_cache.range.second = _events.end ();
|
2023-07-21 11:56:42 -04:00
|
|
|
_search_cache.left = timepos_t::max (time_domain());
|
2022-12-03 08:45:09 -05:00
|
|
|
_search_cache.first = _events.end ();
|
2010-07-11 20:41:45 -04:00
|
|
|
|
|
|
|
if (_curve) {
|
2022-12-03 08:45:09 -05:00
|
|
|
_curve->mark_dirty ();
|
2010-07-11 20:41:45 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::truncate_end (timepos_t const& last_time)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
|
|
|
timepos_t last_coordinate = last_time;
|
2008-09-18 20:47:49 -04:00
|
|
|
ControlEvent cp (last_coordinate, 0);
|
2022-12-03 08:45:09 -05:00
|
|
|
double last_val;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.empty ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (last_coordinate == _events.back ()->when) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (last_coordinate > _events.back ()->when) {
|
|
|
|
/* extending end: */
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator foo = _events.begin ();
|
|
|
|
bool lessthantwo;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (foo == _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
lessthantwo = true;
|
2022-12-03 08:45:09 -05:00
|
|
|
} else if (++foo == _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
lessthantwo = true;
|
|
|
|
} else {
|
|
|
|
lessthantwo = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lessthantwo) {
|
|
|
|
/* less than 2 points: add a new point */
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.push_back (new ControlEvent (last_coordinate, _events.back ()->value));
|
2008-09-18 20:47:49 -04:00
|
|
|
} 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.
|
|
|
|
*/
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator penultimate = _events.end ();
|
2008-09-18 20:47:49 -04:00
|
|
|
--penultimate; /* points at last point */
|
|
|
|
--penultimate; /* points at the penultimate point */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.back ()->value == (*penultimate)->value) {
|
|
|
|
_events.back ()->when = last_coordinate;
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.push_back (new ControlEvent (last_coordinate, _events.back ()->value));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* shortening end */
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::reverse_iterator i;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
last_val = unlocked_eval (last_coordinate);
|
2022-12-03 08:45:09 -05:00
|
|
|
last_val = max ((double)_desc.lower, last_val);
|
|
|
|
last_val = min ((double)_desc.upper, last_val);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05: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))
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
uint32_t sz = _events.size ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
while (i != _events.rend () && sz > 2) {
|
2008-09-18 20:47:49 -04:00
|
|
|
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
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.erase (i.base ());
|
2008-09-18 20:47:49 -04:00
|
|
|
--sz;
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.back ()->when = last_coordinate;
|
|
|
|
_events.back ()->value = last_val;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-13 17:05:45 -04:00
|
|
|
unlocked_invalidate_insert_iterator ();
|
2022-12-03 08:45:09 -05:00
|
|
|
mark_dirty ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::truncate_start (timecnt_t const& overall)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator i;
|
|
|
|
double first_legal_value;
|
|
|
|
timepos_t first_legal_coordinate;
|
|
|
|
timepos_t overall_length (overall);
|
|
|
|
|
|
|
|
if (_events.empty ()) {
|
2014-12-17 19:43:09 -05:00
|
|
|
/* nothing to truncate */
|
|
|
|
return;
|
2022-12-03 08:45:09 -05:00
|
|
|
} else if (overall_length == _events.back ()->when) {
|
2008-09-18 20:47:49 -04:00
|
|
|
/* no change in overall length */
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (overall_length > _events.back ()->when) {
|
2008-09-18 20:47:49 -04:00
|
|
|
/* growing at front: duplicate first point. shift all others */
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
timepos_t shift (_events.back ()->when.distance (overall_length));
|
|
|
|
uint32_t np;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (np = 0, i = _events.begin (); i != _events.end (); ++i, ++np) {
|
2008-09-18 20:47:49 -04:00
|
|
|
(*i)->when += shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (np < 2) {
|
|
|
|
/* less than 2 points: add a new point */
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.push_front (new ControlEvent (timepos_t (time_domain()), _events.front ()->value));
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
} 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.
|
|
|
|
*/
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
iterator second = _events.begin ();
|
2008-09-18 20:47:49 -04:00
|
|
|
++second; /* points at the second point */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.front ()->value == (*second)->value) {
|
2008-09-18 20:47:49 -04:00
|
|
|
/* first segment is flat, just move start point back to zero */
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.front ()->when = timepos_t (time_domain());
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
|
|
|
/* leave non-flat segment in place, add a new leading point. */
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.push_front (new ControlEvent (timepos_t (time_domain()), _events.front ()->value));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* shrinking at front */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
first_legal_coordinate = _events.back ()->when.earlier (overall_length);
|
|
|
|
first_legal_value = unlocked_eval (first_legal_coordinate);
|
|
|
|
first_legal_value = max ((double)_desc.lower, first_legal_value);
|
|
|
|
first_legal_value = min ((double)_desc.upper, first_legal_value);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
/* remove all events earlier than the new "front" */
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
i = _events.begin ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
while (i != _events.end () && !_events.empty ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
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
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (i = _events.begin (); i != _events.end (); ++i) {
|
|
|
|
(*i)->when.shift_earlier (timecnt_t (first_legal_coordinate, timepos_t ()));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add a new point for the interpolated new value */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2023-07-21 11:56:42 -04:00
|
|
|
_events.push_front (new ControlEvent (timepos_t (time_domain()), 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 ();
|
2022-12-03 08:45:09 -05:00
|
|
|
mark_dirty ();
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::unlocked_eval (timepos_t const& xtime) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
int32_t npoints;
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t lpos, upos;
|
2022-12-03 08:45:09 -05:00
|
|
|
double lval, uval;
|
|
|
|
double fraction;
|
|
|
|
double xx;
|
|
|
|
double ll;
|
2022-03-27 00:07:11 -04:00
|
|
|
|
2022-12-03 08:45:09 -05: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) {
|
2022-12-03 08:45:09 -05:00
|
|
|
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) {
|
2022-12-03 08:45:09 -05:00
|
|
|
case 0:
|
|
|
|
return _desc.normal;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
case 1:
|
|
|
|
return _events.front ()->value;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
case 2:
|
|
|
|
if (xtime >= _events.back ()->when) {
|
|
|
|
return _events.back ()->value;
|
|
|
|
} else if (xtime <= _events.front ()->when) {
|
|
|
|
return _events.front ()->value;
|
|
|
|
}
|
2017-06-19 09:45:47 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
lpos = _events.front ()->when;
|
|
|
|
lval = _events.front ()->value;
|
|
|
|
upos = _events.back ()->when;
|
|
|
|
uval = _events.back ()->value;
|
|
|
|
|
|
|
|
xx = lpos.distance (xtime).distance ().val ();
|
|
|
|
ll = lpos.distance (upos).distance ().val ();
|
|
|
|
|
|
|
|
fraction = xx / ll;
|
|
|
|
|
|
|
|
switch (_interpolation) {
|
|
|
|
case Discrete:
|
|
|
|
return lval;
|
|
|
|
case Logarithmic:
|
|
|
|
return interpolate_logarithmic (lval, uval, fraction, _desc.lower, _desc.upper);
|
|
|
|
case Exponential:
|
|
|
|
return interpolate_gain (lval, uval, fraction, _desc.upper);
|
|
|
|
case Curved:
|
|
|
|
/* only used x-fade curves, never direct eval */
|
|
|
|
assert (0);
|
|
|
|
default: // Linear
|
|
|
|
return interpolate_linear (lval, uval, fraction);
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
default:
|
|
|
|
if (xtime >= _events.back ()->when) {
|
|
|
|
return _events.back ()->value;
|
|
|
|
} else if (xtime <= _events.front ()->when) {
|
|
|
|
return _events.front ()->value;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
return multipoint_eval (xtime);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
abort (); /*NOTREACHED*/ /* stupid gcc */
|
2017-06-21 07:40:41 -04:00
|
|
|
return _desc.normal;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::multipoint_eval (timepos_t const& xtime) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t upos, lpos;
|
2022-12-03 08:45:09 -05:00
|
|
|
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) {
|
2022-12-03 08:45:09 -05:00
|
|
|
const ControlEvent cp (xtime, 0);
|
|
|
|
EventList::const_iterator i = lower_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
// shouldn't have made it to multipoint_eval
|
2022-12-03 08:45:09 -05:00
|
|
|
assert (i != _events.end ());
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (i == _events.begin () || (*i)->when == xtime)
|
2008-09-18 20:47:49 -04:00
|
|
|
return (*i)->value;
|
|
|
|
else
|
|
|
|
return (*(--i))->value;
|
|
|
|
}
|
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
/* Only do the range lookup if xtime is in a different range than last time
|
2008-09-18 20:47:49 -04:00
|
|
|
* this was called (or if the lookup cache has been marked "dirty" (left<0) */
|
2023-07-21 11:56:42 -04:00
|
|
|
if ((_lookup_cache.left == timepos_t::max (time_domain())) ||
|
2020-08-24 16:40:03 -04:00
|
|
|
((_lookup_cache.left > xtime) ||
|
2022-12-03 08:45:09 -05:00
|
|
|
(_lookup_cache.range.first == _events.end ()) ||
|
2020-08-24 16:40:03 -04:00
|
|
|
((*_lookup_cache.range.second)->when < xtime))) {
|
|
|
|
const ControlEvent cp (xtime, 0);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
_lookup_cache.range = equal_range (_events.begin (), _events.end (), &cp, time_comparator);
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
pair<const_iterator, const_iterator> range = _lookup_cache.range;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
if (range.first == range.second) {
|
|
|
|
/* x does not exist within the list as a control point */
|
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
_lookup_cache.left = xtime;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (range.first != _events.begin ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
--range.first;
|
|
|
|
lpos = (*range.first)->when;
|
|
|
|
lval = (*range.first)->value;
|
2022-12-03 08:45:09 -05:00
|
|
|
} else {
|
2008-09-18 20:47:49 -04:00
|
|
|
/* we're before the first point */
|
|
|
|
// return _default_value;
|
2022-12-03 08:45:09 -05:00
|
|
|
return _events.front ()->value;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (range.second == _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
/* we're after the last point */
|
2022-12-03 08:45:09 -05:00
|
|
|
return _events.back ()->value;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
upos = (*range.second)->when;
|
|
|
|
uval = (*range.second)->value;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
fraction = (double)lpos.distance (xtime).distance ().val () / (double)lpos.distance (upos).distance ().val ();
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2017-06-19 09:45:47 -04:00
|
|
|
switch (_interpolation) {
|
|
|
|
case Logarithmic:
|
|
|
|
return interpolate_logarithmic (lval, uval, fraction, _desc.lower, _desc.upper);
|
|
|
|
case Exponential:
|
|
|
|
return interpolate_gain (lval, uval, fraction, _desc.upper);
|
|
|
|
case Discrete:
|
|
|
|
/* should not reach here */
|
|
|
|
assert (0);
|
|
|
|
case Curved:
|
|
|
|
/* only used x-fade curves, never direct eval */
|
|
|
|
assert (0);
|
|
|
|
default: // Linear
|
|
|
|
return interpolate_linear (lval, uval, fraction);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert (0);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
/* x is a control point in the data */
|
2023-07-21 11:56:42 -04:00
|
|
|
_lookup_cache.left = timepos_t::max (time_domain());
|
2008-09-18 20:47:49 -04:00
|
|
|
return (*range.first)->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::build_search_cache_if_necessary (timepos_t const& start_time) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t start = start_time;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.empty ()) {
|
2014-12-06 15:44:10 -05:00
|
|
|
/* Empty, nothing to cache, move to end. */
|
2022-12-03 08:45:09 -05:00
|
|
|
_search_cache.first = _events.end ();
|
2023-07-21 11:56:42 -04:00
|
|
|
_search_cache.left = timepos_t::max (time_domain());
|
2014-12-06 15:44:10 -05:00
|
|
|
return;
|
2023-07-21 11:56:42 -04:00
|
|
|
} else if ((_search_cache.left == timepos_t::max (time_domain())) || (_search_cache.left > start)) {
|
2020-08-24 16:40:03 -04:00
|
|
|
/* Marked dirty (left == max), or we're too far forward, re-search. */
|
2008-09-18 20:47:49 -04:00
|
|
|
|
|
|
|
const ControlEvent start_point (start, 0);
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
_search_cache.first = lower_bound (_events.begin (), _events.end (), &start_point, time_comparator);
|
|
|
|
_search_cache.left = start;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2014-12-06 15:44:10 -05:00
|
|
|
|
|
|
|
/* We now have a search cache that is not too far right, but it may be too
|
|
|
|
far left and need to be advanced. */
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
while (_search_cache.first != end () && (*_search_cache.first)->when < start) {
|
2014-12-06 15:44:10 -05:00
|
|
|
++_search_cache.first;
|
|
|
|
}
|
|
|
|
_search_cache.left = start;
|
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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::rt_safe_earliest_event_discrete_unlocked (timepos_t const& start_time, timepos_t& x, double& y, bool inclusive) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t start = start_time;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2010-07-25 19:19:43 -04:00
|
|
|
build_search_cache_if_necessary (start);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_search_cache.first != _events.end ()) {
|
2010-07-25 19:19:43 -04:00
|
|
|
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) */
|
2020-08-24 16:40:03 -04:00
|
|
|
_search_cache.left = first->when;
|
2010-07-25 19:19:43 -04:00
|
|
|
++_search_cache.first;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
assert (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 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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::rt_safe_earliest_event_linear_unlocked (Temporal::timepos_t const& start_time, Temporal::timepos_t& x, double& y, bool inclusive, Temporal::timecnt_t min_x_delta) const
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t start = start_time;
|
2020-08-31 01:39:45 -04:00
|
|
|
|
2022-03-26 23:42:28 -04:00
|
|
|
/* the max value is given as an out-of-bounds default value, when the
|
|
|
|
true default is zero, but the time-domain is not known at compile
|
|
|
|
time. This allows us to reset it to zero with the correct time
|
|
|
|
domain (equality comparisons across time domains where the actual
|
|
|
|
scalar value is zero should always be cheap, but that's not true of
|
|
|
|
other operators such as >, < etc.)
|
|
|
|
*/
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (min_x_delta == Temporal::timecnt_t::max ()) {
|
|
|
|
min_x_delta = Temporal::timecnt_t (time_domain ());
|
2022-03-26 23:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// cout << "earliest_event(start: " << start << ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ") mxd " << min_x_delta << endl;
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
const_iterator length_check_iter = _events.begin ();
|
|
|
|
if (_events.empty ()) {
|
2022-03-27 00:07:11 -04:00
|
|
|
/* no events, so we cannot interpolate */
|
2008-09-18 20:47:49 -04:00
|
|
|
return false;
|
2022-12-03 08:45:09 -05:00
|
|
|
} else if (_events.end () == ++length_check_iter) {
|
2022-03-27 00:07:11 -04:00
|
|
|
/* one event, which decomposes to the same logic as the discrete one */
|
2020-08-14 19:52:38 -04:00
|
|
|
return rt_safe_earliest_event_discrete_unlocked (start + min_x_delta, x, y, inclusive);
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2020-08-14 19:52:38 -04:00
|
|
|
if (min_x_delta > 0) {
|
2022-03-27 00:07:11 -04:00
|
|
|
/* if there is an event between [start ... start + min_x_delta], use it,
|
2020-08-14 19:52:38 -04:00
|
|
|
*/
|
|
|
|
build_search_cache_if_necessary (start);
|
|
|
|
const ControlEvent* first = *_search_cache.first;
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_search_cache.first != _events.end ()) {
|
2023-04-01 11:21:04 -04:00
|
|
|
if (((first->when > start) || (inclusive && first->when == start)) && ((first->when < start + min_x_delta) || (!inclusive && first->when == start + min_x_delta))) {
|
2020-08-14 19:52:38 -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;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
/* No event between start and start + min_x_delta, so otherwise
|
|
|
|
* interpolate at start + min_x_delta
|
|
|
|
*/
|
|
|
|
|
2020-08-14 19:52:38 -04:00
|
|
|
start += min_x_delta;
|
|
|
|
|
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
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_search_cache.first == _events.end ()) {
|
2022-03-27 00:06:32 -04:00
|
|
|
/* No points in the future, so no steps (towards them) in the future */
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
const ControlEvent* first = NULL;
|
2022-12-03 08:45:09 -05:00
|
|
|
const ControlEvent* next = NULL;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_search_cache.first == _events.begin () || (*_search_cache.first)->when <= start) {
|
2022-03-27 00:06:32 -04:00
|
|
|
/* Start is after first */
|
|
|
|
first = *_search_cache.first;
|
|
|
|
++_search_cache.first;
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_search_cache.first == _events.end ()) {
|
2022-03-27 00:06:32 -04:00
|
|
|
/* no later events, nothing to interpolate towards */
|
2014-11-22 00:44:48 -05:00
|
|
|
return false;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2022-03-27 00:06:32 -04:00
|
|
|
next = *_search_cache.first;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
} else {
|
|
|
|
/* Start is before first */
|
2022-12-03 08:45:09 -05:00
|
|
|
assert (_search_cache.first != _events.begin ());
|
2022-03-27 00:06:32 -04:00
|
|
|
const_iterator prev = _search_cache.first;
|
|
|
|
--prev;
|
|
|
|
first = *prev;
|
2022-12-03 08:45:09 -05:00
|
|
|
next = *_search_cache.first;
|
2022-03-27 00:06:32 -04:00
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
if (inclusive && first->when == start) {
|
|
|
|
/* existing point matches start */
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
x = first->when;
|
2008-09-18 20:47:49 -04:00
|
|
|
y = first->value;
|
2022-03-27 00:06:32 -04:00
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range)
|
|
|
|
*/
|
|
|
|
_search_cache.left = first->when;
|
|
|
|
return true;
|
|
|
|
} else if (next->when < start || (!inclusive && next->when == start)) {
|
|
|
|
/* "Next" is before the start, no points left. */
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
if (fabs (first->value - next->value) <= 1) {
|
|
|
|
/* delta between the two spanning points is <= 1,
|
|
|
|
consider the next point as the answer, but only if the next
|
2022-10-30 20:44:28 -04:00
|
|
|
point is actually beyond @p start.
|
2022-03-27 00:06:32 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (next->when > start) {
|
|
|
|
x = next->when;
|
|
|
|
y = next->value;
|
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range) */
|
|
|
|
_search_cache.left = next->when;
|
|
|
|
return true;
|
2020-08-24 16:40:03 -04:00
|
|
|
} else {
|
2022-03-27 00:06:32 -04:00
|
|
|
/* no suitable point can be determined */
|
|
|
|
return false;
|
2020-08-24 16:40:03 -04:00
|
|
|
}
|
2022-03-27 00:06:32 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
/* This method is ONLY used for interpolating to generate value/time
|
2023-04-01 11:21:32 -04:00
|
|
|
* duples not present in the actual ControlList, and because of this,
|
|
|
|
* the desired time domain is always audio time.
|
|
|
|
*/
|
2022-08-17 22:55:17 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
double a = first->when.superclocks ();
|
|
|
|
double b = next->when.superclocks ();
|
2022-08-17 22:55:17 -04:00
|
|
|
const double slope = (b - a) / (next->value - first->value);
|
|
|
|
assert (slope != 0);
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
double t = start_time.superclocks ();
|
2022-08-17 22:55:17 -04:00
|
|
|
double dt = fmod (t, fabs (slope));
|
|
|
|
t += fabs (slope) - dt;
|
|
|
|
x = timecnt_t::from_superclock (t + 1);
|
|
|
|
y = rint (first->value + (t - a) / slope);
|
|
|
|
if (slope > 0) {
|
|
|
|
y = std::max (first->value, std::min (next->value, y));
|
2022-03-27 00:06:32 -04:00
|
|
|
} else {
|
2022-08-17 22:55:17 -04:00
|
|
|
y = std::max (next->value, std::min (first->value, y));
|
2022-03-27 00:06:32 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-03-27 00:06:32 -04:00
|
|
|
const bool past_start = (inclusive ? x >= start : x > start);
|
|
|
|
|
|
|
|
if (past_start) {
|
|
|
|
/* Move left of cache to this point
|
|
|
|
* (Optimize for immediate call this cycle within range) */
|
|
|
|
_search_cache.left = x;
|
2022-12-03 08:45:09 -05:00
|
|
|
assert (inclusive ? x >= start : x > start);
|
2022-03-27 00:06:32 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inclusive) {
|
2022-12-03 08:45:09 -05:00
|
|
|
x = next->when;
|
2022-03-27 00:06:32 -04:00
|
|
|
_search_cache.left = next->when;
|
2008-09-18 20:47:49 -04:00
|
|
|
} else {
|
2022-12-03 08:45:09 -05:00
|
|
|
x = start;
|
2022-03-27 00:06:32 -04:00
|
|
|
_search_cache.left = x;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
2022-03-27 00:06:32 -04:00
|
|
|
|
|
|
|
return true;
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ControlList>
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::cut_copy_clear (timepos_t const& start_time, timepos_t const& end_time, int op)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2023-07-21 11:56:42 -04:00
|
|
|
std::shared_ptr<ControlList> nal = create (_parameter, _desc, *this);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
|
|
|
iterator s, e;
|
|
|
|
timepos_t start = start_time;
|
|
|
|
timepos_t end = end_time;
|
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
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock 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
|
2022-12-03 08:45:09 -05:00
|
|
|
* affected by this operation
|
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if ((s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator)) == _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
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;
|
2022-12-03 08:45:09 -05:00
|
|
|
e = upper_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2011-11-22 19:17:31 -05:00
|
|
|
/* if "start" isn't the location of an existing point,
|
2022-12-03 08:45:09 -05:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-11-22 19:17:31 -05:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
/* before we begin any cut/clear operations, get the value of the curve at "end". */
|
2011-11-22 19:17:31 -05:00
|
|
|
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
|
|
|
|
2022-05-15 10:54:04 -04:00
|
|
|
if (op != 1) { // cut/clear
|
2022-12-03 08:45:09 -05:00
|
|
|
if (start > _events.front ()->when) {
|
2010-08-19 17:09:40 -04:00
|
|
|
_events.insert (s, (new ControlEvent (start, val)));
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 19:17:31 -05:00
|
|
|
|
|
|
|
if (op != 2) { // ! clear
|
2023-07-21 11:56:42 -04:00
|
|
|
nal->_events.push_back (new ControlEvent (timepos_t (time_domain()), val));
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 17:09:40 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (iterator x = s; x != e;) {
|
|
|
|
/* 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) {
|
2020-09-20 18:34:58 -04:00
|
|
|
nal->_events.push_back (new ControlEvent (timepos_t (start.distance ((*x)->when)), (*x)->value));
|
2008-09-18 20:47:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
if (e == _events.end () || (*e)->when != end) {
|
2022-05-15 10:54:04 -04:00
|
|
|
if (op != 1) { // cut/clear
|
2011-11-22 19:17:31 -05:00
|
|
|
_events.insert (e, new ControlEvent (end, end_value));
|
|
|
|
}
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-05-15 10:54:04 -04:00
|
|
|
if (op != 2) { // cut/copy
|
|
|
|
nal->_events.push_back (new ControlEvent (timepos_t (start.distance (end)), end_value));
|
2011-11-22 19:17:31 -05:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ControlList>
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::cut (timepos_t const& start, timepos_t const& end)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
return cut_copy_clear (start, end, 0);
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ControlList>
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::copy (timepos_t const& start, timepos_t const& end)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
|
|
|
return cut_copy_clear (start, end, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::clear (timepos_t const& start, timepos_t const& end)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::paste (const ControlList& alist, timepos_t const& time)
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
if (alist._events.empty ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-15 11:37:49 -04:00
|
|
|
/* when pasting a range of automation, first add guard points so the automation data before and after this range is retained */
|
2022-12-03 08:45:09 -05:00
|
|
|
const ControlEvent* last = alist.back ();
|
2023-01-22 21:19:20 -05:00
|
|
|
add_guard_point (time, -GUARD_POINT_DELTA (*this));
|
|
|
|
add_guard_point (time + last->when, GUARD_POINT_DELTA (*this));
|
2022-05-15 11:37:49 -04:00
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
2022-12-03 08:45:09 -05:00
|
|
|
|
|
|
|
iterator where;
|
|
|
|
iterator prev;
|
|
|
|
timepos_t end;
|
|
|
|
timepos_t pos = time;
|
2008-09-18 20:47:49 -04:00
|
|
|
ControlEvent cp (pos, 0.0);
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
where = upper_bound (_events.begin (), _events.end (), &cp, time_comparator);
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
for (const_iterator i = alist.begin (); i != alist.end (); ++i) {
|
2014-12-06 13:37:08 -05:00
|
|
|
double value = (*i)->value;
|
2022-12-03 08:45:09 -05:00
|
|
|
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.
|
|
|
|
*/
|
2014-12-06 13:37:08 -05:00
|
|
|
|
2016-03-28 15:42:46 -04:00
|
|
|
// TODO various flags from from ARDOUR::ParameterDescriptor
|
|
|
|
// to Evoral::ParameterDescriptor
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
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
|
2015-10-30 12:54:18 -04:00
|
|
|
if (_desc.toggled) {
|
|
|
|
value = (value < 0.5) ? 0.0 : 1.0;
|
|
|
|
}
|
2017-06-21 06:08:12 -04:00
|
|
|
/* catch possible rounding errors */
|
|
|
|
value = std::min ((double)_desc.upper, std::max ((double)_desc.lower, value));
|
2014-12-06 13:37:08 -05:00
|
|
|
}
|
2020-12-07 21:15:34 -05:00
|
|
|
|
|
|
|
timepos_t adj_pos;
|
|
|
|
|
2023-07-21 11:56:42 -04:00
|
|
|
if (time_domain() == (*i)->when.time_domain ()) {
|
2020-12-07 21:15:34 -05:00
|
|
|
adj_pos = (*i)->when + pos;
|
|
|
|
} else {
|
2023-07-21 11:56:42 -04:00
|
|
|
if (time_domain() == AudioTime) {
|
2022-12-03 08:45:09 -05:00
|
|
|
adj_pos = timepos_t (((*i)->when + pos).samples ());
|
2020-12-07 21:15:34 -05:00
|
|
|
} else {
|
2022-12-03 08:45:09 -05:00
|
|
|
adj_pos = timepos_t (((*i)->when + pos).beats ());
|
2020-12-07 21:15:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_events.insert (where, new ControlEvent (adj_pos, value));
|
2008-09-18 20:47:49 -04:00
|
|
|
end = (*i)->when + pos;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
|
|
|
/* move all points after the insertion along the timeline by
|
2022-12-03 08:45:09 -05:00
|
|
|
* the correct amount.
|
|
|
|
*/
|
2008-09-18 20:47:49 -04:00
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
while (where != _events.end ()) {
|
2008-09-18 20:47:49 -04:00
|
|
|
iterator tmp;
|
|
|
|
if ((*where)->when <= end) {
|
|
|
|
tmp = where;
|
|
|
|
++tmp;
|
2022-12-03 08:45:09 -05:00
|
|
|
_events.erase (where);
|
2008-09-18 20:47:49 -04:00
|
|
|
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
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::move_ranges (const list<RangeMove>& movements)
|
2008-12-16 18:21:01 -05:00
|
|
|
{
|
2020-09-20 18:34:58 -04:00
|
|
|
typedef list<RangeMove> RangeMoveList;
|
2009-02-01 21:36:05 -05:00
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
{
|
2015-04-15 12:13:56 -04:00
|
|
|
Glib::Threads::RWLock::WriterLock 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) {
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t start = i->from;
|
2022-12-03 08:45:09 -05:00
|
|
|
timepos_t end = i->from + i->length;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
|
|
|
if (erase_range_internal (start, end, _events)) {
|
2010-08-20 19:58:49 -04:00
|
|
|
things_erased = true;
|
|
|
|
}
|
|
|
|
|
2020-08-24 16:40:03 -04:00
|
|
|
start = i->to;
|
2022-12-03 08:45:09 -05:00
|
|
|
end = i->to + i->length;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
|
|
|
if (erase_range_internal (start, end, _events)) {
|
2010-08-20 19:58:49 -04:00
|
|
|
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 ();
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2020-09-20 18:34:58 -04:00
|
|
|
const timepos_t limit = i->from + i->length;
|
2022-12-03 08:45:09 -05:00
|
|
|
const timecnt_t dx = i->from.distance (i->to);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
|
|
|
while (j != old_events.end ()) {
|
2020-09-20 18:34:58 -04:00
|
|
|
timepos_t jtime;
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2023-07-21 11:56:42 -04:00
|
|
|
switch (time_domain()) {
|
2022-12-03 08:45:09 -05:00
|
|
|
case AudioTime:
|
|
|
|
jtime = (*j)->when;
|
|
|
|
break;
|
|
|
|
case BeatTime:
|
|
|
|
jtime = (*j)->when;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*NOTREACHED*/
|
|
|
|
return false;
|
2020-08-24 16:40:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (jtime > limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jtime >= i->from) {
|
2008-12-16 18:21:01 -05:00
|
|
|
ControlEvent* ev = new ControlEvent (**j);
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2023-07-21 11:56:42 -04:00
|
|
|
switch (time_domain()) {
|
2022-12-03 08:45:09 -05:00
|
|
|
case AudioTime:
|
|
|
|
ev->when += dx;
|
|
|
|
break;
|
|
|
|
case BeatTime:
|
|
|
|
ev->when += dx;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*NOTREACHED*/
|
|
|
|
return false;
|
2020-08-24 16:40:03 -04:00
|
|
|
}
|
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
_events.push_back (ev);
|
|
|
|
}
|
2020-08-24 16:40:03 -04:00
|
|
|
|
2008-12-16 18:21:01 -05:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_frozen) {
|
|
|
|
_events.sort (event_time_less_than);
|
2017-06-21 06:07:12 -04:00
|
|
|
unlocked_remove_duplicates ();
|
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
|
|
|
}
|
|
|
|
|
2017-06-19 09:45:47 -04:00
|
|
|
bool
|
2010-07-13 20:58:15 -04:00
|
|
|
ControlList::set_interpolation (InterpolationStyle s)
|
|
|
|
{
|
|
|
|
if (_interpolation == s) {
|
2017-06-19 09:45:47 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (s) {
|
|
|
|
case Logarithmic:
|
|
|
|
if (_desc.lower * _desc.upper <= 0 || _desc.upper <= _desc.lower) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Exponential:
|
|
|
|
if (_desc.lower != 0 || _desc.upper <= _desc.lower) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2010-07-13 20:58:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_interpolation = s;
|
|
|
|
InterpolationChanged (s); /* EMIT SIGNAL */
|
2017-06-19 09:45:47 -04:00
|
|
|
return true;
|
2010-07-13 20:58:15 -04:00
|
|
|
}
|
|
|
|
|
2023-08-15 10:34:42 -04:00
|
|
|
void
|
|
|
|
ControlList::start_domain_bounce (Temporal::DomainBounceInfo& dbi)
|
|
|
|
{
|
|
|
|
if (time_domain() == dbi.to) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Glib::Threads::RWLock::ReaderLock olm (_lock);
|
|
|
|
|
|
|
|
for (auto const & e : _events) {
|
|
|
|
timepos_t t (e->when);
|
|
|
|
t.set_time_domain (dbi.to);
|
2023-08-16 11:06:10 -04:00
|
|
|
dbi.positions.insert (std::make_pair (&e->when, t));
|
2023-08-15 10:34:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlList::finish_domain_bounce (Temporal::DomainBounceInfo& dbi)
|
|
|
|
{
|
2023-08-16 11:06:10 -04:00
|
|
|
if (time_domain() == dbi.to) {
|
2023-08-15 10:34:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
|
|
|
for (auto const & e : _events) {
|
|
|
|
Temporal::TimeDomainPosChanges::iterator tdc = dbi.positions.find (&e->when);
|
|
|
|
assert (tdc != dbi.positions.end());
|
|
|
|
|
|
|
|
timepos_t t (tdc->second);
|
|
|
|
t.set_time_domain (dbi.from);
|
|
|
|
e->when = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_signal_changed ();
|
|
|
|
}
|
|
|
|
|
2012-06-16 13:20:10 -04:00
|
|
|
bool
|
2022-12-03 08:45:09 -05:00
|
|
|
ControlList::operator!= (ControlList const& other) const
|
2012-06-16 13:20:10 -04:00
|
|
|
{
|
2022-12-03 08:45:09 -05:00
|
|
|
if (_events.size () != other._events.size ()) {
|
2012-06-16 13:20:10 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventList::const_iterator i = _events.begin ();
|
|
|
|
EventList::const_iterator j = other._events.begin ();
|
|
|
|
|
2022-12-03 08:45:09 -05:00
|
|
|
while (i != _events.end () && (*i)->when == (*j)->when && (*i)->value == (*j)->value) {
|
|
|
|
++i;
|
2012-06-16 13:20:10 -04:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != _events.end ()) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-16 13:20:10 -04:00
|
|
|
return (
|
2022-12-03 08:45:09 -05:00
|
|
|
_parameter != other._parameter ||
|
|
|
|
_interpolation != other._interpolation ||
|
|
|
|
_desc.lower != other._desc.lower ||
|
|
|
|
_desc.upper != other._desc.upper ||
|
|
|
|
_desc.normal != other._desc.normal);
|
2012-06-16 13:20:10 -04:00
|
|
|
}
|
|
|
|
|
2017-07-24 14:54:32 -04:00
|
|
|
bool
|
|
|
|
ControlList::is_sorted () const
|
|
|
|
{
|
|
|
|
Glib::Threads::RWLock::ReaderLock lm (_lock);
|
|
|
|
if (_events.size () == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-12-03 08:45:09 -05:00
|
|
|
const_iterator i = _events.begin ();
|
2017-07-24 14:54:32 -04:00
|
|
|
const_iterator n = i;
|
|
|
|
while (++n != _events.end ()) {
|
2022-12-03 08:45:09 -05:00
|
|
|
if (event_time_less_than (*n, *i)) {
|
2017-07-24 14:54:32 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-02 16:10:51 -04:00
|
|
|
void
|
|
|
|
ControlList::dump (ostream& o)
|
|
|
|
{
|
|
|
|
/* NOT LOCKED ... for debugging only */
|
|
|
|
|
2023-02-06 22:18:40 -05:00
|
|
|
for (auto const & e : _events) {
|
|
|
|
o << e->value << " @ " << e->when << endl;
|
2013-04-02 16:10:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-18 20:47:49 -04:00
|
|
|
} // namespace Evoral
|