From b2a051f6c624e01c9f561840b12eaba5e602e5ff Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 Feb 2009 17:54:45 +0000 Subject: [PATCH] More powerful SMF::open interface. git-svn-id: svn://localhost/ardour2/branches/3.0@4554 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/smf_source.h | 4 ++-- libs/ardour/smf_source.cc | 18 +++++++++--------- libs/evoral/evoral/SMF.hpp | 6 +++--- libs/evoral/src/SMF.cpp | 28 +++++++++++++++++----------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index 4fc868fd35..e92ae59c3f 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -25,7 +25,7 @@ #include #include -#include +#include namespace Evoral { template class Event; } @@ -34,7 +34,7 @@ namespace ARDOUR { template class MidiRingBuffer; /** Standard Midi File (Type 0) Source */ -class SMFSource : public MidiSource, public Evoral::LibSMF { +class SMFSource : public MidiSource, public Evoral::SMF { public: enum Flag { Writable = 0x1, diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 5752795ccf..ea558ea281 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -55,7 +55,7 @@ uint64_t SMFSource::header_position_offset; SMFSource::SMFSource (Session& s, std::string path, Flag flags) : MidiSource (s, region_name_from_path(path, false)) - , Evoral::LibSMF () + , Evoral::SMF () , _flags (Flag(flags | Writable)) // FIXME: this needs to be writable for now , _allow_remove_if_empty(true) { @@ -146,7 +146,7 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_ size_t scratch_size = 0; // keep track of scratch to minimize reallocs // FIXME: don't seek to start and search every read (brutal!) - Evoral::LibSMF::seek_to_start(); + Evoral::SMF::seek_to_start(); // FIXME: assumes tempo never changes after start const double frames_per_beat = _session.tempo_map().tempo_at(_timeline_position).frames_per_beat( @@ -155,7 +155,7 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_ const uint64_t start_ticks = (uint64_t)((start / frames_per_beat) * ppqn()); - while (!Evoral::LibSMF::eof()) { + while (!Evoral::SMF::eof()) { int ret = read_event(&ev_delta_t, &ev_size, &ev_buffer); if (ret == -1) { // EOF //cerr << "SMF - EOF\n"; @@ -251,7 +251,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) make_sure_controls_have_the_right_interpolation(); } - Evoral::LibSMF::flush(); + Evoral::SMF::flush(); free(buf); const nframes_t oldlen = _length; @@ -301,7 +301,7 @@ SMFSource::append_event_unlocked(EventTimeUnit unit, const Evoral::Event delta_time = (uint32_t)((ev.time() - last_event_time()) * ppqn()); } - Evoral::LibSMF::append_event_delta(delta_time, ev); + Evoral::SMF::append_event_delta(delta_time, ev); _write_data_count += ev.size(); } @@ -356,7 +356,7 @@ void SMFSource::mark_streaming_midi_write_started (NoteMode mode, nframes_t start_frame) { MidiSource::mark_streaming_midi_write_started (mode, start_frame); - Evoral::LibSMF::begin_write (); + Evoral::SMF::begin_write (); } void @@ -369,7 +369,7 @@ SMFSource::mark_streaming_write_completed () } _model->set_edited(false); - Evoral::LibSMF::end_write (); + Evoral::SMF::end_write (); } void @@ -634,7 +634,7 @@ SMFSource::load_model(bool lock, bool force_reload) } _model->start_write(); - Evoral::LibSMF::seek_to_start(); + Evoral::SMF::seek_to_start(); uint64_t time = 0; /* in SMF ticks */ Evoral::Event ev; @@ -706,6 +706,6 @@ SMFSource::destroy_model() void SMFSource::flush_midi() { - Evoral::LibSMF::end_write(); + Evoral::SMF::end_write(); } diff --git a/libs/evoral/evoral/SMF.hpp b/libs/evoral/evoral/SMF.hpp index f45719cdab..c2760d9df5 100644 --- a/libs/evoral/evoral/SMF.hpp +++ b/libs/evoral/evoral/SMF.hpp @@ -45,6 +45,9 @@ public: SMF() : _last_ev_time(0), _smf(0), _smf_track(0), _empty(true) {}; virtual ~SMF(); + + int open(const std::string& path, bool create=true, int track=1) THROW_FILE_ERROR; + void close() THROW_FILE_ERROR; void seek_to_start() const; @@ -63,9 +66,6 @@ public: int flush_footer() { return 0; } protected: - int open(const std::string& path) THROW_FILE_ERROR; - void close() THROW_FILE_ERROR; - int read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf) const; private: diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index ece9fc4c1e..eda2da233c 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -42,40 +42,46 @@ SMF