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/debug.h"
25 #include "pbd/enum_convert.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"
33 #include "ardour/selection.h"
38 DEFINE_ENUM_CONVERT(ARDOUR::PresentationInfo::Flag);
41 using namespace ARDOUR;
45 string PresentationInfo::state_node_name = X_("PresentationInfo");
47 PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change;
48 Glib::Threads::Mutex PresentationInfo::static_signal_lock;
49 int PresentationInfo::_change_signal_suspended = 0;
50 PBD::PropertyChange PresentationInfo::_pending_static_changes;
51 int PresentationInfo::selection_counter= 0;
54 namespace Properties {
55 PBD::PropertyDescriptor<bool> selected;
56 PBD::PropertyDescriptor<uint32_t> order;
57 PBD::PropertyDescriptor<uint32_t> color;
62 PresentationInfo::suspend_change_signal ()
64 g_atomic_int_add (&_change_signal_suspended, 1);
68 PresentationInfo::unsuspend_change_signal ()
70 Glib::Threads::Mutex::Lock lm (static_signal_lock);
72 if (g_atomic_int_get (const_cast<gint*> (&_change_signal_suspended)) == 1) {
74 /* atomically grab currently pending flags */
76 PropertyChange pc = _pending_static_changes;
77 _pending_static_changes.clear ();
81 /* emit the signal with further emissions still blocked
82 * by _change_signal_suspended, but not by the lock.
84 * This means that if the handlers modify other PI
85 * states, the signal for that won't be sent while they
86 * are handling the current signal.
89 Change (pc); /* EMIT SIGNAL */
94 g_atomic_int_add (const_cast<gint*>(&_change_signal_suspended), -1);
98 PresentationInfo::send_static_change (const PropertyChange& what_changed)
100 if (what_changed.empty()) {
105 if (g_atomic_int_get (&_change_signal_suspended)) {
106 Glib::Threads::Mutex::Lock lm (static_signal_lock);
107 _pending_static_changes.add (what_changed);
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)
149 , _order (other.order())
150 , _flags (other.flags())
151 , _color (other.color())
156 PresentationInfo::get_state ()
158 XMLNode* node = new XMLNode (state_node_name);
159 node->set_property ("order", _order);
160 node->set_property ("flags", _flags);
161 node->set_property ("color", _color);
167 PresentationInfo::set_state (XMLNode const& node, int /* version */)
169 if (node.name() != state_node_name) {
176 if (node.get_property (X_("order"), o)) {
178 pc.add (Properties::order);
185 if (node.get_property (X_("flags"), f)) {
186 if ((f&Hidden) != (_flags&Hidden)) {
187 pc.add (Properties::hidden);
193 if (node.get_property (X_("color"), c)) {
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) {
216 if (child->get_property (X_("flags"), f)) {
225 PresentationInfo::set_color (PresentationInfo::color_t c)
229 send_change (PropertyChange (Properties::color));
230 send_static_change (PropertyChange (Properties::color));
235 PresentationInfo::color_set () const
237 /* all RGBA values zero? not set.
239 * this is heuristic, but it is fairly realistic. who will ever set
240 * a color to completely transparent black? only the constructor ..
246 PresentationInfo::set_hidden (bool yn)
248 if (yn != hidden()) {
251 _flags = Flag (_flags | Hidden);
253 _flags = Flag (_flags & ~Hidden);
256 send_change (PropertyChange (Properties::hidden));
257 send_static_change (PropertyChange (Properties::hidden));
262 PresentationInfo::set_order (order_t order)
264 _flags = Flag (_flags|OrderSet);
266 if (order != _order) {
268 send_change (PropertyChange (Properties::order));
269 send_static_change (PropertyChange (Properties::order));
274 PresentationInfo::operator= (PresentationInfo const& other)
276 if (this != &other) {
277 _order = other.order();
278 _flags = other.flags();
279 _color = other.color();
286 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& pi)
288 return o << pi.order() << '/' << enum_2_string (pi.flags()) << '/' << pi.color();