remove entire "stub" file concept; open new audio and MIDI files on demand (at first write); could be a few gotchas with some corner case scenarios, but apparently works OK

git-svn-id: svn://localhost/ardour2/branches/3.0@9038 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-03-02 17:05:16 +00:00
parent 488d54a341
commit 5e431d1d58
17 changed files with 133 additions and 260 deletions

View file

@ -65,10 +65,8 @@ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags)
if (init(_path, false)) {
throw failed_constructor ();
}
if (create(path)) {
throw failed_constructor ();
}
/* file is not opened until write */
}
/** Constructor used for existing internal-to-session files. */
@ -92,6 +90,8 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
if (open(_path)) {
throw failed_constructor ();
}
_open = true;
}
SMFSource::~SMFSource ()
@ -101,6 +101,16 @@ SMFSource::~SMFSource ()
}
}
int
SMFSource::open_for_write ()
{
if (create (_path)) {
return -1;
}
_open = true;
return 0;
}
/** All stamps in audio frames */
framecnt_t
SMFSource::read_unlocked (Evoral::EventSink<framepos_t>& destination, framepos_t const source_start,
@ -110,6 +120,11 @@ SMFSource::read_unlocked (Evoral::EventSink<framepos_t>& destination, framepos_t
int ret = 0;
uint64_t time = 0; // in SMF ticks, 1 tick per _ppqn
if (writable() && !_open) {
/* nothing to read since nothing has ben written */
return duration;
}
DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("SMF read_unlocked: start %1 duration %2\n", start, duration));
_read_data_count = 0;
@ -206,6 +221,15 @@ SMFSource::read_unlocked (Evoral::EventSink<framepos_t>& destination, framepos_t
framecnt_t
SMFSource::write_unlocked (MidiRingBuffer<framepos_t>& source, framepos_t position, framecnt_t duration)
{
if (!_open && open_for_write()) {
error << string_compose (_("cannot open MIDI file %1 for write"), _path) << endmsg;
return 0;
}
if (!_writing) {
mark_streaming_write_started ();
}
_write_data_count = 0;
framepos_t time;
@ -387,10 +411,11 @@ SMFSource::set_state (const XMLNode& node, int version)
}
void
SMFSource::mark_streaming_midi_write_started (NoteMode mode, framepos_t start_frame)
SMFSource::mark_streaming_midi_write_started (NoteMode mode)
{
Glib::Mutex::Lock lm (_lock);
MidiSource::mark_streaming_midi_write_started (mode, start_frame);
/* CALLER MUST HOLD LOCK */
MidiSource::mark_streaming_midi_write_started (mode);
Evoral::SMF::begin_write ();
_last_ev_time_beats = 0.0;
_last_ev_time_frames = 0;
@ -444,6 +469,10 @@ SMFSource::load_model (bool lock, bool force_reload)
_model->clear();
}
if (writable() && !_open) {
return;
}
_model->start_write();
Evoral::SMF::seek_to_start();
@ -533,7 +562,7 @@ SMFSource::destroy_model ()
void
SMFSource::flush_midi ()
{
if (!writable()) {
if (!writable() || (writable() && !_open)) {
return;
}