1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 12:17:46 +08:00

Implement per-hitobject custom sample banks

This commit is contained in:
smoogipoo 2018-07-20 15:12:44 +09:00
parent de8d05bb0c
commit c087a73f40
4 changed files with 62 additions and 11 deletions

View File

@ -240,6 +240,23 @@ namespace osu.Game.Tests.Beatmaps.Formats
{ {
var hitObjects = decoder.Decode(stream).HitObjects; var hitObjects = decoder.Decode(stream).HitObjects;
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
Assert.AreEqual("normal-hitnormal3", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
}
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]);
}
[Test]
public void TestDecodeHitObjectFileSamples()
{
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
using (var resStream = Resource.OpenResource("hitobject-file-samples.osu"))
using (var stream = new StreamReader(resStream))
{
var hitObjects = decoder.Decode(stream).HitObjects;
Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());

View File

@ -0,0 +1,13 @@
osu file format v14
[General]
SampleSet: Normal
[TimingPoints]
2170,468.75,4,1,0,40,1,0
3107,-100,4,1,2,40,0,0
[HitObjects]
255,193,2170,1,0,0:0:0:0:
256,191,3107,5,0,0:0:0:0:
255,193,4000,1,0,0:0:3:70:

View File

@ -188,7 +188,7 @@ namespace osu.Game.Beatmaps.Formats
{ {
var baseInfo = base.ApplyTo(sampleInfo); var baseInfo = base.ApplyTo(sampleInfo);
if (CustomSampleBank > 1) if (string.IsNullOrEmpty(baseInfo.Suffix) && CustomSampleBank > 1)
baseInfo.Suffix = CustomSampleBank.ToString(); baseInfo.Suffix = CustomSampleBank.ToString();
return baseInfo; return baseInfo;

View File

@ -194,8 +194,8 @@ namespace osu.Game.Rulesets.Objects.Legacy
string[] split = str.Split(':'); string[] split = str.Split(':');
var bank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[0]); var bank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[0]);
var addbank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[1]); var addbank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[1]);
string stringBank = bank.ToString().ToLower(); string stringBank = bank.ToString().ToLower();
if (stringBank == @"none") if (stringBank == @"none")
@ -207,6 +207,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
bankInfo.Normal = stringBank; bankInfo.Normal = stringBank;
bankInfo.Add = stringAddBank; bankInfo.Add = stringAddBank;
if (split.Length > 2)
bankInfo.CustomSampleBank = int.Parse(split[2]);
if (split.Length > 3) if (split.Length > 3)
bankInfo.Volume = int.Parse(split[3]); bankInfo.Volume = int.Parse(split[3]);
@ -258,41 +261,45 @@ namespace osu.Game.Rulesets.Objects.Legacy
var soundTypes = new List<SampleInfo> var soundTypes = new List<SampleInfo>
{ {
new SampleInfo new LegacySampleInfo
{ {
Bank = bankInfo.Normal, Bank = bankInfo.Normal,
Name = SampleInfo.HIT_NORMAL, Name = SampleInfo.HIT_NORMAL,
Volume = bankInfo.Volume Volume = bankInfo.Volume,
CustomSampleBank = bankInfo.CustomSampleBank
} }
}; };
if (type.HasFlag(LegacySoundType.Finish)) if (type.HasFlag(LegacySoundType.Finish))
{ {
soundTypes.Add(new SampleInfo soundTypes.Add(new LegacySampleInfo
{ {
Bank = bankInfo.Add, Bank = bankInfo.Add,
Name = SampleInfo.HIT_FINISH, Name = SampleInfo.HIT_FINISH,
Volume = bankInfo.Volume Volume = bankInfo.Volume,
CustomSampleBank = bankInfo.CustomSampleBank
}); });
} }
if (type.HasFlag(LegacySoundType.Whistle)) if (type.HasFlag(LegacySoundType.Whistle))
{ {
soundTypes.Add(new SampleInfo soundTypes.Add(new LegacySampleInfo
{ {
Bank = bankInfo.Add, Bank = bankInfo.Add,
Name = SampleInfo.HIT_WHISTLE, Name = SampleInfo.HIT_WHISTLE,
Volume = bankInfo.Volume Volume = bankInfo.Volume,
CustomSampleBank = bankInfo.CustomSampleBank
}); });
} }
if (type.HasFlag(LegacySoundType.Clap)) if (type.HasFlag(LegacySoundType.Clap))
{ {
soundTypes.Add(new SampleInfo soundTypes.Add(new LegacySampleInfo
{ {
Bank = bankInfo.Add, Bank = bankInfo.Add,
Name = SampleInfo.HIT_CLAP, Name = SampleInfo.HIT_CLAP,
Volume = bankInfo.Volume Volume = bankInfo.Volume,
CustomSampleBank = bankInfo.CustomSampleBank
}); });
} }
@ -307,9 +314,23 @@ namespace osu.Game.Rulesets.Objects.Legacy
public string Add; public string Add;
public int Volume; public int Volume;
public int CustomSampleBank;
public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone(); public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone();
} }
private class LegacySampleInfo : SampleInfo
{
public int CustomSampleBank
{
set
{
if (value > 1)
Suffix = value.ToString();
}
}
}
private class FileSampleInfo : SampleInfo private class FileSampleInfo : SampleInfo
{ {
public string Filename; public string Filename;