remove debug output
[ardour.git] / libs / ardour / presentation_info.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 #include <sstream>
20 #include <typeinfo>
21
22 #include <cassert>
23
24 #include "pbd/enumwriter.h"
25 #include "pbd/error.h"
26 #include "pbd/failed_constructor.h"
27 #include "pbd/xml++.h"
28
29 #include "ardour/presentation_info.h"
30
31 #include "i18n.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35 using std::string;
36
37 const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
38 const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
39 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
40 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
41
42 PresentationInfo::PresentationInfo (std::string const & str)
43 {
44         if (parse (str)) {
45                 throw failed_constructor ();
46         }
47 }
48
49 int
50 PresentationInfo::parse (string const& str)
51 {
52         std::stringstream s (str);
53
54         /* new school, segmented string "NNN:TYPE" */
55         string f;
56         char c;
57
58         s >> _order;
59         /* skip colon */
60         s >> c;
61         /* grab flags */
62         s >> f;
63
64         _flags = Flag (string_2_enum (f, _flags)|GroupOrderSet);
65
66         return 0;
67 }
68
69 int
70 PresentationInfo::parse (uint32_t n, Flag f)
71 {
72         if (n < UINT32_MAX) {
73                 assert (f != Flag (0));
74                 _order = n;
75                 _flags = Flag (f|GroupOrderSet);
76         } else {
77                 _order = (n & 0xffff);
78                 _flags = Flag ((n >> 16)|GroupOrderSet);
79         }
80
81         return 0;
82 }
83
84 std::string
85 PresentationInfo::to_string() const
86 {
87         std::stringstream ss;
88
89         /* Do not save or selected hidden status, or group-order set bit */
90
91         Flag f = Flag (_flags & ~(Hidden|Selected|GroupOrderSet));
92
93         ss << _order << ':' << enum_2_string (f);
94
95         return ss.str();
96 }
97
98 PresentationInfo::Flag
99 PresentationInfo::get_flags (XMLNode const& node)
100 {
101         const XMLProperty *prop;
102         XMLNodeList nlist = node.children ();
103         XMLNodeConstIterator niter;
104         XMLNode *child;
105
106         for (niter = nlist.begin(); niter != nlist.end(); ++niter){
107                 child = *niter;
108
109                 if (child->name() == X_("PresentationInfo")) {
110                         if ((prop = child->property (X_("value"))) != 0) {
111                                 PresentationInfo pi (prop->value());
112                                 return pi.flags ();
113                         }
114                 }
115         }
116         return Flag (0);
117 }
118
119 std::ostream&
120 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& rid)
121 {
122         return o << rid.to_string ();
123 }