c217b76422698e0592674284db687cbc396ae4f9
[ardour.git] / libs / ardour / crossfade.cc
1 /*
2     Copyright (C) 2003-2006 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #include <sigc++/bind.h>
21
22 #include <pbd/stacktrace.h>
23
24 #include <ardour/types.h>
25 #include <ardour/crossfade.h>
26 #include <ardour/crossfade_compare.h>
27 #include <ardour/audioregion.h>
28 #include <ardour/playlist.h>
29 #include <ardour/utils.h>
30 #include <ardour/session.h>
31
32 #include "i18n.h"
33 #include <locale.h>
34
35 using namespace std;
36 using namespace ARDOUR;
37 using namespace PBD;
38
39 nframes_t Crossfade::_short_xfade_length = 0;
40 Change Crossfade::ActiveChanged = new_change();
41 Change Crossfade::FollowOverlapChanged = new_change();
42
43 /* XXX if and when we ever implement parallel processing of the process()
44    callback, these will need to be handled on a per-thread basis.
45 */
46
47 Sample* Crossfade::crossfade_buffer_out = 0;
48 Sample* Crossfade::crossfade_buffer_in = 0;
49
50 void
51 Crossfade::set_buffer_size (nframes_t sz)
52 {
53         if (crossfade_buffer_out) {
54                 delete [] crossfade_buffer_out;
55                 crossfade_buffer_out = 0;
56         }
57
58         if (crossfade_buffer_in) {
59                 delete [] crossfade_buffer_in;
60                 crossfade_buffer_in = 0;
61         }
62
63         if (sz) {
64                 crossfade_buffer_out = new Sample[sz];
65                 crossfade_buffer_in = new Sample[sz];
66         }
67 }
68
69 bool
70 Crossfade::operator== (const Crossfade& other)
71 {
72         return (_in == other._in) && (_out == other._out);
73 }
74
75 Crossfade::Crossfade (boost::shared_ptr<AudioRegion> in, boost::shared_ptr<AudioRegion> out, 
76                       nframes_t length,
77                       nframes_t position,
78                       AnchorPoint ap)
79         : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB
80           _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB
81 {
82         _in = in;
83         _out = out;
84         
85         _length = length;
86         _position = position;
87         _anchor_point = ap;
88
89         _follow_overlap = false;
90
91         _active = Config->get_xfades_active ();
92         _fixed = true;
93                 
94         initialize ();
95 }
96
97 Crossfade::Crossfade (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioRegion> b, CrossfadeModel model, bool act)
98         : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB
99           _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB
100 {
101         _in_update = false;
102         _fixed = false;
103
104         if (compute (a, b, model)) {
105                 throw failed_constructor();
106         }
107
108         _active = act;
109
110         initialize ();
111 }
112
113 Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
114         :  _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB
115            _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB
116 {
117         boost::shared_ptr<Region> r;
118         XMLProperty* prop;
119         LocaleGuard lg (X_("POSIX"));
120
121         /* we have to find the in/out regions before we can do anything else */
122
123         if ((prop = node.property ("in")) == 0) {
124                 error << _("Crossfade: no \"in\" region in state") << endmsg;
125                 throw failed_constructor();
126         }
127         
128         PBD::ID id (prop->value());
129
130         if ((r = playlist.find_region (id)) == 0) {
131                 error << string_compose (_("Crossfade: no \"in\" region %1 found in playlist %2"), id, playlist.name())
132                       << endmsg;
133                 throw failed_constructor();
134         }
135         
136         if ((_in = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
137                 throw failed_constructor();
138         }
139
140         if ((prop = node.property ("out")) == 0) {
141                 error << _("Crossfade: no \"out\" region in state") << endmsg;
142                 throw failed_constructor();
143         }
144
145         PBD::ID id2 (prop->value());
146
147         if ((r = playlist.find_region (id2)) == 0) {
148                 error << string_compose (_("Crossfade: no \"out\" region %1 found in playlist %2"), id2, playlist.name())
149                       << endmsg;
150                 throw failed_constructor();
151         }
152         
153         if ((_out = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
154                 throw failed_constructor();
155         }
156
157         _length = 0;
158         _active = Config->get_xfades_active();
159
160         initialize();
161         
162         if (set_state (node)) {
163                 throw failed_constructor();
164         }
165 }
166
167 Crossfade::Crossfade (const Crossfade &orig, boost::shared_ptr<AudioRegion> newin, boost::shared_ptr<AudioRegion> newout)
168         : _fade_in(orig._fade_in),
169           _fade_out(orig._fade_out)
170 {
171         _active           = orig._active;
172         _in_update        = orig._in_update;
173         _length           = orig._length;
174         _position         = orig._position;
175         _anchor_point     = orig._anchor_point;
176         _follow_overlap   = orig._follow_overlap;
177         _fixed            = orig._fixed;
178         
179         _in = newin;
180         _out = newout;
181
182         // copied from Crossfade::initialize()
183         _in_update = false;
184         
185         _out->suspend_fade_out ();
186         _in->suspend_fade_in ();
187
188         overlap_type = _in->coverage (_out->position(), _out->last_frame());
189         layer_relation = (int32_t) (_in->layer() - _out->layer());
190
191         // Let's make sure the fade isn't too long
192         set_length(_length);
193 }
194
195
196 Crossfade::~Crossfade ()
197 {
198         notify_callbacks ();
199 }
200
201 void
202 Crossfade::initialize ()
203 {
204         _in_update = false;
205         
206         _out->suspend_fade_out ();
207         _in->suspend_fade_in ();
208
209         _fade_out.freeze ();
210         _fade_out.clear ();
211         _fade_out.add (0.0, 1.0);
212         _fade_out.add ((_length * 0.1), 0.99);
213         _fade_out.add ((_length * 0.2), 0.97);
214         _fade_out.add ((_length * 0.8), 0.03);
215         _fade_out.add ((_length * 0.9), 0.01);
216         _fade_out.add (_length, 0.0);
217         _fade_out.thaw ();
218         
219         _fade_in.freeze ();
220         _fade_in.clear ();
221         _fade_in.add (0.0, 0.0);
222         _fade_in.add ((_length * 0.1),  0.01);
223         _fade_in.add ((_length * 0.2),  0.03);
224         _fade_in.add ((_length * 0.8),  0.97);
225         _fade_in.add ((_length * 0.9),  0.99);
226         _fade_in.add (_length, 1.0);
227         _fade_in.thaw ();
228
229         overlap_type = _in->coverage (_out->position(), _out->last_frame());
230         layer_relation = (int32_t) (_in->layer() - _out->layer());
231 }       
232
233 nframes_t 
234 Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, 
235                     float *gain_buffer, nframes_t start, nframes_t cnt, uint32_t chan_n,
236                     nframes_t read_frames, nframes_t skip_frames)
237 {
238         nframes_t offset;
239         nframes_t to_write;
240
241         if (!_active) {
242                 return 0;
243         }
244
245         if (start < _position) {
246
247                 /* handle an initial section of the read area that we do not
248                    cover.
249                 */
250
251                 offset = _position - start;
252
253                 if (offset < cnt) {
254                         cnt -= offset;
255                 } else {
256                         return 0;
257                 }
258                 
259                 start = _position;
260                 buf += offset;
261                 to_write = min (_length, cnt);
262
263         } else {
264                 
265                 to_write = min (_length - (start - _position), cnt);
266                 
267         }
268
269         offset = start - _position;
270
271         _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames);
272         _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames);
273
274         float* fiv = new float[to_write];
275         float* fov = new float[to_write];
276
277         _fade_in.get_vector (offset, offset+to_write, fiv, to_write);
278         _fade_out.get_vector (offset, offset+to_write, fov, to_write);
279
280         /* note: although we have not explicitly taken into account the return values
281            from _out->read_at() or _in->read_at(), the length() function does this
282            implicitly. why? because it computes a value based on the in+out regions'
283            position and length, and so we know precisely how much data they could return. 
284         */
285
286         for (nframes_t n = 0; n < to_write; ++n) {
287                 buf[n] = (crossfade_buffer_out[n] * fov[n]) + (crossfade_buffer_in[n] * fiv[n]);
288         }
289
290         delete [] fov;
291         delete [] fiv;
292
293         return to_write;
294 }       
295
296 OverlapType 
297 Crossfade::coverage (nframes_t start, nframes_t end) const
298 {
299         nframes_t my_end = _position + _length;
300
301         if ((start >= _position) && (end <= my_end)) {
302                 return OverlapInternal;
303         }
304         if ((end >= _position) && (end <= my_end)) {
305                 return OverlapStart;
306         }
307         if ((start >= _position) && (start <= my_end)) {
308                 return OverlapEnd;
309         }
310         if ((_position >= start) && (_position <= end) && (my_end <= end)) {
311                 return OverlapExternal;
312         }
313         return OverlapNone;
314 }
315
316 void
317 Crossfade::set_active (bool yn)
318 {
319         if (_active != yn) {
320                 _active = yn;
321                 StateChanged (ActiveChanged);
322         }
323 }
324
325 bool
326 Crossfade::refresh ()
327 {
328         /* crossfades must be between non-muted regions */
329         
330         if (_out->muted() || _in->muted()) {
331                 Invalidated (shared_from_this());
332                 return false;
333         }
334
335         /* layer ordering cannot change */
336
337         int32_t new_layer_relation = (int32_t) (_in->layer() - _out->layer());
338
339         if (new_layer_relation * layer_relation < 0) { // different sign, layers rotated 
340                 Invalidated (shared_from_this());
341                 return false;
342         }
343
344         OverlapType ot = _in->coverage (_out->first_frame(), _out->last_frame());
345
346         if (ot == OverlapNone) {
347                 Invalidated (shared_from_this());
348                 return false;
349         } 
350
351         bool send_signal;
352
353         if (ot != overlap_type) {
354
355                 if (_follow_overlap) {
356
357                         try {
358                                 compute (_in, _out, Config->get_xfade_model());
359                         } 
360
361                         catch (NoCrossfadeHere& err) {
362                                 Invalidated (shared_from_this());
363                                 return false;
364                         }
365
366                         send_signal = true;
367
368                 } else {
369
370                         Invalidated (shared_from_this());
371                         return false;
372                 }
373
374         } else {
375
376                 send_signal = update ();
377         }
378
379         if (send_signal) {
380                 StateChanged (BoundsChanged); /* EMIT SIGNAL */
381         }
382
383         _in_update = false;
384
385         return true;
386 }
387
388 bool
389 Crossfade::update ()
390 {
391         nframes_t newlen;
392         
393         if (_follow_overlap) {
394                 newlen = _out->first_frame() + _out->length() - _in->first_frame();
395         } else {
396                 newlen = _length;
397         }
398         
399         if (newlen == 0) {
400                 Invalidated (shared_from_this());
401                 return false;
402         }
403         
404         _in_update = true;
405         
406         if ((_follow_overlap && newlen != _length) || (_length > newlen)) {
407                 
408                 double factor =  newlen / (double) _length;
409                 
410                 _fade_out.x_scale (factor);
411                 _fade_in.x_scale (factor);
412                 
413                 _length = newlen;
414         } 
415                 
416         switch (_anchor_point) {
417         case StartOfIn:
418                 _position = _in->first_frame();
419                 break;
420                 
421         case EndOfIn:
422                 _position = _in->last_frame() - _length;
423                 break;
424                 
425         case EndOfOut:
426                 _position = _out->last_frame() - _length;
427         }
428
429         return true;
430 }
431
432 int
433 Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioRegion> b, CrossfadeModel model)
434 {
435         boost::shared_ptr<AudioRegion> top;
436         boost::shared_ptr<AudioRegion> bottom;
437         nframes_t short_xfade_length;
438
439         short_xfade_length = _short_xfade_length; 
440
441         if (a->layer() < b->layer()) {
442                 top = b;
443                 bottom = a;
444         } else {
445                 top = a;
446                 bottom = b;
447         }
448         
449         /* first check for matching ends */
450         
451         if (top->first_frame() == bottom->first_frame()) {
452
453                 /* Both regions start at the same point */
454                 
455                 if (top->last_frame() < bottom->last_frame()) {
456                         
457                         /* top ends before bottom, so put an xfade
458                            in at the end of top.
459                         */
460                         
461                         /* [-------- top ---------- ]
462                          * {====== bottom =====================}
463                          */
464
465                         _in = bottom;
466                         _out = top;
467
468                         if (top->last_frame() < short_xfade_length) {
469                                 _position = 0;
470                         } else {
471                                 _position = top->last_frame() - short_xfade_length;
472                         }
473
474                         _length = min (short_xfade_length, top->length());
475                         _follow_overlap = false;
476                         _anchor_point = EndOfIn;
477                         _active = true;
478                         _fixed = true;
479
480                 } else {
481                         /* top ends after (or same time) as bottom - no xfade
482                          */
483                         
484                         /* [-------- top ------------------------ ]
485                          * {====== bottom =====================}
486                          */
487
488                         throw NoCrossfadeHere();
489                 }
490                 
491         } else if (top->last_frame() == bottom->last_frame()) {
492                 
493                 /* Both regions end at the same point */
494                 
495                 if (top->first_frame() > bottom->first_frame()) {
496                         
497                         /* top starts after bottom, put an xfade in at the
498                            start of top
499                         */
500                         
501                         /*            [-------- top ---------- ]
502                          * {====== bottom =====================}
503                          */
504
505                         _in = top;
506                         _out = bottom;
507                         _position = top->first_frame();
508                         _length = min (short_xfade_length, top->length());
509                         _follow_overlap = false;
510                         _anchor_point = StartOfIn;
511                         _active = true;
512                         _fixed = true;
513                         
514                 } else {
515                         /* top starts before bottom - no xfade
516                          */
517
518                         /* [-------- top ------------------------ ]
519                          *    {====== bottom =====================}
520                          */
521
522                         throw NoCrossfadeHere();
523                 }
524
525         } else {
526         
527                 /* OK, time to do more regular overlapping */
528
529                 OverlapType ot = top->coverage (bottom->first_frame(), bottom->last_frame());
530
531                 switch (ot) {
532                 case OverlapNone:
533                         /* should be NOTREACHED as a precondition of creating
534                            a new crossfade, but we need to handle it here.
535                         */
536                         throw NoCrossfadeHere();
537                         break;
538                         
539                 case OverlapInternal:
540                 case OverlapExternal:
541                         /* should be NOTREACHED because of tests above */
542                         throw NoCrossfadeHere();
543                         break;
544                         
545                 case OverlapEnd: /* top covers start of bottom but ends within it */
546
547                         /* [---- top ------------------------] 
548                          *                { ==== bottom ============ } 
549                          */ 
550
551                         _in = bottom;
552                         _out = top;
553                         _anchor_point = EndOfOut;
554
555                         if (model == FullCrossfade) {
556                                 _position = bottom->first_frame(); // "{"
557                                 _length = _out->first_frame() + _out->length() - _in->first_frame();
558                                 /* leave active alone */
559                                 _follow_overlap = true;
560                         } else {
561                                 _length = min (short_xfade_length, top->length());
562                                 _position = top->last_frame() - _length;  // "]" - length 
563                                 _active = true;
564                                 _follow_overlap = false;
565                                 
566                         }
567                         break;
568                         
569                 case OverlapStart:   /* top starts within bottom but covers bottom's end */
570
571                         /*                   { ==== top ============ } 
572                          *   [---- bottom -------------------] 
573                          */
574
575                         _in = top;
576                         _out = bottom;
577                         _position = top->first_frame();
578                         _anchor_point = StartOfIn;
579
580                         if (model == FullCrossfade) {
581                                 _length = _out->first_frame() + _out->length() - _in->first_frame();
582                                 /* leave active alone */
583                                 _follow_overlap = true;
584                         } else {
585                                 _length = min (short_xfade_length, top->length());
586                                 _active = true;
587                                 _follow_overlap = false;
588                                 
589                         }
590                         
591                         break;
592                 }
593         }
594         
595         return 0;
596 }
597
598 XMLNode&
599 Crossfade::get_state () 
600 {
601         XMLNode* node = new XMLNode (X_("Crossfade"));
602         XMLNode* child;
603         char buf[64];
604         LocaleGuard lg (X_("POSIX"));
605
606         _out->id().print (buf, sizeof (buf));
607         node->add_property ("out", buf);
608         _in->id().print (buf, sizeof (buf));
609         node->add_property ("in", buf);
610         node->add_property ("active", (_active ? "yes" : "no"));
611         node->add_property ("follow-overlap", (_follow_overlap ? "yes" : "no"));
612         node->add_property ("fixed", (_fixed ? "yes" : "no"));
613         snprintf (buf, sizeof(buf), "%" PRIu32, _length);
614         node->add_property ("length", buf);
615         snprintf (buf, sizeof(buf), "%" PRIu32, (uint32_t) _anchor_point);
616         node->add_property ("anchor-point", buf);
617         snprintf (buf, sizeof(buf), "%" PRIu32, (uint32_t) _position);
618         node->add_property ("position", buf);
619
620         child = node->add_child ("FadeIn");
621
622         for (AutomationList::iterator ii = _fade_in.begin(); ii != _fade_in.end(); ++ii) {
623                 XMLNode* pnode;
624
625                 pnode = new XMLNode ("point");
626
627                 snprintf (buf, sizeof (buf), "%" PRIu32, (nframes_t) floor ((*ii)->when));
628                 pnode->add_property ("x", buf);
629                 snprintf (buf, sizeof (buf), "%.12g", (*ii)->value);
630                 pnode->add_property ("y", buf);
631                 child->add_child_nocopy (*pnode);
632         }
633
634         child = node->add_child ("FadeOut");
635
636         for (AutomationList::iterator ii = _fade_out.begin(); ii != _fade_out.end(); ++ii) {
637                 XMLNode* pnode;
638
639                 pnode = new XMLNode ("point");
640
641                 snprintf (buf, sizeof (buf), "%" PRIu32, (nframes_t) floor ((*ii)->when));
642                 pnode->add_property ("x", buf);
643                 snprintf (buf, sizeof (buf), "%.12g", (*ii)->value);
644                 pnode->add_property ("y", buf);
645                 child->add_child_nocopy (*pnode);
646         }
647
648         return *node;
649 }
650
651 int
652 Crossfade::set_state (const XMLNode& node)
653 {
654         XMLNodeConstIterator i;
655         XMLNodeList children;
656         XMLNode* fi;
657         XMLNode* fo;
658         const XMLProperty* prop;
659         LocaleGuard lg (X_("POSIX"));
660         Change what_changed = Change (0);
661         nframes_t val;
662
663         if ((prop = node.property ("position")) != 0) {
664                 sscanf (prop->value().c_str(), "%" PRIu32, &val);
665                 if (val != _position) {
666                         _position = val;
667                         what_changed = Change (what_changed | PositionChanged);
668                 }
669         } else {
670                 warning << _("old-style crossfade information - no position information") << endmsg;
671                 _position = _in->first_frame();
672         }
673
674         if ((prop = node.property ("active")) != 0) {
675                 bool x = (prop->value() == "yes");
676                 if (x != _active) {
677                         _active = x;
678                         what_changed = Change (what_changed | ActiveChanged);
679                 }
680         } else {
681                 _active = true;
682         }
683
684         if ((prop = node.property ("follow-overlap")) != 0) {
685                 _follow_overlap = (prop->value() == "yes");
686         } else {
687                 _follow_overlap = false;
688         }
689
690         if ((prop = node.property ("fixed")) != 0) {
691                 _fixed = (prop->value() == "yes");
692         } else {
693                 _fixed = false;
694         }
695
696         if ((prop = node.property ("anchor-point")) != 0) {
697                 _anchor_point = AnchorPoint (atoi ((prop->value().c_str())));
698         } else {
699                 _anchor_point = StartOfIn;
700         }
701
702         if ((prop = node.property ("length")) != 0) {
703
704                 sscanf (prop->value().c_str(), "%" PRIu32, &val);
705                 if (val != _length) {
706                         _length = atol (prop->value().c_str());
707                         what_changed = Change (what_changed | LengthChanged);
708                 }
709
710         } else {
711                 
712                 /* XXX this branch is legacy code from before
713                    the point where we stored xfade lengths.
714                 */
715                 
716                 if ((_length = overlap_length()) == 0) {
717                         throw failed_constructor();
718                 }
719         }
720
721         if ((fi = find_named_node (node, "FadeIn")) == 0) {
722                 return -1;
723         }
724         
725         if ((fo = find_named_node (node, "FadeOut")) == 0) {
726                 return -1;
727         }
728
729         /* fade in */
730         
731         _fade_in.freeze ();
732         _fade_in.clear ();
733         
734         children = fi->children();
735         
736         for (i = children.begin(); i != children.end(); ++i) {
737                 if ((*i)->name() == "point") {
738                         nframes_t x;
739                         float y;
740                         
741                         prop = (*i)->property ("x");
742                         sscanf (prop->value().c_str(), "%" PRIu32, &x);
743                         
744                         prop = (*i)->property ("y");
745                         sscanf (prop->value().c_str(), "%f", &y);
746
747                         _fade_in.add (x, y);
748                 }
749         }
750
751         _fade_in.thaw ();
752         
753         /* fade out */
754         
755         _fade_out.freeze ();
756         _fade_out.clear ();
757
758         children = fo->children();
759         
760         for (i = children.begin(); i != children.end(); ++i) {
761                 if ((*i)->name() == "point") {
762                         nframes_t x;
763                         float y;
764                         XMLProperty* prop;
765
766                         prop = (*i)->property ("x");
767                         sscanf (prop->value().c_str(), "%" PRIu32, &x);
768
769                         prop = (*i)->property ("y");
770                         sscanf (prop->value().c_str(), "%f", &y);
771                         
772                         _fade_out.add (x, y);
773                 }
774         }
775
776         _fade_out.thaw ();
777
778         StateChanged (what_changed); /* EMIT SIGNAL */
779
780         return 0;
781 }
782
783 bool
784 Crossfade::can_follow_overlap () const
785 {
786         return !_fixed;
787 }
788
789 void
790 Crossfade::set_follow_overlap (bool yn)
791 {
792         if (yn == _follow_overlap || _fixed) {
793                 return;
794         }
795
796         _follow_overlap = yn;
797
798         if (!yn) {
799                 set_length (_short_xfade_length);
800         } else {
801                 set_length (_out->first_frame() + _out->length() - _in->first_frame());
802         }
803
804         StateChanged (FollowOverlapChanged);
805 }
806
807 nframes_t
808 Crossfade::set_length (nframes_t len)
809 {
810         nframes_t limit;
811
812         switch (_anchor_point) {
813         case StartOfIn:
814                 limit = _in->length();
815                 break;
816
817         case EndOfIn:
818                 limit = _in->length();
819                 break;
820
821         case EndOfOut:
822                 limit = _out->length();
823                 break;
824                 
825         }
826
827         len = min (limit, len);
828
829         double factor = len / (double) _length;
830
831         _in_update = true;
832         _fade_out.x_scale (factor);
833         _fade_in.x_scale (factor);
834         _in_update = false;
835         
836         _length = len;
837
838         StateChanged (LengthChanged);
839
840         return len;
841 }
842
843 nframes_t
844 Crossfade::overlap_length () const
845 {
846         if (_fixed) {
847                 return _length;
848         }
849         return _out->first_frame() + _out->length() - _in->first_frame();
850 }
851
852 void
853 Crossfade::set_short_xfade_length (nframes_t n)
854 {
855         _short_xfade_length = n;
856 }
857
858 void
859 Crossfade::invalidate ()
860 {
861         Invalidated (shared_from_this()); /* EMIT SIGNAL */
862 }