2 Copyright (C) 2011 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.
20 #include "pbd/error.h"
21 #include "pbd/compose.h"
23 #include "ardour/boost_debug.h"
24 #include "ardour/debug.h"
25 #include "ardour/automation_control.h"
26 #include "ardour/automation_list.h"
27 #include "ardour/pannable.h"
28 #include "ardour/panner.h"
29 #include "ardour/pan_controllable.h"
30 #include "ardour/session.h"
31 #include "ardour/value_as_string.h"
37 using namespace ARDOUR;
39 Pannable::Pannable (Session& s)
41 , SessionHandleRef (s)
42 , pan_azimuth_control (new PanControllable (s, "", this, PanAzimuthAutomation))
43 , pan_elevation_control (new PanControllable (s, "", this, PanElevationAutomation))
44 , pan_width_control (new PanControllable (s, "", this, PanWidthAutomation))
45 , pan_frontback_control (new PanControllable (s, "", this, PanFrontBackAutomation))
46 , pan_lfe_control (new PanControllable (s, "", this, PanLFEAutomation))
49 , _responding_to_control_auto_state_change (0)
51 //boost_debug_shared_ptr_mark_interesting (this, "pannable");
53 add_control (pan_azimuth_control);
54 add_control (pan_elevation_control);
55 add_control (pan_width_control);
56 add_control (pan_frontback_control);
57 add_control (pan_lfe_control);
59 /* all controls change state together */
61 pan_azimuth_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
62 pan_elevation_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
63 pan_width_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
64 pan_frontback_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
65 pan_lfe_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
67 pan_azimuth_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
68 pan_elevation_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
69 pan_width_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
70 pan_frontback_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
71 pan_lfe_control->Changed.connect_same_thread (*this, boost::bind (&Pannable::value_changed, this));
74 Pannable::~Pannable ()
76 DEBUG_TRACE (DEBUG::Destruction, string_compose ("pannable @ %1 destructor\n", this));
80 Pannable::control_auto_state_changed (AutoState new_state)
82 if (_responding_to_control_auto_state_change) {
86 _responding_to_control_auto_state_change++;
88 pan_azimuth_control->set_automation_state (new_state);
89 pan_width_control->set_automation_state (new_state);
90 pan_elevation_control->set_automation_state (new_state);
91 pan_frontback_control->set_automation_state (new_state);
92 pan_lfe_control->set_automation_state (new_state);
94 _responding_to_control_auto_state_change--;
96 _auto_state = new_state;
97 automation_state_changed (new_state); /* EMIT SIGNAL */
101 Pannable::set_panner (boost::shared_ptr<Panner> p)
107 Pannable::value_changed ()
110 // prevent the GUI from resetting panners
111 // e.g. when switching to aux-sends and back.
115 _session.set_dirty ();
119 Pannable::set_automation_state (AutoState state)
121 if (state != _auto_state) {
124 const Controls& c (controls());
126 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
127 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
129 ac->alist()->set_automation_state (state);
133 session().set_dirty ();
134 automation_state_changed (_auto_state);
139 Pannable::start_touch (double when)
141 const Controls& c (controls());
143 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
144 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
146 ac->alist()->start_touch (when);
149 g_atomic_int_set (&_touching, 1);
153 Pannable::stop_touch (double when)
155 const Controls& c (controls());
157 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
158 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
160 ac->alist()->stop_touch (when);
163 g_atomic_int_set (&_touching, 0);
167 Pannable::get_state ()
175 XMLNode* node = new XMLNode (X_("Pannable"));
177 node->add_child_nocopy (pan_azimuth_control->get_state());
178 node->add_child_nocopy (pan_width_control->get_state());
179 node->add_child_nocopy (pan_elevation_control->get_state());
180 node->add_child_nocopy (pan_frontback_control->get_state());
181 node->add_child_nocopy (pan_lfe_control->get_state());
183 node->add_child_nocopy (get_automation_xml_state ());
189 Pannable::set_state (const XMLNode& root, int version)
191 if (root.name() != X_("Pannable")) {
192 warning << string_compose (_("Pannable given XML data for %1 - ignored"), root.name()) << endmsg;
196 const XMLNodeList& nlist (root.children());
197 XMLNodeConstIterator niter;
199 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
200 if ((*niter)->name() == Controllable::xml_node_name) {
201 std::string control_name;
203 if (!(*niter)->get_property (X_("name"), control_name)) {
207 if (control_name == pan_azimuth_control->name()) {
208 pan_azimuth_control->set_state (**niter, version);
209 } else if (control_name == pan_width_control->name()) {
210 pan_width_control->set_state (**niter, version);
211 } else if (control_name == pan_elevation_control->name()) {
212 pan_elevation_control->set_state (**niter, version);
213 } else if (control_name == pan_frontback_control->name()) {
214 pan_frontback_control->set_state (**niter, version);
215 } else if (control_name == pan_lfe_control->name()) {
216 pan_lfe_control->set_state (**niter, version);
219 } else if ((*niter)->name() == Automatable::xml_node_name) {
220 set_automation_xml_state (**niter, PanAzimuthAutomation);
223 /* old school (alpha1-6) XML info */
226 if ((*niter)->name() == X_("azimuth")) {
227 if ((*niter)->get_property (X_("value"), val)) {
228 pan_azimuth_control->set_value (val, Controllable::NoGroup);
230 } else if ((*niter)->name() == X_("width")) {
231 if ((*niter)->get_property (X_("value"), val)) {
232 pan_width_control->set_value (val, Controllable::NoGroup);
234 } else if ((*niter)->name() == X_("elevation")) {
235 if ((*niter)->get_property (X_("value"), val)) {
236 pan_elevation_control->set_value (val, Controllable::NoGroup);
238 } else if ((*niter)->name() == X_("frontback")) {
239 if ((*niter)->get_property (X_("value"), val)) {
240 pan_frontback_control->set_value (val, Controllable::NoGroup);
242 } else if ((*niter)->name() == X_("lfe")) {
243 if ((*niter)->get_property (X_("value"), val)) {
244 pan_lfe_control->set_value (val, Controllable::NoGroup);
256 Pannable::value_as_string (boost::shared_ptr<const AutomationControl> ac) const
258 boost::shared_ptr<Panner> p = panner ();
261 return p->value_as_string (ac);
264 return ARDOUR::value_as_string(ac->desc(), ac->get_value());