public void Refresh ()
{
int index = current_track == null ? Count : TrackModel.IndexOf (current_track);
// If the current track is not playing refresh it too.
if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying (current_track)) {
index--;
}
if (index + 1 < Count) {
// Get the ViewOrder of the current_track
long current_view_order = CurrentTrackViewOrder;
// Get the list of generated tracks.
var generated = new HashSet<long> ();
foreach (long trackID in ServiceManager.DbConnection.QueryEnumerable<long> ( @"
SELECT TrackID
FROM CorePlaylistEntries
WHERE PlaylistID = ? AND Generated = 1 AND ViewOrder >= ?",
DbId, current_view_order)) {
generated.Add (trackID);
}
// Collect the indices of all generated tracks.
var ranges = new RangeCollection ();
for (int i = index + 1; i < Count; i++) {
if (generated.Contains (((DatabaseTrackInfo)TrackModel[i]).TrackId)) {
ranges.Add (i);
}
}
bool removed = false;
foreach (var range in ranges.Ranges) {
RemoveTrackRange (DatabaseTrackModel, range);
removed = true;
}
if (removed) {
OnTracksRemoved ();
}
} else if (Count == 0 || current_track == null) {
UpdatePlayQueue ();
}
}