Ejemplo n.º 1
0
        public override async Task <IEnumerable <SoundElement> > GetSoundElements()
        {
            var elements = new ConcurrentBag <SoundElement>();
            var samples  = _osuFile.Events.SampleInfo;

            if (samples == null)
            {
                return(new List <SoundElement>(elements));
            }

            await Task.Run(() =>
            {
                samples.AsParallel()
                .WithDegreeOfParallelism(Environment.ProcessorCount > 1 ? Environment.ProcessorCount - 1 : 1)
                .ForAll(sample =>
                {
                    var element = SoundElement.Create(sample.Offset, sample.Volume / 100f, 0,
                                                      _player.GetFileUntilFind(_sourceFolder,
                                                                               Path.GetFileNameWithoutExtension(sample.Filename))
                                                      );
                    elements.Add(element);
                });
            }).ConfigureAwait(false);

            var elementList = new List <SoundElement>(elements);

            if (PlaybackRate.Equals(1.5f) && !UseTempo)
            {
                var duration = MathEx.Max(_player.MusicChannel.ChannelEndTime,
                                          _player.HitsoundChannel.ChannelEndTime,
                                          TimeSpan.FromMilliseconds(samples.Count == 0 ? 0 : samples.Max(k => k.Offset))
                                          );
                _nightcore = new NightcoreTilingProvider(_osuFile, duration);
                elementList.AddRange(await _nightcore.GetSoundElements().ConfigureAwait(false));
            }

            return(elementList);
        }
Ejemplo n.º 2
0
        private IEnumerable <(string, HitsoundType)> AnalyzeHitsoundFiles(
            HitsoundType itemHitsound, ObjectSamplesetType itemSample, ObjectSamplesetType itemAddition,
            TimingPoint timingPoint, RawHitObject hitObject,
            HashSet <string> waves)
        {
            if (!string.IsNullOrEmpty(hitObject.FileName))
            {
                return(new[]
                {
                    ValueTuple.Create(
                        _player.GetFileUntilFind(_sourceFolder,
                                                 Path.GetFileNameWithoutExtension(hitObject.FileName)),
                        itemHitsound
                        )
                });
            }

            var tuples = new List <(string, HitsoundType)>();

            // hitnormal, sliderslide
            var sampleStr = itemSample != ObjectSamplesetType.Auto
                ? itemSample.ToHitsoundString(null)
                : timingPoint.TimingSampleset.ToHitsoundString();

            // hitclap, hitfinish, hitwhistle, slidertick, sliderwhistle
            string additionStr = itemAddition.ToHitsoundString(sampleStr);

            if (hitObject.ObjectType == HitObjectType.Slider && hitObject.SliderInfo.EdgeHitsounds == null)
            {
                var hitsounds = GetHitsounds(itemHitsound, sampleStr, additionStr);
                tuples.AddRange(hitsounds);
            }
            else
            {
                var hitsounds = GetHitsounds(itemHitsound, sampleStr, additionStr);
                tuples.AddRange(_osuFile.General.Mode == GameMode.Mania
                    ? hitsounds.Take(1)
                    : hitsounds);
            }

            for (var i = 0; i < tuples.Count; i++)
            {
                var fileNameWithoutIndex = tuples[i].Item1;
                var hitsoundType         = tuples[i].Item2;

                int    baseIndex = hitObject.CustomIndex > 0 ? hitObject.CustomIndex : timingPoint.Track;
                string indexStr  = baseIndex > 1 ? baseIndex.ToString() : "";

                var fileNameWithoutExt = fileNameWithoutIndex + indexStr;

                string filePath;
                if (timingPoint.Track == 0)
                {
                    filePath = Path.Combine(Domain.DefaultPath, fileNameWithoutExt + AudioPlaybackEngine.WavExtension);
                }
                else if (waves.Contains(fileNameWithoutExt))
                {
                    filePath = _player.GetFileUntilFind(_sourceFolder, fileNameWithoutExt);
                }
                else
                {
                    filePath = Path.Combine(Domain.DefaultPath, fileNameWithoutIndex + AudioPlaybackEngine.WavExtension);
                }

                tuples[i] = (filePath, hitsoundType);
            }

            return(tuples);
        }