public void SortByTitle() { List <string> names = new List <string>(); List <Song> sorted = new List <Song>(); foreach (var song in Songs) { names.Add(song.Title); } names.Sort(); foreach (var name in names) { foreach (var song in Songs) { if (song.Title == name) { sorted.Add(song); continue; } } } Songs.Clear(); Songs.AddRange(sorted); }
public bool AddSongRange(List <Song> songs) { if (songs == null || songs.Count == 0) { return(false); } Songs.AddRange(songs); return(true); }
public void LoadLibrary() { var songs = _sqlService.SelectAll <Song>().OrderByDescending(p => p.Id); var albums = _sqlService.SelectAll <Album>().OrderByDescending(p => p.Id); var artists = _sqlService.SelectAll <Artist>().OrderByDescending(p => p.Id); foreach (var song in songs) { song.Artist = artists.FirstOrDefault(p => p.Id == song.ArtistId); song.Album = albums.FirstOrDefault(p => p.Id == song.AlbumId); } foreach (var album in albums) { album.Songs.AddRange(songs.Where(p => p.AlbumId == album.Id).OrderBy(p => p.TrackNumber)); album.PrimaryArtist = artists.FirstOrDefault(p => p.Id == album.PrimaryArtistId); if (_dispatcher != null) { _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => album.Artwork = await GetArtworkAsync(album.Id)).AsTask().Wait(); } } foreach (var artist in artists) { artist.Songs.AddRange(songs.Where(p => p.ArtistId == artist.Id)); artist.Albums.AddRange(albums.Where(p => p.PrimaryArtistId == artist.Id)); } //Foreground app if (_dispatcher != null) { _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Songs.AddRange(songs); Artists.AddRange(artists); Albums.AddRange(albums); }); } //background player else { Songs = new ObservableCollection <Song>(songs); Artists = new ObservableCollection <Artist>(artists); Albums = new ObservableCollection <Album>(albums); } LoadQueue(); LoadPlaylists(); CleanupFiles(); }
async void LoadDB() { using (Service.PlaylistService service = new Service.PlaylistService(Playlist.Name)) { if (service.IsValid) { var ss = service.GetTrackCount(); Songs.AddRange(await service.GetTracks().ConfigureAwait(false)); Refresh(); } } }
internal async Task <List <Song> > GetSongsAsync() { if (IsOnline && Songs != null && Songs.Count > 0) { return(Songs); } if (Songs.Count == SongsID.Length) { return(Songs); } Songs.Clear(); var opr = SQLOperator.Current(); var s = await opr.GetSongsAsync(SongsID); var s1 = s.OrderBy(x => x.Track); s1 = s1.OrderBy(x => x.Disc); Songs.AddRange(s1); var t = ThreadPool.RunAsync(async work => { SongsID = s.Select(x => x.ID).ToArray(); if (SongsID.IsNullorEmpty()) { await SQLOperator.Current().RemoveAlbumAsync(ID); } else { await SQLOperator.Current().UpdateAlbumAsync(new Album(ID) { Songs = SongsID, Name = Name ?? string.Empty, Genres = Genres ?? new string[] { }, Year = Year, AlbumSort = AlbumSort ?? string.Empty, TrackCount = TrackCount, DiscCount = DiscCount, AlbumArtists = AlbumArtists ?? new string[] { }, AlbumArtistsSort = AlbumArtistsSort ?? new string[] { }, ReplayGainAlbumGain = ReplayGainAlbumGain, ReplayGainAlbumPeak = ReplayGainAlbumPeak, PicturePath = ArtworkUri == null ? string.Empty : ArtworkUri.AbsolutePath ?? string.Empty, }); } }); return(s1.ToList()); }
//----------------------------------- SONGS --------------------------------------------------------------- public void GetSongs() { try { foreach (var a in Albums) { Songs.AddRange(LastFm.GetSongs(a)); } Songs.RemoveAll(s => s.Duration == 0); //remove songs with duration 0 Songs = Songs.Distinct().ToList(); //remove duplicates Songs.ForEach(s => s.Name = s.Name.Replace("&", "And")); Songs.ForEach(s => s.SqlName = s.Name.Replace("'", "''")); } catch (Exception e) { throw e; } }
public void Shuffle() { List <Song> suffledSongs = new List <Song>(); int step = 3; for (int i = 0; i < step; i++) { int index = i; while (index < Songs.Count) { suffledSongs.Add(Songs[index]); index += step; } } Songs.Clear(); Songs.AddRange(suffledSongs); }
async void LoadDB() { string password = await ShowPasswordDialog(Playlist.IsPrivate); if (password == playlist.Password) { using (PlaylistService service = new PlaylistService(Playlist.Name, Playlist.IsPrivate, password)) { if (service.IsValid) { var ss = service.GetTrackCount(); Songs.AddRange(await service.GetTracks().ConfigureAwait(false)); await Refresh(); } } } else { LoadDB(); } }
public void Add(Playlist playList) { Songs.AddRange(playList.Songs); }
public void Add(ALbum album) { Songs.AddRange(album.Songs); }
public void Add(params Song[] songs) { Songs.AddRange(songs); }
public void Add(Artist artist) { Songs.AddRange(artist.Songs); }
void LoadAlbumSongs(Album album) { Songs.AddRange(album.AlbumSongs); }
void LoadAlbumSongs(Album album) { Songs.AddRange(album.AlbumSongs, true, true); }
private void slurpLocation(object stateInfo) { string location = (string)stateInfo; // Get every file underneath the path given FileInfo[] files = new DirectoryInfo(location).GetFiles("*", SearchOption.AllDirectories); Trace.WriteLine(string.Format("Got {0} files in {1}", files.Length, location)); // Divide the list up into chunks int workItems = Environment.ProcessorCount * ThreadsPerProcessor; int chunkSize = Math.Max(files.Count() / workItems, 1); int count = workItems; // Use an event to wait for all work items using (var manualResetEvent = new ManualResetEvent(false)) { // Each work item processes approx. 1/Nth of the data items WaitCallback callback = state => { int iteration = (int)state; int from = chunkSize * iteration; int to = iteration == workItems - 1 ? files.Count() : chunkSize * (iteration + 1); Trace.WriteLine(string.Format("Thread {1}: Sub-tasked {0} files.", to - from, iteration)); // Create a per-thread list to add to the main list at the end. List <Song> songs = new List <Song>(); // Iterate through our thread's slice of the whole list. while (from < to) { Song song = songFromFileSystemInfo(files[from++]); if (song != null) { songs.Add(song); } } Trace.WriteLine(string.Format("Thread {1}: Filled {0} songs.", songs.Count, iteration)); lock (_locker) { Songs.AddRange(songs); } if (Interlocked.Decrement(ref count) == 0) { manualResetEvent.Set(); } }; // The ThreadPool is used to process all but one of the // chunks; the current thread is used for that chunk, // rather than just blocking. for (int i = 0; i < workItems; i++) { if (i < workItems - 1) { ThreadPool.QueueUserWorkItem(callback, i); } else { callback(i); } } // Wait for all work to complete manualResetEvent.WaitOne(); } }
async void LoadAlbumSongs(Album album) { Songs.AddRange(album.AlbumSongs); await Refresh(); }
public void LoadLibrary() { if (IsLibraryLoaded) { return; } /* * Sqlite makes a transaction to create a shared lock * Wrapping it in one single transactions assures it is only lock and release once */ _sqlService.BeginTransaction(); var songs = _sqlService.SelectAll <Song>().OrderByDescending(p => p.Id).ToList(); var artists = _sqlService.SelectAll <Artist>().OrderByDescending(p => p.Id).ToList(); var albums = _sqlService.SelectAll <Album>().OrderByDescending(p => p.Id).ToList(); Stations = new OptimizedObservableCollection <RadioStation>( _sqlService.SelectAll <RadioStation>().OrderByDescending(p => p.Id).ToList()); // Let go of the lock _sqlService.Commit(); var isForeground = _dispatcher != null; foreach (var song in songs) { song.Artist = artists.FirstOrDefault(p => p.Id == song.ArtistId); song.Album = albums.FirstOrDefault(p => p.Id == song.AlbumId); } if (isForeground) { _dispatcher.RunAsync(() => Songs.AddRange(songs)).Wait(); } else { Songs.AddRange(songs); } if (isForeground) { foreach (var artist in artists) { _dispatcher.RunAsync( () => { var artworkPath = string.Format(_artistArtworkFilePath, artist.Id); artist.Artwork = artist.HasArtwork ? _bitmapFactory.CreateImage( new Uri(_localFilePrefix + artworkPath)) : null; if (ScaledImageSize != 0 && artist.Artwork != null) { artist.Artwork.SetDecodedPixel(ScaledImageSize); } }).Wait(); } } foreach (var album in albums) { album.Songs.AddRange(songs.Where(p => !p.IsTemp && p.AlbumId == album.Id).OrderBy(p => p.TrackNumber)); album.PrimaryArtist = artists.FirstOrDefault(p => p.Id == album.PrimaryArtistId); if (isForeground) { _dispatcher.RunAsync( () => { var artworkPath = string.Format(_artworkFilePath, album.Id); if (album.HasArtwork) { var path = _localFilePrefix + artworkPath; album.Artwork = _bitmapFactory.CreateImage(new Uri(path)); if (ScaledImageSize != 0) { album.Artwork.SetDecodedPixel(ScaledImageSize); album.MediumArtwork = _bitmapFactory.CreateImage(new Uri(path)); album.MediumArtwork.SetDecodedPixel(ScaledImageSize / 2); album.SmallArtwork = _bitmapFactory.CreateImage(new Uri(path)); album.SmallArtwork.SetDecodedPixel(50); } } else { var artwork = album.PrimaryArtist.HasArtwork ? album.PrimaryArtist.Artwork : _missingArtwork; album.Artwork = artwork; album.MediumArtwork = artwork; album.SmallArtwork = artwork; } }).Wait(); } } if (isForeground) { _dispatcher.RunAsync(() => Albums.AddRange(albums)).Wait(); } else { Albums.AddRange(albums); } foreach (var artist in artists) { artist.Songs.AddRange(songs.Where(p => !p.IsTemp && p.ArtistId == artist.Id).OrderBy(p => p.Name)); artist.Albums.AddRange( albums.Where(p => p.PrimaryArtistId == artist.Id && p.Songs.Count > 0).OrderBy(p => p.Name)); var songsAlbums = artist.Songs.Select(p => p.Album); artist.Albums.AddRange(songsAlbums.Where(p => p.Songs.Count > 0 && !artist.Albums.Contains(p))); } if (isForeground) { _dispatcher.RunAsync(() => Artists.AddRange(artists)).Wait(); } else { Artists.AddRange(artists); } IsLibraryLoaded = true; LoadQueue(songs); LoadPlaylists(); if (!isForeground) { return; } var corruptSongs = Songs.ToList() .Where(p => string.IsNullOrEmpty(p.Name) || p.Album == null || p.Artist == null) .ToList(); foreach (var corruptSong in corruptSongs) { DeleteSongAsync(corruptSong).Wait(); } _dispatcher.RunAsync( () => { if (LibraryLoaded != null) { LibraryLoaded(this, null); } }).Wait(); try { CleanupFiles(albums, artists); } catch { // ignored } }
public void AddSongs(List <Song> songs) { Songs.AddRange(songs); }