Coding style cleanups. Preserve mono state in XML for panners.

git-svn-id: svn://localhost/ardour2/branches/3.0@6640 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2010-02-07 02:45:55 +00:00
parent 8d64ce26c4
commit 420e28f4d8
3 changed files with 64 additions and 66 deletions

View file

@ -48,15 +48,14 @@ class StreamPanner : public PBD::Stateful
void set_muted (bool yn); void set_muted (bool yn);
bool muted() const { return _muted; } bool muted() const { return _muted; }
void set_mono (bool);
void set_position (float x, bool link_call = false); void set_position (float x, bool link_call = false);
void set_position (float x, float y, bool link_call = false); void set_position (float x, float y, bool link_call = false);
void set_position (float x, float y, float z, bool link_call = false); void set_position (float x, float y, float z, bool link_call = false);
void get_position (float& xpos) const { xpos = x; } void get_position (float& xpos) const { xpos = _x; }
void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; } void get_position (float& xpos, float& ypos) const { xpos = _x; ypos = _y; }
void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; } void get_position (float& xpos, float& ypos, float& zpos) const { xpos = _x; ypos = _y; zpos = _z; }
void get_effective_position (float& xpos) const { xpos = effective_x; } void get_effective_position (float& xpos) const { xpos = effective_x; }
void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; } void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
@ -73,7 +72,7 @@ class StreamPanner : public PBD::Stateful
* @param src Input buffer. * @param src Input buffer.
* @param obufs Output buffers (one per panner output). * @param obufs Output buffers (one per panner output).
* @param gain_coeff Gain coefficient to apply to output samples. * @param gain_coeff Gain coefficient to apply to output samples.
* @param nframes Numbner of frames in the input. * @param nframes Number of frames in the input.
*/ */
virtual void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0; virtual void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
virtual void do_distribute_automated (AudioBuffer& src, BufferSet& obufs, virtual void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
@ -82,7 +81,7 @@ class StreamPanner : public PBD::Stateful
boost::shared_ptr<AutomationControl> pan_control() { return _control; } boost::shared_ptr<AutomationControl> pan_control() { return _control; }
PBD::Signal0<void> Changed; /* for position */ PBD::Signal0<void> Changed; /* for position */
PBD::Signal0<void> StateChanged; /* for mute */ PBD::Signal0<void> StateChanged; /* for mute, mono */
int set_state (const XMLNode&, int version); int set_state (const XMLNode&, int version);
virtual XMLNode& state (bool full_state) = 0; virtual XMLNode& state (bool full_state) = 0;
@ -90,16 +89,17 @@ class StreamPanner : public PBD::Stateful
Panner & get_parent() { return parent; } Panner & get_parent() { return parent; }
/* old school automation loading */ /* old school automation loading */
virtual int load (std::istream&, std::string path, uint32_t&) = 0; virtual int load (std::istream&, std::string path, uint32_t&) = 0;
protected: protected:
friend class Panner; friend class Panner;
Panner& parent; Panner& parent;
float x; void set_mono (bool);
float y;
float z; float _x;
float _y;
float _z;
/* these are for automation. they store the last value /* these are for automation. they store the last value
used by the most recent process() cycle. used by the most recent process() cycle.
@ -115,6 +115,8 @@ class StreamPanner : public PBD::Stateful
boost::shared_ptr<AutomationControl> _control; boost::shared_ptr<AutomationControl> _control;
void add_state (XMLNode&); void add_state (XMLNode&);
/* Update internal parameters based on _x, _y and _z */
virtual void update () = 0; virtual void update () = 0;
}; };
@ -194,8 +196,9 @@ class Multi2dPanner : public StreamPanner
}; };
///< Class to pan from some number of inputs to some number of outputs /** Class to pan from some number of inputs to some number of outputs.
* This class has a number of StreamPanners, one for each input.
*/
class Panner : public SessionObject, public AutomatableControls class Panner : public SessionObject, public AutomatableControls
{ {
public: public:
@ -206,11 +209,10 @@ public:
pan_t desired_pan; pan_t desired_pan;
Output (float xp, float yp) Output (float xp, float yp)
: x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {} : x (xp), y (yp), current_pan (0), desired_pan (0) {}
}; };
//Panner (std::string name, Session&, int _num_bufs);
Panner (std::string name, Session&); Panner (std::string name, Session&);
virtual ~Panner (); virtual ~Panner ();
@ -228,9 +230,6 @@ public:
/// The fundamental Panner function /// The fundamental Panner function
void run (BufferSet& src, BufferSet& dest, sframes_t start_frame, sframes_t end_frames, nframes_t nframes); void run (BufferSet& src, BufferSet& dest, sframes_t start_frame, sframes_t end_frames, nframes_t nframes);
//void* get_inline_gui() const = 0;
//void* get_full_gui() const = 0;
bool bypassed() const { return _bypassed; } bool bypassed() const { return _bypassed; }
void set_bypassed (bool yn); void set_bypassed (bool yn);
bool mono () const { return _mono; } bool mono () const { return _mono; }
@ -254,8 +253,6 @@ public:
uint32_t nouts() const { return outputs.size(); } uint32_t nouts() const { return outputs.size(); }
Output& output (uint32_t n) { return outputs[n]; } Output& output (uint32_t n) { return outputs[n]; }
std::vector<Output> outputs;
enum LinkDirection { enum LinkDirection {
SameDirection, SameDirection,
OppositeDirection OppositeDirection
@ -299,11 +296,11 @@ public:
}; };
boost::shared_ptr<AutomationControl> pan_control (int id, int chan=0) { boost::shared_ptr<AutomationControl> pan_control (int id, int chan=0) {
return automation_control(Evoral::Parameter (PanAutomation, chan, id)); return automation_control (Evoral::Parameter (PanAutomation, chan, id));
} }
boost::shared_ptr<const AutomationControl> pan_control (int id, int chan=0) const { boost::shared_ptr<const AutomationControl> pan_control (int id, int chan=0) const {
return automation_control(Evoral::Parameter (PanAutomation, chan, id)); return automation_control (Evoral::Parameter (PanAutomation, chan, id));
} }
private: private:
@ -312,6 +309,7 @@ public:
void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, gain_t gain_coeff); void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, gain_t gain_coeff);
std::vector<StreamPanner*> _streampanners; ///< one StreamPanner per input std::vector<StreamPanner*> _streampanners; ///< one StreamPanner per input
std::vector<Output> outputs;
uint32_t current_outs; uint32_t current_outs;
bool _linked; bool _linked;
bool _bypassed; bool _bypassed;

View file

@ -61,32 +61,29 @@ float Panner::current_automation_version_number = 1.0;
string EqualPowerStereoPanner::name = "Equal Power Stereo"; string EqualPowerStereoPanner::name = "Equal Power Stereo";
string Multi2dPanner::name = "Multiple (2D)"; string Multi2dPanner::name = "Multiple (2D)";
/* this is a default mapper of control values to a pan position /* this is a default mapper of control values to a pan position
others can be imagined. others can be imagined.
*/ */
static pan_t direct_control_to_pan (double fract) { static pan_t direct_control_to_pan (double fract)
{
return fract; return fract;
} }
//static double direct_pan_to_control (pan_t val) {
// return val;
//}
StreamPanner::StreamPanner (Panner& p, Evoral::Parameter param) StreamPanner::StreamPanner (Panner& p, Evoral::Parameter param)
: parent (p) : parent (p)
{ {
assert(param.type() != NullAutomation); assert (param.type() != NullAutomation);
_muted = false; _muted = false;
_mono = false; _mono = false;
_control = boost::dynamic_pointer_cast<AutomationControl>( parent.control( param, true ) ); /* get our AutomationControl from our parent Panner, creating it if required */
_control = boost::dynamic_pointer_cast<AutomationControl> (parent.control (param, true));
x = 0.5; _x = 0.5;
y = 0.5; _y = 0.5;
z = 0.5; _z = 0.5;
} }
StreamPanner::~StreamPanner () StreamPanner::~StreamPanner ()
@ -105,7 +102,7 @@ StreamPanner::set_mono (bool yn)
void void
Panner::PanControllable::set_value (float val) Panner::PanControllable::set_value (float val)
{ {
panner.streampanner(parameter().id()).set_position (direct_control_to_pan (val)); panner.streampanner (parameter().id()).set_position (direct_control_to_pan (val));
AutomationControl::set_value(val); AutomationControl::set_value(val);
} }
@ -131,8 +128,8 @@ StreamPanner::set_position (float xpos, bool link_call)
parent.set_position (xpos, *this); parent.set_position (xpos, *this);
} }
if (x != xpos) { if (_x != xpos) {
x = xpos; _x = xpos;
update (); update ();
Changed (); Changed ();
_control->Changed (); _control->Changed ();
@ -146,10 +143,9 @@ StreamPanner::set_position (float xpos, float ypos, bool link_call)
parent.set_position (xpos, ypos, *this); parent.set_position (xpos, ypos, *this);
} }
if (x != xpos || y != ypos) { if (_x != xpos || _y != ypos) {
_x = xpos;
x = xpos; _y = ypos;
y = ypos;
update (); update ();
Changed (); Changed ();
} }
@ -162,10 +158,10 @@ StreamPanner::set_position (float xpos, float ypos, float zpos, bool link_call)
parent.set_position (xpos, ypos, zpos, *this); parent.set_position (xpos, ypos, zpos, *this);
} }
if (x != xpos || y != ypos || z != zpos) { if (_x != xpos || _y != ypos || _z != zpos) {
x = xpos; _x = xpos;
y = ypos; _y = ypos;
z = zpos; _z = zpos;
update (); update ();
Changed (); Changed ();
} }
@ -181,6 +177,10 @@ StreamPanner::set_state (const XMLNode& node, int /*version*/)
set_muted (string_is_affirmative (prop->value())); set_muted (string_is_affirmative (prop->value()));
} }
if ((prop = node.property (X_("mono")))) {
set_mono (string_is_affirmative (prop->value()));
}
return 0; return 0;
} }
@ -188,6 +188,7 @@ void
StreamPanner::add_state (XMLNode& node) StreamPanner::add_state (XMLNode& node)
{ {
node.add_property (X_("muted"), (muted() ? "yes" : "no")); node.add_property (X_("muted"), (muted() ? "yes" : "no"));
node.add_property (X_("mono"), (_mono ? "yes" : "no"));
} }
void void
@ -426,16 +427,16 @@ EqualPowerStereoPanner::update ()
x == 1 => hard right x == 1 => hard right
*/ */
float panR = x; float const panR = _x;
float panL = 1 - panR; float const panL = 1 - panR;
const float pan_law_attenuation = -3.0f; float const pan_law_attenuation = -3.0f;
const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f); float const scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
desired_left = panL * (scale * panL + 1.0f - scale); desired_left = panL * (scale * panL + 1.0f - scale);
desired_right = panR * (scale * panR + 1.0f - scale); desired_right = panR * (scale * panR + 1.0f - scale);
effective_x = x; effective_x = _x;
//_control->set_value(x); //_control->set_value(x);
} }
@ -444,7 +445,7 @@ EqualPowerStereoPanner::do_distribute_automated (AudioBuffer& srcbuf, BufferSet&
nframes_t start, nframes_t end, nframes_t nframes, nframes_t start, nframes_t end, nframes_t nframes,
pan_t** buffers) pan_t** buffers)
{ {
assert(obufs.count().n_audio() == 2); assert (obufs.count().n_audio() == 2);
Sample* dst; Sample* dst;
pan_t* pbuf; pan_t* pbuf;
@ -479,8 +480,8 @@ EqualPowerStereoPanner::do_distribute_automated (AudioBuffer& srcbuf, BufferSet&
for (nframes_t n = 0; n < nframes; ++n) { for (nframes_t n = 0; n < nframes; ++n) {
float panR = buffers[0][n]; float const panR = buffers[0][n];
float panL = 1 - panR; float const panL = 1 - panR;
buffers[0][n] = panL * (scale * panL + 1.0f - scale); buffers[0][n] = panL * (scale * panL + 1.0f - scale);
buffers[1][n] = panR * (scale * panR + 1.0f - scale); buffers[1][n] = panR * (scale * panR + 1.0f - scale);
@ -528,7 +529,7 @@ EqualPowerStereoPanner::state (bool /*full_state*/)
char buf[64]; char buf[64];
LocaleGuard lg (X_("POSIX")); LocaleGuard lg (X_("POSIX"));
snprintf (buf, sizeof (buf), "%.12g", x); snprintf (buf, sizeof (buf), "%.12g", _x);
root->add_property (X_("x"), buf); root->add_property (X_("x"), buf);
root->add_property (X_("type"), EqualPowerStereoPanner::name); root->add_property (X_("type"), EqualPowerStereoPanner::name);
@ -592,7 +593,7 @@ Multi2dPanner::update ()
{ {
static const float BIAS = FLT_MIN; static const float BIAS = FLT_MIN;
uint32_t i; uint32_t i;
uint32_t nouts = parent.outputs.size(); uint32_t const nouts = parent.nouts ();
float dsq[nouts]; float dsq[nouts];
float f, fr; float f, fr;
vector<pan_t> pans; vector<pan_t> pans;
@ -600,7 +601,7 @@ Multi2dPanner::update ()
f = 0.0f; f = 0.0f;
for (i = 0; i < nouts; i++) { for (i = 0; i < nouts; i++) {
dsq[i] = ((x - parent.outputs[i].x) * (x - parent.outputs[i].x) + (y - parent.outputs[i].y) * (y - parent.outputs[i].y) + BIAS); dsq[i] = ((_x - parent.output(i).x) * (_x - parent.output(i).x) + (_y - parent.output(i).y) * (_y - parent.output(i).y) + BIAS);
if (dsq[i] < 0.0) { if (dsq[i] < 0.0) {
dsq[i] = 0.0; dsq[i] = 0.0;
} }
@ -613,10 +614,10 @@ Multi2dPanner::update ()
fr = 1.0 / sqrtf(f); fr = 1.0 / sqrtf(f);
#endif #endif
for (i = 0; i < nouts; ++i) { for (i = 0; i < nouts; ++i) {
parent.outputs[i].desired_pan = 1.0f - (dsq[i] * fr); parent.output(i).desired_pan = 1.0f - (dsq[i] * fr);
} }
effective_x = x; effective_x = _x;
} }
void void
@ -624,8 +625,6 @@ Multi2dPanner::do_distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
{ {
Sample* dst; Sample* dst;
pan_t pan; pan_t pan;
vector<Panner::Output>::iterator o;
uint32_t n;
if (_muted) { if (_muted) {
return; return;
@ -633,8 +632,9 @@ Multi2dPanner::do_distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
Sample* const src = srcbuf.data(); Sample* const src = srcbuf.data();
uint32_t const N = parent.nouts ();
for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) { for (uint32_t n = 0; n < N; ++n) {
Panner::Output& o = parent.output (n);
dst = obufs.get_audio(n).data(); dst = obufs.get_audio(n).data();
@ -660,13 +660,14 @@ Multi2dPanner::do_distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
} else { } else {
#else #else
pan = (*o).desired_pan; pan = o.desired_pan;
if ((pan *= gain_coeff) != 1.0f) { if ((pan *= gain_coeff) != 1.0f) {
if (pan != 0.0f) { if (pan != 0.0f) {
mix_buffers_with_gain(dst,src,nframes,pan); mix_buffers_with_gain(dst,src,nframes,pan);
} }
} else { } else {
mix_buffers_no_gain(dst,src,nframes); mix_buffers_no_gain(dst,src,nframes);
} }
@ -718,9 +719,9 @@ Multi2dPanner::state (bool /*full_state*/)
char buf[64]; char buf[64];
LocaleGuard lg (X_("POSIX")); LocaleGuard lg (X_("POSIX"));
snprintf (buf, sizeof (buf), "%.12g", x); snprintf (buf, sizeof (buf), "%.12g", _x);
root->add_property (X_("x"), buf); root->add_property (X_("x"), buf);
snprintf (buf, sizeof (buf), "%.12g", y); snprintf (buf, sizeof (buf), "%.12g", _y);
root->add_property (X_("y"), buf); root->add_property (X_("y"), buf);
root->add_property (X_("type"), Multi2dPanner::name); root->add_property (X_("type"), Multi2dPanner::name);
@ -747,7 +748,7 @@ Multi2dPanner::set_state (const XMLNode& node, int /*version*/)
newy = atof (prop->value().c_str()); newy = atof (prop->value().c_str());
} }
if (x < 0 || y < 0) { if (_x < 0 || _y < 0) {
error << _("badly-formed positional data for Multi2dPanner - ignored") error << _("badly-formed positional data for Multi2dPanner - ignored")
<< endmsg; << endmsg;
return -1; return -1;

View file

@ -64,7 +64,6 @@ ControlSet::control (const Parameter& parameter, bool create_if_missing)
return ac; return ac;
} else { } else {
//warning << "ControlList " << parameter.to_string() << " not found for " << _name << endmsg;
return boost::shared_ptr<Control>(); return boost::shared_ptr<Control>();
} }
} }