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
This commit is contained in:
Paul Davis 2009-03-05 15:34:01 +00:00
parent 702632a905
commit cb3aaf44cb
5 changed files with 69 additions and 24 deletions

View 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&);

View 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;

View file

@ -47,23 +47,7 @@ using namespace PBD;
AudioTrack::AudioTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
: Track (sess, name, flag, mode)
{
AudioDiskstream::Flag dflags = AudioDiskstream::Flag (0);
if (_flags & Hidden) {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Hidden);
} else {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Recordable);
}
if (mode == Destructive) {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Destructive);
}
boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name, dflags));
_session.add_diskstream (ds);
set_diskstream (boost::dynamic_pointer_cast<AudioDiskstream> (ds), this);
use_new_diskstream ();
}
AudioTrack::AudioTrack (Session& sess, const XMLNode& node)
@ -76,6 +60,28 @@ AudioTrack::~AudioTrack ()
{
}
void
AudioTrack::use_new_diskstream ()
{
AudioDiskstream::Flag dflags = AudioDiskstream::Flag (0);
if (_flags & Hidden) {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Hidden);
} else {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Recordable);
}
if (_mode == Destructive) {
dflags = AudioDiskstream::Flag (dflags | AudioDiskstream::Destructive);
}
boost::shared_ptr<AudioDiskstream> ds (new AudioDiskstream (_session, name(), dflags));
_session.add_diskstream (ds);
set_diskstream (boost::dynamic_pointer_cast<AudioDiskstream> (ds), this);
}
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) {

View 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;

View 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");
}
}