along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#define __STDC_FORMAT_MACROS 1
#include <pbd/error.h>
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
+#include <pbd/enumwriter.h>
#include <ardour/session.h>
#include <ardour/panner.h>
#include <ardour/utils.h>
-#include <ardour/mix.h>
+#include <ardour/runtime_functions.h>
#include <ardour/buffer_set.h>
#include "i18n.h"
return val;
}
-StreamPanner::StreamPanner (Panner& p)
- : parent (p),
- _control (X_("panner"), *this)
+StreamPanner::StreamPanner (Panner& p, Evoral::Parameter param)
+ : parent (p)
+ , _control (new PanControllable(p.session(), X_("panner"), *this, param))
{
+ assert(param.type() != NullAutomation);
+
_muted = false;
- parent.session().add_controllable (&_control);
+ parent.session().add_controllable (_control);
x = 0.5;
y = 0.5;
return direct_pan_to_control (xpos);
}
-bool
-StreamPanner::PanControllable::can_send_feedback () const
-{
- AutoState astate = panner.get_parent().automation_state ();
-
- if ((astate == Play) || (astate == Touch && !panner.get_parent().touching())) {
- return true;
- }
-
- return false;
-}
-
void
StreamPanner::set_muted (bool yn)
{
x = xpos;
update ();
Changed ();
- _control.Changed ();
+ _control->Changed ();
}
}
/*---------------------------------------------------------------------- */
-BaseStereoPanner::BaseStereoPanner (Panner& p)
- : StreamPanner (p), _automation (0.0, 1.0, 0.5)
+BaseStereoPanner::BaseStereoPanner (Panner& p, Evoral::Parameter param)
+ : StreamPanner (p, param)
{
}
{
}
-void
-BaseStereoPanner::snapshot (nframes_t now)
-{
- if (_automation.automation_state() == Write || _automation.automation_state() == Touch) {
- _automation.rt_add (now, x);
- }
-}
-
-void
-BaseStereoPanner::transport_stopped (nframes_t frame)
-{
- _automation.reposition_for_rt_add (frame);
-
- if (_automation.automation_state() != Off) {
- set_position (_automation.eval (frame));
- }
-}
-
-void
-BaseStereoPanner::set_automation_style (AutoStyle style)
-{
- _automation.set_automation_style (style);
-}
-
-void
-BaseStereoPanner::set_automation_state (AutoState state)
-{
- if (state != _automation.automation_state()) {
-
- _automation.set_automation_state (state);
-
- if (state != Off) {
- set_position (_automation.eval (parent.session().transport_frame()));
- }
- }
-}
-
int
BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
{
char line[128];
LocaleGuard lg (X_("POSIX"));
- _automation.clear ();
+ _control->list()->clear ();
while (in.getline (line, sizeof (line), '\n')) {
- jack_nframes_t when;
+ nframes_t when;
double value;
++linecnt;
continue;
}
- _automation.fast_simple_add (when, value);
+ _control->list()->fast_simple_add (when, value);
}
/* now that we are done loading */
- _automation.StateChanged ();
+ ((AutomationList*)_control->list().get())->StateChanged ();
return 0;
}
void
BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes)
{
- assert(obufs.count().get(DataType::AUDIO) == 2);
+ assert(obufs.count().n_audio() == 2);
pan_t delta;
Sample* dst;
return;
}
- Sample* const src = srcbuf.data(nframes);
+ Sample* const src = srcbuf.data();
/* LEFT */
- dst = obufs.get_audio(0).data(nframes);
+ dst = obufs.get_audio(0).data();
if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
pan = left * gain_coeff;
- Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
+ mix_buffers_with_gain (dst+n,src+n,nframes-n,pan);
} else {
if (pan != 0.0f) {
- Session::mix_buffers_with_gain(dst,src,nframes,pan);
+ mix_buffers_with_gain(dst,src,nframes,pan);
/* mark that we wrote into the buffer */
} else {
- Session::mix_buffers_no_gain(dst,src,nframes);
+ mix_buffers_no_gain(dst,src,nframes);
/* mark that we wrote into the buffer */
/* RIGHT */
- dst = obufs.get_audio(1).data(nframes);
+ dst = obufs.get_audio(1).data();
if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
pan = right * gain_coeff;
- Session::mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
+ mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
/* XXX it would be nice to mark the buffer as written to */
if (pan != 0.0f) {
- Session::mix_buffers_with_gain(dst,src,nframes,pan);
+ mix_buffers_with_gain(dst,src,nframes,pan);
/* XXX it would be nice to mark the buffer as written to */
}
} else {
- Session::mix_buffers_no_gain(dst,src,nframes);
+ mix_buffers_no_gain(dst,src,nframes);
/* XXX it would be nice to mark the buffer as written to */
}
/*---------------------------------------------------------------------- */
-EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
- : BaseStereoPanner (p)
+EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p, Evoral::Parameter param)
+ : BaseStereoPanner (p, param)
{
update ();
desired_right = panR * (scale * panR + 1.0f - scale);
effective_x = x;
+ _control->set_value(x);
}
void
nframes_t start, nframes_t end, nframes_t nframes,
pan_t** buffers)
{
- assert(obufs.count().get(DataType::AUDIO) == 2);
+ assert(obufs.count().n_audio() == 2);
Sample* dst;
pan_t* pbuf;
- Sample* const src = srcbuf.data(nframes);
+ Sample* const src = srcbuf.data();
/* fetch positional data */
- if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
+ if (!_control->list()->curve().rt_safe_get_vector (start, end, buffers[0], nframes)) {
/* fallback */
if (!_muted) {
distribute (srcbuf, obufs, 1.0, nframes);
/* store effective pan position. do this even if we are muted */
- if (nframes > 0)
+ if (nframes > 0) {
effective_x = buffers[0][nframes-1];
+ _control->set_value(effective_x); // signal, update UI
+ }
if (_muted) {
return;
/* LEFT */
- dst = obufs.get_audio(0).data(nframes);
+ dst = obufs.get_audio(0).data();
pbuf = buffers[0];
for (nframes_t n = 0; n < nframes; ++n) {
/* RIGHT */
- dst = obufs.get_audio(1).data(nframes);
+ dst = obufs.get_audio(1).data();
pbuf = buffers[1];
for (nframes_t n = 0; n < nframes; ++n) {
}
StreamPanner*
-EqualPowerStereoPanner::factory (Panner& parent)
+EqualPowerStereoPanner::factory (Panner& parent, Evoral::Parameter param)
{
- return new EqualPowerStereoPanner (parent);
+ return new EqualPowerStereoPanner (parent, param);
}
XMLNode&
root->add_property (X_("type"), EqualPowerStereoPanner::name);
XMLNode* autonode = new XMLNode (X_("Automation"));
- autonode->add_child_nocopy (_automation.state (full_state));
+ autonode->add_child_nocopy (((AutomationList*)_control->list().get())->state (full_state));
root->add_child_nocopy (*autonode);
StreamPanner::add_state (*root);
- root->add_child_nocopy (_control.get_state ());
+ root->add_child_nocopy (_control->get_state ());
return *root;
}
for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
- if ((*iter)->name() == X_("panner")) {
-
- _control.set_state (**iter);
+ if ((*iter)->name() == X_("controllable")) {
+ if ((prop = (*iter)->property("name")) != 0 && prop->value() == "panner") {
+ _control->set_state (**iter);
+ }
} else if ((*iter)->name() == X_("Automation")) {
- _automation.set_state (*((*iter)->children().front()));
+ _control->alist()->set_state (*((*iter)->children().front()));
- if (_automation.automation_state() != Off) {
- set_position (_automation.eval (parent.session().transport_frame()));
+ if (_control->alist()->automation_state() != Off) {
+ set_position (_control->list()->eval (parent.session().transport_frame()));
}
}
}
/*----------------------------------------------------------------------*/
-Multi2dPanner::Multi2dPanner (Panner& p)
- : StreamPanner (p), _automation (0.0, 1.0, 0.5) // XXX useless
+Multi2dPanner::Multi2dPanner (Panner& p, Evoral::Parameter param)
+ : StreamPanner (p, param)
{
update ();
}
{
}
-void
-Multi2dPanner::snapshot (nframes_t now)
-{
- // how?
-}
-
-void
-Multi2dPanner::transport_stopped (nframes_t frame)
-{
- //what?
-}
-
-void
-Multi2dPanner::set_automation_style (AutoStyle style)
-{
- //what?
-}
-
-void
-Multi2dPanner::set_automation_state (AutoState state)
-{
- // what?
-}
-
void
Multi2dPanner::update ()
{
}
effective_x = x;
+ _control->set_value(x);
}
void
return;
}
- Sample* const src = srcbuf.data(nframes);
+ Sample* const src = srcbuf.data();
for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
- dst = obufs.get_audio(n).data(nframes);
+ dst = obufs.get_audio(n).data();
#ifdef CAN_INTERP
if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
}
pan = left * gain_coeff;
-
- for (; n < nframes; ++n) {
- dst[n] += src[n] * pan;
- }
+ mix_buffers_with_gain(dst+n,src+n,nframes-n,pan);
} else {
if ((pan *= gain_coeff) != 1.0f) {
if (pan != 0.0f) {
-
- for (nframes_t n = 0; n < nframes; ++n) {
- dst[n] += src[n] * pan;
- }
-
+ mix_buffers_with_gain(dst,src,nframes,pan);
}
-
-
} else {
-
- for (nframes_t n = 0; n < nframes; ++n) {
- dst[n] += src[n];
- }
-
+ mix_buffers_no_gain(dst,src,nframes);
}
#endif
#ifdef CAN_INTERP
}
StreamPanner*
-Multi2dPanner::factory (Panner& p)
+Multi2dPanner::factory (Panner& p, Evoral::Parameter param)
{
- return new Multi2dPanner (p);
+ return new Multi2dPanner (p, param);
}
int
outputs.push_back (Output (1.0, 0));
for (n = 0; n < npans; ++n) {
- push_back (new EqualPowerStereoPanner (*this));
+ push_back (new EqualPowerStereoPanner (*this, Evoral::Parameter(PanAutomation, n)));
}
break;
outputs.push_back (Output (1.0, 1.0));
for (n = 0; n < npans; ++n) {
- push_back (new Multi2dPanner (*this));
+ push_back (new Multi2dPanner (*this, Evoral::Parameter(PanAutomation, n)));
}
break;
outputs.push_back (Output (0, 1.0));
for (n = 0; n < npans; ++n) {
- push_back (new Multi2dPanner (*this));
+ push_back (new Multi2dPanner (*this, Evoral::Parameter(PanAutomation, n)));
}
break;
outputs.push_back (Output (0.5, 0.75));
for (n = 0; n < npans; ++n) {
- push_back (new Multi2dPanner (*this));
+ push_back (new Multi2dPanner (*this, Evoral::Parameter(PanAutomation, n)));
}
break;
}
for (n = 0; n < npans; ++n) {
- push_back (new Multi2dPanner (*this));
+ push_back (new Multi2dPanner (*this, Evoral::Parameter(PanAutomation, n)));
}
break;
if (changed || ((left == 0.5) && (right == 0.5))) {
front()->set_position (0.0);
- front()->automation().reset_default (0.0);
+ front()->pan_control()->list()->reset_default (0.0);
back()->set_position (1.0);
- back()->automation().reset_default (1.0);
+ back()->pan_control()->list()->reset_default (1.0);
changed = true;
}
Panner::set_automation_style (AutoStyle style)
{
for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
- (*i)->set_automation_style (style);
+ ((AutomationList*)(*i)->pan_control()->list().get())->set_automation_style (style);
}
_session.set_dirty ();
}
Panner::set_automation_state (AutoState state)
{
for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
- (*i)->set_automation_state (state);
+ ((AutomationList*)(*i)->pan_control()->list().get())->set_automation_state (state);
}
_session.set_dirty ();
}
Panner::automation_state () const
{
if (!empty()) {
- return front()->automation().automation_state ();
+ return ((AutomationList*)front()->pan_control()->list().get())->automation_state ();
} else {
return Off;
}
Panner::automation_style () const
{
if (!empty()) {
- return front()->automation().automation_style ();
+ return ((AutomationList*)front()->pan_control()->list().get())->automation_style ();
} else {
return Absolute;
}
Panner::transport_stopped (nframes_t frame)
{
for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
- (*i)->transport_stopped (frame);
+ ((AutomationList*)(*i)->pan_control()->list().get())->reposition_for_rt_add (frame);
}
}
Panner::snapshot (nframes_t now)
{
for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
- (*i)->snapshot (now);
+ AutomationList* list = ((AutomationList*)(*i)->pan_control()->list().get());
+ if (list->automation_write())
+ list->rt_add(now, (*i)->pan_control()->get_value());
}
}
Panner::clear_automation ()
{
for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
- (*i)->automation().clear ();
+ (*i)->pan_control()->list()->clear ();
}
_session.set_dirty ();
}
struct PanPlugins {
string name;
uint32_t nouts;
- StreamPanner* (*factory)(Panner&);
+ StreamPanner* (*factory)(Panner&, Evoral::Parameter);
};
PanPlugins pan_plugins[] = {
char buf[32];
root->add_property (X_("linked"), (_linked ? "yes" : "no"));
- snprintf (buf, sizeof (buf), "%d", _link_direction);
- root->add_property (X_("link_direction"), buf);
+ root->add_property (X_("link_direction"), enum_2_string (_link_direction));
root->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
/* add each output */
}
if ((prop = node.property (X_("link_direction"))) != 0) {
- sscanf (prop->value().c_str(), "%d", &i);
- set_link_direction ((LinkDirection) (i));
+ LinkDirection ld; /* here to provide type information */
+ set_link_direction (LinkDirection (string_2_enum (prop->value(), ld)));
}
nlist = node.children();
assumption, but its still an assumption.
*/
- sp = pan_plugins[i].factory (*this);
+ sp = pan_plugins[i].factory (*this, Evoral::Parameter(PanAutomation, 0));
if (sp->set_state (**niter) == 0) {
push_back (sp);
/* automation path is relative */
- automation_path = _session.automation_dir();
- automation_path += prop->value ();
+ automation_path = Glib::build_filename(_session.automation_dir(), prop->value ());
}
return 0;
Panner::touching () const
{
for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
- if ((*i)->automation().touching ()) {
+ if (((AutomationList*)(*i)->pan_control()->list().get())->touching ()) {
return true;
}
}
void
Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes_t nframes, nframes_t offset, gain_t gain_coeff)
{
- if (outbufs.count().get(DataType::AUDIO) == 0) {
+ if (outbufs.count().n_audio() == 0) {
// Don't want to lose audio...
- assert(inbufs.count().get(DataType::AUDIO) == 0);
+ assert(inbufs.count().n_audio() == 0);
return;
}
assert(!empty());
- if (outbufs.count().get(DataType::AUDIO) == 1) {
+ if (outbufs.count().n_audio() == 1) {
AudioBuffer& dst = outbufs.get_audio(0);
dst.read_from(inbufs.get_audio(0), nframes, offset);
// accumulate starting with the second
- BufferSet::audio_iterator i = inbufs.audio_begin();
- for (++i; i != inbufs.audio_end(); ++i) {
- dst.accumulate_from(*i, nframes, offset);
- }
+ if (inbufs.count().n_audio() > 0) {
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (++i; i != inbufs.audio_end(); ++i) {
+ dst.accumulate_from(*i, nframes, offset);
+ }
+ }
} else {
dst.read_from(inbufs.get_audio(0), nframes, offset);
// accumulate (with gain) starting with the second
- BufferSet::audio_iterator i = inbufs.audio_begin();
- for (++i; i != inbufs.audio_end(); ++i) {
- dst.accumulate_with_gain_from(*i, nframes, offset, gain_coeff);
- }
+ if (inbufs.count().n_audio() > 0) {
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (++i; i != inbufs.audio_end(); ++i) {
+ dst.accumulate_with_gain_from(*i, nframes, offset, gain_coeff);
+ }
+ }
}
return;
}
-
- // More than 1 output, we should have 1 panner for each input
- assert(size() == inbufs.count().get(DataType::AUDIO));
/* the terrible silence ... */
for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
}
BufferSet::audio_iterator i = inbufs.audio_begin();
- for (iterator pan = begin(); pan != end(); ++pan, ++i) {
+
+ for (iterator pan = begin(); pan != end() && i != inbufs.audio_end(); ++pan, ++i) {
(*pan)->distribute (*i, outbufs, gain_coeff, nframes);
}
}
void
Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
{
- if (outbufs.count().get(DataType::AUDIO) == 0) {
+ if (outbufs.count().n_audio() == 0) {
// Failing to deliver audio we were asked to deliver is a bug
- assert(inbufs.count().get(DataType::AUDIO) == 0);
+ assert(inbufs.count().n_audio() == 0);
return;
}
// Otherwise.. let the automation flow, baby
- if (outbufs.count().get(DataType::AUDIO) == 1) {
+ if (outbufs.count().n_audio() == 1) {
AudioBuffer& dst = outbufs.get_audio(0);
}
// More than 1 output, we should have 1 panner for each input
- assert(size() == inbufs.count().get(DataType::AUDIO));
+ assert(size() == inbufs.count().n_audio());
/* the terrible silence ... */
for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
void
Panner::set_name (string str)
{
- automation_path = _session.automation_dir();
- automation_path += _session.snap_name();
- automation_path += "-pan-";
- automation_path += legalize_for_path (str);
- automation_path += ".automation";
+ automation_path = Glib::build_filename(_session.automation_dir(),
+ _session.snap_name() + "-pan-" + legalize_for_path (str) + ".automation");
}
int