X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsmf_source.cc;h=22245abe5236ab4267bb658f8de69aa67559a797;hb=47ba20143e06445a9977f4757d816439ea8042d0;hp=cc547ed9f5bd88cdd255acc30cee4e8ad9599eb5;hpb=d5be54080fa25e45e8bf441e9c72e53ffa3daa72;p=ardour.git diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index cc547ed9f5..22245abe52 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -30,7 +30,7 @@ #include "pbd/stl_delete.h" #include "pbd/strsplit.h" -#include +#include "pbd/gstdio_compat.h" #include #include @@ -46,7 +46,7 @@ #include "ardour/session.h" #include "ardour/smf_source.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; using namespace Glib; @@ -71,7 +71,7 @@ SMFSource::SMFSource (Session& s, const string& path, Source::Flag flags) if (init (_path, false)) { throw failed_constructor (); } - + assert (!Glib::file_test (_path, Glib::FILE_TEST_EXISTS)); existence_check (); @@ -107,7 +107,7 @@ SMFSource::SMFSource (Session& s, const string& path) if (init (_path, true)) { throw failed_constructor (); } - + assert (Glib::file_test (_path, Glib::FILE_TEST_EXISTS)); existence_check (); @@ -215,6 +215,7 @@ SMFSource::read_unlocked (const Lock& lock, framepos_t const source_start, framepos_t start, framecnt_t duration, + Evoral::Range* loop_range, MidiStateTracker* tracker, MidiChannelFilter* filter) const { @@ -288,6 +289,10 @@ SMFSource::read_unlocked (const Lock& lock, */ const framepos_t ev_frame_time = converter.to(Evoral::Beats::ticks_at_rate(time, ppqn())) + source_start; + if (loop_range) { + loop_range->squish (ev_frame_time); + } + if (ev_frame_time < start + duration) { if (!filter || !filter->filter(ev_buffer, ev_size)) { destination.write (ev_frame_time, ev_type, ev_size, ev_buffer); @@ -370,7 +375,7 @@ SMFSource::write_unlocked (const Lock& lock, break; } time -= position; - + ev.set(buf, size, time); ev.set_event_type(midi_parameter_type(ev.buffer()[0])); ev.set_id(Evoral::next_event_id()); @@ -397,9 +402,11 @@ SMFSource::append_event_beats (const Glib::Threads::Mutex::Lock& lock, return; } - /*printf("SMFSource: %s - append_event_beats ID = %d time = %lf, size = %u, data = ", +#if 0 + printf("SMFSource: %s - append_event_beats ID = %d time = %lf, size = %u, data = ", name().c_str(), ev.id(), ev.time(), ev.size()); - for (size_t i = 0; i < ev.size(); ++i) printf("%X ", ev.buffer()[i]); printf("\n");*/ + for (size_t i = 0; i < ev.size(); ++i) printf("%X ", ev.buffer()[i]); printf("\n"); +#endif Evoral::Beats time = ev.time(); if (time < _last_ev_time_beats) { @@ -432,6 +439,8 @@ SMFSource::append_event_beats (const Glib::Threads::Mutex::Lock& lock, } _length_beats = max(_length_beats, time); + /* midi is in quarter note format as distinct from ardour beat */ + _length_pulse = _length_beats.to_double() / 4.0; const Evoral::Beats delta_time_beats = time - _last_ev_time_beats; const uint32_t delta_time_ticks = delta_time_beats.to_ticks(ppqn()); @@ -481,6 +490,8 @@ SMFSource::append_event_frames (const Glib::Threads::Mutex::Lock& lock, } _length_beats = max(_length_beats, ev_time_beats); + /* midi is in quarter note format as distinct from ardour beat */ + _length_pulse = _length_beats.to_double() / 4.0; const Evoral::Beats last_time_beats = converter.from (_last_ev_time_frames); const Evoral::Beats delta_time_beats = ev_time_beats - last_time_beats; @@ -575,7 +586,7 @@ SMFSource::safe_midi_file_extension (const string& file) static bool compile = true; const int nmatches = 2; regmatch_t matches[nmatches]; - + if (Glib::file_test (file, Glib::FILE_TEST_EXISTS)) { if (!Glib::file_test (file, Glib::FILE_TEST_IS_REGULAR)) { /* exists but is not a regular file */ @@ -588,7 +599,7 @@ SMFSource::safe_midi_file_extension (const string& file) } else { compile = false; } - + if (regexec (&compiled_pattern, file.c_str(), nmatches, matches, 0)) { return false; } @@ -678,8 +689,8 @@ SMFSource::load_model (const Glib::Threads::Mutex::Lock& lock, bool force_reload ss += b; } - DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("SMF %6 load model delta %1, time %2, size %3 buf %4, type %5\n", - delta_t, time, size, ss , event_type, name())); + DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("SMF %7 load model delta %1, time %2, size %3 buf %4, type %5 id %6\n", + delta_t, time, size, ss , event_type, event_id, name())); #endif eventlist.push_back(make_pair ( @@ -693,6 +704,8 @@ SMFSource::load_model (const Glib::Threads::Mutex::Lock& lock, bool force_reload size = scratch_size; _length_beats = max(_length_beats, event_time); + /* midi is in quarter note format as distinct from ardour beat */ + _length_pulse = _length_beats.to_double() / 4.0; } /* event ID's must immediately precede the event they are for */ @@ -708,6 +721,10 @@ SMFSource::load_model (const Glib::Threads::Mutex::Lock& lock, bool force_reload delete it->first; } + // cerr << "----SMF-SRC-----\n"; + // _playback_buf->dump (cerr); + // cerr << "----------------\n"; + _model->end_write (Evoral::Sequence::ResolveStuckNotes, _length_beats); _model->set_edited (false); invalidate(lock); @@ -778,8 +795,6 @@ SMFSource::prevent_deletion () /* Unlike the audio case, the MIDI file remains mutable (because we can edit MIDI data) */ - + _flags = Flag (_flags & ~(Removable|RemovableIfEmpty|RemoveAtDestroy)); } - -