39c3eba3449f99f3ddc1d7e0cef60bb1c8490848
[ardour.git] / libs / evoral / evoral / ControlSet.hpp
1 /* This file is part of Evoral.
2  * Copyright (C) 2008 Dave 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 #ifndef EVORAL_CONTROLLABLE_HPP
20 #define EVORAL_CONTROLLABLE_HPP
21
22 #include <set>
23 #include <map>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/utility.hpp>
26 #include <glibmm/thread.h>
27 #include "evoral/types.hpp"
28 #include "evoral/Parameter.hpp"
29
30 namespace Evoral {
31
32 class Control;
33 class ControlList;
34 class ControlEvent;
35
36 class ControlSet : public boost::noncopyable {
37 public:
38         ControlSet();
39         virtual ~ControlSet() {}
40
41         virtual boost::shared_ptr<Evoral::Control>
42         control_factory(const Evoral::Parameter& id) = 0;
43
44         boost::shared_ptr<Control>
45         control (const Parameter& id, bool create_if_missing=false);
46
47         inline boost::shared_ptr<const Control>
48         control (const Parameter& id) const {
49                 const Controls::const_iterator i = _controls.find(id);
50                 return (i != _controls.end() ? i->second : boost::shared_ptr<Control>());
51         }
52
53         typedef std::map< Parameter, boost::shared_ptr<Control> > Controls;
54         inline Controls&       controls()       { return _controls; }
55         inline const Controls& controls() const { return _controls; }
56
57         virtual void add_control(boost::shared_ptr<Control>);
58
59         bool find_next_event(FrameTime start, FrameTime end, ControlEvent& ev) const;
60
61         virtual bool controls_empty() const { return _controls.size() == 0; }
62         virtual void clear_controls();
63
64         void what_has_data(std::set<Parameter>&) const;
65
66         Glib::Mutex& control_lock() const { return _control_lock; }
67
68 protected:
69         mutable Glib::Mutex _control_lock;
70         Controls            _controls;
71 };
72
73
74 } // namespace Evoral
75
76 #endif // EVORAL_CONTROLLABLE_HPP