ardour
ControlSet.cpp
Go to the documentation of this file.
1 /* This file is part of Evoral.
2  * Copyright (C) 2008 David Robillard <http://drobilla.net>
3  * Copyright (C) 2000-2008 Paul Davis
4  *
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
8  * version.
9  *
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.
13  *
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
17  */
18 
19 #include <iostream>
20 #include <limits>
21 #include "evoral/ControlSet.hpp"
22 #include "evoral/ControlList.hpp"
23 #include "evoral/Control.hpp"
24 #include "evoral/Event.hpp"
25 
26 using namespace std;
27 
28 namespace Evoral {
29 
30 
31 ControlSet::ControlSet()
32 {
33 }
34 
35 ControlSet::ControlSet (const ControlSet&)
36  : noncopyable ()
37 {
38  /* derived class must copy controls */
39 }
40 
41 void
43 {
44  _controls[ac->parameter()] = ac;
45 
46  ac->ListMarkedDirty.connect_same_thread (_control_connections, boost::bind (&ControlSet::control_list_marked_dirty, this));
47 
48  if (ac->list()) {
49  ac->list()->InterpolationChanged.connect_same_thread (
52  this, ac->parameter(), _1));
53  }
54 }
55 
56 void
57 ControlSet::what_has_data (set<Parameter>& s) const
58 {
60 
61  for (Controls::const_iterator li = _controls.begin(); li != _controls.end(); ++li) {
62  if (li->second->list() && !li->second->list()->empty()) {
63  s.insert (li->first);
64  }
65  }
66 }
67 
73 ControlSet::control (const Parameter& parameter, bool create_if_missing)
74 {
75  Controls::iterator i = _controls.find(parameter);
76 
77  if (i != _controls.end()) {
78  return i->second;
79 
80  } else if (create_if_missing) {
82  add_control(ac);
83  return ac;
84 
85  } else {
87  }
88 }
89 
90 bool
91 ControlSet::find_next_event (double now, double end, ControlEvent& next_event) const
92 {
93  Controls::const_iterator li;
94 
95  next_event.when = std::numeric_limits<double>::max();
96 
97  for (li = _controls.begin(); li != _controls.end(); ++li) {
99  boost::shared_ptr<const ControlList> alist (li->second->list());
100  ControlEvent cp (now, 0.0f);
101  if (!alist) {
102  continue;
103  }
104 
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) {
108  break;
109  }
110  }
111 
112  if (i != alist->end() && (*i)->when < end) {
113  if ((*i)->when < next_event.when) {
114  next_event.when = (*i)->when;
115  }
116  }
117  }
118 
119  return next_event.when != std::numeric_limits<double>::max();
120 }
121 
122 void
124 {
126 
129 
130  for (Controls::iterator li = _controls.begin(); li != _controls.end(); ++li) {
131  if (li->second->list()) {
132  li->second->list()->clear();
133  }
134  }
135 }
136 
137 } // namespace Evoral
boost::shared_ptr< Control > control(const Parameter &id, bool create_if_missing=false)
Definition: ControlSet.cpp:73
bool find_next_event(double start, double end, ControlEvent &ev) const
Definition: ControlSet.cpp:91
tuple f
Definition: signals.py:35
Definition: Beats.hpp:239
Glib::Threads::Mutex _control_lock
Definition: ControlSet.hpp:76
virtual void control_list_interpolation_changed(Parameter, ControlList::InterpolationStyle)
Definition: ControlSet.hpp:74
void what_has_data(std::set< Parameter > &) const
Definition: ControlSet.cpp:57
virtual void clear_controls()
Definition: ControlSet.cpp:123
EventList::const_iterator const_iterator
Definition: ControlList.hpp:84
virtual void add_control(boost::shared_ptr< Control >)
Definition: ControlSet.cpp:42
PBD::ScopedConnectionList _control_connections
Definition: ControlSet.hpp:83
virtual void control_list_marked_dirty()
Definition: ControlSet.hpp:73
PBD::ScopedConnectionList _list_connections
Definition: ControlSet.hpp:79
static bool time_comparator(const ControlEvent *a, const ControlEvent *b)
virtual boost::shared_ptr< Evoral::Control > control_factory(const Evoral::Parameter &id)=0