private TrackInfo QueryTrackLinear (Direction direction, bool restart)
{
if (Source.TrackModel.Count == 0)
return null;
int index = Source.TrackModel.IndexOf (PriorTrack);
// Clear the PriorTrack after using it, it's only meant to be used for a single Query
PriorTrack = null;
if (index == -1) {
return Source.TrackModel[0];
} else {
index += (direction == Direction.Next ? 1 : -1);
if (index >= 0 && index < Source.TrackModel.Count) {
return Source.TrackModel[index];
} else if (!restart) {
return null;
} else if (index < 0) {
return Source.TrackModel[Source.TrackModel.Count - 1];
} else {
return Source.TrackModel[0];
}
}
}