2 Copyright (C) 2016 Paul Davis
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.
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.
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.
24 #include "pbd/convert.h"
25 #include "pbd/debug.h"
26 #include "pbd/enumwriter.h"
27 #include "pbd/error.h"
28 #include "pbd/failed_constructor.h"
29 #include "pbd/xml++.h"
31 #include "ardour/presentation_info.h"
35 using namespace ARDOUR;
39 string PresentationInfo::state_node_name = X_("PresentationInfo");
40 PBD::Signal0<void> PresentationInfo::Change;
43 namespace Properties {
44 PBD::PropertyDescriptor<bool> selected;
45 PBD::PropertyDescriptor<uint32_t> order;
46 PBD::PropertyDescriptor<uint32_t> color;
50 const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
51 const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
52 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
53 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
54 const PresentationInfo::Flag PresentationInfo::AllRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut);
55 const PresentationInfo::Flag PresentationInfo::AllStripables = PresentationInfo::Flag (PresentationInfo::AllRoutes|PresentationInfo::VCA);
58 PresentationInfo::make_property_quarks ()
60 Properties::selected.property_id = g_quark_from_static_string (X_("selected"));
61 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for selected = %1\n", Properties::selected.property_id));
62 Properties::color.property_id = g_quark_from_static_string (X_("color"));
63 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
64 Properties::order.property_id = g_quark_from_static_string (X_("order"));
65 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for order = %1\n", Properties::order.property_id));
68 PresentationInfo::PresentationInfo (Flag f)
70 , _flags (Flag (f & ~OrderSet))
73 /* OrderSet is not set */
76 PresentationInfo::PresentationInfo (order_t o, Flag f)
78 , _flags (Flag (f | OrderSet))
83 PresentationInfo::PresentationInfo (PresentationInfo const& other)
84 : _order (other.order())
85 , _flags (other.flags())
86 , _color (other.color())
91 PresentationInfo::get_state ()
93 XMLNode* node = new XMLNode (state_node_name);
94 node->add_property ("order", PBD::to_string (_order, std::dec));
95 node->add_property ("flags", enum_2_string (_flags));
96 node->add_property ("color", PBD::to_string (_color, std::dec));
102 PresentationInfo::set_state (XMLNode const& node, int /* version */)
104 if (node.name() != state_node_name) {
108 XMLProperty const* prop;
111 if ((prop = node.property (X_("order"))) != 0) {
112 order_t o = atoi (prop->value());
114 pc.add (Properties::order);
117 _order = atoi (prop->value());
120 if ((prop = node.property (X_("flags"))) != 0) {
121 Flag f = Flag (string_2_enum (prop->value(), f));
122 if ((f&Hidden) != (_flags&Hidden)) {
123 pc.add (Properties::hidden);
128 if ((prop = node.property (X_("color"))) != 0) {
129 color_t c = atoi (prop->value());
131 pc.add (Properties::color);
136 send_change (PropertyChange (pc));
142 PresentationInfo::Flag
143 PresentationInfo::get_flags (XMLNode const& node)
145 XMLNodeList nlist = node.children ();
147 for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter){
148 XMLNode* child = *niter;
150 if (child->name() == PresentationInfo::state_node_name) {
151 XMLProperty const* prop = child->property (X_("flags"));
153 Flag f = (Flag) string_2_enum (prop->value(), f);
162 PresentationInfo::set_color (PresentationInfo::color_t c)
166 send_change (PropertyChange (Properties::color));
171 PresentationInfo::color_set () const
173 /* all RGBA values zero? not set.
175 * this is heuristic, but it is fairly realistic. who will ever set
176 * a color to completely transparent black? only the constructor ..
182 PresentationInfo::set_selected (bool yn)
184 if (yn != selected()) {
186 _flags = Flag (_flags | Selected);
188 _flags = Flag (_flags & ~Selected);
190 send_change (PropertyChange (Properties::selected));
195 PresentationInfo::set_hidden (bool yn)
197 if (yn != hidden()) {
200 _flags = Flag (_flags | Hidden);
202 _flags = Flag (_flags & ~Hidden);
205 send_change (PropertyChange (Properties::hidden));
210 PresentationInfo::set_order (order_t order)
212 _flags = Flag (_flags|OrderSet);
214 if (order != _order) {
216 send_change (PropertyChange (Properties::order));
221 PresentationInfo::operator= (PresentationInfo const& other)
223 if (this != &other) {
224 _order = other.order();
225 _flags = other.flags();
226 _color = other.color();
233 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& pi)
235 return o << pi.order() << '/' << enum_2_string (pi.flags()) << '/' << pi.color();