diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-04-13 10:29:07 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-04-14 13:05:08 -0400 |
commit | 0d5f4c553a7365612a44e1e0997a6d0e14d8b7ff (patch) | |
tree | d7031e5df3cbd6cae2b91630405e5f342d66f0e7 /libs/ardour/midi_region.cc | |
parent | 384c0a9facf1bfecc783ac048dbb0bae4ad901fd (diff) |
dramatic change in logic and naming for operations related to adding a MIDI region on demand and cloning/unlinking
Existing code would cause data loss due to creation of two Source objects referring the same path, one with removable flags and one without. Careful code review suggested a variety of thinkos, function naming problems and other confusion that caused this. I have tried ot extensively comment what is going on with these operations, because it is one key area in which MIDI differs from audio: with audio, capture is the only way to add a new audio region, but for MIDI there are GUI input events that can add a new region.
Diffstat (limited to 'libs/ardour/midi_region.cc')
-rw-r--r-- | libs/ardour/midi_region.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 8509e55f97..e7298e7526 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -25,6 +25,8 @@ #include <set> #include <glibmm/threads.h> +#include <glibmm/fileutils.h> +#include <glibmm/miscutils.h> #include "pbd/xml++.h" #include "pbd/basename.h" @@ -36,6 +38,7 @@ #include "ardour/midi_source.h" #include "ardour/region_factory.h" #include "ardour/session.h" +#include "ardour/source_factory.h" #include "ardour/tempo.h" #include "ardour/types.h" @@ -127,15 +130,30 @@ MidiRegion::~MidiRegion () boost::shared_ptr<MidiRegion> MidiRegion::clone (string path) const { + boost::shared_ptr<MidiSource> newsrc; + + /* caller must check for pre-existing file */ + assert (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)); + newsrc = boost::dynamic_pointer_cast<MidiSource>( + SourceFactory::createWritable(DataType::MIDI, _session, + path, false, _session.frame_rate())); + return clone (newsrc); +} + +boost::shared_ptr<MidiRegion> +MidiRegion::clone (boost::shared_ptr<MidiSource> newsrc) const +{ 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 (path, bbegin, bend); + if (midi_source(0)->write_to (newsrc, bbegin, bend)) { + return boost::shared_ptr<MidiRegion> (); + } PropertyList plist; - plist.add (Properties::name, PBD::basename_nosuffix (ms->name())); + plist.add (Properties::name, PBD::basename_nosuffix (newsrc->name())); plist.add (Properties::whole_file, true); plist.add (Properties::start, _start); plist.add (Properties::start_beats, _start_beats); @@ -143,7 +161,7 @@ MidiRegion::clone (string path) const plist.add (Properties::length_beats, _length_beats); plist.add (Properties::layer, 0); - return boost::dynamic_pointer_cast<MidiRegion> (RegionFactory::create (ms, plist, true)); + return boost::dynamic_pointer_cast<MidiRegion> (RegionFactory::create (newsrc, plist, true)); } void |