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