basic support for replicated sources, part two

This commit is contained in:
Paul Davis 2014-08-27 13:48:04 -04:00
parent 595585d84f
commit 18a9bd459a
7 changed files with 64 additions and 8 deletions

View file

@ -175,6 +175,7 @@ class LIBARDOUR_API AudioDiskstream : public Diskstream
Sample *speed_buffer;
boost::shared_ptr<AudioFileSource> write_source;
boost::shared_ptr<AudioFileSource> replication_source;
/** Information about the Port that our audio data comes from */
ChannelSource source;
@ -262,7 +263,7 @@ class LIBARDOUR_API AudioDiskstream : public Diskstream
int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
void reset_replication_sources ();
int reset_replication_sources ();
};
} // namespace ARDOUR

View file

@ -183,7 +183,7 @@ class LIBARDOUR_API Diskstream : public SessionObject, public PublicDiskstream
static PBD::Signal0<void> DiskOverrun;
static PBD::Signal0<void> DiskUnderrun;
static PBD::Signal0<void> ReplicationPathChange;
static PBD::Signal0<int> ReplicationPathChange;
protected:
friend class Session;
@ -339,7 +339,7 @@ class LIBARDOUR_API Diskstream : public SessionObject, public PublicDiskstream
void route_going_away ();
virtual void reset_replication_sources () = 0;
virtual int reset_replication_sources () = 0;
};
}; /* namespace ARDOUR */

View file

@ -182,7 +182,7 @@ class LIBARDOUR_API MidiDiskstream : public Diskstream
MidiBuffer _gui_feed_buffer;
mutable Glib::Threads::Mutex _gui_feed_buffer_mutex;
void reset_replication_sources () { /* no replication for MIDI */ }
int reset_replication_sources () { return 0; /* no replication for MIDI */ }
};
}; /* namespace ARDOUR */

View file

@ -613,6 +613,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
boost::shared_ptr<AudioFileSource> create_audio_source_for_session (
size_t, std::string const &, uint32_t, bool destructive);
boost::shared_ptr<AudioFileSource> create_replicated_audio_source (boost::shared_ptr<AudioFileSource> original, const std::string& replication_parent_folder);
boost::shared_ptr<MidiSource> create_midi_source_for_session (std::string const &);
boost::shared_ptr<MidiSource> create_midi_source_by_stealing_name (boost::shared_ptr<Track>);

View file

@ -1932,6 +1932,8 @@ AudioDiskstream::use_new_write_source (uint32_t n)
chan->write_source->set_allow_remove_if_empty (!destructive());
reset_replication_sources ();
return 0;
}
@ -2499,8 +2501,23 @@ AudioDiskstream::set_write_source_name (const std::string& str) {
return true;
}
void
int
AudioDiskstream::reset_replication_sources ()
{
RCUWriter<ChannelList> writer (channels);
boost::shared_ptr<ChannelList> c = writer.get_copy();
try {
for (ChannelList::iterator chan = c->begin(); chan != c->end(); ++chan) {
if (!_replication_path.empty()) {
// (*chan)->replication_source = session.create_replicated_audio_source ((*c)->write_source, _replication_path);
} else {
(*chan)->replication_source.reset ();
}
}
return 0;
} catch (...) {
error << string_compose (_("%1: cannot create replication sources @ %2"), _name, _replication_path) << endmsg;
return -1;
}
}

View file

@ -63,7 +63,7 @@ string Diskstream::_replication_path;
PBD::Signal0<void> Diskstream::DiskOverrun;
PBD::Signal0<void> Diskstream::DiskUnderrun;
PBD::Signal0<void> Diskstream::ReplicationPathChange;
PBD::Signal0<int> Diskstream::ReplicationPathChange;
Diskstream::Diskstream (Session &sess, const string &name, Flag flag)
: SessionObject(sess, name)
@ -753,6 +753,9 @@ void
Diskstream::set_replication_path (const std::string& path)
{
_replication_path = path;
ReplicationPathChange (); /* EMIT SIGNAL */
if (ReplicationPathChange ()) { /* EMIT SIGNAL */
// error
}
}

View file

@ -4120,6 +4120,40 @@ Session::create_audio_source_for_session (size_t n_chans, string const & base, u
}
}
/** Create a new within-session audio source */
boost::shared_ptr<AudioFileSource>
Session::create_replicated_audio_source (boost::shared_ptr<AudioFileSource> original, const std::string& replication_parent_folder)
{
if (!Glib::file_test (replication_parent_folder.c_str(), Glib::FileTest (G_FILE_TEST_EXISTS|G_FILE_TEST_IS_DIR))) {
throw failed_constructor ();
}
string session_dirname = Glib::path_get_basename (_path);
vector<string> v;
v.push_back (replication_parent_folder);
v.push_back (session_dirname);
v.push_back (X_("audio"));
string repdir = Glib::build_filename (v);
if (!Glib::file_test (repdir.c_str(), Glib::FileTest (G_FILE_TEST_EXISTS|G_FILE_TEST_IS_DIR))) {
if (g_mkdir_with_parents (repdir.c_str(), 0755) < 0) {
throw failed_constructor ();
}
}
string file = Glib::path_get_basename (original->path());
string path = Glib::build_filename (repdir, file);
if (!path.empty()) {
return boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createWritable (DataType::AUDIO, *this, path, false, frame_rate()));
} else {
throw failed_constructor ();
}
}
/** Create a new within-session MIDI source */
boost::shared_ptr<MidiSource>
Session::create_midi_source_for_session (string const & basic_name)