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, _cache.GetFileUntilFind(_sourceFolder, Path.GetFileNameWithoutExtension(sample.Filename)) ); elements.Add(element); }); }).ConfigureAwait(false); var elementList = new List <SoundElement>(elements); if (PlaybackRate.Equals(1.5f) && !UseTempo) { var duration1 = MathEx.Max(ReferencedChannels.Select(k => k.ChannelEndTime)); var duration = MathEx.Max(duration1, 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); }
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( _cache.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 + Information.WavExtension); } else if (waves.Contains(fileNameWithoutExt)) { filePath = _cache.GetFileUntilFind(_sourceFolder, fileNameWithoutExt); } else { filePath = Path.Combine(Domain.DefaultPath, fileNameWithoutIndex + Information.WavExtension); } tuples[i] = (filePath, hitsoundType); } return(tuples); }