Exemple #1
0
    // Use this for initialization

    void Start()
    {
        match_music.clip = staticstuff.SelectedMusic.audio;
        Onsetfile        = staticstuff.SelectedMusic.onset;
        segmentfile      = staticstuff.SelectedMusic.segment;
        Beatfile         = staticstuff.SelectedMusic.beat;
        Pitchfile        = staticstuff.SelectedMusic.pitch;

        parser       = new CSVParser();
        musicinfo    = new MusicInfoScript();
        musicprocess = new MusicProcessor(musicinfo);
        bulletsystem = new BulletSystemControl(defaultenemybullet, origin, bulletrepo);
        bulletcontroler.musicinfo = musicinfo;


        musicprocess.processMusicOnset(parser.parseFile(Onsetfile));
        musicprocess.processMusicSegment(parser.parseFile(segmentfile));
        musicprocess.processMusicBeat(parser.parseFile(Beatfile));
        musicprocess.processMusicPitch(parser.parseFile(Pitchfile));
        Debug.Log("music loaded");

        musicinfo.calculateValues();
        Debug.Log("Info calced");

        bulletsystem.createpatterns(musicinfo);
        Debug.Log("Patterns loaded");

        bulletcontroler.loadBullets(bulletsystem.createBullets());
        Debug.Log("bullets created");


        loadanim   = new LoadAnimation();
        animations = loadanim.load(staticstuff.SelectedSprite);
        shipanimations.Init(animations, staticstuff.SelectedSprite.config.frame_length, staticstuff.SelectedSprite.config.frames_per_line - 2);
        colliderbox.size = (new Vector2((float)(staticstuff.SelectedSprite.config.width / staticstuff.SelectedSprite.config.pixel_per_unit * 0.6), (float)(staticstuff.SelectedSprite.config.height / staticstuff.SelectedSprite.config.pixel_per_unit * 0.6)));
        Debug.Log("sprite loaded");


        player.Xvelocity        = staticstuff.config.x_velocity;
        player.Yvelocity        = staticstuff.config.y_velocity;
        player.usemouse         = staticstuff.config.use_mouse;
        player.mousesensitivity = staticstuff.config.mouse_sensitivity;
        Debug.Log("loaded config");

        int musiclength = (int)match_music.clip.length;


        enemy.sethp(7 * (musiclength / 10));
        player.sethp(5 * (musiclength / 10));
        enemy.punchdmg = (int)player.HP / 20;

        hud.musiclenght = musiclength;
        bulletcontroler.audiosource.Play();
        Cursor.visible = false;
        Debug.Log("Music activated START THE HELL");
    }
Exemple #2
0
        public void OverrideRating_ValidCall()
        {
            //Arragnge
            var mock   = new Mock <IDataAccess>();
            var rating = TestData.SampleRatingData(1)[0];

            mock.Setup(x => x.UpdateData_Rating(It.IsAny <int>(), It.IsAny <int?>())).Returns(true);
            var cls = new MusicProcessor(mock.Object);

            //Act
            var actual = cls.OverrideRating(It.IsAny <int>(), It.IsAny <int?>());

            //Assert
            mock.Setup(x => x.UpdateData_Rating(It.IsAny <Rating>())).Verifiable();
            Assert.AreEqual("Rating record was updated.", actual);
        }
Exemple #3
0
        public void OverrideAlbum_ValidCall()
        {
            //Arragnge
            var mock  = new Mock <IDataAccess>();
            var album = TestData.SampleAlbumData(1)[0];

            mock.Setup(x => x.UpdateData_Album(It.IsAny <Album>())).Returns(true);
            var cls = new MusicProcessor(mock.Object);

            //Act
            var actual = cls.OverrideAlbum(album);

            //Assert
            mock.Setup(x => x.UpdateData_Album(It.IsAny <Album>())).Verifiable();
            Assert.AreEqual("Album record was updated.", actual);
        }
Exemple #4
0
        public void OverrideUser_ValidCall()
        {
            //Arragnge
            var mock = new Mock <IDataAccess>();
            var user = TestData.SampleUserData(1)[0];

            mock.Setup(x => x.UpdateData_User(It.IsAny <User>())).Returns(true);
            var cls = new MusicProcessor(mock.Object);

            //Act
            var actual = cls.OverrideUser(user);

            //Assert
            mock.Setup(x => x.UpdateData_User(It.IsAny <User>())).Verifiable();
            Assert.AreEqual("User record was updated.", actual);
        }
Exemple #5
0
        public async Task Tick()
        {
            if (Feed.AudioDestination.Length != 0)
            {
                SongData SongData;
                if (Playing == null && Queue.TryDequeue(out SongData))
                {
                    //Dequeue a song
                    Playing = new MusicProcessor(SongData, Filter);
                    Task.Delay(150).ContinueWith(x => UpdateAll());
                }

                if (NextSend != null)
                {
                    while (Sending.Count > 2)
                    {
                        await Sending.Dequeue();
                    }

                    Sending.Enqueue(Feed.StreamAll(NextSend));
                    if (CurrentSend != null)
                    {
                        MusicProcessor.Buffers.Return(CurrentSend);
                    }

                    CurrentSend = NextSend;
                    NextSend    = null;
                }

                if (Playing != null)
                {
                    if (Playing.QueuedBuffers.Count > 0)
                    {
                        NextSend = Playing.QueuedBuffers.Dequeue();
                        Playing.Waiter.Release(1);
                    }
                    else if (Playing.Skip.IsCancellationRequested)
                    {
                        Playing.Dispose();
                        Playing = null;
                        await UpdateAll();
                    }
                }
            }
        }
Exemple #6
0
        public void Login_IsValid()
        {
            //arrrange
            var sampleUser          = TestData.SampleUserData(1);
            Mock <IDataAccess> mock = new Mock <IDataAccess>();

            mock.Setup(x => x.ReadData_User(It.IsAny <string>(), It.IsAny <string>())).Returns(sampleUser[0]);
            MusicProcessor cls = new MusicProcessor(mock.Object);

            //act
            var actual   = cls.Login(sampleUser[0].Username, sampleUser[0].Password);
            var expected = sampleUser[0];

            //Assert
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.Rank, actual.Rank);
            Assert.AreEqual(expected.IdUser, actual.IdUser);
        }
Exemple #7
0
        public void AddRating_AlbumOrUserNotFoundInDB()
        {
            //Arrange
            Mock <IDataAccess> mock = new Mock <IDataAccess>();

            mock.Setup(x => x.ReadData_User(It.IsAny <int>())).Returns((User)null);
            mock.Setup(x => x.ReadData_Album(It.IsAny <int>())).Returns((Album)null);
            var cls = new MusicProcessor(mock.Object);
            //act
            Rating testRating = new Rating {
                IdAlbum = 1, IdUser = 1
            };
            string actual   = cls.AddRating(testRating);
            string expected = "Error: album or user record not found.";

            //
            mock.Verify(x => x.ReadData_User(It.IsAny <int>()), Times.Exactly(1));
            mock.Verify(x => x.ReadData_Album(It.IsAny <int>()), Times.Exactly(1));
            Assert.AreEqual(expected, actual);
        }
Exemple #8
0
        async Task OnSearch()
        {
            OnCancelSearch();

            Results                 = null;
            ResultsTime             = "Running..";
            cancellationTokenSource = new CancellationTokenSource();
            CancelSearch.RaiseCanExecuteChanged();

            serviceLocator.Get <INavigationService>()
            .NavigateAsync(AppPages.Results, this).IgnoreResult();

            ConcurrentBag <TrackViewModel> foundTracks = new ConcurrentBag <TrackViewModel>();

            int            numConsumers = NumberOfConsumers;
            MusicProcessor processor    = new MusicProcessor(numConsumers,
                                                             t => SearchCriteria.All(sc => sc.Test(t)),
                                                             t => foundTracks.Add(new TrackViewModel(t)));

            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                await processor.Start(cancellationTokenSource.Token);
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                sw.Stop();

                ResultsTime = string.Format("{0} consumer took {1} for {2} records.",
                                            numConsumers, sw.Elapsed, foundTracks.Count);
                Results = foundTracks.Distinct().OrderBy(t => t.Index).ToList();
                cancellationTokenSource = null;
                CancelSearch.RaiseCanExecuteChanged();
            }
        }
Exemple #9
0
        public async Task Run()
        {
            //delayed start, force new thread
            await Task.Delay(100);

            SongData PlaySong;

            byte[] CurrentSend = null;
            byte[] NextSend    = null;

            while (!StopRequested)
            {
                try
                {
                    if (CurrentSong != null && CurrentSong.Skip)
                    {
                        $"Finished sending {CurrentSong.Song.Name}".Log();
                        CurrentSong.Dispose();
                        CurrentSong = null;
                    }

                    if (AudioClient != null)
                    {
                        if (AudioClient.State != ConnectionState.Connected)
                        {
                            try
                            {
                                AudioClient = await AudioClient.Channel.JoinAudio();
                            }
                            catch
                            {
                                await DisconnectClient();

                                continue;
                            }
                        }

                        if (CurrentSong == null)
                        {
                            //Dequeue a song
                            if (SongQueue.TryDequeue(out PlaySong))
                            {
                                CurrentSong = new MusicProcessor(PlaySong);

                                foreach (Channel Channel in ServerData.Servers[AudioClient.Server.Id].ChannelsWithCategory(typeof(Music).Name))
                                {
                                    SendCurrentSong(Channel);
                                }
                            }
                            else
                            {
                                //No new song in queue
                                await Task.Delay(100);
                            }
                        }
                        else
                        {
                            if (NextSend != null)
                            {
                                if (Sending != null)
                                {
                                    await Task.WhenAny(Sending, Task.Delay(1000));
                                }

                                Sending = AudioClient.OutputStream.WriteAsync(NextSend, 0, NextSend.Length);
                                if (CurrentSend != null)
                                {
                                    Buffers.Return(CurrentSend);
                                }

                                CurrentSend = NextSend;
                                NextSend    = null;
                            }

                            if (CurrentSong.QueuedBuffers.Count > 0)
                            {
                                //Speedtest
                                if (Adhd && CurrentSong.QueuedBuffers.Count > 1)
                                {
                                    CurrentSong.QueuedBuffers.Dequeue();
                                    CurrentSong.Waiter.Release(1);
                                }

                                NextSend = CurrentSong.QueuedBuffers.Dequeue();
                                CurrentSong.Waiter.Release(1);

                                if (NextSend != null)
                                {
                                    NextSend = NextSend.AdjustVolume(Volume);
                                }
                            }
                            else if (CurrentSong.FinishedBuffer)
                            {
                                CurrentSong.Skip = true;
                            }
                        }
                    }
                    else
                    {
                        //Paused or not in voice chat
                        await Task.Delay(100);
                    }
                }
                catch (OperationCanceledException)
                { }
                catch (AggregateException)
                { }
                catch (Exception Ex)
                {
                    $"Music Handler Loop Exception: {Ex}".Log();
                }
            }

            try
            {
                if (CurrentSong != null)
                {
                    CurrentSong.Skip = true;
                }
            }
            catch { }

            await DisconnectClient();
        }