Ejemplo n.º 1
0
        protected virtual void ApplyMods(Mod[] mods)
        {
            var track = new TrackVirtual(10000);

            mods.OfType <IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
            TimeRate = track.Rate;
        }
        public void AddPlayableTrack(TrackBase source)
        {
            PlayableTrackInfo playable = new PlayableTrackInfo();

            playable.Title  = source.MetaData.Title.Value;
            playable.Artist = source.MetaData.AlbumArtists.JoinedValue;

            playable.IsPlayableOffline = source.PlayableOffline;
            playable.IsPlayableOnline  = source.PlayableOnline;

            if (source.PlayableOffline)
            {
                playable.OfflinePlayer = source.SupportedMediaPlayers;
            }
            else
            {
                playable.OnlinePlayer = source.SupportedMediaPlayers;
            }

            if (source is TrackVirtual && source.PlayableOnline)
            {
                TrackVirtual sourceVirtual = source as TrackVirtual;
                playable.SpotifyURI        = sourceVirtual.SpotifyURI;
                playable.PlaytimeInSeconds = 10; // TODO
            }
            else if (source is TrackLocal && source.PlayableOffline)
            {
                TrackLocal sourceLocal = source as TrackLocal;
                playable.FilePath          = sourceLocal.MusicFileProperties.Path;
                playable.PlaytimeInSeconds = sourceLocal.MusicFileProperties.Duration;
            }

            tracks.Add(playable);
        }
Ejemplo n.º 3
0
        public async static void AddMusicFileSpotify(string trackID)
        {
            if (String.IsNullOrWhiteSpace(trackID))
            {
                throw new ArgumentException($"Cannot add new music file, since its ID is null or empty.", nameof(trackID));
            }

            try
            {
                ISpotifyService             spotifyService = DependencyInjector.GetService <ISpotifyService>();
                Dictionary <string, string> tagData        = await spotifyService.GetTrackData(trackID);

                MetaData trackData = UtilityHelper.FormatMetaDataSpotify(tagData, out string trackURI);

                TrackVirtual track = new TrackVirtual(trackData, false);
                track.SpotifyID  = trackID;
                track.SpotifyURI = trackURI;
                SpotifyTracks.Add(track);
                FilteredSpotifyTracks.Add(track);
            }
            catch (Exception) // TODO: more polished exception handling
            {
                UtilityHelper.ShowExceptionDialog(
                    "Track parsing error",
                    "Track parsing error happened while trying to parse a music file from Spotify. This file will be omitted from Playzone!",
                    $"Track URI: {trackID}");
            }
        }
Ejemplo n.º 4
0
        public static TrackBase CopyTrack(TrackBase source)
        {
            TrackBase target = null;

            if (source is TrackVirtual)
            {
                TrackVirtual sourceVirtual = source as TrackVirtual;
                target = new TrackVirtual(sourceVirtual.MetaData, sourceVirtual.IsOnlyMetaData)
                {
                    SpotifyID  = sourceVirtual.SpotifyID,
                    SpotifyURI = sourceVirtual.SpotifyURI
                };
            }
            else if (source is TrackLocal)
            {
                TrackLocal sourceLocal = source as TrackLocal;
                target = new TrackLocal(sourceLocal.MusicFileProperties, sourceLocal.MetaData, sourceLocal.MetaDataExtended)
                {
                    MatchCandidates          = sourceLocal.MatchCandidates,
                    ActiveCandidateMBTrackID = sourceLocal.ActiveCandidateMBTrackID
                };
            }

            target.PlayableOffline       = source.PlayableOffline;
            target.PlayableOnline        = source.PlayableOnline;
            target.SupportedMediaPlayers = source.SupportedMediaPlayers;

            return(target);
        }
Ejemplo n.º 5
0
 public void SetUp()
 {
     track = new TrackVirtual(20_000);
     // define a fake playfield to re-calculate the current rate by ModTimeRamp.Update(Playfield).
     playfield = new OsuPlayfield {
         Clock = new FramedClock(track)
     };
 }
Ejemplo n.º 6
0
        public static void RemoveMusicFileSpotify(string trackID)
        {
            TrackVirtual itemToRemove = SpotifyTracks.SingleOrDefault(t => t.SpotifyID == trackID);

            if (itemToRemove != null)
            {
                SpotifyTracks.Remove(itemToRemove);
                FilteredSpotifyTracks.Remove(itemToRemove);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Calculates the difficulty of the beatmap using a specific mod combination.
        /// </summary>
        /// <param name="mods">The mods that should be applied to the beatmap.</param>
        /// <returns>A structure describing the difficulty of the beatmap.</returns>
        public DifficultyAttributes Calculate(params Mod[] mods)
        {
            mods = mods.Select(m => m.CreateCopy()).ToArray();

            IBeatmap playableBeatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods);

            var track = new TrackVirtual(10000);
            mods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));

            return calculate(playableBeatmap, mods, track.Rate);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Performs required tasks before every calculation.
        /// </summary>
        /// <param name="mods">The original list of <see cref="Mod"/>s.</param>
        private void preProcess(Mod[] mods)
        {
            playableMods = mods.Select(m => m.DeepClone()).ToArray();

            Beatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, playableMods);

            var track = new TrackVirtual(10000);

            playableMods.OfType <IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
            clockRate = track.Rate;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Performs required tasks before every calculation.
        /// </summary>
        /// <param name="mods">The original list of <see cref="Mod"/>s.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        private void preProcess([NotNull] IEnumerable <Mod> mods, CancellationToken cancellationToken = default)
        {
            playableMods = mods.Select(m => m.DeepClone()).ToArray();

            Beatmap = beatmap.GetPlayableBeatmap(ruleset, playableMods, cancellationToken);

            var track = new TrackVirtual(10000);

            playableMods.OfType <IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
            clockRate = track.Rate;
        }
Ejemplo n.º 10
0
            public Track GetVirtual(double length = double.PositiveInfinity)
            {
                if (IsDisposed)
                {
                    throw new ObjectDisposedException($"Cannot retrieve items for an already disposed {nameof(PreviewTrackStore)}");
                }

                var track = new TrackVirtual(length);

                AddItem(track);
                return(track);
            }
Ejemplo n.º 11
0
        public void TestStartZeroLength()
        {
            // override default with custom length
            track = new TrackVirtual(0);

            track.Start();
            updateTrack();

            Thread.Sleep(50);

            Assert.IsTrue(!track.IsRunning);
            Assert.AreEqual(0, track.CurrentTime);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Performs required tasks before every calculation.
        /// </summary>
        /// <param name="mods">The original list of <see cref="Mod"/>s.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        private void preProcess([NotNull] IEnumerable <Mod> mods, CancellationToken cancellationToken = default)
        {
            playableMods = mods.Select(m => m.DeepClone()).ToArray();

            // Only pass through the cancellation token if it's non-default.
            // This allows for the default timeout to be applied for playable beatmap construction.
            Beatmap = cancellationToken == default
                ? beatmap.GetPlayableBeatmap(ruleset, playableMods)
                : beatmap.GetPlayableBeatmap(ruleset, playableMods, cancellationToken);

            var track = new TrackVirtual(10000);

            playableMods.OfType <IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
            clockRate = track.Rate;
        }
Ejemplo n.º 13
0
 public void Setup()
 {
     track = new TrackVirtual(60000);
     updateTrack();
 }