Exemplo n.º 1
0
        public void Shuffle_TraverseWhole_SequenceIsTheSameAsContentProperty()
        {
            //arrange
            ISongQueue queue   = new SongQueue();
            var        initial = TestData(113);

            queue.Set(initial);
            queue.Shuffle = true;
            var          traversed = new List <Song>();
            IList <Song> content;

            //act
            content = queue.Content.ToList();
            while (queue.HasNext)
            {
                traversed.Add(queue.Next);
            }

            //assert
            //also check if the first original is the first on the list
            content.Should().Equal(traversed);
            content.Should().NotEqual(initial);
            content.Count.Should().Be(initial.Count);
            content.Count.Should().Be(traversed.Count);
            content
            .OrderBy(x => x.Id)
            .Should()
            .Equal(initial);
            traversed
            .OrderBy(x => x.Id)
            .Should()
            .Equal(initial);
            traversed[0].Should().Be(initial.First());
            content[0].Should().Be(initial.First());
        }
        /// <summary>
        /// Move song to top
        /// </summary>
        /// <param name="p_Service">Chat service</param>
        /// <param name="p_Message">Chat message</param>
        /// <param name="p_ID">ID of the BSR</param>
        private void Command_MoveToTop(IChatService p_Service, IChatMessage p_Message, string p_ID)
        {
            if (!HasPower(p_Message.Sender))
            {
                SendChatMessage($"@{p_Message.Sender.UserName} You have no power here!");
                return;
            }

            string l_Key = p_ID.ToLower();

            lock (SongQueue)
            {
                var l_BeatMap = SongQueue.Where(x => x.BeatMap.Key.ToLower() == l_Key).FirstOrDefault();
                if (l_BeatMap != null)
                {
                    SongQueue.Remove(l_BeatMap);
                    SongQueue.Insert(0, l_BeatMap);

                    SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_BeatMap.BeatMap.Key}) {l_BeatMap.BeatMap.Metadata.SongName} / {l_BeatMap.BeatMap.Metadata.LevelAuthorName} is now on top of queue!");

                    /// Update request manager
                    OnQueueChanged();

                    return;
                }

                SendChatMessage($"@{p_Message.Sender.UserName} No song in queue found with the key \"{l_Key}\"!");
            }
        }
        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;
            }
        }
Exemplo n.º 4
0
        public void ShuffleInTheMiddle_WholeQueueIsRandom()
        {
            ISongQueue queue   = new SongQueue();
            var        initial = TestData(26);

            queue.Set(initial);

            //act
            var actual = new List <Song>();

            for (var i = 0; i < 4; i++)
            {
                _ = queue.Next;
            }

            queue.Shuffle = true;
            while (queue.HasNext)
            {
                actual.Add(queue.Next);
            }

            //assert
            Assert.Equal(actual.Count, initial.Count);
            actual
            .Should()
            .NotEqual(initial);
            actual.OrderBy(x => x.Id)
            .Should()
            .Equal(initial);
        }
        /// <summary>
        /// Command remove
        /// </summary>
        /// <param name="p_Service">Chat service</param>
        /// <param name="p_Message">Chat message</param>
        private void Command_Remove(IChatService p_Service, IChatMessage p_Message, string p_ID)
        {
            if (!HasPower(p_Message.Sender))
            {
                SendChatMessage($"@{p_Message.Sender.UserName} You have no power here!");
                return;
            }

            string l_Key = p_ID.ToLower();

            SongEntry l_SongEntry = null;

            lock (SongQueue)
            {
                l_SongEntry = SongQueue.Where(x => x.BeatMap.Key.ToLower() == l_Key).FirstOrDefault();
                if (l_SongEntry != null)
                {
                    SongQueue.Remove(l_SongEntry);
                }
            }

            if (l_SongEntry != null)
            {
                SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_SongEntry.BeatMap.Key}) {l_SongEntry.BeatMap.Metadata.SongName} / {l_SongEntry.BeatMap.Metadata.LevelAuthorName} is removed from queue!");

                /// Update request manager
                OnQueueChanged();
            }
            else
            {
                SendChatMessage($"@{p_Message.Sender.UserName} No song in queue found with the key \"{l_Key}\"!");
            }
        }
        /// <summary>
        /// Command wrong
        /// </summary>
        /// <param name="p_Service">Chat service</param>
        /// <param name="p_Message">Chat message</param>
        private void Command_Wrong(IChatService p_Service, IChatMessage p_Message)
        {
            SongEntry l_SongEntry = null;

            lock (SongQueue)
            {
                l_SongEntry = SongQueue.Where(x => x.RequesterName == p_Message.Sender.UserName).LastOrDefault();
                if (l_SongEntry != null)
                {
                    SongQueue.Remove(l_SongEntry);
                }
            }

            if (l_SongEntry != null)
            {
                SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_SongEntry.BeatMap.Key}) {l_SongEntry.BeatMap.Metadata.SongName} / {l_SongEntry.BeatMap.Metadata.LevelAuthorName} is removed from queue!");

                /// Update request manager
                OnQueueChanged();
            }
            else
            {
                SendChatMessage($"@{p_Message.Sender.UserName} You have no song in queue!");
            }
        }
Exemplo n.º 7
0
        public async Task QueueSongAsync(QueueSong song)
        {
            this.SongQueue.Enqueue(song);

            if (SongQueue.Count() == 1)
            {
                await NextSongAsync();
            }
            await server.sendRoomUpdate(this);
        }
Exemplo n.º 8
0
        public void ToArray_ShouldEqual()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(first);
            Song[] actual   = queue.Content.ToArray();
            Song[] expected = first.ToArray();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 9
0
        public void Clear_ShouldBeEmpty()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(second);

            queue.Clear();

            Assert.Empty(queue.Content.ToArray());
        }
Exemplo n.º 10
0
        public void Insert_InsertingAnElement_ShouldEqual()
        {
            //prepare

            ISongQueue queue = new SongQueue();
            Song       song  = new Song
            {
                Id   = 30,
                Name = "For Whom the Bell Tolls"
            };
            //list 3
            List <Song> list = new List <Song>
            {
                new Song
                {
                    Id   = 11,
                    Name = "Kitty Later"
                },
                new Song
                {
                    Id   = 12,
                    Name = "Ashtray Heart"
                },
                song,
                new Song
                {
                    Id   = 13,
                    Name = "Battle for the Sun"
                },
                new Song
                {
                    Id   = 14,
                    Name = "For What It's worth"
                },
                new Song
                {
                    Id   = 15,
                    Name = "Devil in the Details"
                }
            };



            //act
            queue.Set(third);
            _ = queue.Next; //doing it two times, because for the first time "next" takes the first of the queue
            _ = queue.Next;
            queue.Insert(song);

            Song[] expected = list.ToArray();
            Song[] actual   = queue.Content.ToArray();
            //asserting

            Assert.Equal(expected, actual);
        }
Exemplo n.º 11
0
 public void Play()
 {
     if (String.IsNullOrEmpty(_soundMaker.NowPlaying))
     {
         if (songQueue.Count() > 0)
         {
             _soundMaker.Play(songQueue.FirstOrDefault());
             songQueue.Remove(SongQueue.First());
         }
     }
 }
Exemplo n.º 12
0
        public async void PlayOverrideQueue(object parameter)
        {
            SongQueue.Add((Song)parameter);
            CurrentSong = SongQueue.Count - 1;
            string streamUrl = await GetStreamUrl(SongQueue[CurrentSong]);

            BackgroundMediaPlayer.Current.SetUriSource(new Uri(streamUrl));
            BackgroundMediaPlayer.Current.Volume = BackgroundMediaPlayer.Current.Volume;
            BackgroundMediaPlayer.Current.Play();
            QueueControl.GetInstance().UpdateQueue();
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public void StartCheck()
        {
            while (SongQueue.Count > 0)
            {
                if (!SongQueue.TryDequeue(out currentSong))
                {
                    currentSong = null;
                    continue;
                }

                Process();
            }
        }
Exemplo n.º 15
0
        public void StartDownload()
        {
            while (SongQueue.Count > 0)
            {
                if (!SongQueue.TryDequeue(out currentSong))
                {
                    currentSong = null;
                    continue;
                }

                Process();
            }

            //EventBus.Publish(new EventDownloadComplete());
            Application.Current.Dispatcher.Invoke(() => EventBus.Publish(new EventDownloadComplete()));
        }
Exemplo n.º 16
0
        public void StartMerge()
        {
            using (var outputStream = File.Create(Path.Combine(Directory.GetCurrentDirectory(), "final.mp3")))
            {
                while (SongQueue.Count > 0)
                {
                    if (!SongQueue.TryDequeue(out currentSong))
                    {
                        currentSong = null;
                        continue;
                    }

                    Process(outputStream);
                }
            }
        }
        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);
            }
        }
Exemplo n.º 18
0
        public override async Task NextSongAsync()
        {
            await server.sendRoomUpdate(this);

            if (SongQueue.Count() <= 0)
            {
                await server.BroadcastRoomAsync(this, new Packet(PacketType.PauseMusic, null));

                return;
            }

            var song = SongQueue.Peek();

            await server.BroadcastRoomAsync(this, new Packet(PacketType.StartPlaying, new StartPlayingData()
            {
                SongToPlay = song
            }));
        }
Exemplo n.º 19
0
        public void Previous_FewTimes_ShouldReturnPrevious()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(first);

            Song expected1 = new Song
            {
                Id   = 1,
                Name = "Sweet Home Alabama"
            };

            Song expected2 = new Song
            {
                Id   = 3,
                Name = "Loud Like Love"
            };

            Song expected3 = new Song
            {
                Id   = 2,
                Name = "Processed Beats"
            };

            _ = queue.Next;
            _ = queue.Next;

            Song actual1 = queue.Previous;

            _ = queue.Next;
            _ = queue.Next;
            _ = queue.Next;
            _ = queue.Next;
            _ = queue.Previous;

            Song actual2 = queue.Previous;
            Song actual3 = queue.Previous;

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
            Assert.Equal(expected3, actual3);
        }
Exemplo n.º 20
0
        public void ShuffleInTheMiddle_HasNoPrevious_FirstElementIsWhereShuffleStarted()
        {
            ISongQueue queue   = new SongQueue();
            var        initial = TestData(10);

            queue.Set(initial);

            //act
            _ = queue.Next;
            _ = queue.Next;
            var expected = queue.Next;

            queue.Shuffle = true;

            //asset
            Assert.False(queue.HasPrevious);
            Assert.True(queue.HasNext);
            //started shuffle on third index so it should be the first
            queue.Content[0].Should().Be(expected);
        }
Exemplo n.º 21
0
        public void ShuffleFromStart_OrderShouldBeRandom()
        {
            ISongQueue queue   = new SongQueue();
            var        initial = TestData(18);

            queue.Set(initial);

            //act
            var traversed = new List <Song>();

            queue.Shuffle = true;
            while (queue.HasNext)
            {
                traversed.Add(queue.Next);
            }

            //assert
            traversed.Count.Should().Be(initial.Count);
            traversed.Should().NotEqual(initial);
            traversed.OrderBy(x => x.Id).Should().Equal(initial);
        }
Exemplo n.º 22
0
        public void Current_ShouldReturnCurrentElement()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(third);

            Song expected1 = new Song
            {
                Id   = 11,
                Name = "Kitty Later"
            };

            Song expected2 = new Song
            {
                Id   = 14,
                Name = "For What It's worth"
            };

            Song expected3 = new Song
            {
                Id   = 12,
                Name = "Ashtray Heart"
            };

            _ = queue.Next;
            _ = queue.Next;
            Song actual1 = queue.Previous;

            _ = queue.Next;
            _ = queue.Next;
            Song actual2 = queue.Next;

            _ = queue.Previous;
            Song actual3 = queue.Previous;

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
            Assert.Equal(expected3, actual3);
        }
Exemplo n.º 23
0
        public void Add_AddToEnd_ShouldEqual()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(second);

            Song song = new Song
            {
                Id   = 11,
                Name = "Kitty Later"
            };

            List <Song> list = second.ToList();

            list.Add(song);
            queue.Add(song);

            Song[] expected = list.ToArray();
            Song[] actual   = queue.Content.ToArray();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 24
0
        public void TurnShuffleOn_ThenOff_CurrentSongIsTheSameAsTheOneThatShuffleWasTurnedOffOn()
        {
            //arrange
            ISongQueue queue   = new SongQueue();
            var        initial = TestData(1200);

            queue.Set(initial);
            queue.Shuffle = true;

            //act
            for (int i = 0; i < 16; i++) //skip 16 in total and take the 17th
            {
                _ = queue.Next;
            }
            var expeted = queue.Next;

            queue.Shuffle = false;

            //assert
            queue.Content[queue.CurrentIndex].Should().Be(expeted);
            queue.Content.Count.Should().Be(initial.Count);
            queue.Content.Should().Equal(initial);
        }
Exemplo n.º 25
0
        public void Next_FewTimes_ShouldReturnNext()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(second);

            Song actual1   = queue.Next;
            Song expected1 = new Song
            {
                Id   = 6,
                Name = "Hold on to Me"
            };

            Song actual2   = queue.Next;
            Song expected2 = new Song
            {
                Id   = 7,
                Name = "Rob the Bank"
            };

            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
        }
Exemplo n.º 26
0
        public void Jump_RemoveAllToEndAndInsertRange_ShouldEqual()
        {
            ISongQueue queue = new SongQueue();

            queue.Set(first);

            var expected = new[]
            {
                first[0],
                first[1],
                second[0],
                second[1],
                second[2],
                second[3],
                second[4],
            };

            _ = queue.Next;
            _ = queue.Next;
            queue.Replace(second);

            Song[] actual = queue.Content.ToArray();
            actual.Should().Equal(expected);
        }
Exemplo n.º 27
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Load database
        /// </summary>
        private void LoadDatabase()
        {
            try
            {
                string l_FilePath = m_DBFilePath;
                if (!System.IO.File.Exists(l_FilePath))
                {
                    Logger.Instance.Error("File not found " + m_DBFilePath);
                    return;
                }

                var l_JSON = JObject.Parse(System.IO.File.ReadAllText(l_FilePath, UTF8Encoding.UTF8));
                if (l_JSON["queue"] != null)
                {
                    JArray l_JSONSongs = (JArray)l_JSON["queue"];
                    for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++)
                    {
                        SongEntry l_Entry = new SongEntry();
                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key"))
                            l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]);
                        else
                        {
                            l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", "");
                            JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap);
                        }

                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt"))
                            l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>());

                        l_Entry.RequesterName   = (string)l_JSONSongs[l_SongIt]["rqn"];

                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr"))
                            l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"];

                        SongQueue.Add(l_Entry);

                        /// Start populate
                        l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry));
                    }
                }
                if (l_JSON["history"] != null)
                {
                    JArray l_JSONSongs = (JArray)l_JSON["history"];
                    for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++)
                    {
                        SongEntry l_Entry = new SongEntry();
                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key"))
                            l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]);
                        else
                        {
                            l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", "");
                            JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap);
                        }

                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt"))
                            l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>());

                        l_Entry.RequesterName   = (string)l_JSONSongs[l_SongIt]["rqn"];

                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr"))
                            l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"];

                        SongHistory.Add(l_Entry);

                        /// Start populate
                        l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry));
                    }
                }
                if (l_JSON["blacklist"] != null)
                {
                    JArray l_JSONSongs = (JArray)l_JSON["blacklist"];
                    for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++)
                    {
                        SongEntry l_Entry = new SongEntry();
                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key"))
                            l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]);
                        else
                        {
                            l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", "");
                            JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap);
                        }

                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt"))
                            l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>());

                        l_Entry.RequesterName   = (string)l_JSONSongs[l_SongIt]["rqn"];

                        if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr"))
                            l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"];

                        SongBlackList.Add(l_Entry);

                        /// Start populate
                        l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry));
                    }
                }
            }
            catch (System.Exception p_Exception)
            {
                Logger.Instance.Critical("LoadDataBase");
                Logger.Instance.Critical(p_Exception);
            }
        }
Exemplo n.º 28
0
        public void Insert_InsertRange_ShouldEqual()
        {
            //prepare

            ISongQueue  queue        = new SongQueue();
            List <Song> toBeInserted = new List <Song>
            {
                new Song
                {
                    Id   = 31,
                    Name = "Getting Even"
                },
                new Song
                {
                    Id   = 32,
                    Name = "Rituals"
                }
            };

            List <Song> list = new List <Song>
            {
                new Song
                {
                    Id   = 6,
                    Name = "Hold on to Me"
                },
                new Song
                {
                    Id   = 7,
                    Name = "Rob the Bank"
                },
                new Song
                {
                    Id   = 8,
                    Name = "A Million Little Places"
                },

                toBeInserted[0],
                toBeInserted[1],

                new Song
                {
                    Id   = 9,
                    Name = "Exit Wounds"
                },
                new Song
                {
                    Id   = 10,
                    Name = "Purify"
                }
            };

            queue.Set(second);

            //act

            _ = queue.Next;
            _ = queue.Next;
            _ = queue.Next;

            queue.Insert(toBeInserted);

            //assert

            Song[] expected = list.ToArray();
            Song[] actual   = queue.Content.ToArray();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 29
0
 public void AddToQueue(Song parameter)
 {
     SongQueue.Add(parameter);
     QueueControl.GetInstance().UpdateQueue();
 }
Exemplo n.º 30
0
 public void RemoveFromQueue(Song parameter)
 {
     SongQueue.Remove(parameter);
 }