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 if (!_pending_static_changes.empty()) {
70 std::cerr << "PI change (unsuspended): ";
71 for (PropertyChange::const_iterator x = _pending_static_changes.begin(); x != _pending_static_changes.end(); ++x) {
72 std::cerr << g_quark_to_string (*x) << ',';
76 /* emit the signal with further emissions still
77 * blocked, so that if the handlers modify other PI
78 * states, the signal for that won't be sent while
79 * they are handling this one.
82 Change (_pending_static_changes); /* EMIT SIGNAL */
84 _pending_static_changes.clear ();
87 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()) {
98 Glib::Threads::Mutex::Lock lm (static_signal_lock);
100 if (g_atomic_int_get (&_change_signal_suspended)) {
101 _pending_static_changes.add (what_changed);
105 std::cerr << "PI change (direct): ";
106 for (PropertyChange::const_iterator x = what_changed.begin(); x != what_changed.end(); ++x) {
107 std::cerr << g_quark_to_string (*x) << ',';
111 Change (what_changed);
114 const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
115 const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
116 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
117 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
118 const PresentationInfo::Flag PresentationInfo::AllRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut);
119 const PresentationInfo::Flag PresentationInfo::AllStripables = PresentationInfo::Flag (PresentationInfo::AllRoutes|PresentationInfo::VCA);
122 PresentationInfo::make_property_quarks ()
124 Properties::selected.property_id = g_quark_from_static_string (X_("selected"));
125 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for selected = %1\n", Properties::selected.property_id));
126 Properties::color.property_id = g_quark_from_static_string (X_("color"));
127 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
128 Properties::order.property_id = g_quark_from_static_string (X_("order"));
129 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for order = %1\n", Properties::order.property_id));
132 PresentationInfo::PresentationInfo (Flag f)
134 , _flags (Flag (f & ~OrderSet))
137 /* OrderSet is not set */
140 PresentationInfo::PresentationInfo (order_t o, Flag f)
142 , _flags (Flag (f | OrderSet))
145 /* OrderSet is set */
147 PresentationInfo::PresentationInfo (PresentationInfo const& other)
148 : _order (other.order())
149 , _flags (other.flags())
150 , _color (other.color())
155 PresentationInfo::get_state ()
157 XMLNode* node = new XMLNode (state_node_name);
158 node->add_property ("order", PBD::to_string (_order, std::dec));
159 node->add_property ("flags", enum_2_string (_flags));
160 node->add_property ("color", PBD::to_string (_color, std::dec));
166 PresentationInfo::set_state (XMLNode const& node, int /* version */)
168 if (node.name() != state_node_name) {
172 XMLProperty const* prop;
175 if ((prop = node.property (X_("order"))) != 0) {
176 order_t o = atoi (prop->value());
178 pc.add (Properties::order);
181 _order = atoi (prop->value());
184 if ((prop = node.property (X_("flags"))) != 0) {
185 Flag f = Flag (string_2_enum (prop->value(), f));
186 if ((f&Hidden) != (_flags&Hidden)) {
187 pc.add (Properties::hidden);
192 if ((prop = node.property (X_("color"))) != 0) {
193 color_t c = atoi (prop->value());
195 pc.add (Properties::color);
200 send_change (PropertyChange (pc));
206 PresentationInfo::Flag
207 PresentationInfo::get_flags (XMLNode const& node)
209 XMLNodeList nlist = node.children ();
211 for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter){
212 XMLNode* child = *niter;
214 if (child->name() == PresentationInfo::state_node_name) {
215 XMLProperty const* prop = child->property (X_("flags"));
217 Flag f = (Flag) string_2_enum (prop->value(), f);
226 PresentationInfo::set_color (PresentationInfo::color_t c)
230 send_change (PropertyChange (Properties::color));
231 send_static_change (PropertyChange (Properties::color));
236 PresentationInfo::color_set () const
238 /* all RGBA values zero? not set.
240 * this is heuristic, but it is fairly realistic. who will ever set
241 * a color to completely transparent black? only the constructor ..
247 PresentationInfo::set_selected (bool yn)
249 if (yn != selected()) {
251 _flags = Flag (_flags | Selected);
253 _flags = Flag (_flags & ~Selected);
255 send_change (PropertyChange (Properties::selected));
256 send_static_change (PropertyChange (Properties::selected));
261 PresentationInfo::set_hidden (bool yn)
263 if (yn != hidden()) {
266 _flags = Flag (_flags | Hidden);
268 _flags = Flag (_flags & ~Hidden);
271 send_change (PropertyChange (Properties::hidden));
272 send_static_change (PropertyChange (Properties::hidden));
277 PresentationInfo::set_order (order_t order)
279 _flags = Flag (_flags|OrderSet);
281 if (order != _order) {
283 send_change (PropertyChange (Properties::order));
284 send_static_change (PropertyChange (Properties::order));
289 PresentationInfo::operator= (PresentationInfo const& other)
291 if (this != &other) {
292 _order = other.order();
293 _flags = other.flags();
294 _color = other.color();
301 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& pi)
303 return o << pi.order() << '/' << enum_2_string (pi.flags()) << '/' << pi.color();