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