Skip to content

Commit acf4d85

Browse files
Fix issues with changing the track a song is associated with
1 parent 4a2a078 commit acf4d85

File tree

7 files changed

+55
-24
lines changed

7 files changed

+55
-24
lines changed

MSUScripter/Configs/MsuTrackInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ public void MoveSong(MsuProject project, MsuSongInfo song, int index)
8484
UpdateSongPath(project, oldTrack.Songs[i], i);
8585
}
8686

87+
song.TrackName = TrackName;
88+
song.TrackNumber = TrackNumber;
89+
8790
Songs.Insert(index, song);
8891
for (var i = 0; i < Songs.Count; i++)
8992
{
9093
UpdateSongPath(project, Songs[i], i);
9194
}
92-
93-
song.TrackName = TrackName;
94-
song.TrackNumber = TrackNumber;
9595
}
9696

9797
private void UpdateSongPath(MsuProject project, MsuSongInfo song, int? index = null)
@@ -107,12 +107,12 @@ private void UpdateSongPath(MsuProject project, MsuSongInfo song, int? index = n
107107
}
108108
else if (!song.IsAlt)
109109
{
110-
song.OutputPath = msu.FullName.Replace(msu.Extension, $"-{TrackNumber}.pcm");
110+
song.OutputPath = msu.FullName.Replace(msu.Extension, $"-{song.TrackNumber}.pcm");
111111
}
112112
else
113113
{
114114
var altSuffix = index == 1 ? "alt" : $"alt{index}";
115-
song.OutputPath = msu.FullName.Replace(msu.Extension, $"-{TrackNumber}_{altSuffix}.pcm");
115+
song.OutputPath = msu.FullName.Replace(msu.Extension, $"-{song.TrackNumber}_{altSuffix}.pcm");
116116
}
117117

118118
song.MsuPcmInfo.Output = song.OutputPath;

MSUScripter/MSUScripter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
99
<ApplicationIcon>MSUScripterIcon.ico</ApplicationIcon>
1010
<PackageIcon>MSUScripterIcon.ico</PackageIcon>
11-
<Version>5.0.1</Version>
11+
<Version>5.0.2</Version>
1212
<RuntimeFrameworkVersion>9.0.0</RuntimeFrameworkVersion>
1313
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1414
<LangVersion>12</LangVersion>

MSUScripter/Services/ControlServices/CopyProjectWindowService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public void LogError(Exception e, string message)
148148
private void UpdateSongPaths(MsuSongInfo song, CopyProjectViewModel update, string oldMsuPath, string newMsuPath)
149149
{
150150
song.OutputPath = song.OutputPath?.Replace(oldMsuPath, newMsuPath);
151+
song.MsuPcmInfo.Output = song.OutputPath;
151152
if (song.MsuPcmInfo.HasFiles())
152153
{
153154
UpdateMsuPcmInfo(song.MsuPcmInfo, update);

MSUScripter/Services/MsuPcmService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ public async Task<GeneratePcmFileResponse> CreatePcm(MsuProject project, MsuSong
197197
{
198198
outputPath = project.Tracks.First(x => x.TrackNumber == song.TrackNumber).Songs.First(x => !x.IsAlt).OutputPath;
199199
}
200-
else if (song.TrackNumber is >= 1000 or < 0)
200+
else if (song.TrackNumber is >= 999 or < 0)
201201
{
202202
song.OutputPath = tempPcmPath;
203+
song.MsuPcmInfo.Output = tempPcmPath;
203204
outputPath = tempPcmPath;
204205
}
205206

MSUScripter/Services/ProjectService.cs

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,32 @@ public void SaveMsuProject(MsuProject project, bool isBackup)
120120
{
121121
foreach (var song in track.Songs)
122122
{
123+
if (string.IsNullOrEmpty(song.Id))
124+
{
125+
song.Id = Guid.NewGuid().ToString("N");
126+
}
127+
128+
// Each song should have a unique output path. If it doesn't, we need to correct it and all duplicates
129+
var hasDuplicate = false;
123130
foreach (var duplicate in project.Tracks.SelectMany(x => x.Songs).Where(x => x != song && x.OutputPath == song.OutputPath))
124131
{
132+
hasDuplicate = true;
125133
var duplicateTrack = project.Tracks.First(x => x.Songs.Contains(duplicate));
126134
duplicate.TrackNumber = duplicateTrack.TrackNumber;
127135
duplicate.TrackName = duplicateTrack.TrackName;
128-
var index = duplicateTrack.Songs.IndexOf(duplicate);
129-
if (index == 0)
130-
{
131-
duplicate.OutputPath = $"{msuBasePath}-{duplicateTrack.TrackNumber}.pcm";
132-
duplicate.IsAlt = false;
133-
}
134-
else
135-
{
136-
var altSuffix = index == 1 ? "alt" : $"alt{index}";
137-
duplicate.OutputPath = $"{msuBasePath}-{duplicateTrack.TrackNumber}_{altSuffix}.pcm";
138-
duplicate.IsAlt = true;
139-
}
136+
FixSongPath(project, track, song, msuBasePath);
140137
}
141138

142-
song.DisplayAdvancedMode ??= song.MsuPcmInfo.HasAdvancedData();
143-
144-
if (string.IsNullOrEmpty(song.Id))
139+
// Fix tracks that have "temp.pcm" instead of the proper pcm file path and tracks where the msupcm++
140+
// output path does not match the song output path
141+
var isInvalidTempPath = !track.IsScratchPad && song.OutputPath?.EndsWith("temp.pcm") == true;
142+
var isOutputMismatch = song.OutputPath != song.MsuPcmInfo.Output;
143+
if (isInvalidTempPath || isOutputMismatch || hasDuplicate)
145144
{
146-
song.Id = Guid.NewGuid().ToString("N");
145+
FixSongPath(project, track, song, msuBasePath);
147146
}
147+
148+
song.DisplayAdvancedMode ??= song.MsuPcmInfo.HasAdvancedData();
148149
}
149150
}
150151

@@ -211,6 +212,33 @@ public void SaveMsuProject(MsuProject project, bool isBackup)
211212
return project;
212213
}
213214

215+
private void FixSongPath(MsuProject project, MsuTrackInfo track, MsuSongInfo song, string msuBasePath)
216+
{
217+
if (track.IsScratchPad)
218+
{
219+
var tempFolderPath = project.GetMsuGenerationTempFilePath(song);
220+
song.OutputPath = Path.Combine(tempFolderPath, "temp.pcm");
221+
song.MsuPcmInfo.Output = song.OutputPath;
222+
}
223+
else
224+
{
225+
var index = track.Songs.IndexOf(song);
226+
if (index == 0)
227+
{
228+
song.OutputPath = $"{msuBasePath}-{track.TrackNumber}.pcm";
229+
song.MsuPcmInfo.Output = song.OutputPath;
230+
song.IsAlt = false;
231+
}
232+
else
233+
{
234+
var altSuffix = index == 1 ? "alt" : $"alt{index}";
235+
song.OutputPath = $"{msuBasePath}-{track.TrackNumber}_{altSuffix}.pcm";
236+
song.MsuPcmInfo.Output = song.OutputPath;
237+
song.IsAlt = true;
238+
}
239+
}
240+
}
241+
214242
public MsuProject NewMsuProject(string projectPath, MsuType msuType, string msuPath, string? msuPcmTracksJsonPath, string? msuPcmWorkingDirectory, string? projectName, string? creatorName)
215243
{
216244
var project = new MsuProject()

MSUScripter/ViewModels/MsuSongAdvancedPanelViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public override void SaveChanges()
316316

317317
if (_isTopLevelMsuPcmInfo)
318318
{
319-
CurrentSongInfo.OutputPath = CurrentSongInfo.OutputPath;
319+
CurrentSongInfo.OutputPath = Output;
320320
_currentSongMsuPcmInfo.Output = CurrentSongInfo.OutputPath;
321321
}
322322

MSUScripter/ViewModels/MsuSongBasicPanelViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public override void SaveChanges()
160160
_currentSongInfo.MsuPcmInfo.TrimEnd = TrimEnd;
161161
_currentSongInfo.MsuPcmInfo.Loop = LoopPoint;
162162
_currentSongInfo.MsuPcmInfo.Normalization = Normalization;
163+
_currentSongInfo.MsuPcmInfo.Output = OutputFilePath;
163164
HasBeenModified = false;
164165
}
165166

0 commit comments

Comments
 (0)