libardour now has CoreSelection object to manage selection status of Stripables and...
[ardour.git] / libs / ardour / stripable.cc
1 /*
2     Copyright (C) 2016 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 #include <boost/algorithm/string.hpp>
21
22 #include "pbd/compose.h"
23 #include "pbd/convert.h"
24 #include "pbd/i18n.h"
25
26
27 #include "ardour/debug.h"
28 #include "ardour/rc_configuration.h"
29 #include "ardour/session.h"
30 #include "ardour/selection.h"
31 #include "ardour/stripable.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35 using std::string;
36
37 Stripable::Stripable (Session& s, string const & name, PresentationInfo const & pi)
38         : SessionObject (s, name)
39         , Automatable (s)
40         , _presentation_info (pi)
41         , _active_color_picker (0)
42 {
43 }
44
45 Stripable::~Stripable ()
46 {
47         _session.selection().remove_stripable_by_id (id());
48 }
49
50 void
51 Stripable::set_presentation_order (PresentationInfo::order_t order)
52 {
53         _presentation_info.set_order (order);
54 }
55
56 int
57 Stripable::set_state (XMLNode const& node, int version)
58 {
59         const XMLProperty *prop;
60         XMLNodeList const & nlist (node.children());
61         XMLNodeConstIterator niter;
62         XMLNode *child;
63
64         if (version > 3001) {
65
66                 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
67                         child = *niter;
68
69                         if (child->name() == PresentationInfo::state_node_name) {
70                                 _presentation_info.set_state (*child, version);
71                         }
72                 }
73
74         } else {
75
76                 /* Older versions of Ardour stored "_flags" as a property of the Route
77                  * node, only for 3 special Routes (MasterOut, MonitorOut, Auditioner.
78                  *
79                  * Their presentation order was stored in a node called "RemoteControl"
80                  *
81                  * This information is now part of the PresentationInfo of every Stripable.
82                  */
83
84                 if ((prop = node.property (X_("flags"))) != 0) {
85
86                         /* 4.x and earlier - didn't have Stripable but the
87                          * relevant enums have the same names (MasterOut,
88                          * MonitorOut, Auditioner), so we can use string_2_enum
89                          */
90
91                         PresentationInfo::Flag flags;
92
93                         if (version < 3000) {
94                                 string f (prop->value());
95                                 boost::replace_all (f, "ControlOut", "MonitorOut");
96                                 flags = PresentationInfo::Flag (string_2_enum (f, flags));
97                         } else {
98                                 flags = PresentationInfo::Flag (string_2_enum (prop->value(), flags));
99                         }
100
101                         _presentation_info.set_flags (flags);
102
103                 }
104
105                 if (!_presentation_info.special()) {
106                         if ((prop = node.property (X_("order-key"))) != 0) {
107                                 _presentation_info.set_order (atol (prop->value()));
108                         }
109                 }
110         }
111
112         return 0;
113 }
114
115 bool
116 Stripable::is_selected() const
117 {
118         try {
119                 boost::shared_ptr<const Stripable> s (shared_from_this());
120         } catch (...) {
121                 std::cerr << "cannot shared-from-this for " << this << std::endl;
122                 abort ();
123         }
124         return _session.selection().selected (shared_from_this());
125 }