1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Added a guarantee that the TrackSerialiser won't modify tracks it receives.

This commit is contained in:
Thomas Harte 2018-05-18 23:03:28 -04:00
parent ed06533e60
commit 8263c48a1d
9 changed files with 21 additions and 18 deletions

View File

@ -27,7 +27,7 @@ PCMPatchedTrack::PCMPatchedTrack(const PCMPatchedTrack &original) {
active_period_ = periods_.begin(); active_period_ = periods_.begin();
} }
Track *PCMPatchedTrack::clone() { Track *PCMPatchedTrack::clone() const {
return new PCMPatchedTrack(*this); return new PCMPatchedTrack(*this);
} }

View File

@ -43,9 +43,9 @@ class PCMPatchedTrack: public Track {
void add_segment(const Time &start_time, const PCMSegment &segment, bool clamp_to_index_hole); void add_segment(const Time &start_time, const PCMSegment &segment, bool clamp_to_index_hole);
// To satisfy Storage::Disk::Track // To satisfy Storage::Disk::Track
Event get_next_event(); Event get_next_event() override;
Time seek_to(const Time &time_since_index_hole); Time seek_to(const Time &time_since_index_hole) override;
Track *clone(); Track *clone() const override;
private: private:
std::shared_ptr<Track> underlying_track_; std::shared_ptr<Track> underlying_track_;

View File

@ -46,7 +46,7 @@ PCMTrack::PCMTrack(const PCMTrack &original) : PCMTrack() {
segment_event_sources_ = original.segment_event_sources_; segment_event_sources_ = original.segment_event_sources_;
} }
Track *PCMTrack::clone() { Track *PCMTrack::clone() const {
return new PCMTrack(*this); return new PCMTrack(*this);
} }

View File

@ -42,9 +42,9 @@ class PCMTrack: public Track {
PCMTrack(const PCMTrack &); PCMTrack(const PCMTrack &);
// as per @c Track // as per @c Track
Event get_next_event(); Event get_next_event() override;
Time seek_to(const Time &time_since_index_hole); Time seek_to(const Time &time_since_index_hole) override;
Track *clone(); Track *clone() const override;
private: private:
// storage for the segments that describe this track // storage for the segments that describe this track

View File

@ -114,7 +114,7 @@ class Track {
/*! /*!
The virtual copy constructor pattern; returns a copy of the Track. The virtual copy constructor pattern; returns a copy of the Track.
*/ */
virtual Track *clone() = 0; virtual Track *clone() const = 0;
}; };
} }

View File

@ -8,11 +8,14 @@
#include "TrackSerialiser.hpp" #include "TrackSerialiser.hpp"
#include <memory>
// TODO: if this is a PCMTrack with only one segment and that segment's bit rate is within tolerance, // TODO: if this is a PCMTrack with only one segment and that segment's bit rate is within tolerance,
// just return a copy of that segment. // just return a copy of that segment.
Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time length_of_a_bit) { Storage::Disk::PCMSegment Storage::Disk::track_serialisation(const Track &track, Time length_of_a_bit) {
unsigned int history_size = 16; unsigned int history_size = 16;
DigitalPhaseLockedLoop pll(100, history_size); DigitalPhaseLockedLoop pll(100, history_size);
std::unique_ptr<Track> track_copy(track.clone());
struct ResultAccumulator: public DigitalPhaseLockedLoop::Delegate { struct ResultAccumulator: public DigitalPhaseLockedLoop::Delegate {
PCMSegment result; PCMSegment result;
@ -29,12 +32,12 @@ Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time
length_multiplier.simplify(); length_multiplier.simplify();
// start at the index hole // start at the index hole
track.seek_to(Time(0)); track_copy->seek_to(Time(0));
// grab events until the next index hole // grab events until the next index hole
Time time_error = Time(0); Time time_error = Time(0);
while(true) { while(true) {
Track::Event next_event = track.get_next_event(); Track::Event next_event = track_copy->get_next_event();
if(next_event.type == Track::Event::IndexHole) break; if(next_event.type == Track::Event::IndexHole) break;
Time extended_length = next_event.length * length_multiplier + time_error; Time extended_length = next_event.length * length_multiplier + time_error;
@ -47,7 +50,7 @@ Storage::Disk::PCMSegment Storage::Disk::track_serialisation(Track &track, Time
if(history_size) { if(history_size) {
history_size--; history_size--;
if(!history_size) { if(!history_size) {
track.seek_to(Time(0)); track_copy->seek_to(Time(0));
time_error.set_zero(); time_error.set_zero();
pll.set_delegate(&result_accumulator); pll.set_delegate(&result_accumulator);
} }

View File

@ -30,7 +30,7 @@ namespace Disk {
@param length_of_a_bit The expected length of a single bit, as a proportion of the @param length_of_a_bit The expected length of a single bit, as a proportion of the
track length. track length.
*/ */
PCMSegment track_serialisation(Track &track, Time length_of_a_bit); PCMSegment track_serialisation(const Track &track, Time length_of_a_bit);
} }
} }

View File

@ -21,6 +21,6 @@ Storage::Time UnformattedTrack::seek_to(const Time &time_since_index_hole) {
return Time(0); return Time(0);
} }
Track *UnformattedTrack::clone() { Track *UnformattedTrack::clone() const {
return new UnformattedTrack; return new UnformattedTrack;
} }

View File

@ -19,9 +19,9 @@ namespace Disk {
*/ */
class UnformattedTrack: public Track { class UnformattedTrack: public Track {
public: public:
Event get_next_event(); Event get_next_event() override;
Time seek_to(const Time &time_since_index_hole); Time seek_to(const Time &time_since_index_hole) override;
Track *clone(); Track *clone() const override;
}; };
} }