Skip to content

Commit 716925b

Browse files
Add ApplyCascadingSettings to SongInfoViewModel
1 parent 9d64db9 commit 716925b

8 files changed

+41
-48
lines changed

MSUScripter/Services/ControlServices/AddSongWindowService.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,22 @@ public void UpdateFromPyMusicLooper(PyMusicLooperResultViewModel? result)
164164

165165
var song = new MsuSongInfoViewModel
166166
{
167-
TrackNumber = track.TrackNumber,
168-
TrackName = track.TrackName,
169-
Track = track,
170167
SongName = _model.SongName,
171168
Artist = _model.ArtistName,
172169
Album = _model.AlbumName,
173170
OutputPath = outputPath,
174-
IsAlt = isAlt,
175-
LastModifiedDate = DateTime.Now,
176-
Project = _model.MsuProjectViewModel,
177171
MsuPcmInfo = new MsuSongMsuPcmInfoViewModel
178172
{
179173
Loop = _model.LoopPoint,
180174
TrimStart = _model.TrimStart,
181175
TrimEnd = _model.TrimEnd,
182176
Normalization = _model.Normalization,
183-
File = _model.FilePath,
184-
IsAlt = isAlt
177+
File = _model.FilePath
185178
}
186179
};
187180

181+
song.ApplyCascadingSettings(_model.MsuProjectViewModel, track, isAlt, false, true, true);
182+
188183
track.Songs.Add(song);
189184

190185
_model.AddSongButtonText = "Added Song";

MSUScripter/Services/ControlServices/CopyMoveTrackWindowService.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.IO;
23
using System.Linq;
34
using AvaloniaControls.ControlServices;
@@ -41,11 +42,6 @@ public void RunCopyMove()
4142

4243
var songInfo = _model.PreviousSong;
4344

44-
songInfo.TrackNumber = destinationTrack.TrackNumber;
45-
songInfo.TrackName = destinationTrack.TrackName;
46-
songInfo.IsAlt = destinationTrack.Songs.Count > 0;
47-
songInfo.MsuPcmInfo.IsAlt = songInfo.IsAlt;
48-
4945
var msu = new FileInfo(_model.Project.MsuPath);
5046
if (!songInfo.MsuPcmInfo.IsAlt)
5147
{
@@ -58,8 +54,10 @@ public void RunCopyMove()
5854
msu.FullName.Replace(msu.Extension, $"-{destinationTrack.TrackNumber}_{altSuffix}.pcm");
5955
}
6056

61-
_model.PreviousTrack.Songs.Remove(_model.PreviousSong);
62-
destinationTrack.Songs.Add(_model.PreviousSong);
57+
_model.PreviousTrack.Songs.Remove(songInfo);
58+
songInfo.ApplyCascadingSettings(_model.Project, destinationTrack, destinationTrack.Songs.Count > 0, songInfo.CanPlaySongs, true, true);
59+
destinationTrack.Songs.Add(songInfo);
60+
6361
}
6462
else
6563
{
@@ -86,7 +84,7 @@ public void RunCopyMove()
8684
var msuSongInfoCloned = new MsuSongInfoViewModel();
8785
converterService.ConvertViewModel(msuSongInfo, msuSongInfoCloned);
8886
converterService.ConvertViewModel(msuSongInfo.MsuPcmInfo, msuSongInfoCloned.MsuPcmInfo);
89-
msuSongInfoCloned.Project = _model.Project;
87+
msuSongInfoCloned.ApplyCascadingSettings(_model.Project, destinationTrack, msuSongInfo.IsAlt, _model.PreviousSong.CanPlaySongs, true, true);
9088
destinationTrack.Songs.Add(msuSongInfoCloned);
9189
}
9290
}

MSUScripter/Services/ControlServices/MsuSongInfoPanelService.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,9 @@ public void ImportAudioMetadata(string file)
129129
return "Invalid song details";
130130
}
131131

132-
_model.Project = originalProject;
133-
_model.Track = originalTrack;
134-
_model.TrackNumber = originalTrackNumber;
135-
_model.TrackName = originalTrackName;
136-
_model.IsAlt = originalIsAlt;
137-
_model.CanPlaySongs = originalCanPlaySongs;
138132
_model.OutputPath = originalOutputPath;
139133

140-
_model.MsuPcmInfo.ApplyCascadingSettings(originalProject, _model, originalIsAlt, null, originalCanPlaySongs, true, true);
141-
_model.LastModifiedDate = DateTime.Now;
134+
_model.ApplyCascadingSettings(originalProject, originalTrack, originalIsAlt, originalCanPlaySongs, true, true);
142135
return null;
143136
}
144137

MSUScripter/Services/ControlServices/MsuSongMsuPcmInfoPanelService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public void HideSubTracksSubChannelsWarning()
154154
}
155155

156156
_model.ApplyCascadingSettings(originalProject, originalSong, originalIsAlt, originalParent, originalCanPlaySongs, true, true);
157-
_model.LastModifiedDate = DateTime.Now;
158157
return null;
159158
}
160159

MSUScripter/Services/ControlServices/MsuTrackInfoPanelService.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ public void InitializeModel(MsuTrackInfoViewModel model)
1515

1616
public void AddSong()
1717
{
18-
var songInfo = new MsuSongInfoViewModel()
19-
{
20-
TrackNumber = _model.TrackNumber,
21-
TrackName = _model.TrackName,
22-
IsAlt = _model.Songs.Count > 0,
23-
};
18+
var songInfo = new MsuSongInfoViewModel();
19+
20+
var isAlt = _model.Songs.Count > 0;
2421

2522
var msu = new FileInfo(_model.Project.MsuPath);
26-
if (!songInfo.IsAlt)
23+
if (!isAlt)
2724
{
2825
songInfo.OutputPath = msu.FullName.Replace(msu.Extension, $"-{_model.TrackNumber}.pcm");
2926
}
@@ -33,9 +30,7 @@ public void AddSong()
3330
songInfo.OutputPath = msu.FullName.Replace(msu.Extension, $"-{_model.TrackNumber}_{altSuffix}.pcm");
3431
}
3532

36-
songInfo.Project = _model.Project;
37-
songInfo.Track = _model;
38-
songInfo.MsuPcmInfo.ApplyCascadingSettings(songInfo.Project, songInfo, songInfo.IsAlt, null, songInfo.CanPlaySongs, true, true);
33+
songInfo.ApplyCascadingSettings(_model.Project, _model, isAlt, true, true, true);
3934
_model.Songs.Add(songInfo);
4035
}
4136
}

MSUScripter/Services/ConverterService.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,10 @@ public MsuProjectViewModel ConvertProject(MsuProject project)
8484

8585
foreach (var song in track.Songs)
8686
{
87-
var songViewModel = new MsuSongInfoViewModel
88-
{
89-
Project = viewModel,
90-
Track = trackViewModel
91-
};
92-
87+
var songViewModel = new MsuSongInfoViewModel();
9388
ConvertViewModel(song, songViewModel);
9489
ConvertViewModel(song.MsuPcmInfo, songViewModel.MsuPcmInfo);
95-
songViewModel.MsuPcmInfo.ApplyCascadingSettings(viewModel, songViewModel, songViewModel.IsAlt, null, false, false, false);
96-
90+
songViewModel.ApplyCascadingSettings(viewModel, trackViewModel, songViewModel.IsAlt, songViewModel.CanPlaySongs, false, false);
9791
trackViewModel.Songs.Add(songViewModel);
9892
}
9993

MSUScripter/ViewModels/MsuSongInfoViewModel.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ public void ApplyAudioMetadata(AudioMetadata metadata, bool force)
8686
Url = metadata.Url;
8787
}
8888

89+
public void ApplyCascadingSettings(MsuProjectViewModel projectModel, MsuTrackInfoViewModel track, bool isAlt, bool canPlaySongs, bool updateLastModified, bool forceOpen)
90+
{
91+
var lastModified = updateLastModified ? DateTime.Now : LastModifiedDate;
92+
Project = projectModel;
93+
Track = track;
94+
TrackName = track.TrackName;
95+
TrackNumber = track.TrackNumber;
96+
IsAlt = isAlt;
97+
CanPlaySongs = canPlaySongs;
98+
99+
if (forceOpen)
100+
{
101+
ShowPanel = true;
102+
}
103+
104+
MsuPcmInfo.ApplyCascadingSettings(Project, this, isAlt, null, canPlaySongs, updateLastModified, forceOpen);
105+
106+
LastModifiedDate = lastModified;
107+
}
108+
109+
89110
public override ViewModelBase DesignerExample()
90111
{
91112
return this;

MSUScripter/ViewModels/MsuSongMsuPcmInfoViewModel.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,13 @@ public int GetFileCount()
126126

127127
public void ApplyCascadingSettings(MsuProjectViewModel projectModel, MsuSongInfoViewModel songModel, bool isAlt, MsuSongMsuPcmInfoViewModel? parent, bool canPlaySongs, bool updateLastModified, bool forceOpen)
128128
{
129+
var lastModified = updateLastModified ? DateTime.Now : LastModifiedDate;
129130
Project = projectModel;
130131
Song = songModel;
131132
IsAlt = isAlt;
132133
ParentMsuPcmInfo = parent;
133134
CanPlaySongs = canPlaySongs;
134135

135-
if (updateLastModified)
136-
{
137-
LastModifiedDate = DateTime.Now;
138-
}
139-
140136
if (forceOpen)
141137
{
142138
ShowPanel = forceOpen;
@@ -146,6 +142,8 @@ public void ApplyCascadingSettings(MsuProjectViewModel projectModel, MsuSongInfo
146142
{
147143
subItem.ApplyCascadingSettings(projectModel, songModel, isAlt, this, canPlaySongs, updateLastModified, forceOpen);
148144
}
145+
146+
LastModifiedDate = lastModified;
149147
}
150148

151149
[SkipConvert]

0 commit comments

Comments
 (0)