summaryrefslogtreecommitdiff
path: root/libs/ardour/audioregion.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ardour/audioregion.cc')
-rw-r--r--libs/ardour/audioregion.cc72
1 files changed, 50 insertions, 22 deletions
diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc
index bc66f0d6b0..1d3032c1e0 100644
--- a/libs/ardour/audioregion.cc
+++ b/libs/ardour/audioregion.cc
@@ -15,7 +15,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#include <cmath>
@@ -41,7 +40,6 @@
#include <ardour/playlist.h>
#include <ardour/audiofilter.h>
#include <ardour/audiofilesource.h>
-#include <ardour/destructive_filesource.h>
#include <ardour/region_factory.h>
#include "i18n.h"
@@ -454,12 +452,12 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff
nframes_t buf_offset;
nframes_t to_read;
- /* precondition: caller has verified that we cover the desired section */
-
- if (chan_n >= sources.size()) {
+ if (muted()) {
return 0; /* read nothing */
}
-
+
+ /* precondition: caller has verified that we cover the desired section */
+
if (position < _position) {
internal_offset = 0;
buf_offset = _position - position;
@@ -484,17 +482,29 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff
mixdown_buffer += buf_offset;
}
- if (muted()) {
- return 0; /* read nothing */
- }
-
_read_data_count = 0;
- if (srcs[chan_n]->read (mixdown_buffer, _start + internal_offset, to_read) != to_read) {
- return 0; /* "read nothing" */
- }
+ if (chan_n < n_channels()) {
+
+ if (srcs[chan_n]->read (mixdown_buffer, _start + internal_offset, to_read) != to_read) {
+
+ return 0; /* "read nothing" */
+ }
+
+ _read_data_count += srcs[chan_n]->read_data_count();
+
+ } else {
+
+ /* track is N-channel, this region has less channels; silence the ones
+ we don't have.
+ */
+
+ memset (mixdown_buffer, 0, sizeof (Sample) * cnt);
- _read_data_count += srcs[chan_n]->read_data_count();
+ /* no fades required */
+
+ goto merge;
+ }
/* fade in */
@@ -505,7 +515,7 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff
/* see if this read is within the fade in */
if (internal_offset < fade_in_length) {
-
+
nframes_t limit;
limit = min (to_read, fade_in_length - internal_offset);
@@ -579,13 +589,15 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff
Session::apply_gain_to_buffer (mixdown_buffer, to_read, _scale_amplitude);
}
+ merge:
+
if (!opaque()) {
/* gack. the things we do for users.
*/
buf += buf_offset;
-
+
for (nframes_t n = 0; n < to_read; ++n) {
buf[n] += mixdown_buffer[n];
}
@@ -948,6 +960,18 @@ AudioRegion::set_fade_out_active (bool yn)
send_change (FadeOutActiveChanged);
}
+bool
+AudioRegion::fade_in_is_default () const
+{
+ return _fade_in_shape == Linear && _fade_in.back()->when == 64;
+}
+
+bool
+AudioRegion::fade_out_is_default () const
+{
+ return _fade_out_shape == Linear && _fade_out.back()->when == 64;
+}
+
void
AudioRegion::set_default_fade_in ()
{
@@ -1059,7 +1083,6 @@ AudioRegion::separate_by_channel (Session& session, vector<boost::shared_ptr<Aud
boost::shared_ptr<Region> r = RegionFactory::create (srcs, _start, _length, new_name, _layer, f);
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (r);
- cerr << "new region name is " << ar->name() << endl;
v.push_back (ar);
@@ -1313,14 +1336,16 @@ void
AudioRegion::suspend_fade_in ()
{
if (++_fade_in_disabled == 1) {
- set_fade_in_active (false);
+ if (fade_in_is_default()) {
+ set_fade_in_active (false);
+ }
}
}
void
AudioRegion::resume_fade_in ()
{
- if (_fade_in_disabled && --_fade_in_disabled == 0) {
+ if (--_fade_in_disabled == 0 && _fade_in_disabled) {
set_fade_in_active (true);
}
}
@@ -1329,14 +1354,16 @@ void
AudioRegion::suspend_fade_out ()
{
if (++_fade_out_disabled == 1) {
- set_fade_out_active (false);
+ if (fade_out_is_default()) {
+ set_fade_out_active (false);
+ }
}
}
void
AudioRegion::resume_fade_out ()
{
- if (_fade_out_disabled && --_fade_out_disabled == 0) {
+ if (--_fade_out_disabled == 0 &&_fade_out_disabled) {
set_fade_out_active (true);
}
}
@@ -1369,6 +1396,7 @@ void
AudioRegion::set_playlist (boost::weak_ptr<Playlist> wpl)
{
boost::shared_ptr<Playlist> old_playlist = (_playlist.lock());
+
boost::shared_ptr<Playlist> pl (wpl.lock());
if (old_playlist == pl) {
@@ -1391,7 +1419,7 @@ AudioRegion::set_playlist (boost::weak_ptr<Playlist> wpl)
} else {
if (old_playlist) {
for (SourceList::const_iterator i = sources.begin(); i != sources.end(); ++i) {
- (*i)->remove_playlist (_playlist);
+ (*i)->remove_playlist (old_playlist);
}
}
}