summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_source.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-05-19 03:03:28 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-05-19 03:03:28 +0000
commite258b2622a4386b405c2216d79b34887c3ed55bf (patch)
treec2abdacc5a31e9d572257050256c704b41fb46f5 /libs/ardour/midi_source.cc
parentc25c7598c134af88bb85b5690aabc35472c77adf (diff)
MIDI region forking, plus Playlist::regions_to_read() fix forward ported from 2.X. region forking requires a few cleanups
git-svn-id: svn://localhost/ardour2/branches/3.0@7118 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/midi_source.cc')
-rw-r--r--libs/ardour/midi_source.cc80
1 files changed, 49 insertions, 31 deletions
diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc
index 2b0efd78e1..5e8bda1ea2 100644
--- a/libs/ardour/midi_source.cc
+++ b/libs/ardour/midi_source.cc
@@ -28,6 +28,8 @@
#include <iomanip>
#include <algorithm>
+#include <glibmm/fileutils.h>
+
#include "pbd/xml++.h"
#include "pbd/pthread_utils.h"
#include "pbd/basename.h"
@@ -81,6 +83,7 @@ MidiSource::MidiSource (Session& s, const XMLNode& node)
}
}
+
MidiSource::~MidiSource ()
{
}
@@ -223,44 +226,59 @@ MidiSource::mark_streaming_write_completed ()
_writing = false;
}
+boost::shared_ptr<MidiSource>
+MidiSource::clone (Evoral::MusicalTime begin, Evoral::MusicalTime end)
+{
+ string newname = PBD::basename_nosuffix(_name.val());
+ string newpath;
+
+ /* get a new name for the MIDI file we're going to write to
+ */
+
+ do {
+
+ newname = bump_name_once (newname, '-');
+ /* XXX build path safely */
+ newpath = _session.session_directory().midi_path().to_string() +"/"+ newname + ".mid";
+
+ } while (Glib::file_test (newpath, Glib::FILE_TEST_EXISTS));
+
+ boost::shared_ptr<MidiSource> newsrc = boost::dynamic_pointer_cast<MidiSource>(
+ SourceFactory::createWritable(DataType::MIDI, _session,
+ newpath, false, _session.frame_rate()));
+
+ newsrc->set_timeline_position(_timeline_position);
+
+ if (_model) {
+ _model->write_to (newsrc, begin, end);
+ } else {
+ error << string_compose (_("programming error: %1"), X_("no model for MidiSource during ::clone()"));
+ return boost::shared_ptr<MidiSource>();
+ }
+
+ newsrc->flush_midi();
+
+ /* force a reload of the model if the range is partial */
+
+ if (begin != Evoral::MinMusicalTime || end != Evoral::MaxMusicalTime) {
+ newsrc->load_model (true, true);
+ }
+
+ return newsrc;
+}
+
void
MidiSource::session_saved()
{
flush_midi();
if (_model && _model->edited()) {
- string newname;
- const string basename = PBD::basename_nosuffix(_name.val());
- string::size_type last_dash = basename.find_last_of("-");
- if (last_dash == string::npos || last_dash == basename.find_first_of("-")) {
- newname = basename + "-1";
- } else {
- stringstream ss(basename.substr(last_dash+1));
- unsigned write_count = 0;
- ss >> write_count;
- // cerr << "WRITE COUNT: " << write_count << endl;
- ++write_count; // start at 1
- ss.clear();
- ss << basename.substr(0, last_dash) << "-" << write_count;
- newname = ss.str();
- }
-
- string newpath = _session.session_directory().midi_path().to_string() +"/"+ newname + ".mid";
-
- boost::shared_ptr<MidiSource> newsrc = boost::dynamic_pointer_cast<MidiSource>(
- SourceFactory::createWritable(DataType::MIDI, _session,
- newpath, false, _session.frame_rate()));
-
- newsrc->set_timeline_position(_timeline_position);
- _model->write_to(newsrc);
-
- // cyclic dependency here, ugly :(
- newsrc->set_model(_model);
- _model->set_midi_source(newsrc.get());
-
- newsrc->flush_midi();
+ boost::shared_ptr<MidiSource> newsrc = clone ();
- Switched (newsrc); /* EMIT SIGNAL */
+ if (newsrc) {
+ _model->set_midi_source (newsrc.get());
+ Switched (newsrc); /* EMIT SIGNAL */
+ }
}
}