move ControllableDescriptor from libpbd to libardour; add support for describing...
[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
25 #include "ardour/debug.h"
26 #include "ardour/rc_configuration.h"
27 #include "ardour/stripable.h"
28
29 #include "i18n.h"
30
31 using namespace ARDOUR;
32 using namespace PBD;
33 using std::string;
34
35 PBD::Signal0<void> Stripable::PresentationInfoChange;
36
37 Stripable::Stripable (Session& s, string const & name, PresentationInfo const & pi)
38         : SessionObject (s, name)
39         , _presentation_info (pi)
40 {
41 }
42
43 void
44 Stripable::set_presentation_group_order (PresentationInfo::order_t order, bool notify_class_listeners)
45 {
46         set_presentation_info (PresentationInfo (order, _presentation_info.flags()), notify_class_listeners);
47 }
48
49 void
50 Stripable::set_presentation_group_order_explicit (PresentationInfo::order_t order)
51 {
52         set_presentation_group_order (order, false);
53 }
54
55 void
56 Stripable::set_presentation_info (PresentationInfo pi, bool notify_class_listeners)
57 {
58         if (pi != presentation_info()) {
59
60                 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), pi));
61
62                 if (is_master()) {
63                         _presentation_info = PresentationInfo (0, PresentationInfo::MasterOut);
64                 } else if (is_monitor()) {
65                         _presentation_info = PresentationInfo (0, PresentationInfo::MonitorOut);
66                 } else {
67                         _presentation_info = pi;
68                 }
69
70                 PresentationInfoChanged ();
71
72                 if (notify_class_listeners) {
73                         PresentationInfoChange ();
74                 }
75         }
76 }
77
78 void
79 Stripable::set_presentation_info_explicit (PresentationInfo pi)
80 {
81         set_presentation_info (pi, false);
82 }
83
84 int
85 Stripable::set_state (XMLNode const& node, int version)
86 {
87         const XMLProperty *prop;
88         XMLNodeList const & nlist (node.children());
89         XMLNodeConstIterator niter;
90         XMLNode *child;
91
92         if (version > 3001) {
93
94                 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
95                         child = *niter;
96
97                         if (child->name() == X_("PresentationInfo")) {
98                                 if ((prop = child->property (X_("value"))) != 0) {
99                                         _presentation_info = prop->value ();
100                                 }
101                         }
102                 }
103
104         } else {
105
106                 /* Older versions of Ardour stored "_flags" as a property of the Route
107                  * node, only for 3 special Routes (MasterOut, MonitorOut, Auditioner.
108                  *
109                  * Their presentation order was stored in a node called "RemoteControl"
110                  *
111                  * This information is now part of the PresentationInfo of every Stripable.
112                  */
113
114                 if ((prop = node.property (X_("flags"))) != 0) {
115
116                         /* 4.x and earlier - didn't have Stripable but the
117                          * relevant enums have the same names (MasterOut,
118                          * MonitorOut, Auditioner), so we can use string_2_enum
119                          */
120
121                         PresentationInfo::Flag flags;
122
123                         if (version < 3000) {
124                                 string f (prop->value());
125                                 boost::replace_all (f, "ControlOut", "MonitorOut");
126                                 flags = PresentationInfo::Flag (string_2_enum (f, flags));
127                         } else {
128                                 flags = PresentationInfo::Flag (string_2_enum (prop->value(), flags));
129                         }
130
131                         _presentation_info.set_flags (flags);
132
133                 }
134
135                 if (!_presentation_info.special()) {
136                         if ((prop = node.property (X_("order-key"))) != 0) {
137                                 _presentation_info.set_group_order (atol (prop->value()));
138                         }
139                 }
140         }
141
142         return 0;
143 }
144
145 void
146 Stripable::add_state (XMLNode& node) const
147 {
148         XMLNode* remote_control_node = new XMLNode (X_("PresentationInfo"));
149         remote_control_node->add_property (X_("value"), _presentation_info.to_string());
150         node.add_child_nocopy (*remote_control_node);
151 }