The new class 'ARDOUR::CoreSelection' needs to be exportable (since it gets used...
[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 PresentationInfo;
40
41 class LIBARDOUR_API CoreSelection : public PBD::Stateful {
42   public:
43         CoreSelection (Session& s);
44         ~CoreSelection ();
45
46         void toggle (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
47         void add (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
48         void remove (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
49         void set (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>);
50         void clear_stripables();
51
52         bool selected (boost::shared_ptr<const Stripable>) const;
53         bool selected (boost::shared_ptr<const AutomationControl>) const;
54         uint32_t selected() const;
55
56         struct StripableAutomationControl {
57                 boost::shared_ptr<Stripable> stripable;
58                 boost::shared_ptr<AutomationControl> controllable;
59                 int order;
60
61                 StripableAutomationControl (boost::shared_ptr<Stripable> s, boost::shared_ptr<AutomationControl> c, int o)
62                         : stripable (s), controllable (c), order (o) {}
63         };
64
65         typedef std::vector<StripableAutomationControl> StripableAutomationControls;
66
67         void get_stripables (StripableAutomationControls&) const;
68
69         XMLNode& get_state (void);
70         int set_state (const XMLNode&, int version);
71
72   protected:
73         friend class AutomationControl;
74         void remove_control_by_id (PBD::ID const &);
75
76   protected:
77         friend class Stripable;
78         void remove_stripable_by_id (PBD::ID const &);
79
80   private:
81         mutable Glib::Threads::RWLock _lock;
82         Session& session;
83         int selection_order;
84
85         struct SelectedStripable {
86                 SelectedStripable (boost::shared_ptr<Stripable>, boost::shared_ptr<AutomationControl>, int);
87                 SelectedStripable (PBD::ID const & s, PBD::ID const & c, int o)
88                         : stripable (s), controllable (c), order (o) {}
89
90                 PBD::ID stripable;
91                 PBD::ID controllable;
92                 int order;
93
94                 bool operator< (SelectedStripable const & other) const {
95                         if (stripable == other.stripable) {
96                                 return controllable < other.controllable;
97                         }
98                         return stripable < other.stripable;
99                 }
100         };
101
102         typedef std::set<SelectedStripable> SelectedStripables;
103
104         SelectedStripables _stripables;
105
106         void send_selection_change ();
107 };
108
109 } // namespace ARDOUR
110
111 #endif /* __ardour_selection_h__ */