From cb3aaf44cb6d8262962c016ff148fedcb0dd71ba Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 5 Mar 2009 15:34:01 +0000 Subject: fixes for creating tracks from templates - a new Diskstream is needed, andgetting it set up is quite tricky; also fix naming of template-based new Routes git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@4733 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/audio_track.h | 3 ++- libs/ardour/ardour/track.h | 2 ++ libs/ardour/audio_track.cc | 58 ++++++++++++++++++++++++++++------------ libs/ardour/session.cc | 13 ++++++++- libs/ardour/track.cc | 7 +++++ 5 files changed, 64 insertions(+), 19 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/audio_track.h b/libs/ardour/ardour/audio_track.h index 96a12c9bd4..63fa2945e0 100644 --- a/libs/ardour/ardour/audio_track.h +++ b/libs/ardour/ardour/audio_track.h @@ -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& buffers, uint32_t nbufs, nframes_t nframes, nframes_t end_frame); void freeze (InterThreadInfo&); diff --git a/libs/ardour/ardour/track.h b/libs/ardour/ardour/track.h index 4ba1b88fb7..e756b10699 100644 --- a/libs/ardour/ardour/track.h +++ b/libs/ardour/ardour/track.h @@ -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; diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index 0fdd523f8f..920367ae94 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -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 ds (new AudioDiskstream (_session, name, dflags)); + boost::shared_ptr ds (new AudioDiskstream (_session, name(), dflags)); _session.add_diskstream (ds); set_diskstream (boost::dynamic_pointer_cast (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 (&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) { diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 7019910381..52f799695c 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -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 (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(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; diff --git a/libs/ardour/track.cc b/libs/ardour/track.cc index 6615a3dacd..91bc623f84 100644 --- a/libs/ardour/track.cc +++ b/libs/ardour/track.cc @@ -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"); + } +} -- cgit v1.2.3