+ framecnt_t const curve_offset = fade_interval_start - (_length - _fade_out->back()->when);
+
+ if (opaque()) {
+ if (_inverse_fade_out) {
+
+ _inverse_fade_out->curve().get_vector (curve_offset, curve_offset + fade_out_limit, gain_buffer, fade_out_limit);
+
+ /* Fade the data from lower levels out */
+ for (framecnt_t n = 0, m = fade_out_offset; n < fade_out_limit; ++n, ++m) {
+ buf[m] *= gain_buffer[n];
+ }
+
+ /* fetch the actual fade out */
+
+ _fade_out->curve().get_vector (curve_offset, curve_offset + fade_out_limit, gain_buffer, fade_out_limit);
+
+ } else {
+
+ /* no explicit inverse fade out, so just use (1 - fade
+ * out) for the fade in of lower layers
+ */
+
+ _fade_out->curve().get_vector (curve_offset, curve_offset + fade_out_limit, gain_buffer, fade_out_limit);
+
+ for (framecnt_t n = 0, m = fade_out_offset; n < fade_out_limit; ++n, ++m) {
+ buf[m] *= 1 - gain_buffer[n];
+ }
+ }
+ } else {
+ _fade_out->curve().get_vector (curve_offset, curve_offset + fade_out_limit, gain_buffer, fade_out_limit);
+ }
+
+ /* Mix our newly-read data out, with the fade */
+ for (framecnt_t n = 0, m = fade_out_offset; n < fade_out_limit; ++n, ++m) {
+ buf[m] += mixdown_buffer[m] * gain_buffer[n];
+ }
+ }
+
+
+ /* MIX OR COPY THE REGION BODY FROM mixdown_buffer INTO buf */
+
+ framecnt_t const N = to_read - fade_in_limit - fade_out_limit;
+ if (N > 0) {
+ if (opaque ()) {
+ memcpy (buf + fade_in_limit, mixdown_buffer + fade_in_limit, N * sizeof (Sample));
+ } else {
+ mix_buffers_no_gain (buf + fade_in_limit, mixdown_buffer + fade_in_limit, N);
+ }
+ }
+
+ return to_read;
+}
+
+/** Read data directly from one of our sources, accounting for the situation when the track has a different channel
+ * count to the region.
+ *
+ * @param srcs Source list to get our source from.
+ * @param limit Furthest that we should read, as an offset from the region position.
+ * @param buf Buffer to write data into (existing contents of the buffer will be overwritten)
+ * @param position Position to read from, in session frames.
+ * @param cnt Number of frames to read.
+ * @param chan_n Channel to read from.
+ * @return Number of frames read.
+ */
+
+framecnt_t
+AudioRegion::read_from_sources (SourceList const & srcs, framecnt_t limit, Sample* buf, framepos_t position, framecnt_t cnt, uint32_t chan_n) const
+{
+ frameoffset_t const internal_offset = position - _position;
+ if (internal_offset >= limit) {
+ return 0;
+ }
+
+ framecnt_t const to_read = min (cnt, limit - internal_offset);
+ if (to_read == 0) {
+ return 0;
+ }
+
+ if (chan_n < n_channels()) {