mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Attempted to implemnt seek_to
and to finish add_segment
. Started doing a little of get_next_event
but ran out of time for the day.
This commit is contained in:
parent
8f937ceac8
commit
1ef1f6ec69
@ -24,7 +24,8 @@ void PCMPatchedTrack::add_segment(const Time &start_time, const PCMSegment &segm
|
|||||||
event_sources_.emplace_back(segment);
|
event_sources_.emplace_back(segment);
|
||||||
|
|
||||||
Time zero(0);
|
Time zero(0);
|
||||||
Period insertion_period(start_time, start_time + event_sources_.back().get_length(), zero, &event_sources_.back());
|
Time end_time = start_time + event_sources_.back().get_length();
|
||||||
|
Period insertion_period(start_time, end_time, zero, &event_sources_.back());
|
||||||
|
|
||||||
// the new segment may wrap around, so divide it up into track-length parts if required
|
// the new segment may wrap around, so divide it up into track-length parts if required
|
||||||
Time one = Time(1);
|
Time one = Time(1);
|
||||||
@ -38,6 +39,17 @@ void PCMPatchedTrack::add_segment(const Time &start_time, const PCMSegment &segm
|
|||||||
insertion_period.end_time = next_end_time;
|
insertion_period.end_time = next_end_time;
|
||||||
}
|
}
|
||||||
insert_period(insertion_period);
|
insert_period(insertion_period);
|
||||||
|
|
||||||
|
// the vector may have been resized, potentially invalidating active_period_ even if
|
||||||
|
// the thing it pointed to is still the same thing. So work it out afresh.
|
||||||
|
for(auto period : periods_)
|
||||||
|
{
|
||||||
|
if(period.start_time <= current_time_ && period.end_time > current_time_)
|
||||||
|
{
|
||||||
|
active_period_ = .
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCMPatchedTrack::insert_period(const Period &period)
|
void PCMPatchedTrack::insert_period(const Period &period)
|
||||||
@ -82,10 +94,44 @@ void PCMPatchedTrack::insert_period(const Period &period)
|
|||||||
|
|
||||||
Track::Event PCMPatchedTrack::get_next_event()
|
Track::Event PCMPatchedTrack::get_next_event()
|
||||||
{
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
Track::Event event;
|
||||||
|
if(active_period_->event_source) event = active_period_->event_source->get_next_event();
|
||||||
|
else event = underlying_track_->get_next_event();
|
||||||
|
|
||||||
|
current_time_ += event.length;
|
||||||
|
if(current_time_ >= active_period_->end_time)
|
||||||
|
{
|
||||||
|
current_time_ -= active_period_->end_time;
|
||||||
|
active_period_++;
|
||||||
|
// if(active_period_
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// return active_period_->event_source->seek_to(zero);
|
||||||
|
|
||||||
return underlying_track_->get_next_event();
|
return underlying_track_->get_next_event();
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::Time PCMPatchedTrack::seek_to(const Time &time_since_index_hole)
|
Storage::Time PCMPatchedTrack::seek_to(const Time &time_since_index_hole)
|
||||||
{
|
{
|
||||||
|
for(auto period : periods_)
|
||||||
|
{
|
||||||
|
if(period.start_time <= time_since_index_hole && period.end_time > time_since_index_hole)
|
||||||
|
{
|
||||||
|
active_period_ = .
|
||||||
|
if(period.event_source)
|
||||||
|
return period.event_source->seek_to(time_since_index_hole - period.start_time) + period.start_time;
|
||||||
|
else
|
||||||
return underlying_track_->seek_to(time_since_index_hole);
|
return underlying_track_->seek_to(time_since_index_hole);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this should never be reached
|
||||||
|
Time zero(0);
|
||||||
|
active_period_ = &periods_[0];
|
||||||
|
if(active_period_->event_source)
|
||||||
|
return active_period_->event_source->seek_to(zero);
|
||||||
|
else
|
||||||
|
return underlying_track_->seek_to(zero);
|
||||||
|
}
|
||||||
|
@ -50,6 +50,7 @@ class PCMPatchedTrack: public Track {
|
|||||||
};
|
};
|
||||||
std::vector<Period> periods_;
|
std::vector<Period> periods_;
|
||||||
Period *active_period_;
|
Period *active_period_;
|
||||||
|
Time current_time_;
|
||||||
|
|
||||||
void insert_period(const Period &period);
|
void insert_period(const Period &period);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user