private long CalculateViewOrder (QueueMode mode)
{
long view_order = 0;
long current_view_order = CurrentTrackViewOrder;
switch (mode) {
case QueueMode.AfterCurrentTrack:
// view_order will point to the currently playing track, or if we're playing from
// somewhere besides the play queue it will point to the very top of the queue.
// We want to insert tracks after this one.
view_order = ServiceManager.PlaybackController.Source is PlayQueueSource
? current_view_order
: current_view_order - 1;
break;
case QueueMode.AfterCurrentAlbum:
// view order will point to the last track of the currently
// playing album.
IterateTrackModelUntilEndMatch (out view_order, true);
break;
case QueueMode.AfterCurrentArtist:
// view order will point to the last track of the currently
// playing artist.
IterateTrackModelUntilEndMatch (out view_order, false);
break;
case QueueMode.Normal:
// view_order will point to the last pending non-generated track in the queue
// or to the current_track if all tracks are generated. We want to insert tracks after it.
view_order = Math.Max(current_view_order, ServiceManager.DbConnection.Query<long> (@"
SELECT MAX(ViewOrder)
FROM CorePlaylistEntries
WHERE PlaylistID = ? AND ViewOrder > ? AND Generated = 0",
DbId, current_view_order
));
break;
default:
throw new ArgumentException ("Handling for that QueueMode has not been defined");
}
return view_order;
}