Skip to content

Commit 66d051d

Browse files
Prevent short tracks from being loop along long tracks
1 parent 017345e commit 66d051d

File tree

7 files changed

+57
-34
lines changed

7 files changed

+57
-34
lines changed

MSURandomizer/MSURandomizer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9-
<Version>2.0.0-rc.7</Version>
9+
<Version>2.0.1-rc.1</Version>
1010
<ApplicationIcon>MSURandomizerIcon.ico</ApplicationIcon>
1111
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1212
<PackageId>MattEqualsCoder.MSURandomizer.Avalonia</PackageId>

MSURandomizerLibrary/Configs/Track.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public Track(string trackName, int number, string songName, string path, string?
4242
IsAlt = isAlt;
4343
OriginalPath = path;
4444
IsBaseFile = isBaseFile;
45+
Duration = File.Exists(path) ? (new FileInfo(path).Length - 8.0) / 44100 / 4 : 30;
4546
}
4647

4748
/// <summary>
@@ -68,6 +69,7 @@ public Track(Track other, int? number = null, string? path = null, string? track
6869
MsuCreator = other.MsuCreator;
6970
OriginalPath = other.OriginalPath;
7071
OriginalMsu = other.OriginalMsu ?? other.Msu;
72+
Duration = other.Duration;
7173
}
7274

7375
/// <summary>
@@ -150,6 +152,11 @@ public Track(Track other, int? number = null, string? path = null, string? track
150152
/// </summary>
151153
public string OriginalTrackName { get; set; } = "";
152154

155+
/// <summary>
156+
/// The length of the song
157+
/// </summary>
158+
public double Duration { get; set; }
159+
153160
/// <summary>
154161
/// The MSU this track is currently part of
155162
/// </summary>
@@ -179,6 +186,12 @@ public Track(Track other, int? number = null, string? path = null, string? track
179186
/// </summary>
180187
[JsonIgnore]
181188
public string? DisplayUrl => Url ?? Msu?.Url;
189+
190+
/// <summary>
191+
/// If the track is a short track that is at most 20 seconds
192+
/// </summary>
193+
[JsonIgnore]
194+
public bool IsShortTrack => Duration <= 20;
182195

183196
/// <summary>
184197
/// Gets text to represent the song

MSURandomizerLibrary/MSURandomizerLibrary.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
1515
<IncludeSymbols>False</IncludeSymbols>
1616
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
17-
<Version>2.0.0-rc.15</Version>
17+
<Version>2.0.1-rc.1</Version>
1818
<PackageId>MattEqualsCoder.MSURandomizer.Library</PackageId>
1919
<GenerateDocumentationFile>True</GenerateDocumentationFile>
2020
<TargetFramework>net8.0</TargetFramework>

MSURandomizerLibrary/Services/MsuCacheService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace MSURandomizerLibrary.Services;
66

77
internal class MsuCacheService : IMsuCacheService
88
{
9-
private static readonly int _currentCacheVersion = 1;
9+
private const int CurrentCacheVersion = 2;
1010
private readonly IMsuTypeService _msuTypeService;
1111
private readonly MsuUserOptions _msuUserOptions;
1212
private readonly ILogger<MsuCacheService> _logger;
1313

1414
private MsuLookupCache _cache = new()
1515
{
16-
CacheVersion = _currentCacheVersion
16+
CacheVersion = CurrentCacheVersion
1717
};
1818

1919
private string _cachePath = "";
@@ -45,7 +45,7 @@ public void Initialize(string cachePath)
4545
_logger.LogInformation("Loading MSU Cache from {Path}", _cachePath);
4646
var text = File.ReadAllText(_cachePath);
4747
var tempCache = JsonSerializer.Deserialize<MsuLookupCache>(text) ?? new MsuLookupCache();
48-
if (tempCache.CacheVersion == _currentCacheVersion)
48+
if (tempCache.CacheVersion == CurrentCacheVersion)
4949
{
5050
_cache = tempCache;
5151
}

MSURandomizerLibrary/Services/MsuSelectorService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public MsuSelectorResponse CreateShuffledMsu(MsuSelectorRequest request)
122122
}
123123
}
124124

125-
var specialTrackNumbers = msuType.Tracks.Where(x => x.IsSpecial).Select(x => x.Number).ToHashSet();
125+
var shortTrackNumbers = msuType.Tracks.Where(x => x.IsSpecial).Select(x => x.Number).ToHashSet();
126126

127127
foreach (var msuTypeTrack in msuType.Tracks.OrderBy(x => x.Number))
128128
{
@@ -145,18 +145,18 @@ public MsuSelectorResponse CreateShuffledMsu(MsuSelectorRequest request)
145145
}
146146
else
147147
{
148-
possibleTracks = possibleTracks.Where(t => !specialTrackNumbers.Contains(t.Number)).ToList();
148+
possibleTracks = possibleTracks.Where(t => !t.IsShortTrack).ToList();
149149
}
150150
}
151151
else if (request.ShuffleStyle == MsuShuffleStyle.ChaosJingleTracks)
152152
{
153153
if (msuTypeTrack.IsSpecial)
154154
{
155-
possibleTracks = possibleTracks.Where(t => specialTrackNumbers.Contains(t.Number)).ToList();
155+
possibleTracks = possibleTracks.Where(t => t.IsShortTrack).ToList();
156156
}
157157
else
158158
{
159-
possibleTracks = possibleTracks.Where(t => !specialTrackNumbers.Contains(t.Number)).ToList();
159+
possibleTracks = possibleTracks.Where(t => !t.IsShortTrack).ToList();
160160
}
161161
}
162162
else if (request.ShuffleStyle == MsuShuffleStyle.ChaosAllTracks)
@@ -165,22 +165,22 @@ public MsuSelectorResponse CreateShuffledMsu(MsuSelectorRequest request)
165165
{
166166
if (msuTypeTrack.IsSpecial)
167167
{
168-
possibleTracks = possibleTracks.Where(t => !specialTrackNumbers.Contains(t.Number)).ToList();
168+
possibleTracks = possibleTracks.Where(t => !t.IsShortTrack).ToList();
169169
}
170170
else
171171
{
172-
possibleTracks = possibleTracks.Where(t => specialTrackNumbers.Contains(t.Number)).ToList();
172+
possibleTracks = possibleTracks.Where(t => t.IsShortTrack).ToList();
173173
}
174174
}
175175
else
176176
{
177177
if (msuTypeTrack.IsSpecial)
178178
{
179-
possibleTracks = possibleTracks.Where(t => specialTrackNumbers.Contains(t.Number)).ToList();
179+
possibleTracks = possibleTracks.Where(t => t.IsShortTrack).ToList();
180180
}
181181
else
182182
{
183-
possibleTracks = possibleTracks.Where(t => !specialTrackNumbers.Contains(t.Number)).ToList();
183+
possibleTracks = possibleTracks.Where(t => !t.IsShortTrack).ToList();
184184
}
185185
}
186186
}

MSURandomizerLibraryTests/MsuSelectorServiceTests.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,21 +373,23 @@ public void ChaosJingleTracksMsuTest()
373373
{
374374
new() { (1, 4) }
375375
},
376-
new List<List<(int, int)>>()
377-
{
378-
new() { (1, 4) },
379-
new() { (1, 4) },
380-
new() { (1, 4) },
381-
new() { (1, 4) },
382-
new() { (1, 4) },
383-
new() { (1, 4) },
384-
new() { (1, 4) },
385-
new() { (1, 4) },
386-
new() { (1, 4) },
387-
new() { (1, 4) },
388-
new() { (1, 4) },
389-
},
390-
out var msuTypes, out var msus, new Dictionary<int, List<int>>() { { 1, new List<int>() { 2 } }}, [1, 2]);
376+
[
377+
[(1, 4)],
378+
[(1, 4)],
379+
[(1, 4)],
380+
[(1, 4)],
381+
[(1, 4)],
382+
[(1, 4)],
383+
[(1, 4)],
384+
[(1, 4)],
385+
[(1, 4)],
386+
[(1, 4)],
387+
[(1, 4)]
388+
],
389+
out var msuTypes,
390+
out var msus,
391+
new Dictionary<int, List<int>> { { 1, [2] }},
392+
[1, 2]);
391393

392394
var anyNotMatchedTrack1 = false;
393395
var anyNotMatchedTrack2 = false;
@@ -740,7 +742,7 @@ private MsuSelectorService CreateMsuSelectorService(List<List<(int, int)>> msuTy
740742
var folder = "";
741743
foreach (var tracks in msuTracks)
742744
{
743-
var path = TestHelpers.CreateMsu(tracks, $"test-msu-{index}", index == 1);
745+
var path = TestHelpers.CreateMsu(tracks, $"test-msu-{index}", index == 1, specialTracks: specialTracks);
744746
if (string.IsNullOrEmpty(folder))
745747
{
746748
folder = new FileInfo(path).Directory?.Parent?.FullName;;

MSURandomizerLibraryTests/TestHelpers.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static IMsuCacheService CreateMockMsuCacheService()
139139
return service.Object;
140140
}
141141

142-
public static string CreateMsu(List<int> tracks, string msuName = "test-msu", bool deleteOld = true, bool createAlts = false)
142+
public static string CreateMsu(List<int> tracks, string msuName = "test-msu", bool deleteOld = true, bool createAlts = false, List<int>? specialTracks = null)
143143
{
144144
if (deleteOld && Directory.Exists(MsuTestFolder))
145145
{
@@ -160,9 +160,17 @@ public static string CreateMsu(List<int> tracks, string msuName = "test-msu", bo
160160

161161
foreach (var trackNumber in tracks)
162162
{
163-
var pcmPath = Path.Combine(folder, $"{msuName}-{trackNumber}.pcm");
164-
using (File.Create(pcmPath)) {}
163+
var pcmPath = Path.Combine(folder, $"{msuName}-{trackNumber}.pcm");System.IO.File.WriteAllBytes("file.txt", new byte[100]);
165164

165+
if (specialTracks == null || specialTracks.Contains(trackNumber))
166+
{
167+
using (File.Create(pcmPath)) {}
168+
}
169+
else
170+
{
171+
File.WriteAllBytes(pcmPath, new byte[5292000]);
172+
}
173+
166174
if (createAlts)
167175
{
168176
pcmPath = Path.Combine(folder, $"{msuName}-{trackNumber}_alt.pcm");
@@ -173,9 +181,9 @@ public static string CreateMsu(List<int> tracks, string msuName = "test-msu", bo
173181
return msuPath;
174182
}
175183

176-
public static string CreateMsu(List<(int, int)> tracks, string msuName = "test-msu", bool deleteOld = true, bool createAlts = false)
184+
public static string CreateMsu(List<(int, int)> tracks, string msuName = "test-msu", bool deleteOld = true, bool createAlts = false, List<int>? specialTracks = null)
177185
{
178-
return CreateMsu(GetTracksFromRanges(tracks), msuName, deleteOld, createAlts);
186+
return CreateMsu(GetTracksFromRanges(tracks), msuName, deleteOld, createAlts, specialTracks);
179187
}
180188

181189
public static IMsuDetailsService CreateMockMsuDetailsService(MsuDetails? returnMsuDetails, Msu? returnMsu)

0 commit comments

Comments
 (0)