X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fcrossfade.cc;h=46a8e6e40086cc34276cb85a2eb575ebcd2cd246;hb=1bd4c5b3a212460eed1773f6b049d18c89625565;hp=379c9333b04ff088e30022ace8259284a72e8a96;hpb=d4dd338beb813bcfe7470729cf6611aeea55cfa4;p=ardour.git diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index 379c9333b0..46a8e6e400 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2003 Paul Davis + Copyright (C) 2003-2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,8 +35,9 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -jack_nframes_t Crossfade::_short_xfade_length = 0; -Change Crossfade::ActiveChanged = ARDOUR::new_change(); +nframes_t Crossfade::_short_xfade_length = 0; +Change Crossfade::ActiveChanged = new_change(); +Change Crossfade::FollowOverlapChanged = new_change(); /* XXX if and when we ever implement parallel processing of the process() callback, these will need to be handled on a per-thread basis. @@ -46,7 +47,7 @@ Sample* Crossfade::crossfade_buffer_out = 0; Sample* Crossfade::crossfade_buffer_in = 0; void -Crossfade::set_buffer_size (jack_nframes_t sz) +Crossfade::set_buffer_size (nframes_t sz) { if (crossfade_buffer_out) { delete [] crossfade_buffer_out; @@ -70,26 +71,34 @@ Crossfade::operator== (const Crossfade& other) return (_in == other._in) && (_out == other._out); } -Crossfade::Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, - jack_nframes_t length, - jack_nframes_t position, +Crossfade::Crossfade (boost::shared_ptr in, boost::shared_ptr out, + nframes_t length, + nframes_t position, AnchorPoint ap) : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB { - _in = ∈ - _out = &out; + _in = in; + _out = out; _length = length; _position = position; _anchor_point = ap; - _follow_overlap = false; - _active = true; + + switch (Config->get_xfade_model()) { + case ShortCrossfade: + _follow_overlap = false; + break; + default: + _follow_overlap = true; + } + + _active = Config->get_xfades_active (); _fixed = true; initialize (); } -Crossfade::Crossfade (ARDOUR::AudioRegion& a, ARDOUR::AudioRegion& b, CrossfadeModel model, bool act) +Crossfade::Crossfade (boost::shared_ptr a, boost::shared_ptr b, CrossfadeModel model, bool act) : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB { @@ -110,7 +119,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB { - Region* r; + boost::shared_ptr r; XMLProperty* prop; LocaleGuard lg (X_("POSIX")); @@ -129,7 +138,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) throw failed_constructor(); } - if ((_in = dynamic_cast (r)) == 0) { + if ((_in = boost::dynamic_pointer_cast (r)) == 0) { throw failed_constructor(); } @@ -146,33 +155,31 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) throw failed_constructor(); } - if ((_out = dynamic_cast (r)) == 0) { + if ((_out = boost::dynamic_pointer_cast (r)) == 0) { throw failed_constructor(); } _length = 0; - initialize(false); + _active = Config->get_xfades_active(); + + initialize(); if (set_state (node)) { throw failed_constructor(); } - - save_state ("initial"); } -Crossfade::Crossfade (const Crossfade &orig, ARDOUR::AudioRegion *newin, ARDOUR::AudioRegion *newout) +Crossfade::Crossfade (const Crossfade &orig, boost::shared_ptr newin, boost::shared_ptr newout) : _fade_in(orig._fade_in), _fade_out(orig._fade_out) { - _active = orig._active; - _in_update = orig._in_update; - _length = orig._length; - _position = orig._position; - _anchor_point = orig._anchor_point; - _follow_overlap = orig._follow_overlap; - _fixed = orig._fixed; - _follow_overlap = orig._follow_overlap; - _short_xfade_length = orig._short_xfade_length; + _active = orig._active; + _in_update = orig._in_update; + _length = orig._length; + _position = orig._position; + _anchor_point = orig._anchor_point; + _follow_overlap = orig._follow_overlap; + _fixed = orig._fixed; _in = newin; _out = newout; @@ -192,13 +199,11 @@ Crossfade::Crossfade (const Crossfade &orig, ARDOUR::AudioRegion *newin, ARDOUR: Crossfade::~Crossfade () { - for (StateMap::iterator i = states.begin(); i != states.end(); ++i) { - delete *i; - } + Invalidated (this); } void -Crossfade::initialize (bool savestate) +Crossfade::initialize () { _in_update = false; @@ -225,31 +230,27 @@ Crossfade::initialize (bool savestate) _fade_in.add (_length, 1.0); _fade_in.thaw (); -// _in->StateChanged.connect (slot (*this, &Crossfade::member_changed)); -// _out->StateChanged.connect (slot (*this, &Crossfade::member_changed)); + _in->StateChanged.connect (sigc::mem_fun (*this, &Crossfade::member_changed)); + _out->StateChanged.connect (sigc::mem_fun (*this, &Crossfade::member_changed)); overlap_type = _in->coverage (_out->position(), _out->last_frame()); - - if (savestate) { - save_state ("initial"); - } } int -Crossfade::compute (AudioRegion& a, AudioRegion& b, CrossfadeModel model) +Crossfade::compute (boost::shared_ptr a, boost::shared_ptr b, CrossfadeModel model) { - AudioRegion* top; - AudioRegion* bottom; - jack_nframes_t short_xfade_length; + boost::shared_ptr top; + boost::shared_ptr bottom; + nframes_t short_xfade_length; short_xfade_length = _short_xfade_length; - if (a.layer() < b.layer()) { - top = &b; - bottom = &a; + if (a->layer() < b->layer()) { + top = b; + bottom = a; } else { - top = &a; - bottom = &b; + top = a; + bottom = b; } /* first check for matching ends */ @@ -400,13 +401,13 @@ Crossfade::compute (AudioRegion& a, AudioRegion& b, CrossfadeModel model) return 0; } -jack_nframes_t +nframes_t Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, - float *gain_buffer, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n, - jack_nframes_t read_frames, jack_nframes_t skip_frames) + float *gain_buffer, nframes_t start, nframes_t cnt, uint32_t chan_n, + nframes_t read_frames, nframes_t skip_frames) { - jack_nframes_t offset; - jack_nframes_t to_write; + nframes_t offset; + nframes_t to_write; if (!_active) { return 0; @@ -453,7 +454,7 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, position and length, and so we know precisely how much data they could return. */ - for (jack_nframes_t n = 0; n < to_write; ++n) { + for (nframes_t n = 0; n < to_write; ++n) { buf[n] = (crossfade_buffer_out[n] * fov[n]) + (crossfade_buffer_in[n] * fiv[n]); } @@ -464,9 +465,9 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, } OverlapType -Crossfade::coverage (jack_nframes_t start, jack_nframes_t end) const +Crossfade::coverage (nframes_t start, nframes_t end) const { - jack_nframes_t my_end = _position + _length; + nframes_t my_end = _position + _length; if ((start >= _position) && (end <= my_end)) { return OverlapInternal; @@ -488,8 +489,7 @@ Crossfade::set_active (bool yn) { if (_active != yn) { _active = yn; - save_state (_("active changed")); - send_state_changed (ActiveChanged); + StateChanged (ActiveChanged); } } @@ -534,8 +534,7 @@ Crossfade::refresh () bool Crossfade::update (bool force) { - jack_nframes_t newlen; - bool save = false; + nframes_t newlen; if (_follow_overlap) { newlen = _out->first_frame() + _out->length() - _in->first_frame(); @@ -559,41 +558,32 @@ Crossfade::update (bool force) _length = newlen; - save = true; - } switch (_anchor_point) { case StartOfIn: if (_position != _in->first_frame()) { _position = _in->first_frame(); - save = true; } break; case EndOfIn: if (_position != _in->last_frame() - _length) { _position = _in->last_frame() - _length; - save = true; } break; case EndOfOut: if (_position != _out->last_frame() - _length) { _position = _out->last_frame() - _length; - save = true; } } - if (save) { - save_state ("updated"); - } - /* UI's may need to know that the overlap changed even though the xfade length did not. */ - send_state_changed (BoundsChanged); /* EMIT SIGNAL */ + StateChanged (BoundsChanged); /* EMIT SIGNAL */ _in_update = false; @@ -605,72 +595,13 @@ Crossfade::member_changed (Change what_changed) { Change what_we_care_about = Change (Region::MuteChanged| Region::LayerChanged| - ARDOUR::BoundsChanged); + BoundsChanged); if (what_changed & what_we_care_about) { refresh (); } } -Change -Crossfade::restore_state (StateManager::State& state) -{ - CrossfadeState* xfstate = dynamic_cast (&state); - Change what_changed = Change (0); - - _in_update = true; - - xfstate->fade_in_memento (); - xfstate->fade_out_memento (); - - if (_length != xfstate->length) { - what_changed = Change (what_changed|LengthChanged); - _length = xfstate->length; - } - if (_active != xfstate->active) { - what_changed = Change (what_changed|ActiveChanged); - _active = xfstate->active; - } - if (_position != xfstate->position) { - what_changed = Change (what_changed|PositionChanged); - _position = xfstate->position; - } - - /* XXX what to do about notifications for these? I don't - think (G)UI cares about them because they are - implicit in the bounds. - */ - - _follow_overlap = xfstate->follow_overlap; - _anchor_point = xfstate->anchor_point; - - _in_update = false; - - return Change (what_changed); -} - -StateManager::State* -Crossfade::state_factory (std::string why) const -{ - CrossfadeState* state = new CrossfadeState (why); - - state->fade_in_memento = _fade_in.get_memento (); - state->fade_out_memento = _fade_out.get_memento (); - state->active = _active; - state->length = _length; - state->position = _position; - state->follow_overlap = _follow_overlap; - state->anchor_point = _anchor_point; - - return state; -} - -UndoAction -Crossfade::get_memento() const -{ - return sigc::bind (mem_fun (*(const_cast (this)), &StateManager::use_state), _current_state_id); -} - XMLNode& Crossfade::get_state () { @@ -679,9 +610,9 @@ Crossfade::get_state () char buf[64]; LocaleGuard lg (X_("POSIX")); - _out->id().print (buf); + _out->id().print (buf, sizeof (buf)); node->add_property ("out", buf); - _in->id().print (buf); + _in->id().print (buf, sizeof (buf)); node->add_property ("in", buf); node->add_property ("active", (_active ? "yes" : "no")); node->add_property ("follow-overlap", (_follow_overlap ? "yes" : "no")); @@ -700,7 +631,7 @@ Crossfade::get_state () pnode = new XMLNode ("point"); - snprintf (buf, sizeof (buf), "%" PRIu32, (jack_nframes_t) floor ((*ii)->when)); + snprintf (buf, sizeof (buf), "%" PRIu32, (nframes_t) floor ((*ii)->when)); pnode->add_property ("x", buf); snprintf (buf, sizeof (buf), "%.12g", (*ii)->value); pnode->add_property ("y", buf); @@ -714,7 +645,7 @@ Crossfade::get_state () pnode = new XMLNode ("point"); - snprintf (buf, sizeof (buf), "%" PRIu32, (jack_nframes_t) floor ((*ii)->when)); + snprintf (buf, sizeof (buf), "%" PRIu32, (nframes_t) floor ((*ii)->when)); pnode->add_property ("x", buf); snprintf (buf, sizeof (buf), "%.12g", (*ii)->value); pnode->add_property ("y", buf); @@ -733,16 +664,26 @@ Crossfade::set_state (const XMLNode& node) XMLNode* fo; const XMLProperty* prop; LocaleGuard lg (X_("POSIX")); + Change what_changed = Change (0); + nframes_t val; if ((prop = node.property ("position")) != 0) { - _position = atoi (prop->value().c_str()); + sscanf (prop->value().c_str(), "%" PRIu32, &val); + if (val != _position) { + _position = val; + what_changed = Change (what_changed | PositionChanged); + } } else { warning << _("old-style crossfade information - no position information") << endmsg; _position = _in->first_frame(); } if ((prop = node.property ("active")) != 0) { - _active = (prop->value() == "yes"); + bool x = (prop->value() == "yes"); + if (x != _active) { + _active = x; + what_changed = Change (what_changed | ActiveChanged); + } } else { _active = true; } @@ -767,7 +708,11 @@ Crossfade::set_state (const XMLNode& node) if ((prop = node.property ("length")) != 0) { - _length = atol (prop->value().c_str()); + sscanf (prop->value().c_str(), "%" PRIu32, &val); + if (val != _length) { + _length = atol (prop->value().c_str()); + what_changed = Change (what_changed | LengthChanged); + } } else { @@ -790,13 +735,14 @@ Crossfade::set_state (const XMLNode& node) /* fade in */ + _fade_in.freeze (); _fade_in.clear (); children = fi->children(); for (i = children.begin(); i != children.end(); ++i) { if ((*i)->name() == "point") { - jack_nframes_t x; + nframes_t x; float y; prop = (*i)->property ("x"); @@ -808,16 +754,19 @@ Crossfade::set_state (const XMLNode& node) _fade_in.add (x, y); } } + + _fade_in.thaw (); /* fade out */ + _fade_in.freeze (); _fade_out.clear (); children = fo->children(); for (i = children.begin(); i != children.end(); ++i) { if ((*i)->name() == "point") { - jack_nframes_t x; + nframes_t x; float y; XMLProperty* prop; @@ -831,6 +780,10 @@ Crossfade::set_state (const XMLNode& node) } } + _fade_out.thaw (); + + StateChanged (what_changed); /* EMIT SIGNAL */ + return 0; } @@ -854,12 +807,14 @@ Crossfade::set_follow_overlap (bool yn) } else { set_length (_out->first_frame() + _out->length() - _in->first_frame()); } + + StateChanged (FollowOverlapChanged); } -jack_nframes_t -Crossfade::set_length (jack_nframes_t len) +nframes_t +Crossfade::set_length (nframes_t len) { - jack_nframes_t limit; + nframes_t limit; switch (_anchor_point) { case StartOfIn: @@ -887,14 +842,12 @@ Crossfade::set_length (jack_nframes_t len) _length = len; - save_state ("length changed"); - - send_state_changed (LengthChanged); + StateChanged (LengthChanged); return len; } -jack_nframes_t +nframes_t Crossfade::overlap_length () const { if (_fixed) { @@ -904,7 +857,13 @@ Crossfade::overlap_length () const } void -Crossfade::set_short_xfade_length (jack_nframes_t n) +Crossfade::set_short_xfade_length (nframes_t n) { _short_xfade_length = n; } + +void +Crossfade::invalidate () +{ + Invalidated (this); /* EMIT SIGNAL */ +}