- midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
- assert(_name.val().find("/") == string::npos);
- assert(_type == DataType::MIDI);
+/** Create a new MidiRegion that has its own version of some/all of the Source used by another.
+ */
+boost::shared_ptr<MidiRegion>
+MidiRegion::clone ()
+{
+ BeatsFramesConverter bfc (_session.tempo_map(), _position);
+ Evoral::MusicalTime const bbegin = bfc.from (_start);
+ Evoral::MusicalTime const bend = bfc.from (_start + _length);
+
+ boost::shared_ptr<MidiSource> ms = midi_source(0)->clone (bbegin, bend);
+
+ PropertyList plist;
+
+ plist.add (Properties::name, ms->name());
+ plist.add (Properties::whole_file, true);
+ plist.add (Properties::start, _start);
+ plist.add (Properties::length, _length);
+ plist.add (Properties::length_beats, _length_beats);
+ plist.add (Properties::layer, 0);
+
+ return boost::dynamic_pointer_cast<MidiRegion> (RegionFactory::create (ms, plist, true));