rename TransportMasterManager::init() to ::set_default_configuration() to make its...
[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
31 #include "ardour/presentation_info.h"
32 #include "ardour/types.h"
33
34 namespace ARDOUR {
35
36 class AutomationControl;
37 class RouteGroup;
38 class Session;
39 class Stripable;
40 class VCAManager;
41 class PresentationInfo;
42
43 class LIBARDOUR_API CoreSelection : public PBD::Stateful {
44   public:
45         CoreSelection (Session& s);
46         ~CoreSelection ();
47
48         void toggle (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
49         void add (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
50         void remove (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
51         void set (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
52         void set (StripableList&);
53
54         void select_next_stripable (bool mixer_order, bool routes_only);
55         void select_prev_stripable (bool mixer_order, bool routes_only);
56         bool select_stripable_and_maybe_group (boost::shared_ptr<Stripable> s, bool with_group, bool routes_only, RouteGroup*);
57
58         void clear_stripables();
59
60         bool selected (boost::shared_ptr<const Stripable>) const;
61         bool selected (boost::shared_ptr<const AutomationControl>) const;
62         uint32_t selected() const;
63
64         struct StripableAutomationControl {
65                 boost::shared_ptr<Stripable> stripable;
66                 boost::shared_ptr<AutomationControl> controllable;
67                 int order;
68
69                 StripableAutomationControl (boost::shared_ptr<Stripable> s, boost::shared_ptr<AutomationControl> c, int o)
70                         : stripable (s), controllable (c), order (o) {}
71         };
72
73         typedef std::vector<StripableAutomationControl> StripableAutomationControls;
74
75         void get_stripables (StripableAutomationControls&) const;
76
77         XMLNode& get_state (void);
78         int set_state (const XMLNode&, int version);
79
80   protected:
81         friend class AutomationControl;
82         void remove_control_by_id (PBD::ID const &);
83
84   protected:
85         friend class Stripable;
86         friend class Session;
87         friend class VCAManager;
88         void remove_stripable_by_id (PBD::ID const &);
89
90   private:
91         mutable Glib::Threads::RWLock _lock;
92         Session& session;
93         int selection_order;
94
95         struct SelectedStripable {
96                 SelectedStripable (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>, int);
97                 SelectedStripable (PBD::ID const & s, PBD::ID const & c, int o)
98                         : stripable (s), controllable (c), order (o) {}
99
100                 PBD::ID stripable;
101                 PBD::ID controllable;
102                 int order;
103
104                 bool operator< (SelectedStripable const & other) const {
105                         if (stripable == other.stripable) {
106                                 return controllable < other.controllable;
107                         }
108                         return stripable < other.stripable;
109                 }
110         };
111
112         typedef std::set<SelectedStripable> SelectedStripables;
113
114         SelectedStripables _stripables;
115
116         void send_selection_change ();
117
118         template<typename IterTypeCore>
119                 void select_adjacent_stripable (bool mixer_order, bool routes_only,
120                                                 IterTypeCore (StripableList::*begin_method)(),
121                                                 IterTypeCore (StripableList::*end_method)());
122 };
123
124 } // namespace ARDOUR
125
126 #endif /* __ardour_selection_h__ */