1 #ifndef UnsizedSegmentation_hxx
2 #define UnsizedSegmentation_hxx
14 const char *
what()
const throw () {
return "Segmentation point inserted out of limits";}
37 for (
const TData * it=begin; it!=end; it++)
50 TimePositions::iterator insertPoint =
55 _onsets.push_back(timePosition);
59 unsigned position = insertPoint -
_offsets.begin();
60 _offsets.insert(insertPoint, timePosition);
72 void remove(
unsigned segment)
85 unsigned pickOffset(
double timePosition,
double tolerance)
const
87 return pickPosition(
_offsets, timePosition, tolerance);
95 unsigned pickOnset(
double timePosition,
double tolerance)
const
97 return pickPosition(
_onsets, timePosition, tolerance);
104 if (timePosition<0)
return _offsets.size();
105 TimePositions::const_iterator upperBound =
107 if (upperBound ==
_offsets.begin())
return 0;
108 if (timePosition - *(upperBound-1) > *upperBound - timePosition)
return upperBound -
_offsets.begin();
109 return upperBound -
_offsets.begin()-1;
116 void dragOnset(
unsigned segment,
double newTimePosition)
128 if (segment==
_offsets.size())
return;
131 double leftLimit = segment!=0 ?
133 double rightLimit = segment+1<
_offsets.size()?
135 if (newTimePosition<leftLimit)
136 newTimePosition = leftLimit;
138 if (newTimePosition>rightLimit)
139 newTimePosition = rightLimit;
143 _onsets[segment]=newTimePosition;
150 unsigned nSegments =
_onsets.size();
151 segmentation.
Resize(nSegments);
152 segmentation.
SetSize(nSegments);
153 for (
unsigned i=0; i<nSegments; i++)
167 unsigned pickPosition(
const TimePositions & positions,
double timePosition,
double tolerance)
const
169 TimePositions::const_iterator lowerBound =
170 std::lower_bound(positions.begin(), positions.end(), timePosition-tolerance);
171 TimePositions::const_iterator upperBound =
172 std::upper_bound(lowerBound, positions.end(), timePosition+tolerance);
174 if (lowerBound==upperBound)
return positions.size();
177 unsigned lowerSegment = lowerBound - positions.begin();
178 unsigned upperSegment = upperBound - positions.begin();
179 double lastDifference = std::fabs(timePosition-positions[lowerSegment]);
180 for (
unsigned i=lowerSegment; i<upperSegment; i++)
182 double newDifference = std::fabs(timePosition-positions[i]);
183 if (newDifference>lastDifference)
break;
184 lastDifference = newDifference;
195 #endif//UnsizedSegmentation_hxx