コード例 #1
0
        // Randomizes the ViewOrder of all the enabled, unplayed/playing songs
        public void Shuffle()
        {
            if (!Populate)
            {
                if (current_track == null)
                {
                    return;
                }

                int enabled_count    = EnabledCount;
                int first_view_order = (int)CurrentTrackViewOrder;
                int last_view_order  = first_view_order + enabled_count;

                // If the current track is playing, don't shuffle it
                if (ServiceManager.PlayerEngine.IsPlaying(current_track))
                {
                    first_view_order++;
                }

                // Nothing to do if less than 2 tracks
                if (last_view_order - first_view_order < 2)
                {
                    return;
                }

                // Save the current_track index, so we can update the current track
                // to be whatever one is at that position after we shuffle them -- assuming
                // the current_track isn't already playing.
                int current_index = TrackModel.IndexOf(current_track);

                // Setup a function that will return a random ViewOrder in the range we want
                var rand        = new Random();
                var func_id     = "play-queue-shuffle-order-" + rand.NextDouble().ToString();
                var view_orders = Enumerable.Range(first_view_order, last_view_order)
                                  .OrderBy(a => rand.NextDouble())
                                  .ToList();
                int i = 0;
                BinaryFunction.Add(func_id, (f, b) => view_orders[i++]);

                ServiceManager.DbConnection.Execute(
                    "UPDATE CorePlaylistEntries SET ViewOrder = HYENA_BINARY_FUNCTION (?, NULL, NULL) WHERE PlaylistID = ? AND ViewOrder >= ?",
                    func_id, DbId, first_view_order
                    );

                BinaryFunction.Remove(func_id);
                Reload();

                // Update the current track unless it was playing (and therefore wasn't moved)
                if (!ServiceManager.PlayerEngine.IsPlaying(current_track))
                {
                    SetCurrentTrack(TrackModel[current_index] as DatabaseTrackInfo);
                }
            }
        }
コード例 #2
0
        public AlbumDuplicateSolver()
        {
            Id          = "dupe-album";
            Name        = Catalog.GetString("Duplicate Albums");
            Description = Catalog.GetString("Displayed are albums that should likely be merged.  For each row, click the desired title to make it bold, or uncheck it to take no action.");

            AddFinder(
                "Title", "AlbumID", "CoreAlbums, CoreArtists",
                "CoreAlbums.ArtistID = CoreArtists.ArtistID AND Title IS NOT NULL AND Name IS NOT NULL AND " +
                String.Format("AlbumID IN (SELECT DISTINCT(AlbumID) FROM CoreTracks WHERE PrimarySourceID = {0})", ServiceManager.SourceManager.MusicLibrary.DbId),
                "HYENA_BINARY_FUNCTION ('dupe-album', Title, Name)"
                );

            BinaryFunction.Add(Id, NormalizedGroup);
        }
コード例 #3
0
        public ArtistDuplicateSolver()
        {
            Id          = "dupe-artist";
            Name        = Catalog.GetString("Duplicate Artists");
            Description = Catalog.GetString("Displayed are artists that should likely be merged.  For each row, click the desired name to make it bold, or uncheck it to take no action.");

            AddFinder(
                "Name", "ArtistID", "CoreArtists",
                String.Format(
                    @"(Name IS NOT NULL AND ArtistID IN (SELECT DISTINCT(ArtistID) FROM CoreTracks WHERE PrimarySourceID = {0})
                        OR ArtistID IN (SELECT DISTINCT(a.ArtistID) FROM CoreTracks t, CoreAlbums a WHERE t.AlbumID = a.AlbumID AND t.PrimarySourceID = {0}))",
                    EnableUnitTests ? 0 : ServiceManager.SourceManager.MusicLibrary.DbId
                    ),
                "HYENA_BINARY_FUNCTION ('dupe-artist', Name, NULL)"
                );

            BinaryFunction.Add(Id, NormalizeArtistName);
        }
コード例 #4
0
        public GenreDuplicateSolver()
        {
            Id          = "dupe-genre";
            Name        = Catalog.GetString("Duplicate Genres");
            Description = Catalog.GetString("Displayed are genres that should likely be merged.  For each row, click the desired genre to make it bold, or uncheck it to take no action.");

            AddFinder(
                "Genre", "TrackID", "CoreTracks",
                String.Format(@"
                    TrackID IN (SELECT TrackID FROM CoreTracks
                        WHERE PrimarySourceID = {0} GROUP BY Genre
                    ) AND Genre IS NOT NULL",
                              ServiceManager.SourceManager.MusicLibrary.DbId
                              ),
                "HYENA_BINARY_FUNCTION ('dupe-genre', Genre, NULL)"
                );

            BinaryFunction.Add(Id, NormalizedGroup);
        }