2 * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2011 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2011 David Robillard <d@drobilla.net>
5 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "pbd/error.h"
24 #include "pbd/compose.h"
26 #include "ardour/boost_debug.h"
27 #include "ardour/debug.h"
28 #include "ardour/automation_control.h"
29 #include "ardour/automation_list.h"
30 #include "ardour/pannable.h"
31 #include "ardour/panner.h"
32 #include "ardour/pan_controllable.h"
33 #include "ardour/session.h"
34 #include "ardour/value_as_string.h"
40 using namespace ARDOUR;
42 Pannable::Pannable (Session& s)
44 , SessionHandleRef (s)
45 , pan_azimuth_control (new PanControllable (s, "", this, PanAzimuthAutomation))
46 , pan_elevation_control (new PanControllable (s, "", this, PanElevationAutomation))
47 , pan_width_control (new PanControllable (s, "", this, PanWidthAutomation))
48 , pan_frontback_control (new PanControllable (s, "", this, PanFrontBackAutomation))
49 , pan_lfe_control (new PanControllable (s, "", this, PanLFEAutomation))
52 , _responding_to_control_auto_state_change (0)
54 //boost_debug_shared_ptr_mark_interesting (this, "pannable");
56 add_control (pan_azimuth_control);
57 add_control (pan_elevation_control);
58 add_control (pan_width_control);
59 add_control (pan_frontback_control);
60 add_control (pan_lfe_control);
62 /* all controls change state together */
64 pan_azimuth_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
65 pan_elevation_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
66 pan_width_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
67 pan_frontback_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
68 pan_lfe_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
70 pan_azimuth_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
71 pan_elevation_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
72 pan_width_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
73 pan_frontback_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
74 pan_lfe_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
77 Pannable::~Pannable ()
79 DEBUG_TRACE (DEBUG::Destruction, string_compose ("pannable @ %1 destructor\n", this));
83 Pannable::control_auto_state_changed (AutoState new_state)
85 if (_responding_to_control_auto_state_change) {
89 _responding_to_control_auto_state_change++;
91 pan_azimuth_control->set_automation_state (new_state);
92 pan_width_control->set_automation_state (new_state);
93 pan_elevation_control->set_automation_state (new_state);
94 pan_frontback_control->set_automation_state (new_state);
95 pan_lfe_control->set_automation_state (new_state);
97 _responding_to_control_auto_state_change--;
99 _auto_state = new_state;
100 automation_state_changed (new_state); /* EMIT SIGNAL */
104 Pannable::set_panner (boost::shared_ptr<Panner> p)
110 Pannable::value_changed ()
113 // prevent the GUI from resetting panners
114 // e.g. when switching to aux-sends and back.
118 _session.set_dirty ();
122 Pannable::set_automation_state (AutoState state)
124 if (state != _auto_state) {
127 const Controls& c (controls());
129 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
130 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
132 ac->alist()->set_automation_state (state);
136 session().set_dirty ();
137 automation_state_changed (_auto_state);
142 Pannable::start_touch (double when)
144 const Controls& c (controls());
146 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
147 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
149 ac->alist()->start_touch (when);
152 g_atomic_int_set (&_touching, 1);
156 Pannable::stop_touch (double when)
158 const Controls& c (controls());
160 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
161 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
163 ac->alist()->stop_touch (when);
166 g_atomic_int_set (&_touching, 0);
170 Pannable::get_state ()
178 XMLNode* node = new XMLNode (X_("Pannable"));
180 node->add_child_nocopy (pan_azimuth_control->get_state());
181 node->add_child_nocopy (pan_width_control->get_state());
182 node->add_child_nocopy (pan_elevation_control->get_state());
183 node->add_child_nocopy (pan_frontback_control->get_state());
184 node->add_child_nocopy (pan_lfe_control->get_state());
186 node->add_child_nocopy (get_automation_xml_state ());
192 Pannable::set_state (const XMLNode& root, int version)
194 if (root.name() != X_("Pannable")) {
195 warning << string_compose (_("Pannable given XML data for %1 - ignored"), root.name()) << endmsg;
199 const XMLNodeList& nlist (root.children());
200 XMLNodeConstIterator niter;
202 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
203 if ((*niter)->name() == Controllable::xml_node_name) {
204 std::string control_name;
206 if (!(*niter)->get_property (X_("name"), control_name)) {
210 if (control_name == pan_azimuth_control->name()) {
211 pan_azimuth_control->set_state (**niter, version);
212 } else if (control_name == pan_width_control->name()) {
213 pan_width_control->set_state (**niter, version);
214 } else if (control_name == pan_elevation_control->name()) {
215 pan_elevation_control->set_state (**niter, version);
216 } else if (control_name == pan_frontback_control->name()) {
217 pan_frontback_control->set_state (**niter, version);
218 } else if (control_name == pan_lfe_control->name()) {
219 pan_lfe_control->set_state (**niter, version);
222 } else if ((*niter)->name() == Automatable::xml_node_name) {
223 set_automation_xml_state (**niter, PanAzimuthAutomation);
226 /* old school (alpha1-6) XML info */
229 if ((*niter)->name() == X_("azimuth")) {
230 if ((*niter)->get_property (X_("value"), val)) {
231 pan_azimuth_control->set_value (val, Controllable::NoGroup);
233 } else if ((*niter)->name() == X_("width")) {
234 if ((*niter)->get_property (X_("value"), val)) {
235 pan_width_control->set_value (val, Controllable::NoGroup);
237 } else if ((*niter)->name() == X_("elevation")) {
238 if ((*niter)->get_property (X_("value"), val)) {
239 pan_elevation_control->set_value (val, Controllable::NoGroup);
241 } else if ((*niter)->name() == X_("frontback")) {
242 if ((*niter)->get_property (X_("value"), val)) {
243 pan_frontback_control->set_value (val, Controllable::NoGroup);
245 } else if ((*niter)->name() == X_("lfe")) {
246 if ((*niter)->get_property (X_("value"), val)) {
247 pan_lfe_control->set_value (val, Controllable::NoGroup);
259 Pannable::value_as_string (boost::shared_ptr<const AutomationControl> ac) const
261 boost::shared_ptr<Panner> p = panner ();
264 return p->value_as_string (ac);
267 return ARDOUR::value_as_string(ac->desc(), ac->get_value());