Banshee.PlayQueue.PlayQueueSource.UpdatePlayQueue C# (CSharp) Method

UpdatePlayQueue() private method

private UpdatePlayQueue ( ) : void
return void
        private void UpdatePlayQueue ()
        {
            // Find the ViewOrder of the current_track.
            long view_order;
            if (current_track == null) {
                view_order = ServiceManager.DbConnection.Query<long> (@"
                    SELECT MAX(ViewOrder) + 1
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ?", DbId
                );
            } else {
                view_order = ServiceManager.DbConnection.Query<long> (@"
                    SELECT ViewOrder
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ? AND EntryID = ?",
                    DbId, Convert.ToInt64 (current_track.CacheEntryId)
                );
            }

            // Offset the model so that no more than played_songs_number tracks are shown before the current_track.
            Offset = played_songs_number == 0 ? view_order : ServiceManager.DbConnection.Query<long> (@"
                SELECT MIN(ViewOrder)
                FROM (
                    SELECT ViewOrder
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ? AND ViewOrder < ?
                    ORDER BY ViewOrder DESC
                    LIMIT ?
                )", DbId, view_order, played_songs_number
            );

            // Check if we need to add more tracks.
            int tracks_to_add = upcoming_songs_number -
                (current_track == null ? 0 : Count - TrackModel.IndexOf (current_track) - 1);

            // If the current track is not playing count it as well.
            if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying (current_track)) {
                tracks_to_add--;
            }

            if (tracks_to_add > 0 && Populate && populate_from != null) {
                // Add songs from the selected source, skip if all tracks need to be populated.
                bool skip = tracks_to_add == upcoming_songs_number;
                for (int i = 0; i < tracks_to_add; i++) {

                    var track = populate_from.DatabaseTrackModel.GetRandom (
                        source_set_at, populate_shuffle_mode, false, skip && i == 0, shuffler) as DatabaseTrackInfo;

                    if (track != null) {
                        EnqueueId (track.TrackId, false, true);
                    }
                }
                OnTracksAdded ();
                if (current_track == null && Count > 0) {
                    // If the queue was empty, make the first added track the current one.
                    SetCurrentTrack (TrackModel[0] as DatabaseTrackInfo);
                    ServiceManager.PlayerEngine.OpenPlay (current_track);
                }
            }
        }