attempt to handle poly-pressure (polyphonic aftertouch) similarly to other MIDI messages
[ardour.git] / libs / evoral / evoral / ControlSet.hpp
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 #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/threads.h>
27 #include "pbd/signals.h"
28
29 #include "evoral/visibility.h"
30 #include "evoral/Parameter.hpp"
31 #include "evoral/ControlList.hpp"
32
33 namespace Evoral {
34
35 class Control;
36 class ControlEvent;
37
38 class LIBEVORAL_API ControlSet : public boost::noncopyable {
39 public:
40         ControlSet();
41         ControlSet (const ControlSet&);
42         virtual ~ControlSet() {}
43
44         virtual boost::shared_ptr<Evoral::Control>
45         control_factory(const Evoral::Parameter& id) = 0;
46
47         boost::shared_ptr<Control>
48         control (const Parameter& id, bool create_if_missing=false);
49
50         inline boost::shared_ptr<const Control>
51         control (const Parameter& id) const {
52                 const Controls::const_iterator i = _controls.find(id);
53                 return (i != _controls.end() ? i->second : boost::shared_ptr<Control>());
54         }
55
56         typedef std::map< Parameter, boost::shared_ptr<Control> > Controls;
57         inline Controls&       controls()       { return _controls; }
58         inline const Controls& controls() const { return _controls; }
59
60         virtual void add_control(boost::shared_ptr<Control>);
61
62         virtual bool find_next_event(double start, double end, ControlEvent& ev, bool only_active = true) const = 0;
63
64         virtual bool controls_empty() const { return _controls.size() == 0; }
65         virtual void clear_controls();
66
67         void what_has_data(std::set<Parameter>&) const;
68
69         Glib::Threads::Mutex& control_lock() const { return _control_lock; }
70
71 protected:
72         virtual void control_list_marked_dirty () {}
73         virtual void control_list_interpolation_changed (Parameter, ControlList::InterpolationStyle) {}
74
75         mutable Glib::Threads::Mutex _control_lock;
76         Controls            _controls;
77
78         PBD::ScopedConnectionList _list_connections;
79
80 private:
81
82         PBD::ScopedConnectionList _control_connections;
83 };
84
85
86 } // namespace Evoral
87
88 #endif // EVORAL_CONTROLLABLE_HPP