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/stacktrace.h"
30 #include "pbd/xml++.h"
32 #include "ardour/presentation_info.h"
36 using namespace ARDOUR;
40 string PresentationInfo::state_node_name = X_("PresentationInfo");
42 PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change;
43 Glib::Threads::Mutex PresentationInfo::static_signal_lock;
44 int PresentationInfo::_change_signal_suspended = 0;
45 PBD::PropertyChange PresentationInfo::_pending_static_changes;
48 namespace Properties {
49 PBD::PropertyDescriptor<bool> selected;
50 PBD::PropertyDescriptor<uint32_t> order;
51 PBD::PropertyDescriptor<uint32_t> color;
56 PresentationInfo::suspend_change_signal ()
58 g_atomic_int_add (&_change_signal_suspended, 1);
62 PresentationInfo::unsuspend_change_signal ()
64 Glib::Threads::Mutex::Lock lm (static_signal_lock);
66 if (g_atomic_int_get (const_cast<gint*> (&_change_signal_suspended)) == 1) {
68 /* atomically grab currently pending flags */
70 PropertyChange pc = _pending_static_changes;
71 _pending_static_changes.clear ();
75 /* emit the signal with further emissions still blocked
76 * by _change_signal_suspended, but not by the lock.
78 * This means that if the handlers modify other PI
79 * states, the signal for that won't be sent while they
80 * are handling the current signal.
83 Change (pc); /* EMIT SIGNAL */
88 g_atomic_int_add (const_cast<gint*>(&_change_signal_suspended), -1);
92 PresentationInfo::send_static_change (const PropertyChange& what_changed)
94 if (what_changed.empty()) {
99 if (g_atomic_int_get (&_change_signal_suspended)) {
100 Glib::Threads::Mutex::Lock lm (static_signal_lock);
101 _pending_static_changes.add (what_changed);
105 Change (what_changed);
108 const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
109 const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
110 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
111 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
112 const PresentationInfo::Flag PresentationInfo::AllRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut);
113 const PresentationInfo::Flag PresentationInfo::AllStripables = PresentationInfo::Flag (PresentationInfo::AllRoutes|PresentationInfo::VCA);
116 PresentationInfo::make_property_quarks ()
118 Properties::selected.property_id = g_quark_from_static_string (X_("selected"));
119 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for selected = %1\n", Properties::selected.property_id));
120 Properties::color.property_id = g_quark_from_static_string (X_("color"));
121 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
122 Properties::order.property_id = g_quark_from_static_string (X_("order"));
123 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for order = %1\n", Properties::order.property_id));
126 PresentationInfo::PresentationInfo (Flag f)
128 , _flags (Flag (f & ~OrderSet))
131 /* OrderSet is not set */
134 PresentationInfo::PresentationInfo (order_t o, Flag f)
136 , _flags (Flag (f | OrderSet))
139 /* OrderSet is set */
141 PresentationInfo::PresentationInfo (PresentationInfo const& other)
142 : _order (other.order())
143 , _flags (other.flags())
144 , _color (other.color())
149 PresentationInfo::get_state ()
151 XMLNode* node = new XMLNode (state_node_name);
152 node->add_property ("order", PBD::to_string (_order, std::dec));
153 node->add_property ("flags", enum_2_string (_flags));
154 node->add_property ("color", PBD::to_string (_color, std::dec));
160 PresentationInfo::set_state (XMLNode const& node, int /* version */)
162 if (node.name() != state_node_name) {
166 XMLProperty const* prop;
169 if ((prop = node.property (X_("order"))) != 0) {
170 order_t o = atoi (prop->value());
172 pc.add (Properties::order);
175 _order = atoi (prop->value());
178 if ((prop = node.property (X_("flags"))) != 0) {
179 Flag f = Flag (string_2_enum (prop->value(), f));
180 if ((f&Hidden) != (_flags&Hidden)) {
181 pc.add (Properties::hidden);
186 if ((prop = node.property (X_("color"))) != 0) {
187 color_t c = atoi (prop->value());
189 pc.add (Properties::color);
194 send_change (PropertyChange (pc));
200 PresentationInfo::Flag
201 PresentationInfo::get_flags (XMLNode const& node)
203 XMLNodeList nlist = node.children ();
205 for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter){
206 XMLNode* child = *niter;
208 if (child->name() == PresentationInfo::state_node_name) {
209 XMLProperty const* prop = child->property (X_("flags"));
211 Flag f = (Flag) string_2_enum (prop->value(), f);
220 PresentationInfo::set_color (PresentationInfo::color_t c)
224 send_change (PropertyChange (Properties::color));
225 send_static_change (PropertyChange (Properties::color));
230 PresentationInfo::color_set () const
232 /* all RGBA values zero? not set.
234 * this is heuristic, but it is fairly realistic. who will ever set
235 * a color to completely transparent black? only the constructor ..
241 PresentationInfo::set_selected (bool yn)
243 if (yn != selected()) {
245 _flags = Flag (_flags | Selected);
247 _flags = Flag (_flags & ~Selected);
249 send_change (PropertyChange (Properties::selected));
250 send_static_change (PropertyChange (Properties::selected));
255 PresentationInfo::set_hidden (bool yn)
257 if (yn != hidden()) {
260 _flags = Flag (_flags | Hidden);
262 _flags = Flag (_flags & ~Hidden);
265 send_change (PropertyChange (Properties::hidden));
266 send_static_change (PropertyChange (Properties::hidden));
271 PresentationInfo::set_order (order_t order)
273 _flags = Flag (_flags|OrderSet);
275 if (order != _order) {
277 send_change (PropertyChange (Properties::order));
278 send_static_change (PropertyChange (Properties::order));
283 PresentationInfo::operator= (PresentationInfo const& other)
285 if (this != &other) {
286 _order = other.order();
287 _flags = other.flags();
288 _color = other.color();
295 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& pi)
297 return o << pi.order() << '/' << enum_2_string (pi.flags()) << '/' << pi.color();