mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-14 18:46:34 +01:00
Add infrastructure to merge ControlLists
This commit is contained in:
parent
9c0f6ea948
commit
8b917c4c16
2 changed files with 48 additions and 1 deletions
|
|
@ -124,6 +124,7 @@ public:
|
||||||
void shift (double before, double distance);
|
void shift (double before, double distance);
|
||||||
|
|
||||||
void y_transform (boost::function<double(double)> callback);
|
void y_transform (boost::function<double(double)> callback);
|
||||||
|
void list_merge (ControlList const& other, boost::function<double(double, double)> callback);
|
||||||
|
|
||||||
/** add automation events
|
/** add automation events
|
||||||
* @param when absolute time in samples
|
* @param when absolute time in samples
|
||||||
|
|
@ -217,7 +218,7 @@ public:
|
||||||
* @param where absolute time in samples
|
* @param where absolute time in samples
|
||||||
* @returns parameter value
|
* @returns parameter value
|
||||||
*/
|
*/
|
||||||
double eval (double where) {
|
double eval (double where) const {
|
||||||
Glib::Threads::RWLock::ReaderLock lm (_lock);
|
Glib::Threads::RWLock::ReaderLock lm (_lock);
|
||||||
return unlocked_eval (where);
|
return unlocked_eval (where);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,52 @@ ControlList::y_transform (boost::function<double(double)> callback)
|
||||||
maybe_signal_changed ();
|
maybe_signal_changed ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ControlList::list_merge (ControlList const& other, boost::function<double(double, double)> callback)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Glib::Threads::RWLock::WriterLock lm (_lock);
|
||||||
|
EventList nel;
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
for (iterator i = _events.begin(); i != _events.end(); ++i) {
|
||||||
|
float val = callback ((*i)->value, other.eval ((*i)->when));
|
||||||
|
nel.push_back (new ControlEvent ((*i)->when , val));
|
||||||
|
}
|
||||||
|
/* Now add events which are only present in the master-list. */
|
||||||
|
const EventList& evl (other.events());
|
||||||
|
for (const_iterator i = evl.begin(); i != evl.end(); ++i) {
|
||||||
|
bool found = false;
|
||||||
|
// TODO: optimize, remember last matching iterator (lists are sorted)
|
||||||
|
for (iterator j = _events.begin(); j != _events.end(); ++j) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
|
||||||
|
delete (*x);
|
||||||
|
}
|
||||||
|
_events.clear ();
|
||||||
|
_events = nel;
|
||||||
|
|
||||||
|
unlocked_invalidate_insert_iterator ();
|
||||||
|
mark_dirty ();
|
||||||
|
}
|
||||||
|
maybe_signal_changed ();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ControlList::_x_scale (double factor)
|
ControlList::_x_scale (double factor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue