public IEnumerator Enso_ScrubbingToEndsOfTrackShouldNotThrowError()
        {
            SetUpMusicPlayer();

            yield return(null);

            MusicTrack track = new MusicTrack
            {
                Track      = AudioClip.Create("test", 13803264, 2, 44100, false),
                LoopStart  = 11130,
                LoopLength = 6477145
            };

            track.CreateAndCacheClips();

            yield return(null);

            musicPlayer.Play(track);

            yield return(null);

            musicPlayer.Scrub(152.098f);

            yield return(null);

            musicPlayer.ScrubAsPercentage(.97f);
        }
        public IEnumerator Enso_CrossfadeShouldSetCurrentTrack()
        {
            // Arrange
            SetUpMusicPlayer();
            MusicTrack track = new MusicTrack
            {
                Name  = "test",
                Track = AudioClip.Create("test", 1000000, 1, 1000, false)
            };

            track.CreateAndCacheClips();

            musicPlayer.Tracks.Add(track);

            // Act
            musicPlayer.Play("MusicTest");

            yield return(null);

            musicPlayer.CrossFadeTo("test");

            yield return(null);

            // Assert
            Assert.AreNotSame(musicPlayer.PlayingTrack, musicPlayer.Tracks.Where(x => x.Name == "MusicTest").First());
        }
        public IEnumerator Enso_PlayShouldSetCurrentTrack()
        {
            // Arrange
            SetUpMusicPlayer();

            // Play(string) test
            // Act
            musicPlayer.Play("MusicTest");

            yield return(null);

            // Assert
            Assert.IsNotNull(musicPlayer.PlayingTrack);

            // Play(MusicTrack) test
            // Arrange
            MusicTrack track = new MusicTrack
            {
                Track = AudioClip.Create("test", 1000000, 1, 1000, false)
            };

            track.CreateAndCacheClips();

            // Act
            musicPlayer.Stop();
            musicPlayer.Play(track);

            yield return(null);

            // Assert
            Assert.IsNotNull(musicPlayer.PlayingTrack);
        }
        public IEnumerator Enso_FadeOutTrack()
        {
            SetUpMusicPlayer();

            yield return(null);

            MusicTrack track = new MusicTrack
            {
                Track = AudioClip.Create("test", 2000, 1, 1000, false)
            };

            track.CreateAndCacheClips();
            module.Play(track, EnsoConstants.PlayEndlessly);

            float originalVolume = speaker1.volume;

            yield return(null);

            module.FadeOut(2);

            Assert.AreEqual(Speaker.VolumeStatuses.FadingOut, module.VolumeStatus);

            yield return(null);

            Assert.AreNotEqual(speaker1.volume, originalVolume, "The volume isn't changing when fading out.");

            yield return(new WaitForSecondsRealtime(2));

            Assert.AreEqual(Speaker.VolumeStatuses.Static, module.VolumeStatus);
            Assert.AreEqual(speaker1.volume, 0f, "Speaker volume doesn't equal 0 when fading out is complete.");
        }
        public IEnumerator Enso_PlayAfterFadeOut()
        {
            SetUpMusicPlayer();

            yield return(null);

            MusicTrack track = new MusicTrack
            {
                Track = AudioClip.Create("test", 2000, 1, 1000, false)
            };

            track.CreateAndCacheClips();

            musicPlayer.Play(track);

            yield return(null);

            musicPlayer.FadeOut();

            yield return(new WaitForSeconds(2));

            Assert.IsTrue(speaker1.volume <= 0f, "Speaker should be muted after fadeout.");

            musicPlayer.Play("MusicTest");

            yield return(null);

            Assert.IsTrue(speaker1.volume == musicPlayer.Volume, "Speaker1 should be back at player volume after PlayTrack() is called.");
            Assert.IsTrue(speaker2.volume == musicPlayer.Volume, "Speaker2 should be back at player volume after PlayTrack() is called.");
            Assert.IsTrue(speaker3.volume == musicPlayer.Volume, "Speaker3 should be back at player volume after PlayTrack() is called.");
            Assert.IsTrue(speaker4.volume == musicPlayer.Volume, "Speaker4 should be back at player volume after PlayTrack() is called.");
        }
        public IEnumerator Enso_FadeInTrack()
        {
            SetUpMusicPlayer();

            yield return(null);

            musicPlayer.CrossFadeTime = 1f;
            musicPlayer.SetVolume(.75f);
            MusicTrack track = new MusicTrack
            {
                Track = AudioClip.Create("test", 2000, 1, 1000, false)
            };

            track.CreateAndCacheClips();
            module.Play(track, EnsoConstants.PlayEndlessly);
            module.SetSpeakerVolume(0f);

            yield return(null);

            module.FadeIn(musicPlayer.CrossFadeTime);
            float originalVolume = speaker1.volume;

            Assert.AreEqual(Speaker.VolumeStatuses.FadingIn, module.VolumeStatus);

            yield return(null);

            Assert.AreNotEqual(speaker1.volume, originalVolume, "The volume isn't changing when fading in.");

            yield return(new WaitForSeconds(2));

            Assert.AreEqual(Speaker.VolumeStatuses.Static, module.VolumeStatus);
            Assert.AreEqual(musicPlayer.Volume, speaker1.volume, "Speaker volume doesn't equal 1 when fading in is complete.");
        }
        public IEnumerator Enso_DontChangeVolumeWhileFading()
        {
            SetUpMusicPlayer();

            yield return(null);

            MusicTrack track = new MusicTrack
            {
                Track      = AudioClip.Create("test", 4000, 1, 1000, false),
                LoopStart  = 1000,
                LoopLength = 1000
            };

            track.CreateAndCacheClips();
            musicPlayer.Play(track);

            yield return(null);

            musicPlayer.FadeIn();
            float originalVolume = speaker1.volume;

            musicPlayer.SetVolume(.5f);

            Assert.AreNotEqual(speaker1.volume, .5f, "Volume should not be changeable while fading in.");

            yield return(new WaitForSeconds(2));

            musicPlayer.FadeOut();
            musicPlayer.SetVolume(.5f);

            Assert.AreNotEqual(speaker1.volume, .5f, "Volume should not be changeable while fading out.");
        }
 /// <summary>
 /// Crossfades to a track.
 /// </summary>
 /// <param name="track">The track to play</param>
 public void CrossFadeTo(MusicTrack track, int timesToLoop = 0)
 {
     CurrentSpeaker.FadeOut(CrossFadeTime, true);
     SwitchSpeakers();
     PlayingTrack = track;
     CurrentSpeaker.SetSpeakerVolume(0f);
     CurrentSpeaker.Play(PlayingTrack, timesToLoop);
     CurrentSpeaker.FadeInTo(Volume, CrossFadeTime);
 }
        /// <summary>
        /// Plays the given track starting at the given play position.
        /// </summary>
        /// <param name="track">The track to play</param>
        /// <param name="time">The time to play the track at, in seconds</param>
        /// <param name="numberOfLoops">The number of times to loop the track. Set to 0 for endless play.</param>
        public void PlayAtPoint(MusicTrack track, float time, int numberOfLoops)
        {
            RemovePauseState();
            Stop();
            SetTrack(track);

            IntroSource.clip = PlayingTrack.IntroClip;
            LoopSource.clip  = PlayingTrack.LoopClip;

            PlayAtPosition(PlayingTrack.SecondsToSamples(time), numberOfLoops);
        }
 internal void SetPosition(MusicTrack track, int position)
 {
     SetTrack(track);
     if (IsPaused)
     {
         pausePosition = Math.Min(position, CurrentLengthInSamples);
     }
     else if (IsPlaying)
     {
         PlayAtPoint(PlayingTrack.SamplesToSeconds(position), numberOfLoopsLeft);
     }
 }
Exemple #11
0
        public void Enso_OverriddenTagValue()
        {
            MusicTrack track = new MusicTrack
            {
                Track      = AudioClip.Create("test", 2000, 1, 1000, false),
                LoopStart  = 42,
                LoopLength = 79
            };

            Assert.AreEqual(42, track.LoopStart);
            Assert.AreEqual(79, track.LoopLength);
        }
        public IEnumerator Enso_NullLoopPointsShouldNotThrowException()
        {
            SetUpMusicPlayer();

            yield return(null);

            MusicTrack track = new MusicTrack
            {
                Track = AudioClip.Create("test", 10000, 1, 1000, false),
            };

            track.CreateAndCacheClips();
        }
        /// <summary>
        /// Gets a track by its playlist name.
        /// </summary>
        /// <param name="name">The name of the track</param>
        /// <returns>The track with the given playlist name</returns>
        public MusicTrack GetTrackByName(string name)
        {
            MusicTrack track
                = (from t in Tracks
                   where t.Name == name
                   select t).FirstOrDefault();

            if (track == null)
            {
                throw new KeyNotFoundException(string.Format(@"A song with the name ""{0}"" could not be found.", name));
            }

            return(track);
        }
Exemple #14
0
        public void Enso_NoLoopSettings()
        {
            // Arrange
            var clip = AudioClip.Create("test", 20000, 2, 1000, false);

            MusicTrack track = new MusicTrack
            {
                Track      = clip,
                LoopStart  = 0,
                LoopLength = 0
            };

            track.Track = clip;

            // Act
            track.CreateAndCacheClips();
        }
Exemple #15
0
        public void Enso_OutOfBoundsFailsafe()
        {
            // Arrange
            var clip = AudioClip.Create("test", 20000, 2, 1000, false);

            MusicTrack track = new MusicTrack
            {
                Track      = clip,
                LoopStart  = 10,
                LoopLength = 50
            };

            track.Track = clip;

            // Act
            track.CreateAndCacheClips();
        }
Exemple #16
0
        public void Enso_LengthInSamples()
        {
            // Arrange
            var clip = AudioClip.Create("test", 20000, 2, 1000, false);

            MusicTrack track = new MusicTrack
            {
                Track      = clip,
                LoopStart  = 3,
                LoopLength = 10
            };

            track.Track = clip;

            // Act
            track.CreateAndCacheClips();

            // Assert
            Assert.AreEqual(13, track.LengthInSamples);
        }
 /// <summary>
 /// Plays the given track.
 /// </summary>
 /// <param name="track">The track to play</param>
 /// <param name="numberOfLoops">The number of times to loop the track. Set to 0 for endless play.</param>
 public void Play(MusicTrack track, int numberOfLoops)
 {
     SetTrack(track);
     PlayAtPoint(track, track.SamplesToSeconds(pausePosition), numberOfLoops);
     RemovePauseState();
 }
 public void SetTrack(MusicTrack musicTrack)
 {
     PlayingTrack = musicTrack;
 }
 /// <summary>
 /// Play a music track.
 /// </summary>
 /// <param name="track">The track to play</param>
 /// <param name="timesToLoop">The number of times to loop the track. Set to 0 for endless play.</param>
 public void Play(MusicTrack track, int timesToLoop = 0)
 {
     PlayingTrack = track;
     PlayAtPoint(track, 0f, timesToLoop);
 }
 /// <summary>
 /// Plays the track starting at the given point on its timeline.
 /// </summary>
 /// <param name="track">The track to play</param>
 /// <param name="time">The time to play the track at, in seconds</param>
 /// <param name="timesToLoop">The number of times to loop the track. Set to 0 for endless play.</param>
 public void PlayAtPoint(MusicTrack track, float time, int timesToLoop = 0)
 {
     ResetSpeakerVolumeStatuses();
     RefreshSpeakerVolume();
     CurrentSpeaker.PlayAtPoint(track, time, timesToLoop);
 }
 /// <summary>
 /// Fades in the given track starting at the given point on its timeline.
 /// </summary>
 /// <param name="track">The track to play</param>
 /// <param name="time">The playback time for the next track, in seconds</param>
 /// <param name="timesToLoop">The number of times to loop the track. Set to 0 for endless play.</param>
 public void FadeInAtPoint(MusicTrack track, float time, int timesToLoop = 0)
 {
     PlayingTrack = track;
     CurrentSpeaker.PlayAtPoint(track, time, timesToLoop);
     CurrentSpeaker.FadeIn(CrossFadeTime);
 }
 /// <summary>
 /// Crossfades to the given track at the given point on its timeline.
 /// </summary>
 /// <param name="track">The track to crossfade to</param>
 /// <param name="time">The playback time for the next track, in seconds</param>
 /// <param name="timesToLoop">The number of times to loop the track. Set to 0 for endless play.</param>
 public void CrossFadeAtPoint(MusicTrack track, float time, int timesToLoop = 0)
 {
     CrossFadeTo(track, timesToLoop);
     Scrub(time);
     CurrentSpeaker.FadeInTo(Volume, CrossFadeTime);
 }