1 /* This file is part of Evoral.
2 * Copyright (C) 2008 David Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
5 * Evoral is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "evoral/ControlSet.hpp"
22 #include "evoral/ControlList.hpp"
23 #include "evoral/Control.hpp"
24 #include "evoral/Event.hpp"
31 ControlSet::ControlSet()
35 ControlSet::ControlSet (const ControlSet&)
38 /* derived class must copy controls */
42 ControlSet::add_control(boost::shared_ptr<Control> ac)
44 _controls[ac->parameter()] = ac;
46 ac->ListMarkedDirty.connect_same_thread (_control_connections, boost::bind (&ControlSet::control_list_marked_dirty, this));
49 ac->list()->InterpolationChanged.connect_same_thread (
51 boost::bind (&ControlSet::control_list_interpolation_changed,
52 this, ac->parameter(), _1));
57 ControlSet::what_has_data (set<Parameter>& s) const
59 Glib::Threads::Mutex::Lock lm (_control_lock);
61 for (Controls::const_iterator li = _controls.begin(); li != _controls.end(); ++li) {
62 if (li->second->list() && !li->second->list()->empty()) {
68 /** If a control for the given parameter does not exist and \a create_if_missing is true,
69 * a control will be created, added to this set, and returned.
70 * If \a create_if_missing is false this function may return null.
72 boost::shared_ptr<Control>
73 ControlSet::control (const Parameter& parameter, bool create_if_missing)
75 Controls::iterator i = _controls.find(parameter);
77 if (i != _controls.end()) {
80 } else if (create_if_missing) {
81 boost::shared_ptr<Control> ac(control_factory(parameter));
86 return boost::shared_ptr<Control>();
91 ControlSet::find_next_event (double now, double end, ControlEvent& next_event) const
93 Controls::const_iterator li;
95 next_event.when = std::numeric_limits<double>::max();
97 for (li = _controls.begin(); li != _controls.end(); ++li) {
98 ControlList::const_iterator i;
99 boost::shared_ptr<const ControlList> alist (li->second->list());
100 ControlEvent cp (now, 0.0f);
105 for (i = lower_bound (alist->begin(), alist->end(), &cp, ControlList::time_comparator);
106 i != alist->end() && (*i)->when < end; ++i) {
107 if ((*i)->when > now) {
112 if (i != alist->end() && (*i)->when < end) {
113 if ((*i)->when < next_event.when) {
114 next_event.when = (*i)->when;
119 return next_event.when != std::numeric_limits<double>::max();
123 ControlSet::clear_controls ()
125 Glib::Threads::Mutex::Lock lm (_control_lock);
127 _control_connections.drop_connections ();
128 _list_connections.drop_connections ();
130 for (Controls::iterator li = _controls.begin(); li != _controls.end(); ++li) {
131 if (li->second->list()) {
132 li->second->list()->clear();
137 } // namespace Evoral