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/convert.h"
23 #include "ardour/debug.h"
24 #include "ardour/automation_control.h"
25 #include "ardour/automation_list.h"
26 #include "ardour/pannable.h"
27 #include "ardour/panner.h"
28 #include "ardour/pan_controllable.h"
29 #include "ardour/session.h"
33 using namespace ARDOUR;
35 Pannable::Pannable (Session& s)
37 , SessionHandleRef (s)
38 , pan_azimuth_control (new PanControllable (s, "", this, PanAzimuthAutomation))
39 , pan_elevation_control (new PanControllable (s, "", this, PanElevationAutomation))
40 , pan_width_control (new PanControllable (s, "", this, PanWidthAutomation))
41 , pan_frontback_control (new PanControllable (s, "", this, PanFrontBackAutomation))
42 , pan_lfe_control (new PanControllable (s, "", this, PanLFEAutomation))
44 , _auto_style (Absolute)
46 , _responding_to_control_auto_state_change (0)
48 add_control (pan_azimuth_control);
49 add_control (pan_elevation_control);
50 add_control (pan_width_control);
51 add_control (pan_frontback_control);
52 add_control (pan_lfe_control);
54 /* all controls change state together */
56 pan_azimuth_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
57 pan_elevation_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
58 pan_width_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
59 pan_frontback_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
60 pan_lfe_control->alist()->automation_state_changed.connect_same_thread (*this, boost::bind (&Pannable::control_auto_state_changed, this, _1));
63 Pannable::~Pannable ()
65 DEBUG_TRACE (DEBUG::Destruction, string_compose ("pannable @ %1 destructor\n", this));
69 Pannable::control_auto_state_changed (AutoState new_state)
71 if (_responding_to_control_auto_state_change) {
75 _responding_to_control_auto_state_change++;
77 pan_azimuth_control->set_automation_state (new_state);
78 pan_width_control->set_automation_state (new_state);
79 pan_elevation_control->set_automation_state (new_state);
80 pan_frontback_control->set_automation_state (new_state);
81 pan_lfe_control->set_automation_state (new_state);
83 _responding_to_control_auto_state_change--;
85 _auto_state = new_state;
86 automation_state_changed (new_state); /* EMIT SIGNAL */
90 Pannable::set_panner (boost::shared_ptr<Panner> p)
96 Pannable::set_automation_state (AutoState state)
98 if (state != _auto_state) {
101 const Controls& c (controls());
103 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
104 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
106 ac->alist()->set_automation_state (state);
110 session().set_dirty ();
111 automation_state_changed (_auto_state);
116 Pannable::set_automation_style (AutoStyle style)
118 if (style != _auto_style) {
121 const Controls& c (controls());
123 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
124 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
126 ac->alist()->set_automation_style (style);
130 session().set_dirty ();
131 automation_style_changed ();
136 Pannable::start_touch (double when)
138 const Controls& c (controls());
140 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
141 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
143 ac->alist()->start_touch (when);
146 g_atomic_int_set (&_touching, 1);
150 Pannable::stop_touch (bool mark, double when)
152 const Controls& c (controls());
154 for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
155 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
157 ac->alist()->stop_touch (mark, when);
160 g_atomic_int_set (&_touching, 0);
164 Pannable::get_state ()
170 Pannable::state (bool full)
172 XMLNode* node = new XMLNode (X_("Pannable"));
173 XMLNode* control_node;
176 control_node = new XMLNode (X_("azimuth"));
177 snprintf (buf, sizeof(buf), "%.12g", pan_azimuth_control->get_value());
178 control_node->add_property (X_("value"), buf);
179 node->add_child_nocopy (*control_node);
181 control_node = new XMLNode (X_("width"));
182 snprintf (buf, sizeof(buf), "%.12g", pan_width_control->get_value());
183 control_node->add_property (X_("value"), buf);
184 node->add_child_nocopy (*control_node);
186 control_node = new XMLNode (X_("elevation"));
187 snprintf (buf, sizeof(buf), "%.12g", pan_elevation_control->get_value());
188 control_node->add_property (X_("value"), buf);
189 node->add_child_nocopy (*control_node);
191 control_node = new XMLNode (X_("frontback"));
192 snprintf (buf, sizeof(buf), "%.12g", pan_frontback_control->get_value());
193 control_node->add_property (X_("value"), buf);
194 node->add_child_nocopy (*control_node);
196 control_node = new XMLNode (X_("lfe"));
197 snprintf (buf, sizeof(buf), "%.12g", pan_lfe_control->get_value());
198 control_node->add_property (X_("value"), buf);
199 node->add_child_nocopy (*control_node);
201 node->add_child_nocopy (get_automation_xml_state ());
207 Pannable::set_state (const XMLNode& root, int /*version - not used*/)
209 if (root.name() != X_("Pannable")) {
210 warning << string_compose (_("Pannable given XML data for %1 - ignored"), root.name()) << endmsg;
215 XMLNodeConstIterator niter;
216 const XMLProperty *prop;
218 nlist = root.children();
220 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
221 if ((*niter)->name() == X_("azimuth")) {
222 prop = (*niter)->property (X_("value"));
224 pan_azimuth_control->set_value (atof (prop->value()));
226 } else if ((*niter)->name() == X_("width")) {
227 prop = (*niter)->property (X_("value"));
229 pan_width_control->set_value (atof (prop->value()));
231 } else if ((*niter)->name() == X_("elevation")) {
232 prop = (*niter)->property (X_("value"));
234 pan_elevation_control->set_value (atof (prop->value()));
236 } else if ((*niter)->name() == X_("azimuth")) {
237 prop = (*niter)->property (X_("value"));
239 pan_frontback_control->set_value (atof (prop->value()));
241 } else if ((*niter)->name() == X_("lfe")) {
242 prop = (*niter)->property (X_("value"));
244 pan_lfe_control->set_value (atof (prop->value()));
246 } else if ((*niter)->name() == Automatable::xml_node_name) {
247 set_automation_xml_state (**niter, PanAzimuthAutomation);
257 Pannable::value_as_string (boost::shared_ptr<AutomationControl> ac) const
259 boost::shared_ptr<Panner> p = panner ();
262 return p->value_as_string (ac);
265 return Automatable::value_as_string (ac);