Add length_pulse to MidiSource, usr quarter-notes in midi_read().
- MidiSource _length_beats is in quarter notes. Here we duplicate length_beats for backwards compatibility
This commit is contained in:
parent
2c7a5815ee
commit
21054f6d8d
@ -93,8 +93,8 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha
|
||||
MidiStateTracker* tracker,
|
||||
MidiChannelFilter* filter,
|
||||
const std::set<Evoral::Parameter>& filtered,
|
||||
double beat,
|
||||
double start_beat) const;
|
||||
const double pulse,
|
||||
const double start_pulse) const;
|
||||
|
||||
/** Write data from a MidiRingBuffer to this source.
|
||||
* @param source Source to read from.
|
||||
@ -167,6 +167,7 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha
|
||||
|
||||
void set_length_beats(TimeType l) { _length_beats = l; }
|
||||
TimeType length_beats() const { return _length_beats; }
|
||||
double length_pulse() const { return _length_pulse; }
|
||||
|
||||
virtual void load_model(const Glib::Threads::Mutex::Lock& lock, bool force_reload=false) = 0;
|
||||
virtual void destroy_model(const Glib::Threads::Mutex::Lock& lock) = 0;
|
||||
@ -231,6 +232,7 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha
|
||||
mutable bool _model_iter_valid;
|
||||
|
||||
mutable Evoral::Beats _length_beats;
|
||||
mutable double _length_pulse;
|
||||
mutable framepos_t _last_read_end;
|
||||
|
||||
/** The total duration of the current capture. */
|
||||
|
@ -63,6 +63,7 @@ MidiSource::MidiSource (Session& s, string name, Source::Flag flags)
|
||||
, _writing(false)
|
||||
, _model_iter_valid(false)
|
||||
, _length_beats(0.0)
|
||||
, _length_pulse(0.0)
|
||||
, _last_read_end(0)
|
||||
, _capture_length(0)
|
||||
, _capture_loop_length(0)
|
||||
@ -74,6 +75,7 @@ MidiSource::MidiSource (Session& s, const XMLNode& node)
|
||||
, _writing(false)
|
||||
, _model_iter_valid(false)
|
||||
, _length_beats(0.0)
|
||||
, _length_pulse(0.0)
|
||||
, _last_read_end(0)
|
||||
, _capture_length(0)
|
||||
, _capture_loop_length(0)
|
||||
@ -194,11 +196,13 @@ MidiSource::midi_read (const Lock& lm,
|
||||
MidiStateTracker* tracker,
|
||||
MidiChannelFilter* filter,
|
||||
const std::set<Evoral::Parameter>& filtered,
|
||||
double beat,
|
||||
double start_beat) const
|
||||
const double pulse,
|
||||
const double start_pulse) const
|
||||
{
|
||||
//BeatsFramesConverter converter(_session.tempo_map(), source_start);
|
||||
|
||||
const int32_t tpb = Timecode::BBT_Time::ticks_per_beat;
|
||||
const double pulse_tick_res = floor ((pulse * 4.0 * tpb) + 0.5) / tpb;
|
||||
const double start_qn = (pulse - start_pulse) * 4.0;
|
||||
DEBUG_TRACE (DEBUG::MidiSourceIO,
|
||||
string_compose ("MidiSource::midi_read() %5 sstart %1 start %2 cnt %3 tracker %4\n",
|
||||
source_start, start, cnt, tracker, name()));
|
||||
@ -250,7 +254,7 @@ MidiSource::midi_read (const Lock& lm,
|
||||
* some way (maybe keep an iterator per playlist).
|
||||
*/
|
||||
for (i = _model->begin(); i != _model->end(); ++i) {
|
||||
if (i->time().to_double() + (beat - start_beat) >= beat) {
|
||||
if (floor (((i->time().to_double() + start_qn) * tpb) + 0.5) / tpb >= pulse_tick_res) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -265,8 +269,8 @@ MidiSource::midi_read (const Lock& lm,
|
||||
|
||||
// Copy events in [start, start + cnt) into dst
|
||||
for (; i != _model->end(); ++i) {
|
||||
const framecnt_t time_frames = _session.tempo_map().frame_at_beat (i->time().to_double() + (beat - start_beat));
|
||||
|
||||
const framecnt_t time_frames = _session.tempo_map().frame_at_quarter_note (i->time().to_double() + start_qn);
|
||||
if (time_frames < start + cnt + source_start) {
|
||||
if (filter && filter->filter(i->buffer(), i->size())) {
|
||||
DEBUG_TRACE (DEBUG::MidiSourceIO,
|
||||
@ -346,8 +350,10 @@ MidiSource::mark_write_starting_now (framecnt_t position,
|
||||
_capture_length = capture_length;
|
||||
_capture_loop_length = loop_length;
|
||||
|
||||
BeatsFramesConverter converter(_session.tempo_map(), position);
|
||||
TempoMap& map (_session.tempo_map());
|
||||
BeatsFramesConverter converter(map, position);
|
||||
_length_beats = converter.from(capture_length);
|
||||
_length_pulse = map.pulse_at_frame (position + capture_length) - map.pulse_at_frame (position);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -434,6 +434,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());
|
||||
@ -483,6 +485,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;
|
||||
@ -695,6 +699,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 */
|
||||
|
Loading…
Reference in New Issue
Block a user