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;
46 int PresentationInfo::selection_counter = 0;
49 namespace Properties {
50 PBD::PropertyDescriptor<bool> selected;
51 PBD::PropertyDescriptor<uint32_t> order;
52 PBD::PropertyDescriptor<uint32_t> color;
57 PresentationInfo::suspend_change_signal ()
59 g_atomic_int_add (&_change_signal_suspended, 1);
63 PresentationInfo::unsuspend_change_signal ()
65 Glib::Threads::Mutex::Lock lm (static_signal_lock);
67 if (g_atomic_int_get (const_cast<gint*> (&_change_signal_suspended)) == 1) {
69 /* atomically grab currently pending flags */
71 PropertyChange pc = _pending_static_changes;
72 _pending_static_changes.clear ();
76 /* emit the signal with further emissions still blocked
77 * by _change_signal_suspended, but not by the lock.
79 * This means that if the handlers modify other PI
80 * states, the signal for that won't be sent while they
81 * are handling the current signal.
84 Change (pc); /* EMIT SIGNAL */
89 g_atomic_int_add (const_cast<gint*>(&_change_signal_suspended), -1);
93 PresentationInfo::send_static_change (const PropertyChange& what_changed)
95 if (what_changed.empty()) {
100 if (g_atomic_int_get (&_change_signal_suspended)) {
101 Glib::Threads::Mutex::Lock lm (static_signal_lock);
102 _pending_static_changes.add (what_changed);
106 Change (what_changed);
109 const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
110 const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
111 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
112 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
113 const PresentationInfo::Flag PresentationInfo::AllRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut);
114 const PresentationInfo::Flag PresentationInfo::AllStripables = PresentationInfo::Flag (PresentationInfo::AllRoutes|PresentationInfo::VCA);
117 PresentationInfo::make_property_quarks ()
119 Properties::selected.property_id = g_quark_from_static_string (X_("selected"));
120 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for selected = %1\n", Properties::selected.property_id));
121 Properties::color.property_id = g_quark_from_static_string (X_("color"));
122 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
123 Properties::order.property_id = g_quark_from_static_string (X_("order"));
124 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for order = %1\n", Properties::order.property_id));
127 PresentationInfo::PresentationInfo (Flag f)
129 , _flags (Flag (f & ~OrderSet))
132 /* OrderSet is not set */
135 PresentationInfo::PresentationInfo (order_t o, Flag f)
137 , _flags (Flag (f | OrderSet))
140 /* OrderSet is set */
142 PresentationInfo::PresentationInfo (PresentationInfo const& other)
143 : _order (other.order())
144 , _flags (other.flags())
145 , _color (other.color())
150 PresentationInfo::get_state ()
152 XMLNode* node = new XMLNode (state_node_name);
153 node->add_property ("order", PBD::to_string (_order, std::dec));
154 node->add_property ("flags", enum_2_string (_flags));
155 node->add_property ("color", PBD::to_string (_color, std::dec));
161 PresentationInfo::set_state (XMLNode const& node, int /* version */)
163 if (node.name() != state_node_name) {
167 XMLProperty const* prop;
170 if ((prop = node.property (X_("order"))) != 0) {
171 order_t o = atoi (prop->value());
173 pc.add (Properties::order);
176 _order = atoi (prop->value());
179 if ((prop = node.property (X_("flags"))) != 0) {
180 Flag f = Flag (string_2_enum (prop->value(), f));
181 if ((f&Hidden) != (_flags&Hidden)) {
182 pc.add (Properties::hidden);
187 if ((prop = node.property (X_("color"))) != 0) {
188 color_t c = atoi (prop->value());
190 pc.add (Properties::color);
195 send_change (PropertyChange (pc));
201 PresentationInfo::Flag
202 PresentationInfo::get_flags (XMLNode const& node)
204 XMLNodeList nlist = node.children ();
206 for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter){
207 XMLNode* child = *niter;
209 if (child->name() == PresentationInfo::state_node_name) {
210 XMLProperty const* prop = child->property (X_("flags"));
212 Flag f = (Flag) string_2_enum (prop->value(), f);
221 PresentationInfo::set_color (PresentationInfo::color_t c)
225 send_change (PropertyChange (Properties::color));
226 send_static_change (PropertyChange (Properties::color));
231 PresentationInfo::color_set () const
233 /* all RGBA values zero? not set.
235 * this is heuristic, but it is fairly realistic. who will ever set
236 * a color to completely transparent black? only the constructor ..
242 PresentationInfo::set_selected (bool yn)
244 if (yn != selected()) {
246 _flags = Flag (_flags | Selected);
247 _selection_cnt = g_atomic_int_add (&selection_counter, 1);
249 _flags = Flag (_flags & ~Selected);
252 send_change (PropertyChange (Properties::selected));
253 send_static_change (PropertyChange (Properties::selected));
258 PresentationInfo::set_hidden (bool yn)
260 if (yn != hidden()) {
263 _flags = Flag (_flags | Hidden);
265 _flags = Flag (_flags & ~Hidden);
268 send_change (PropertyChange (Properties::hidden));
269 send_static_change (PropertyChange (Properties::hidden));
274 PresentationInfo::set_order (order_t order)
276 _flags = Flag (_flags|OrderSet);
278 if (order != _order) {
280 send_change (PropertyChange (Properties::order));
281 send_static_change (PropertyChange (Properties::order));
286 PresentationInfo::operator= (PresentationInfo const& other)
288 if (this != &other) {
289 _order = other.order();
290 _flags = other.flags();
291 _color = other.color();
298 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& pi)
300 return o << pi.order() << '/' << enum_2_string (pi.flags()) << '/' << pi.color();