Ejemplo n.º 1
0
        private void UpdateListWithNewSong(string newWindowTitle)
        {
            //Set finish time in last song
            if (CurrentSong != null)             //If there is a last song and it doesn't have a finish time
            {
                SongInfo curSong = CurrentSong.GetValueOrDefault();

                _songs[_songs.Count - 1] = new SongInfo(
                    artist: curSong.Artist,
                    songName: curSong.SongName,
                    startTime: curSong.StartTime,
                    endTime: DateTime.Now,
                    isSong: curSong.IsSong
                    );
            }

            //Add the new song
            if (!string.IsNullOrEmpty(newWindowTitle))             //Don't add a song when Spotify isn't running (or similar situations)
            {
                _songs.Add(
                    new SongInfo(
                        spotifySongInfo: new SpotifySongInfo(newWindowTitle, this.SongClassificationInfo),
                        timeStarted: DateTime.Now,
                        timeStopped: null
                        )
                    );
            }
            ;

            //Remove the first song if MaxSongs has been reached
            if (MaxSongs >= 0 && _songs.Count > MaxSongs)
            {
                _songs.RemoveAt(0);                 //Inefficient but I can't think of a more efficient EASY way to do this
            }
        }
Ejemplo n.º 2
0
        public async Task ApplyResult_WithVotingCandidates_AppliesWinnerCandidate()
        {
            // Arrange
            var songId          = Guid.NewGuid();
            var votingCandidate = new SongWithVoteCount
            {
                Song = new Song {
                    Id = songId
                },
                VoteCount = 3
            };

            var currentSong = new CurrentSong
            {
                Song      = votingCandidate.Song,
                VoteCount = votingCandidate.VoteCount
            };

            _votingCandidateRepository.GetWithVoteCountBySongOrDefaultAsync(songId).Returns(Task.FromResult(votingCandidate));
            _currentSongService.UpdateOrCreateAsync(Arg.Any <SongWithVoteCount>()).Returns(Task.FromResult(currentSong));

            // Act
            await _votingFinisher.ApplyResultAsync(songId);

            // Assert
            await _currentSongService.Received(1).UpdateOrCreateAsync(votingCandidate);
        }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

        ImplicitGrantAuth();

        context = _spotify.GetPlayback();

        Debug.Log("Device Id: " + context.Device.Id);

        shuffleState = context.ShuffleState;

        repeatState = context.RepeatState;

        privateProfile = _spotify.GetPrivateProfile();

        Debug.Log(privateProfile.Country);

        audioVisualizer = GameObject.Find("AudioVisualizer");

        audioVisualizerScript = audioVisualizer.GetComponent <AudioVisualizer>();

        featuredPlaylistTabScript = FeaturedPlaylistTab.GetComponent <FeaturedPlaylistTabScript>();

        searchResultsScript = searchResultsTab.GetComponent <SearchResultsScript>();

        currentSongScript = CurrentSongGameObject.GetComponent <CurrentSong>();

        recordPlayerScript = recordPlayer.GetComponent <RecordPlayer>();

        //Ignore collisions between character controller and vinyls
        Physics.IgnoreLayerCollision(8, 9);

        OnClicked += SendAudioAnaylisToParticleVisualizer;
    }
        public async Task LoadNextSong()
        {
            CurrentSong?.Stop();
            CurrentSong = null;
            if (SongQueue.Count != 0)
            {
                lock (_voiceLock) {
                    CurrentSong = SongQueue[0];
                    SongQueue.RemoveAt(0);
                }
            }
            else
            {
                Stop();
                return;
            }

            try {
                if (VoiceClient == null)
                {
                    Console.WriteLine($"Joining voice channel [{DateTime.Now.Second}]");
                    //todo add a new event, to tell people nadeko is trying to join
                    VoiceClient = await Task.Run(async() => await VoiceChannel.JoinAudio());

                    Console.WriteLine($"Joined voicechannel [{DateTime.Now.Second}]");
                }
                await Task.Factory.StartNew(async() => await CurrentSong?.Start(), TaskCreationOptions.LongRunning).Unwrap();
            }
            catch (Exception ex) {
                Console.WriteLine($"Starting failed: {ex}");
                CurrentSong?.Stop();
                CurrentSong = null;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// returns true if it is a new song
        /// </summary>
        /// <returns></returns>
        internal bool SaveSong()
        {
            if (txtTitle.Text.Trim() == "")
            {
                Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot be blank");
                return(false);
            }

            //update the song object with the data in the gui
            updateSongObjectFromGui();

            //Check if there is already a song with the name chosen
            bool anotherSongWithThisNameAlreadyExists = !string.Equals(CurrentSong.SongFileName, CurrentSong.title, StringComparison.OrdinalIgnoreCase) && Song.Exists(CurrentSong.title);

            if (anotherSongWithThisNameAlreadyExists)
            {
                Helpers.PopupMessages.ShowErrorMessage(this, "Song '{0}' already exists please choose another name", CurrentSong.title);
                return(false);
            }

            //save the song
            CurrentSong.deleteSong();
            bool isNewSong = CurrentSong.saveSong();

            //notify the user
            Helpers.PopupMessages.ShowInformationMessage(this, "Song '{0}' saved", CurrentSong.title);

            SongChanged = false;

            return(isNewSong);
        }
Ejemplo n.º 6
0
 void _cqman_SetSongMetaRequest(object sender, object meta)
 {
     if (CurrentSong != null)
     {
         CurrentSong.SetMetaObject(sender, meta);
     }
 }
Ejemplo n.º 7
0
 public void Update()
 {
     if (CurrentSong != null && CurrentSong.IsStopped)
     {
         CurrentSong = SoundBank.GetCue(CurrentSong.Name);
         CurrentSong.Play();
     }
 }
Ejemplo n.º 8
0
 internal void FixFormatting()
 {
     updateSongObjectFromGui();
     CurrentSong.fixFormatting();
     CurrentSong.fixLyricsOrdering();
     CurrentSong.fixNoteOrdering();
     updateGuiFromSongObject();
 }
Ejemplo n.º 9
0
 private void Unsubscribe(IEnumerable <Song> songs)
 {
     foreach (Song song in songs ?? Enumerable.Empty <Song>())
     {
         CurrentSong.Unsubscribe(song);
         OtherSongs.Unsubscribe(song);
         AllSongs.Unsubscribe(song);
     }
 }
Ejemplo n.º 10
0
 public void PlaySong(string cueName)
 {
     if (CurrentSong != null)
     {
         CurrentSong.Stop(AudioStopOptions.Immediate);
     }
     CurrentSong = SoundBank.GetCue(cueName);
     CurrentSong.Play();
 }
        /// <returns>(title, artist) of the currently playing song or ("", "") if unknown</returns>
        public (string, string) GetSongAndArtist()
        {
            var cut = CurrentSong.Split(Splitstring, 2, StringSplitOptions.TrimEntries);

            return(cut.Length switch
            {
                1 => (cut[0], string.Empty),
                2 => (cut[0], cut[1]),
                _ => (string.Empty, string.Empty)
            });
Ejemplo n.º 12
0
        private void OnCurrentSongChanged(object sender, CurrentSongChangedEventArgs e)
        {
            CurrentSong.Unsubscribe(e.OldCurrentSong);
            CurrentSong.Subscribe(e.NewCurrentSong);

            OtherSongs.Unsubscribe(e.NewCurrentSong);
            OtherSongs.Subscribe(e.OldCurrentSong);

            CurrentSongChanged?.Invoke(this, new SubscriptionsEventArgs <IPlaylist, CurrentSongChangedEventArgs>(sender, e));
        }
Ejemplo n.º 13
0
        internal void ExportToHtml(DisplayAndPrintSettings settings)
        {
            if (CurrentSong.title == "")
            {
                Helpers.PopupMessages.ShowErrorMessage(this, "Please select a song");
                return;
            }
            string destination = CurrentSong.ExportToHtml(settings);

            Process.Start(destination);
        }
Ejemplo n.º 14
0
 private void Refresh()
 {
     if (CurrentSong?.Equals(TargetSong) ?? false)
     {
         ShowAnimation.Begin();
     }
     else
     {
         HideAnimation.Begin();
     }
 }
Ejemplo n.º 15
0
 internal bool DeleteSong()
 {
     if (Helpers.PopupMessages.ShowConfirmationMessage(this, "Are you sure you want to delete song '{0}'?", CurrentSong.SongFileName))
     {
         CurrentSong.deleteSong();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
        public ActionResult Post([FromBody] int songId)
        {
            CurrentSong songToAdd = new CurrentSong
            {
                Id     = 1,
                SongId = songId
            };

            currentSongContext.CurrentSongs.Add(songToAdd);
            currentSongContext.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// returns true if it is a new song
        /// </summary>
        /// <returns></returns>
        internal bool SaveSong()
        {
            if (txtTitle.Text.Trim() == "")
            {
                Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot be blank");
                return(false);
            }

            if (txtTitle.Text.Contains("\\"))
            {
                Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot contain '\\' character");
                return(false);
            }

            if (txtTitle.Text.Contains("/"))
            {
                Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot contain '/' character");
                return(false);
            }

            string originalSongName = (string.IsNullOrWhiteSpace(CurrentSong.SongSubFolder))
                                        ? CurrentSong.title : $"{CurrentSong.SongSubFolder}/{CurrentSong.title}";
            string newSongName = (string.IsNullOrWhiteSpace(txtSubFolder.Text))
                                    ? txtTitle.Text : $"{txtSubFolder.Text}/{txtTitle.Text}";
            bool wasSongNameChanged = !string.Equals(originalSongName, newSongName, StringComparison.InvariantCultureIgnoreCase);

            //Check if there is already a song with the name chosen
            bool doesSongExist = Song.Exists(newSongName);

            if (doesSongExist && wasSongNameChanged)
            {
                Helpers.PopupMessages.ShowErrorMessage(this, $"Song '{newSongName}' already exists please choose another name");
                return(false);
            }

            // If the song is a rename delete the old song
            if (wasSongNameChanged)
            {
                CurrentSong.deleteSong();
            }

            // Save the song and
            updateSongObjectFromGui();
            bool isNewSong = CurrentSong.saveSong();

            //notify the user
            Helpers.PopupMessages.ShowInformationMessage(this, $"Song '{CurrentSong.SongTitleIncludingSubFolder}' saved");

            SongChanged = false;

            return(isNewSong);
        }
Ejemplo n.º 18
0
        internal void Stop()
        {
            Stopped = true;
            SongQueue.Clear();
            CurrentSong?.Stop();
            CurrentSong = null;
            VoiceClient?.Disconnect();
            VoiceClient = null;

            MusicControls throwAwayValue;

            MusicModule.musicPlayers.TryRemove(_e.Server, out throwAwayValue);
        }
Ejemplo n.º 19
0
        public async Task <SignalRMessage> ExecuteAsync(StartSongCommand command, SignalRMessage previousResult)
        {
            var song = await _songRepository.GetById(command.SongId);

            if (song == null)
            {
                return(null);
            }

            song.Finished = true;
            await _songRepository.Update(song);

            var user = await _userRepository.GetById(song.AddedByUser);

            var currentSong = await _currentSongRepository.FirstOrDefault();

            if (currentSong != null)
            {
                await _currentSongRepository.Remove(currentSong.Id);
            }

            var actualCurrentSong = new CurrentSong
            {
                AddedAt       = song.AddedAt,
                AddedByUser   = song.AddedByUser,
                Author        = song.Author,
                Description   = song.Description,
                Duration      = song.Duration,
                Finished      = false,
                Id            = Guid.NewGuid(),
                NoAuthor      = song.NoAuthor,
                NoDescription = song.NoDescription,
                SongId        = song.Id,
                StartedAt     = DateTimeOffset.UtcNow,
                Thumbnail     = song.Thumbnail,
                Title         = song.Title,
                Url           = song.Url,
                ViewCount     = song.ViewCount,
                UserName      = user.UserName
            };

            await _currentSongRepository.Add(actualCurrentSong);

            return(new SignalRMessage
            {
                Arguments = new object[] { actualCurrentSong },
                GroupName = null,
                Target = "startSongCommandNotification",
            });
        }
Ejemplo n.º 20
0
        public MusicPlayer(Channel startingVoiceChannel, float?defaultVolume)
        {
            if (startingVoiceChannel == null)
            {
                throw new ArgumentNullException(nameof(startingVoiceChannel));
            }
            if (startingVoiceChannel.Type != ChannelType.Voice)
            {
                throw new ArgumentException("Channel must be of type voice");
            }
            Volume = defaultVolume ?? 1.0f;

            PlaybackVoiceChannel = startingVoiceChannel;
            SongCancelSource     = new CancellationTokenSource();
            cancelToken          = SongCancelSource.Token;

            Task.Run(async() => {
                while (true)
                {
                    try {
                        _client = await PlaybackVoiceChannel.JoinAudio();
                    }
                    catch {
                        await Task.Delay(1000);
                        continue;
                    }
                    CurrentSong = GetNextSong();
                    if (CurrentSong != null)
                    {
                        try {
                            OnStarted(CurrentSong);
                            await CurrentSong.Play(_client, cancelToken);
                        }
                        catch (OperationCanceledException) {
                            Console.WriteLine("Song canceled");
                        }
                        catch (Exception ex) {
                            Console.WriteLine($"Exception in PlaySong: {ex}");
                        }
                        try {
                            OnCompleted(CurrentSong);
                        }
                        catch { }
                        SongCancelSource = new CancellationTokenSource();
                        cancelToken      = SongCancelSource.Token;
                    }
                    await Task.Delay(1000);
                }
            });
        }
Ejemplo n.º 21
0
        /// <summary> Включить следующую песню </summary>
        public void NextSong()
        {
            MP.Stop();

            if (CurrentSong.CurrentIdValue() + 1 > CurrentMusicContainer.Songs.Count)
            {
                SetCurrentSong(CurrentSong);
                return;
            }

            var temp = CurrentMusicContainer.Songs.FirstOrDefault(x => x.IdValueInMC(CurrentMusicContainer) == CurrentSong.CurrentIdValue() + 1);

            SetCurrentSong(temp);
        }
Ejemplo n.º 22
0
        private void showCurrentSong(HttpRequestEventArgs e)
        {
            DisplayAndPrintSettings displayAndPrintSettings = getDisplaySettingsOption(e);

            using (var writer = new StreamWriter(e.Response.OutputStream))
            {
                if (CurrentSong == null)
                {
                    writer.Write("No song selected");
                    return;
                }
                var htmlSong = CurrentSong.getHtml(displayAndPrintSettings, enableAutoRefresh: true);
                writer.Write(htmlSong);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 获取当前状态,用于向线程池加入任务时传递参数
        /// </summary>
        /// <returns></returns>
        private PlayerState GetPlayerState()
        {
            PlayerState ps = null;

            if (CheckAccess())
            {
                ps = new PlayerState(Settings.User == null ? null : (User)Settings.User.Clone(),
                                     CurrentChannel == null ? null : (Channel)CurrentChannel.Clone(),
                                     CurrentSong == null ? null : (Song)CurrentSong.Clone());
            }
            else
            {
                Dispatcher.Invoke(new Action(() => { ps = GetPlayerState(); }));
            }
            return(ps);
        }
Ejemplo n.º 24
0
 internal void ChangeToSong(Song newSong)
 {
     if (SongChanged)
     {
         if (Helpers.PopupMessages.ShowConfirmationMessage(this, "Save changes to current song '{0}' before changing to another song?", CurrentSong.title))
         {
             this.SaveSong(); //save the song if we want the changes if the user clicks Yes
         }
         else
         {
             CurrentSong.revertToSaved(); //otherwise we want to revert the song to its original state
         }
     }
     CurrentSong = newSong;
     refreshPanel();
 }
Ejemplo n.º 25
0
        private void Subscribe(IEnumerable <Song> songs)
        {
            foreach (Song song in songs ?? Enumerable.Empty <Song>())
            {
                bool isCurrentSong = song == song.Parent.Parent.CurrentSong;

                if (isCurrentSong)
                {
                    CurrentSong.Subscribe(song);
                }
                else
                {
                    OtherSongs.Subscribe(song);
                }

                AllSongs.Subscribe(song);
            }
        }
        internal void Stop(bool leave = false)
        {
            Stopped = true;
            SongQueue.Clear();
            try {
                CurrentSong?.Stop();
            }
            catch { }
            CurrentSong = null;
            if (leave)
            {
                VoiceClient?.Disconnect();
                VoiceClient = null;

                MusicControls throwAwayValue;
                MusicModule.musicPlayers.TryRemove(_e.Server, out throwAwayValue);
            }
        }
Ejemplo n.º 27
0
 public DataModel(MainWindow mainWindow)
 {
     MainWindow = mainWindow;
     ServerList = new ServerList();
     ServerSession = new ServerSession(this);
     ServerStatus = new ServerStatus(this);
     Database = new Database(this);
     QuickSearch = new QuickSearch(this);
     AdvancedSearch = new AdvancedSearch(this);
     DatabaseView = new DatabaseView(this);
     StreamsCollection = new StreamsCollection();
     SavedPlaylists = new SavedPlaylists(this);
     CurrentSong = new CurrentSong(this);
     Playlist = new Playlist(this);
     OutputCollection = new OutputCollection(this);
     CustomDateNormalizer = new DateNormalizer();
     CustomDateNormalizer.ReadFromSettings();
     YearNormalizer = new DateNormalizer(new string[] {"YYYY"});
 }
Ejemplo n.º 28
0
        public Server(MainPage mainPage)
        {
            _mainPage = mainPage;

            _Statistics  = new Statistic(_mainPage);
            _Status      = new Status(_mainPage);
            _CurrentSong = new CurrentSong(_mainPage);

            _Playlist       = new ObservableObjectCollection <Track>(_mainPage);
            _FileList       = new ObservableObjectCollection <File>(_mainPage);
            _SavedPlaylists = new ObservableObjectCollection <File>(_mainPage);
            _Outputs        = new ObservableObjectCollection <Output>(_mainPage);
            _Artists        = new ObservableObjectCollection <CommonGridItem>(_mainPage);
            _Genres         = new ObservableObjectCollection <CommonGridItem>(_mainPage);
            _Albums         = new ObservableObjectCollection <CommonGridItem>(_mainPage);
            _Tracks         = new ObservableObjectCollection <Track>(_mainPage);

            _Connection.PropertyChanged += Connection_PropertyChanged;
        }
Ejemplo n.º 29
0
 public DataModel(MainWindow mainWindow)
 {
     MainWindow           = mainWindow;
     NetworkLog           = null;
     ServerList           = new ServerList();
     ServerSession        = new ServerSession(this);
     ServerStatus         = new ServerStatus(this);
     Database             = new Database(this);
     QuickSearch          = new QuickSearch(this);
     AdvancedSearch       = new AdvancedSearch(this);
     DatabaseView         = new DatabaseView(this);
     StreamsCollection    = new StreamsCollection();
     SavedPlaylists       = new SavedPlaylists(this);
     CurrentSong          = new CurrentSong(this);
     Playlist             = new Playlist(this);
     OutputCollection     = new OutputCollection(this);
     CustomDateNormalizer = new DateNormalizer();
     CustomDateNormalizer.ReadFromSettings();
     YearNormalizer = new DateNormalizer(new string[] { "YYYY" });
 }
Ejemplo n.º 30
0
        private async void HandleStationSongMetadata(SongMetadata songMetadata, StationStream currentStream, StationItem currentStation)
        {
            if (CurrentProgram != null)
            {
                if (CurrentProgram.Style == StationProgramStyle.Hosted)
                {
                    CurrentProgram = null; //hosted program ended.
                }
            }

            //filter out station messages
            if (!string.IsNullOrWhiteSpace(currentStream.ParentStation))
            {
                if (currentStation.StationMessages != null)
                {
                    if (currentStation.StationMessages.Contains(songMetadata.Track) ||
                        currentStation.StationMessages.Contains(songMetadata.Artist))
                    {
                        NepAppStationMessageReceived?.Invoke(this, new NepAppStationMessageReceivedEventArgs(songMetadata));
                        metadataLock.Release();
                        return;
                    }
                }
            }

            if (CurrentSong != null)
            {
                if (CurrentSong.ToString().Equals(songMetadata.ToString()))
                {
                    return;
                }
            }

            CurrentSong = songMetadata;
            //this is used for the now playing bar via data binding.
            RaisePropertyChanged(nameof(CurrentSong));

            PreSongChanged?.Invoke(this, new NepAppSongChangedEventArgs(songMetadata));

            await HandleStationSongMetadataStage2Async(songMetadata);
        }
Ejemplo n.º 31
0
        public void Map_MapsAllProperties()
        {
            // Arrange
            var currentSong       = new CurrentSong();
            var songWithVoteCount = new SongWithVoteCount
            {
                Song = new Song {
                    DurationInSeconds = 120
                },
                VoteCount = 22
            };

            // Act
            currentSong.Map(songWithVoteCount, _clock);

            // Assert
            Assert.That(currentSong.SongId, Is.EqualTo(songWithVoteCount.Song.Id));
            Assert.That(currentSong.Song, Is.EqualTo(songWithVoteCount.Song));
            Assert.That(currentSong.VoteCount, Is.EqualTo(songWithVoteCount.VoteCount));
            Assert.That(currentSong.EndsAtTime.UtcDateTime, Is.EqualTo(_clock.UtcNow.AddSeconds(115)));
        }