merge changes from harrison branch back into trunk, by hand
[ardour.git] / libs / ardour / location.cc
index ca88a2851b131826d9a88ab0a04c396ef49050dc..30b28c6abee73a937e76d9eec31988ab66f3d5c9 100644 (file)
@@ -30,6 +30,7 @@
 #include <pbd/xml++.h>
 
 #include <ardour/location.h>
+#include <ardour/session.h>
 #include <ardour/audiofilesource.h>
 
 #include "i18n.h"
@@ -51,6 +52,13 @@ Location::Location (const Location& other)
        _flags = Flags (_flags & ~IsEnd);
 }
 
+Location::Location (const XMLNode& node)
+{
+       if (set_state (node)) {
+               throw failed_constructor ();
+       }
+}
+
 Location*
 Location::operator= (const Location& other)
 {
@@ -77,8 +85,12 @@ Location::set_start (jack_nframes_t s)
                        _end = s;
                        start_changed(this); /* EMIT SIGNAL */
                        if ( is_start() ) {
+                               Session::StartTimeChanged (); /* EMIT SIGNAL */
                                AudioFileSource::set_header_position_offset ( s );
                        }
+                       if ( is_end() ) {
+                               Session::EndTimeChanged (); /* EMIT SIGNAL */
+                       }
                }
                return 0;
        }
@@ -241,13 +253,16 @@ XMLNode&
 Location::get_state (void)
 {
        XMLNode *node = new XMLNode ("Location");
-       char buf[32];
+       char buf[64];
 
        typedef map<string, string>::const_iterator CI;
+
        for(CI m = cd_info.begin(); m != cd_info.end(); ++m){
                node->add_child_nocopy(cd_info_node(m->first, m->second));
        }
 
+       id().print (buf);
+       node->add_property("id", buf);
        node->add_property ("name", name());
        snprintf (buf, sizeof (buf), "%u", start());
        node->add_property ("start", buf);
@@ -262,7 +277,6 @@ Location::get_state (void)
 int
 Location::set_state (const XMLNode& node)
 {
-       XMLPropertyList plist;
        const XMLProperty *prop;
 
        XMLNodeList cd_list = node.children();
@@ -272,14 +286,17 @@ Location::set_state (const XMLNode& node)
        string cd_name;
        string cd_value;
 
-
        if (node.name() != "Location") {
                error << _("incorrect XML node passed to Location::set_state") << endmsg;
                return -1;
        }
 
-       plist = node.properties();
-               
+       if ((prop = node.property ("id")) == 0) {
+               warning << _("XML node for Location has no ID information") << endmsg;
+       } else {
+               _id = prop->value ();
+       }
+
        if ((prop = node.property ("name")) == 0) {
                error << _("XML node for Location has no name information") << endmsg;
                return -1;
@@ -582,16 +599,20 @@ Locations::set_state (const XMLNode& node)
                Glib::Mutex::Lock lm (lock);
 
                for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-                       Location *loc = new Location;
                        
-                       if (loc->set_state (**niter)) {
-                               delete loc;
-                       } else {
+                       try {
+
+                               Location *loc = new Location (**niter);
                                locations.push_back (loc);
                        }
+
+                       catch (failed_constructor& err) {
+                               error << _("could not load location from session file - ignored") << endmsg;
+                       }
                }
                
                if (locations.size()) {
+
                        current_location = locations.front();
                } else {
                        current_location = 0;