Use XMLNode::get/set_property API in ExportFormatSpecification
[ardour.git] / libs / ardour / audio_diskstream.cc
index c33b56f984fdeb37278c5c1c24b2ee22890e5f08..b2bf7b2b4a8fedffd56ea70d6bb67e1c68fb37e1 100644 (file)
@@ -1641,6 +1641,7 @@ AudioDiskstream::transport_stopped_wallclock (struct tm& when, time_t twhen, boo
                _playlist->set_capture_insertion_in_progress (true);
                _playlist->freeze ();
 
+               const framepos_t preroll_off = _session.preroll_record_trim_len ();
                for (buffer_position = c->front()->write_source->last_capture_start_frame(), ci = capture_info.begin(); ci != capture_info.end(); ++ci) {
 
                        string region_name;
@@ -1660,6 +1661,9 @@ AudioDiskstream::transport_stopped_wallclock (struct tm& when, time_t twhen, boo
 
                                boost::shared_ptr<Region> rx (RegionFactory::create (srcs, plist));
                                region = boost::dynamic_pointer_cast<AudioRegion> (rx);
+                               if (preroll_off > 0) {
+                                       region->trim_front (buffer_position + preroll_off);
+                               }
                        }
 
                        catch (failed_constructor& err) {
@@ -1669,7 +1673,7 @@ AudioDiskstream::transport_stopped_wallclock (struct tm& when, time_t twhen, boo
 
                        i_am_the_modifier++;
 
-                       _playlist->add_region (region, (*ci)->start, 1, non_layered());
+                       _playlist->add_region (region, (*ci)->start + preroll_off, 1, non_layered());
                        _playlist->set_layer (region, DBL_MAX);
                        i_am_the_modifier--;
 
@@ -1901,12 +1905,10 @@ XMLNode&
 AudioDiskstream::get_state ()
 {
        XMLNode& node (Diskstream::get_state());
-       char buf[64] = "";
        LocaleGuard lg;
 
        boost::shared_ptr<ChannelList> c = channels.reader();
-       snprintf (buf, sizeof(buf), "%u", (unsigned int) c->size());
-       node.add_property ("channels", buf);
+       node.set_property ("channels", (uint32_t)c->size());
 
        if (!capturing_sources.empty() && _session.get_record_enabled()) {
 
@@ -1915,7 +1917,7 @@ AudioDiskstream::get_state ()
 
                for (vector<boost::shared_ptr<AudioFileSource> >::iterator i = capturing_sources.begin(); i != capturing_sources.end(); ++i) {
                        cs_grandchild = new XMLNode (X_("file"));
-                       cs_grandchild->add_property (X_("path"), (*i)->path());
+                       cs_grandchild->set_property (X_("path"), (*i)->path());
                        cs_child->add_child_nocopy (*cs_grandchild);
                }
 
@@ -1923,13 +1925,14 @@ AudioDiskstream::get_state ()
 
                Location* pi;
 
-               if (_session.config.get_punch_in() && ((pi = _session.locations()->auto_punch_location()) != 0)) {
-                       snprintf (buf, sizeof (buf), "%" PRId64, pi->start());
+               if (_session.preroll_record_punch_enabled ()) {
+                       cs_child->set_property (X_("at"), _session.preroll_record_punch_pos());
+               } else if (_session.config.get_punch_in() && ((pi = _session.locations()->auto_punch_location()) != 0)) {
+                       cs_child->set_property (X_("at"), pi->start());
                } else {
-                       snprintf (buf, sizeof (buf), "%" PRId64, _session.transport_frame());
+                       cs_child->set_property (X_("at"), _session.transport_frame());
                }
 
-               cs_child->add_property (X_("at"), buf);
                node.add_child_nocopy (*cs_child);
        }
 
@@ -1939,10 +1942,8 @@ AudioDiskstream::get_state ()
 int
 AudioDiskstream::set_state (const XMLNode& node, int version)
 {
-       XMLProperty const * prop;
        XMLNodeList nlist = node.children();
        XMLNodeIterator niter;
-       uint32_t nchans = 1;
        XMLNode* capture_pending_node = 0;
        LocaleGuard lg;
 
@@ -1964,9 +1965,8 @@ AudioDiskstream::set_state (const XMLNode& node, int version)
                return -1;
        }
 
-       if ((prop = node.property ("channels")) != 0) {
-               nchans = atoi (prop->value().c_str());
-       }
+       uint32_t nchans = 1;
+       node.get_property ("channels", nchans);
 
        // create necessary extra channels
        // we are always constructed with one and we always need one
@@ -1983,8 +1983,6 @@ AudioDiskstream::set_state (const XMLNode& node, int version)
                remove_channel (_n_channels.n_audio() - nchans);
        }
 
-
-
        if (!destructive() && capture_pending_node) {
                /* destructive streams have one and only one source per channel,
                   and so they never end up in pending capture in any useful