1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*
Copyright (C) 2016 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sstream>
#include <typeinfo>
#include <cassert>
#include "pbd/enumwriter.h"
#include "pbd/error.h"
#include "pbd/failed_constructor.h"
#include "pbd/xml++.h"
#include "ardour/presentation_info.h"
#include "i18n.h"
using namespace ARDOUR;
using namespace PBD;
using std::string;
const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
PresentationInfo::PresentationInfo (std::string const & str)
{
if (parse (str)) {
throw failed_constructor ();
}
}
int
PresentationInfo::parse (string const& str)
{
std::stringstream s (str);
/* new school, segmented string "NNN:TYPE" */
string f;
char c;
s >> _order;
/* skip colon */
s >> c;
/* grab flags */
s >> f;
_flags = Flag (string_2_enum (f, _flags)|GroupOrderSet);
std::cerr << "Parsed [" << str << "] as " << _order << " + " << enum_2_string (_flags) << std::endl;
return 0;
}
int
PresentationInfo::parse (uint32_t n, Flag f)
{
if (n < UINT32_MAX) {
assert (f != Flag (0));
_order = n;
_flags = Flag (f|GroupOrderSet);
} else {
_order = (n & 0xffff);
_flags = Flag ((n >> 16)|GroupOrderSet);
}
return 0;
}
std::string
PresentationInfo::to_string() const
{
std::stringstream ss;
/* Do not save or selected hidden status, or group-order set bit */
Flag f = Flag (_flags & ~(Hidden|Selected|GroupOrderSet));
ss << _order << ':' << enum_2_string (f);
return ss.str();
}
PresentationInfo::Flag
PresentationInfo::get_flags (XMLNode const& node)
{
const XMLProperty *prop;
XMLNodeList nlist = node.children ();
XMLNodeConstIterator niter;
XMLNode *child;
for (niter = nlist.begin(); niter != nlist.end(); ++niter){
child = *niter;
if (child->name() == X_("PresentationInfo")) {
if ((prop = child->property (X_("value"))) != 0) {
PresentationInfo pi (prop->value());
return pi.flags ();
}
}
}
return Flag (0);
}
std::ostream&
operator<<(std::ostream& o, ARDOUR::PresentationInfo const& rid)
{
return o << rid.to_string ();
}
|