add and use Source::empty() since it can be done more efficiently than length(pos) == 0

git-svn-id: svn://localhost/ardour2/branches/3.0@7300 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-06-24 18:04:38 +00:00
parent e72d710734
commit de24d4f8b1
7 changed files with 28 additions and 13 deletions

View file

@ -50,6 +50,7 @@ class AudioSource : virtual public Source,
framecnt_t readable_length() const { return _length; }
uint32_t n_channels() const { return 1; }
bool empty() const;
framecnt_t length (framepos_t pos) const;
void update_length (framepos_t pos, framecnt_t cnt);

View file

@ -74,8 +74,9 @@ class MidiSource : virtual public Source
virtual void append_event_unlocked_frames(const Evoral::Event<nframes_t>& ev,
sframes_t source_start) = 0;
virtual sframes_t length (sframes_t pos) const;
virtual void update_length (sframes_t pos, sframes_t cnt);
virtual bool empty () const;
virtual framecnt_t length (framepos_t pos) const;
virtual void update_length (framepos_t pos, framecnt_t cnt);
virtual void mark_streaming_midi_write_started (NoteMode mode, sframes_t start_time);
virtual void mark_streaming_write_started ();

View file

@ -60,6 +60,7 @@ class Source : public SessionObject
time_t timestamp() const { return _timestamp; }
void stamp (time_t when) { _timestamp = when; }
virtual bool empty () const = 0;
virtual framecnt_t length (framepos_t pos) const = 0;
virtual void update_length (framepos_t pos, framecnt_t cnt) = 0;

View file

@ -126,14 +126,20 @@ AudioSource::set_state (const XMLNode& node, int /*version*/)
return 0;
}
sframes_t
AudioSource::length (sframes_t /*pos*/) const
bool
AudioSource::empty () const
{
return _length == 0;
}
framecnt_t
AudioSource::length (framepos_t /*pos*/) const
{
return _length;
}
void
AudioSource::update_length (sframes_t pos, sframes_t cnt)
AudioSource::update_length (framepos_t pos, framecnt_t cnt)
{
if (pos + cnt > _length) {
_length = pos + cnt;

View file

@ -82,7 +82,7 @@ FileSource::removable () const
{
return (_flags & Removable)
&& ((_flags & RemoveAtDestroy) ||
((_flags & RemovableIfEmpty) && length(timeline_position()) == 0));
((_flags & RemovableIfEmpty) && empty() == 0));
}
int

View file

@ -112,9 +112,19 @@ MidiSource::set_state (const XMLNode& node, int /*version*/)
return 0;
}
sframes_t
MidiSource::length (sframes_t pos) const
bool
MidiSource::empty () const
{
return _length_beats == 0;
}
framecnt_t
MidiSource::length (framepos_t pos) const
{
if (_length_beats == 0) {
return 0;
}
BeatsFramesConverter converter(_session.tempo_map(), pos);
return converter.to(_length_beats);
}

View file

@ -1044,14 +1044,10 @@ Session::state(bool full_state)
and unused by any regions.
*/
cerr << "Source " << siter->second->name() << " has UC = " << siter->second->used()
<< " length = " << siter->second->length (0)
<< endl;
boost::shared_ptr<FileSource> fs;
if ((fs = boost::dynamic_pointer_cast<FileSource> (siter->second)) != 0) {
if (!fs->destructive()) {
if (fs->length(fs->timeline_position()) == 0 && !fs->used()) {
if (fs->empty() && !fs->used()) {
continue;
}
}