diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2011-03-02 17:05:16 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2011-03-02 17:05:16 +0000 |
commit | 5e431d1d5806e8f617b9bfa10c5c8766e0b1a4ce (patch) | |
tree | 2561e389524a2348eb2c0f8f9ed6462c3220a593 /libs/ardour/smf_source.cc | |
parent | 488d54a341b2d4f6bb23f8801d293356f664a96a (diff) |
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
Diffstat (limited to 'libs/ardour/smf_source.cc')
-rw-r--r-- | libs/ardour/smf_source.cc | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index f134ff5335..c686ae3d27 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -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; } |