bool used() const { return use_count() > 0; }
uint32_t level() const { return _level; }
+ std::string ancestor_name() { return _ancestor_name.empty() ? name() : _ancestor_name; }
+ void set_ancestor_name(const std::string& name) { _ancestor_name = name; }
+
protected:
DataType _type;
Flag _flags;
mutable Glib::Threads::Mutex _analysis_lock;
gint _use_count; /* atomic */
uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
+ std::string _ancestor_name;
private:
void fix_writable_flags ();
boost::shared_ptr<MidiSource> newsrc;
/* caller must check for pre-existing file */
+ assert (!path.empty());
assert (!Glib::file_test (path, Glib::FILE_TEST_EXISTS));
newsrc = boost::dynamic_pointer_cast<MidiSource>(
SourceFactory::createWritable(DataType::MIDI, _session,
#include <inttypes.h>
+#include "pbd/basename.h"
#include "pbd/error.h"
#include "ardour/audioregion.h"
} else if ((mr = boost::dynamic_pointer_cast<const MidiRegion>(region)) != 0) {
if (mr->session().config.get_midi_copy_is_fork()) {
- ret = mr->clone ();
+ /* What we really want to do here is what Editor::fork_region()
+ does via Session::create_midi_source_by_stealing_name(), but we
+ don't have a Track. We'll just live with the skipped number,
+ and store the ancestral name of sources so multiple clones
+ generates reasonable names that don't have too many suffixes. */
+ const std::string ancestor_name = mr->sources().front()->ancestor_name();
+ const std::string base = PBD::basename_nosuffix(ancestor_name);
+
+ boost::shared_ptr<MidiSource> source = mr->session().create_midi_source_for_session(base);
+ source->set_ancestor_name(mr->sources().front()->name());
+ ret = mr->clone(source);
} else {
ret = boost::shared_ptr<Region> (new MidiRegion (mr, 0));
}
return s;
}
-/** Return a unique name based on \a owner_name for a new internal MIDI source */
+/** Return a unique name based on `base` for a new internal MIDI source */
string
Session::new_midi_source_path (const string& base)
{