add and use Source::empty() since it can be done more efficiently than length(pos...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 24 Jun 2010 18:04:38 +0000 (18:04 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 24 Jun 2010 18:04:38 +0000 (18:04 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7300 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audiosource.h
libs/ardour/ardour/midi_source.h
libs/ardour/ardour/source.h
libs/ardour/audiosource.cc
libs/ardour/file_source.cc
libs/ardour/midi_source.cc
libs/ardour/session_state.cc

index fa9e3439c18c74ef052349cd7de6c6b9fd80168b..2d749dd6734e7860715db60ffb2e55235e14a11b 100644 (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);
 
index c418559d6eeffe222a7119e19c8c8207627f986b..36c8548e2044c49c1da09373fe2ab611aae284f2 100644 (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 ();
index 3ee1e609fcb25a3b0f580e824280309c51b121d7..9abf7ff8f0671ea53c31adc0354593f9591ae455 100644 (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;
 
index d8640306463708c61bedeb64c23d08c546478686..a25e24ab7a4a6053559d8798c0531883eb4bfd06 100644 (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;
index c00e3ddbc3ed3062e37b5dbaa7e51095e0c3d64e..fd66a7a1678291c1cc90d2f7381c357a1bcf3f59 100644 (file)
@@ -82,7 +82,7 @@ FileSource::removable () const
 {
        return (_flags & Removable)
                && ((_flags & RemoveAtDestroy) || 
-                   ((_flags & RemovableIfEmpty) && length(timeline_position()) == 0));
+                   ((_flags & RemovableIfEmpty) && empty() == 0));
 }
 
 int
index 54b287cbdf1b9b6be031e59dbbe5ec4f77da85df..94c1a9b811e85f761dde90ea2c969f660ae53a28 100644 (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);
 }
index f26933d8757ed364a4fcfade1e07b6aa7edeacd2..c94fa7b9767436d905f0031cb426674e364a4d75 100644 (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;
                                        }
                                }