2 * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
4 * Copyright (C) 2018 Len Ovens <len@ovenwerks.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "pbd/debug.h"
27 #include "pbd/enum_convert.h"
28 #include "pbd/enumwriter.h"
29 #include "pbd/error.h"
30 #include "pbd/failed_constructor.h"
31 #include "pbd/stacktrace.h"
32 #include "pbd/xml++.h"
34 #include "ardour/presentation_info.h"
35 #include "ardour/selection.h"
40 DEFINE_ENUM_CONVERT(ARDOUR::PresentationInfo::Flag);
43 using namespace ARDOUR;
47 string PresentationInfo::state_node_name = X_("PresentationInfo");
49 PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change;
50 Glib::Threads::Mutex PresentationInfo::static_signal_lock;
51 int PresentationInfo::_change_signal_suspended = 0;
52 PBD::PropertyChange PresentationInfo::_pending_static_changes;
53 int PresentationInfo::selection_counter= 0;
56 namespace Properties {
57 PBD::PropertyDescriptor<bool> selected;
58 PBD::PropertyDescriptor<uint32_t> order;
59 PBD::PropertyDescriptor<uint32_t> color;
64 PresentationInfo::suspend_change_signal ()
66 g_atomic_int_add (&_change_signal_suspended, 1);
70 PresentationInfo::unsuspend_change_signal ()
72 Glib::Threads::Mutex::Lock lm (static_signal_lock);
74 if (g_atomic_int_get (const_cast<gint*> (&_change_signal_suspended)) == 1) {
76 /* atomically grab currently pending flags */
78 PropertyChange pc = _pending_static_changes;
79 _pending_static_changes.clear ();
83 /* emit the signal with further emissions still blocked
84 * by _change_signal_suspended, but not by the lock.
86 * This means that if the handlers modify other PI
87 * states, the signal for that won't be sent while they
88 * are handling the current signal.
91 Change (pc); /* EMIT SIGNAL */
96 g_atomic_int_add (const_cast<gint*>(&_change_signal_suspended), -1);
100 PresentationInfo::send_static_change (const PropertyChange& what_changed)
102 if (what_changed.empty()) {
107 if (g_atomic_int_get (&_change_signal_suspended)) {
108 Glib::Threads::Mutex::Lock lm (static_signal_lock);
109 _pending_static_changes.add (what_changed);
113 Change (what_changed);
116 const PresentationInfo::order_t PresentationInfo::max_order = UINT32_MAX;
117 const PresentationInfo::Flag PresentationInfo::Bus = PresentationInfo::Flag (PresentationInfo::AudioBus|PresentationInfo::MidiBus);
118 const PresentationInfo::Flag PresentationInfo::Track = PresentationInfo::Flag (PresentationInfo::AudioTrack|PresentationInfo::MidiTrack);
119 const PresentationInfo::Flag PresentationInfo::Route = PresentationInfo::Flag (PresentationInfo::Bus|PresentationInfo::Track);
120 const PresentationInfo::Flag PresentationInfo::AllRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut|PresentationInfo::FoldbackBus);
121 const PresentationInfo::Flag PresentationInfo::MixerRoutes = PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::MasterOut|PresentationInfo::MonitorOut);
122 const PresentationInfo::Flag PresentationInfo::AllStripables = PresentationInfo::Flag (PresentationInfo::AllRoutes|PresentationInfo::VCA);
123 const PresentationInfo::Flag PresentationInfo::MixerStripables = PresentationInfo::Flag (PresentationInfo::MixerRoutes|PresentationInfo::VCA);
126 PresentationInfo::make_property_quarks ()
128 Properties::selected.property_id = g_quark_from_static_string (X_("selected"));
129 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for selected = %1\n", Properties::selected.property_id));
130 Properties::color.property_id = g_quark_from_static_string (X_("color"));
131 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for color = %1\n", Properties::color.property_id));
132 Properties::order.property_id = g_quark_from_static_string (X_("order"));
133 DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for order = %1\n", Properties::order.property_id));
136 PresentationInfo::PresentationInfo (Flag f)
138 , _flags (Flag (f & ~OrderSet))
141 /* OrderSet is not set */
144 PresentationInfo::PresentationInfo (order_t o, Flag f)
146 , _flags (Flag (f | OrderSet))
149 /* OrderSet is set */
151 PresentationInfo::PresentationInfo (PresentationInfo const& other)
153 , _order (other.order())
154 , _flags (other.flags())
155 , _color (other.color())
160 PresentationInfo::get_state ()
162 XMLNode* node = new XMLNode (state_node_name);
163 node->set_property ("order", _order);
164 node->set_property ("flags", _flags);
165 node->set_property ("color", _color);
171 PresentationInfo::set_state (XMLNode const& node, int /* version */)
173 if (node.name() != state_node_name) {
180 if (node.get_property (X_("order"), o)) {
182 pc.add (Properties::order);
189 if (node.get_property (X_("flags"), f)) {
190 if ((f&Hidden) != (_flags&Hidden)) {
191 pc.add (Properties::hidden);
197 if (node.get_property (X_("color"), c)) {
199 pc.add (Properties::color);
204 send_change (PropertyChange (pc));
210 PresentationInfo::Flag
211 PresentationInfo::get_flags (XMLNode const& node)
213 XMLNodeList nlist = node.children ();
215 for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter){
216 XMLNode* child = *niter;
218 if (child->name() == PresentationInfo::state_node_name) {
220 if (child->get_property (X_("flags"), f)) {
229 PresentationInfo::set_color (PresentationInfo::color_t c)
233 send_change (PropertyChange (Properties::color));
234 send_static_change (PropertyChange (Properties::color));
239 PresentationInfo::color_set () const
241 /* all RGBA values zero? not set.
243 * this is heuristic, but it is fairly realistic. who will ever set
244 * a color to completely transparent black? only the constructor ..
250 PresentationInfo::set_hidden (bool yn)
252 if (yn != hidden()) {
255 _flags = Flag (_flags | Hidden);
257 _flags = Flag (_flags & ~Hidden);
260 send_change (PropertyChange (Properties::hidden));
261 send_static_change (PropertyChange (Properties::hidden));
266 PresentationInfo::set_order (order_t order)
268 _flags = Flag (_flags|OrderSet);
270 if (order != _order) {
272 send_change (PropertyChange (Properties::order));
273 send_static_change (PropertyChange (Properties::order));
278 PresentationInfo::operator= (PresentationInfo const& other)
280 if (this != &other) {
281 _order = other.order();
282 _flags = other.flags();
283 _color = other.color();
290 operator<<(std::ostream& o, ARDOUR::PresentationInfo const& pi)
292 return o << pi.order() << '/' << enum_2_string (pi.flags()) << '/' << pi.color();