first vaguely working version using PresentationInfo
[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_internal (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 (Config->get_remote_model() != UserOrdered) {
59                 return;
60         }
61
62         set_presentation_info_internal (pi, notify_class_listeners);
63 }
64
65 void
66 Stripable::set_presentation_info_internal (PresentationInfo pi, bool notify_class_listeners)
67 {
68         if (pi != presentation_info()) {
69
70                 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), pi));
71
72                 if (is_master()) {
73                         _presentation_info = PresentationInfo (0, PresentationInfo::MasterOut);
74                 } else if (is_monitor()) {
75                         _presentation_info = PresentationInfo (0, PresentationInfo::MonitorOut);
76                 } else {
77                         _presentation_info = pi;
78                 }
79
80                 PresentationInfoChanged ();
81
82                 if (notify_class_listeners) {
83                         PresentationInfoChange ();
84                 }
85         }
86 }
87
88 void
89 Stripable::set_presentation_info_explicit (PresentationInfo pi)
90 {
91         set_presentation_info_internal (pi, false);
92 }
93
94 int
95 Stripable::set_state (XMLNode const& node, int version)
96 {
97         const XMLProperty *prop;
98         XMLNodeList const & nlist (node.children());
99         XMLNodeConstIterator niter;
100         XMLNode *child;
101
102         if (version > 3000) {
103
104                 std::cerr << "Looking for PI\n";
105
106                 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
107                         child = *niter;
108
109                         if (child->name() == X_("PresentationInfo")) {
110                                 std::cerr << "Found it\n";
111                                 if ((prop = child->property (X_("value"))) != 0) {
112                                         _presentation_info = prop->value ();
113                                         std::cerr << "Set pinfo to " << _presentation_info << " from " << prop->value() << std::endl;
114                                 }
115                         }
116                 }
117
118         } else {
119                 std::cerr << "Old\n";
120
121                 /* Older versions of Ardour stored "_flags" as a property of the Route
122                  * node, only for 3 special Routes (MasterOut, MonitorOut, Auditioner.
123                  *
124                  * Their presentation order was stored in a node called "RemoteControl"
125                  *
126                  * This information is now part of the PresentationInfo of every Stripable.
127                  */
128
129                 if ((prop = node.property (X_("flags"))) != 0) {
130
131                         /* 4.x and earlier - didn't have Stripable but the
132                          * relevant enums have the same names (MasterOut,
133                          * MonitorOut, Auditioner), so we can use string_2_enum
134                          */
135
136                         PresentationInfo::Flag flags;
137
138                         if (version < 3000) {
139                                 string f (prop->value());
140                                 boost::replace_all (f, "ControlOut", "MonitorOut");
141                                 flags = PresentationInfo::Flag (string_2_enum (f, flags));
142                         } else {
143                                 flags = PresentationInfo::Flag (string_2_enum (prop->value(), flags));
144                         }
145
146                         _presentation_info.set_flags (flags);
147
148                 }
149         }
150
151         return 0;
152 }
153
154 void
155 Stripable::add_state (XMLNode& node) const
156 {
157         XMLNode* remote_control_node = new XMLNode (X_("PresentationInfo"));
158         remote_control_node->add_property (X_("value"), _presentation_info.to_string());
159         node.add_child_nocopy (*remote_control_node);
160 }