/// <summary>
        /// Handles user input and programmatic changes for viewed songs and selected song
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Input0: CurrentPlaylist.AllSongs, Input1: CurrentPlaylist.CurrentSong, Input2: CurrentPlaylist.WannaSong, Input3: lbxSongs.SelectedIndex</param>
        /// <returns>The list of Songs to view on UI.</returns>
        private object MicCurrentSongIndex_ConvertRef(object sender, MultiplesInputsConvert4EventArgs args)
        {
            if (args.Input0 == null)
            {
                args.Input3 = -1;
                return(null);
            }
            if (args.ChangedValueIndex == 2)
            {
                return(args.Input0);
            }

            IEnumerable <Song> allSongs = (IEnumerable <Song>)args.Input0;
            Song?currentSong            = (Song?)args.Input1;
            int  index = (int)args.Input3;

            if (args.ChangedValueIndex == 3 && index != -1)
            {
                args.Input2 = RequestSong.Start(allSongs.ElementAt(index));
            }
            else if (!currentSong.HasValue)
            {
                args.Input3 = -1;
            }
            else
            {
                args.Input3 = allSongs.IndexOf(currentSong.Value);
            }

            return(allSongs);
        }
示例#2
0
        private static void CheckCurrentSong(IPlaylist playlist)
        {
            if (playlist == null)
            {
                return;
            }

            if (playlist.Songs == null || playlist.Songs.Length == 0)
            {
                playlist.WannaSong = null;
            }
            else if (!playlist.WannaSong.HasValue || !playlist.Songs.Contains(playlist.WannaSong.Value.Song))
            {
                playlist.WannaSong = RequestSong.Start(playlist.Songs.First());
            }
        }
示例#3
0
        private object MicCurrentSongIndex_ConvertRef(Song?currentSong, ref RequestSong?wannaSong,
                                                      IEnumerable <Song> allSongs, IEnumerable <Song> searchSongs, bool isSearching, ref int lbxIndex, int changedInput)
        {
            IEnumerable <Song> songs;
            IPlaylist          currentPlaylist   = viewModel.AudioServiceUI?.CurrentPlaylist;
            bool isCurrentPlaylistSourcePlaylist = currentPlaylist is ISourcePlaylist;

            if (!isSearching)
            {
                songs = allSongs;
            }
            else if (isCurrentPlaylistSourcePlaylist)
            {
                songs = searchSongs;
            }
            else
            {
                songs = searchSongs.Except(allSongs);
            }

            if (changedInput == 6 && lbxIndex != -1 && (isSearching || isChangingSelectedSongIndex))
            {
                ;
            }
            else if (changedInput == 6 && lbxIndex != -1 && allSongs.Contains(songs.ElementAt(lbxIndex)))
            {
                wannaSong = RequestSong.Start(songs.ElementAt(lbxIndex));
            }
            else if (!currentSong.HasValue)
            {
                lbxIndex = -1;
            }
            else if (songs.Contains(currentSong.Value))
            {
                lbxIndex = songs.IndexOf(currentSong.Value);
            }
            else if (songs.Any())
            {
                lbxIndex = 0;
            }
            else
            {
                lbxIndex = -1;
            }

            return(songs);
        }
        public static void AddSongsToFirstPlaylist(this IAudioService service, IEnumerable <Song> songs,
                                                   bool prepend, IInvokeDispatcherHelper helper)
        {
            songs = songs as Song[] ?? songs.ToArray();

            if (!songs.Any())
            {
                return;
            }

            IPlaylist currentPlaylist = service.CurrentPlaylist;
            Song?     currentSong     = currentPlaylist?.CurrentSong;

            if (service.Playlists.Count > 0)
            {
                IPlaylist playlist = service.Playlists[0];

                if (playlist.ID == currentPlaylist?.ID)
                {
                    if (prepend)
                    {
                        playlist.Songs     = songs.Concat(playlist.Songs).Distinct().ToArray();
                        playlist.WannaSong = RequestSong.Start(songs.First());
                    }
                    else
                    {
                        playlist.Songs = playlist.Songs.Concat(songs).Distinct().ToArray();
                    }
                }
                else
                {
                    if (prepend || !currentSong.HasValue)
                    {
                        playlist.Songs     = songs.Distinct().ToArray();
                        playlist.WannaSong = RequestSong.Start(songs.First());
                        playlist.Duration  = currentPlaylist.Duration;
                        playlist.Position  = currentPlaylist.Position;

                        service.CurrentPlaylist = playlist;
                    }
                    else
                    {
                        playlist.Songs     = songs.Insert(0, currentSong.Value).Distinct().ToArray();
                        playlist.WannaSong = RequestSong.Get(currentSong.Value, null, currentPlaylist.Duration);

                        service.CurrentPlaylist = playlist;

                        currentPlaylist.CurrentSong = currentPlaylist.Songs.Cast <Song?>()
                                                      .NextOrDefault(currentSong).next;
                        currentPlaylist.Position  = TimeSpan.Zero;
                        currentPlaylist.WannaSong = RequestSong.Start(currentPlaylist.CurrentSong);
                    }
                }
            }
            else
            {
                IPlaylist playlist = new Playlist(helper)
                {
                    Name    = "Custom",
                    Loop    = LoopType.Next,
                    Shuffle = OrderType.Custom
                };

                if (prepend || !currentSong.HasValue)
                {
                    playlist.Songs     = songs.ToArray();
                    playlist.WannaSong = RequestSong.Start(songs.First());
                    playlist.Duration  = currentPlaylist.Duration;
                    playlist.Position  = currentPlaylist.Position;

                    service.Playlists.Add(playlist);
                    service.CurrentPlaylist = playlist;
                }
                else
                {
                    playlist.Songs     = songs.Insert(0, currentSong.Value).ToArray();
                    playlist.WannaSong = RequestSong.Get(currentSong.Value, null, currentPlaylist.Duration);

                    service.Playlists.Add(playlist);
                    service.CurrentPlaylist = playlist;

                    currentPlaylist.CurrentSong = currentPlaylist.Songs.Cast <Song?>()
                                                  .NextOrDefault(currentSong).next;
                    currentPlaylist.Position  = TimeSpan.Zero;
                    currentPlaylist.WannaSong = RequestSong.Start(currentPlaylist.CurrentSong);
                }
            }
        }