1 #ifndef ContiguousSegmentation_hxx
2 #define ContiguousSegmentation_hxx
14 const char *
what()
const throw () {
return "Segmentation point inserted out of limits";}
44 for (
const TData * it=begin; it!=end; it++)
54 TimePositions::iterator insertPoint =
59 unsigned position = insertPoint -
_offsets.begin() +1;
60 _offsets.insert(insertPoint, timePosition);
81 void remove(
unsigned segment)
84 unsigned offsetToRemove = segment? segment-1 : 0;
97 unsigned pickOffset(
double timePosition,
double tolerance)
const
99 return pickPosition(
_offsets, timePosition, tolerance);
107 unsigned pickOnset(
double timePosition,
double tolerance)
const
109 return pickPosition(
_onsets, timePosition, tolerance);
116 if (timePosition<0)
return _offsets.size();
117 TimePositions::const_iterator lowerBound =
119 return lowerBound -
_offsets.begin();
126 void dragOnset(
unsigned segment,
double newTimePosition)
129 if (segment==0)
return;
140 if (segment==
_offsets.size())
return;
141 if (segment==
_offsets.size()-1)
return;
144 if (newTimePosition<
_onsets[segment])
145 newTimePosition =
_onsets[segment];
147 if (newTimePosition>
_offsets[segment+1])
148 newTimePosition =
_offsets[segment+1];
152 _onsets[segment+1]=newTimePosition;
159 unsigned nSegments=
_onsets.size();
160 segmentation.
Resize(nSegments-1);
161 segmentation.
SetSize(nSegments-1);
162 for(
unsigned i=1; i<nSegments; i++)
175 unsigned pickPosition(
const TimePositions & positions,
double timePosition,
double tolerance)
const
177 TimePositions::const_iterator lowerBound =
178 std::lower_bound(positions.begin(), positions.end(), timePosition-tolerance);
179 TimePositions::const_iterator upperBound =
180 std::upper_bound(lowerBound, positions.end(), timePosition+tolerance);
182 if (lowerBound==upperBound)
return positions.size();
185 unsigned lowerSegment = lowerBound - positions.begin();
186 unsigned upperSegment = upperBound - positions.begin();
187 double lastDifference = std::fabs(timePosition-positions[lowerSegment]);
188 for (
unsigned i=lowerSegment; i<upperSegment; i++)
190 double newDifference = std::fabs(timePosition-positions[i]);
191 if (newDifference>lastDifference)
break;
192 lastDifference = newDifference;
203 #endif//ContiguousSegmentation_hxx