Update plugin classification
[ardour.git] / libs / ardour / ardour / selection.h
1 /*
2   Copyright (C) 2017 Paul Davis
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_selection_h__
21 #define __ardour_selection_h__
22
23 #include <set>
24 #include <vector>
25
26 #include <boost/weak_ptr.hpp>
27 #include <boost/shared_ptr.hpp>
28
29 #include "pbd/stateful.h"
30 #include "pbd/i18n.h"
31
32 #include "ardour/presentation_info.h"
33
34 namespace ARDOUR {
35
36 class AutomationControl;
37 class Session;
38 class Stripable;
39 class VCAManager;
40 class PresentationInfo;
41
42 class LIBARDOUR_API CoreSelection : public PBD::Stateful {
43   public:
44         CoreSelection (Session& s);
45         ~CoreSelection ();
46
47         void toggle (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
48         void add (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
49         void remove (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
50         void set (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
51         void clear_stripables();
52
53         bool selected (boost::shared_ptr<const Stripable>) const;
54         bool selected (boost::shared_ptr<const AutomationControl>) const;
55         uint32_t selected() const;
56
57         struct StripableAutomationControl {
58                 boost::shared_ptr<Stripable> stripable;
59                 boost::shared_ptr<AutomationControl> controllable;
60                 int order;
61
62                 StripableAutomationControl (boost::shared_ptr<Stripable> s, boost::shared_ptr<AutomationControl> c, int o)
63                         : stripable (s), controllable (c), order (o) {}
64         };
65
66         typedef std::vector<StripableAutomationControl> StripableAutomationControls;
67
68         void get_stripables (StripableAutomationControls&) const;
69
70         XMLNode& get_state (void);
71         int set_state (const XMLNode&, int version);
72
73   protected:
74         friend class AutomationControl;
75         void remove_control_by_id (PBD::ID const &);
76
77   protected:
78         friend class Stripable;
79         friend class Session;
80         friend class VCAManager;
81         void remove_stripable_by_id (PBD::ID const &);
82
83   private:
84         mutable Glib::Threads::RWLock _lock;
85         Session& session;
86         int selection_order;
87
88         struct SelectedStripable {
89                 SelectedStripable (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>, int);
90                 SelectedStripable (PBD::ID const & s, PBD::ID const & c, int o)
91                         : stripable (s), controllable (c), order (o) {}
92
93                 PBD::ID stripable;
94                 PBD::ID controllable;
95                 int order;
96
97                 bool operator< (SelectedStripable const & other) const {
98                         if (stripable == other.stripable) {
99                                 return controllable < other.controllable;
100                         }
101                         return stripable < other.stripable;
102                 }
103         };
104
105         typedef std::set<SelectedStripable> SelectedStripables;
106
107         SelectedStripables _stripables;
108
109         void send_selection_change ();
110 };
111
112 } // namespace ARDOUR
113
114 #endif /* __ardour_selection_h__ */