fixes for creating tracks from templates - a new Diskstream is needed, andgetting...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 5 Mar 2009 15:34:01 +0000 (15:34 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 5 Mar 2009 15:34:01 +0000 (15:34 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@4733 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audio_track.h
libs/ardour/ardour/track.h
libs/ardour/audio_track.cc
libs/ardour/session.cc
libs/ardour/track.cc

index 96a12c9bd4a5df1fcdf8a24db30c897d230acc89..63fa2945e082312115e80938f1ac8826e25c7b9a 100644 (file)
@@ -52,7 +52,8 @@ class AudioTrack : public Track
 
        int use_diskstream (string name);
        int use_diskstream (const PBD::ID& id);
-       
+       void use_new_diskstream ();
+
        int export_stuff (vector<Sample*>& buffers, uint32_t nbufs, nframes_t nframes, nframes_t end_frame);
 
        void freeze (InterThreadInfo&);
index 4ba1b88fb754075955abbb9de5a74f9e9b7e11c5..e756b106991d4547e350f274e478188edac6fed2 100644 (file)
@@ -83,6 +83,8 @@ class Track : public Route
        XMLNode&    get_template();
        virtual int set_state(const XMLNode& node) = 0;
 
+       static void zero_diskstream_id_in_xml (XMLNode&);
+
        PBD::Controllable& rec_enable_control() { return _rec_enable_control; }
 
        bool record_enabled() const;
index 0fdd523f8f8bfc1698013614cbe4e4ef1232e339..920367ae94c5e475989de0f66d7549be3db8faa0 100644 (file)
@@ -46,6 +46,22 @@ using namespace PBD;
 
 AudioTrack::AudioTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
        : Track (sess, name, flag, mode)
+{
+       use_new_diskstream ();
+}
+
+AudioTrack::AudioTrack (Session& sess, const XMLNode& node)
+       : Track (sess, node)
+{
+       _set_state (node, false);
+}
+
+AudioTrack::~AudioTrack ()
+{
+}
+
+void
+AudioTrack::use_new_diskstream ()
 {
        AudioDiskstream::Flag dflags = AudioDiskstream::Flag (0);
 
@@ -55,27 +71,17 @@ AudioTrack::AudioTrack (Session& sess, string name, Route::Flag flag, TrackMode
                dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Recordable);
        }
 
-       if (mode == Destructive) {
+       if (_mode == Destructive) {
                dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Destructive);
        }
 
-       boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name, dflags));
+       boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name(), dflags));
        
        _session.add_diskstream (ds);
 
        set_diskstream (boost::dynamic_pointer_cast<AudioDiskstream> (ds), this);
 }
 
-AudioTrack::AudioTrack (Session& sess, const XMLNode& node)
-       : Track (sess, node)
-{
-       _set_state (node, false);
-}
-
-AudioTrack::~AudioTrack ()
-{
-}
-
 int
 AudioTrack::set_mode (TrackMode m)
 {
@@ -269,8 +275,19 @@ AudioTrack::_set_state (const XMLNode& node, bool call_base)
        } else {
                
                PBD::ID id (prop->value());
-               
-               if (use_diskstream (id)) {
+               PBD::ID zero ("0");
+
+               /* this wierd hack is used when creating tracks from a template. there isn't
+                  a particularly good time to interpose between setting the first part of
+                  the track state (notably Route::set_state() and the track mode), and the
+                  second part (diskstream stuff). So, we have a special ID for the diskstream
+                  that means "you should create a new diskstream here, not look for
+                  an old one.
+               */
+
+               if (id == zero) {
+                       use_new_diskstream ();
+               } else if (use_diskstream (id)) {
                        return -1;
                }
        }
@@ -292,7 +309,11 @@ AudioTrack::_set_state (const XMLNode& node, bool call_base)
 
        pending_state = const_cast<XMLNode*> (&node);
 
-       _session.StateReady.connect (mem_fun (*this, &AudioTrack::set_state_part_two));
+       if (_session.state_of_the_state() & Session::Loading) {
+               _session.StateReady.connect (mem_fun (*this, &AudioTrack::set_state_part_two));
+       } else {
+               set_state_part_two ();
+       }
 
        return 0;
 }
@@ -353,8 +374,11 @@ AudioTrack::set_state_part_two ()
        XMLProperty* prop;
        LocaleGuard lg (X_("POSIX"));
 
-       /* This is called after all session state has been restored but before
-          have been made ports and connections are established.
+       /* During session loading: this is called after all session state has been restored but before
+          ports have been created and connections are established.
+
+          During creation from templates: this is called after ports have been created, and connections
+          are established.
        */
 
        if (pending_state == 0) {
index 7019910381051ba00a28f09aaba36887bbeca658..52f799695cf7a06dfa14f33b882af5c2a8ed16a1 100644 (file)
@@ -2077,9 +2077,11 @@ Session::new_route_from_template (uint32_t how_many, const std::string& template
                                /*NOTREACHED*/
                        }
 
-                       IO::set_name_in_state (node_copy, name);
+                       IO::set_name_in_state (*node_copy.children().front(), name);
                }
 
+               Track::zero_diskstream_id_in_xml (node_copy);
+               
                try {
                        shared_ptr<Route> route (XMLRouteFactory (node_copy));
            
@@ -2088,6 +2090,15 @@ Session::new_route_from_template (uint32_t how_many, const std::string& template
                                goto out;
                        }
 
+                       if (boost::dynamic_pointer_cast<Track>(route)) {
+                               /* force input/output change signals so that the new diskstream
+                                  picks up the configuration of the route. During session
+                                  loading this normally happens in a different way.
+                               */
+                               route->input_changed (IOChange (ConfigurationChanged|ConnectionsChanged), this);
+                               route->output_changed (IOChange (ConfigurationChanged|ConnectionsChanged), this);
+                       }
+
                        route->set_remote_control_id (control_id);
                        ++control_id;
            
index 6615a3dacd79ff5ecec802164c48721723d19fa6..91bc623f8448df1f634c35ccf55a3e9aa5e0432d 100644 (file)
@@ -220,3 +220,10 @@ Track::set_latency_delay (nframes_t longest_session_latency)
        _diskstream->set_roll_delay (_roll_delay);
 }
 
+void
+Track::zero_diskstream_id_in_xml (XMLNode& node)
+{
+       if (node.property ("diskstream-id")) {
+               node.add_property ("diskstream-id", "0");
+       }
+}