]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/trackchain.cpp
Add a function to check if a track chain forms a loop
[r2c2.git] / source / libr2c2 / trackchain.cpp
index 3d9d66a915e78bc5ecf7b50da83ac7bf9a340922..0c3282ad4845a4893f2c776fef7d2f49d2c48413 100644 (file)
@@ -3,6 +3,8 @@
 #include "track.h"
 #include "trackchain.h"
 
+using namespace std;
+
 namespace R2C2 {
 
 TrackChain::TrackChain(Layout &l):
@@ -11,6 +13,12 @@ TrackChain::TrackChain(Layout &l):
        layout.signal_object_removed.connect(sigc::mem_fun(this, &TrackChain::object_removed));
 }
 
+void TrackChain::set_name(const string &n)
+{
+       name = n;
+       signal_name_changed.emit(name);
+}
+
 void TrackChain::add_track(Track &track)
 {
        if(tracks.count(&track))
@@ -23,6 +31,7 @@ void TrackChain::add_track(Track &track)
        tracks.insert(&track);
        update_ends(track);
        on_track_added(track);
+       signal_track_added.emit(track);
 }
 
 void TrackChain::add_tracks(const TrackSet &trks)
@@ -38,10 +47,12 @@ void TrackChain::add_tracks(const TrackSet &trks)
                for(TrackSet::iterator i=pending.begin(); i!=pending.end(); ++i)
                        if((valid=check_validity(**i))==VALID)
                        {
-                               tracks.insert(*i);
-                               update_ends(**i);
-                               on_track_added(**i);
+                               Track *t = *i;
                                pending.erase(i);
+                               tracks.insert(t);
+                               update_ends(*t);
+                               on_track_added(*t);
+                               signal_track_added.emit(*t);
                                break;
                        }
 
@@ -124,12 +135,20 @@ bool TrackChain::has_track(Track &t) const
        return tracks.count(&t);
 }
 
+bool TrackChain::is_loop() const
+{
+       return !tracks.empty() && !ends[0] && !ends[1];
+}
+
 void TrackChain::object_removed(Object &obj)
 {
        if(Track *track = dynamic_cast<Track *>(&obj))
+       {
                tracks.erase(track);
                /* TODO If the track was in the middle of the chain, keep only the
                longest fragment */
+               signal_track_removed.emit(*track);
+       }
 }
 
 } // namespace R2C2