From 6bdde542c5ca08d79135d7c6b80aee534dfb83e7 Mon Sep 17 00:00:00 2001 From: Thomas Harte <thomas.harte@gmail.com> Date: Tue, 20 Dec 2016 07:52:14 -0500 Subject: [PATCH] Edging towards functioning automatic tests, fixed right-period adjustment and slightly decreased searching cost while in the process of adding a test. --- .../Clock SignalTests/PCMPatchedTrackTests.mm | 17 +++++++++++++++-- Storage/Disk/PCMPatchedTrack.cpp | 10 +++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm b/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm index a8d1b4d95..79f828df9 100644 --- a/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm +++ b/OSBindings/Mac/Clock SignalTests/PCMPatchedTrackTests.mm @@ -55,11 +55,24 @@ - (void)testZeroPatch { - std::shared_ptr<Storage::Disk::Track> patchableTrack = self.togglingTrack; + std::shared_ptr<Storage::Disk::Track> patchableTrack = self.patchableTogglingTrack; Storage::Disk::PCMPatchedTrack *patchable = dynamic_cast<Storage::Disk::PCMPatchedTrack *>(patchableTrack.get()); if(patchable) { - printf("."); + // add a single one, at 1/32 length at 3/128. So that should shift the location of the second flux transition + Storage::Disk::PCMSegment zero_segment; + zero_segment.data = {0xff}; + zero_segment.number_of_bits = 1; + zero_segment.length_of_a_bit.length = 1; + zero_segment.length_of_a_bit.clock_rate = 32; + patchable->add_segment(Storage::Time(3, 128), zero_segment); + } + + std::vector<Storage::Disk::Track::Event> events; + int c = 5; + while(c--) + { + events.push_back(patchableTrack->get_next_event()); } } diff --git a/Storage/Disk/PCMPatchedTrack.cpp b/Storage/Disk/PCMPatchedTrack.cpp index 240ae9b1b..3123c24ba 100644 --- a/Storage/Disk/PCMPatchedTrack.cpp +++ b/Storage/Disk/PCMPatchedTrack.cpp @@ -54,7 +54,7 @@ void PCMPatchedTrack::insert_period(const Period &period) while(periods_[start_index].start_time >= period.end_time) start_index++; // find the existing period that the new period end in - size_t end_index = 0; + size_t end_index = start_index; while(periods_[end_index].end_time < period.end_time) end_index++; // perform a division if called for @@ -62,8 +62,8 @@ void PCMPatchedTrack::insert_period(const Period &period) { Period right_period = periods_[start_index]; - Time adjustment = period.start_time - right_period.start_time; - right_period.end_time += adjustment; + Time adjustment = period.end_time - right_period.start_time; + right_period.start_time += adjustment; right_period.segment_start_time += adjustment; periods_[start_index].end_time = period.start_time; @@ -75,8 +75,8 @@ void PCMPatchedTrack::insert_period(const Period &period) // perform a left chop on the thing at the start and a right chop on the thing at the end periods_[start_index].end_time = period.start_time; - Time adjustment = period.start_time - periods_[end_index].start_time; - periods_[end_index].end_time += adjustment; + Time adjustment = period.end_time - periods_[end_index].start_time; + periods_[end_index].start_time += adjustment; periods_[end_index].segment_start_time += adjustment; // remove anything in between