Skip to content

Added scratch pad track #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MSUScripter/Configs/MsuTrackInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using MSUScripter.Models;
using MSUScripter.Tools;

namespace MSUScripter.Configs;

Expand All @@ -10,6 +9,7 @@ public class MsuTrackInfo
public int TrackNumber { get; set; }
public string TrackName { get; set; } = "";
public DateTime LastModifiedDate { get; set; }
public bool IsScratchPad { get; set; }

[SkipConvert]
public List<MsuSongInfo> Songs { get; set; } = new List<MsuSongInfo>();
Expand Down
2 changes: 1 addition & 1 deletion MSUScripter/MSUScripter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>MSUScripterIcon.ico</ApplicationIcon>
<PackageIcon>MSUScripterIcon.ico</PackageIcon>
<Version>4.0.1</Version>
<Version>4.1.0</Version>
<RuntimeFrameworkVersion>8.0.0</RuntimeFrameworkVersion>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>12</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AddSongWindowViewModel InitializeModel(MsuProjectViewModel project, int?
_model.SingleMode = singleMode;
_model.TrackSearchItems = [new ComboBoxAndSearchItem(null, "Track", addDescriptions ? "Default description" : null)];
_model.TrackSearchItems.AddRange(project.Tracks.OrderBy(x => x.TrackNumber).Select(x =>
new ComboBoxAndSearchItem(x, $"Track #{x.TrackNumber} - {x.TrackName}", x.Description)));
new ComboBoxAndSearchItem(x, x.ToString(), x.Description)));
_model.SelectedTrack = trackNumber == null ? null : project.Tracks.FirstOrDefault(x => x.TrackNumber == trackNumber);

UpdateFilePath(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public AudioAnalysisViewModel InitializeModel(MsuProjectViewModel project)
return _model;
}

var songs = project.Tracks.SelectMany(x => x.Songs)
var songs = project.Tracks
.Where(x => !x.IsScratchPad)
.SelectMany(x => x.Songs)
.OrderBy(x => x.TrackNumber)
.Select(x => new AudioAnalysisSongViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace MSUScripter.Services.ControlServices;

public class CopyMoveTrackWindowService (ConverterService converterService, ILogger<CopyMoveTrackWindowService> logger) : ControlService
public class CopyMoveTrackWindowService (ConverterService converterService) : ControlService
{
private readonly CopyMoveTrackWindowViewModel _model = new();

Expand Down Expand Up @@ -76,34 +76,6 @@ public void RunCopyMove()
}
}

private void FixTrackSuffixes(MsuTrackInfoViewModel track)
{
if (_model.Project == null)
{
return;
}

var msu = new FileInfo(_model.Project.MsuPath);

for (var i = 0; i < track.Songs.Count; i++)
{
var songInfo = track.Songs[i];

if (i == 0)
{
songInfo.OutputPath = msu.FullName.Replace(msu.Extension, $"-{track.TrackNumber}.pcm");
}
else
{
var altSuffix = i == 1 ? "alt" : $"alt{i}";
songInfo.OutputPath =
msu.FullName.Replace(msu.Extension, $"-{track.TrackNumber}_{altSuffix}.pcm");
}

songInfo.ApplyCascadingSettings(_model.Project, track, i > 0, _model.PreviousSong?.CanPlaySongs == true, true, true);
}
}

public void UpdateTrackLocations()
{
List<string> locationOptions = [];
Expand All @@ -122,8 +94,6 @@ public void UpdateTrackLocations()
}
}

logger.LogInformation("{Location}", _model.TargetTrack.TrackName);

if (_model.Type != CopyMoveType.Swap)
{
locationOptions.Add("At the end of the list");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public bool OpenFolder()
public void UpdateExportMenuOptions()
{
_model.DisplayAltSwapperExportButton =
_model.CreateAltSwapper && _model.MsuProjectViewModel?.Tracks.Any(x => x.Songs.Count > 1) == true;
_model.CreateAltSwapper && _model.MsuProjectViewModel?.Tracks.Any(x => x is { IsScratchPad: false, Songs.Count: > 1 }) == true;
}

public void Disable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public MsuPcmGenerationViewModel InitializeModel(MsuProjectViewModel project, bo
var msuDirectory = new FileInfo(project.MsuPath).DirectoryName;
if (string.IsNullOrEmpty(msuDirectory)) return _model;

var songs = project.Tracks.SelectMany(x => x.Songs)
var songs = project.Tracks
.Where(x => !x.IsScratchPad)
.SelectMany(x => x.Songs)
.OrderBy(x => x.TrackNumber)
.Select(x => new MsuPcmGenerationSongViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -30,6 +31,8 @@ public class PackageMsuWindowService : ControlService
public PackageMsuWindowViewModel InitializeModel(MsuProjectViewModel project)
{
_model.Project = project;
_model.ValidPcmPaths = project.Tracks.Where(x => !x.IsScratchPad).SelectMany(x => x.Songs)
.Select(x => x.OutputPath).Where(x => !string.IsNullOrEmpty(x)).Cast<string>().ToList();
return _model;
}

Expand Down Expand Up @@ -66,6 +69,12 @@ public void PackageProjectTask(string zipPath)
{
continue;
}

if (string.Equals(Path.GetExtension(file), ".pcm", StringComparison.OrdinalIgnoreCase) &&
!_model.ValidPcmPaths.Contains(file))
{
continue;
}

sb.AppendLine($"... adding {file}");
_model.Response = sb.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async void GenerateTempPcm(PyMusicLooperResultViewModel result)
private async Task<GeneratePcmFileResponse> CreateTempPcm(PyMusicLooperResultViewModel result, bool skipCleanup)
{
var normalization = _model.MsuSongMsuPcmInfoViewModel.Normalization ??
_model.MsuProjectViewModel.BasicInfo.Normalization ?? -25;
_model.MsuProjectViewModel.BasicInfo.Normalization;
return await msuPcmService.CreateTempPcm(false, _model.MsuProject, _model.MsuSongMsuPcmInfoViewModel.GetEffectiveFile()!, result.LoopStart, result.LoopEnd, normalization, skipCleanup: skipCleanup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void RefreshTracks()

_model.Rows.Clear();

foreach (var track in tracks.OrderBy(x => x.TrackNumber))
foreach (var track in tracks.Where(x => !x.IsScratchPad).OrderBy(x => x.TrackNumber))
{
if (!track.Songs.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public VideoCreatorWindowViewModel InitializeModel(MsuProjectViewModel project)
{
_model.PreviousPath = settings.PreviousPath;

_model.PcmPaths = project.Tracks.SelectMany(x => x.Songs)
_model.PcmPaths = project.Tracks.Where(x => !x.IsScratchPad).SelectMany(x => x.Songs)
.Where(x => x.CheckCopyright && File.Exists(x.OutputPath)).Select(x => x.OutputPath).ToList();

if (_model.PcmPaths.Count == 0)
Expand Down
6 changes: 4 additions & 2 deletions MSUScripter/Services/ConverterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ public MsuProjectViewModel ConvertProject(MsuProject project)

foreach (var track in project.Tracks)
{
var msuTypeTrack = project.MsuType.Tracks.First(x => x.Number == track.TrackNumber);
var msuTypeTrack = project.MsuType.Tracks.FirstOrDefault(x => x.Number == track.TrackNumber);

var trackViewModel = new MsuTrackInfoViewModel()
{
Project = viewModel,
Description = msuTypeTrack.Description
Description = track.IsScratchPad
? "Use this page to add songs for keeping and editing without including them in the MSU. All songs included in this will not be included when generating and packaging the MSU."
: msuTypeTrack?.Description
};

ConvertViewModel(track, trackViewModel);
Expand Down
6 changes: 3 additions & 3 deletions MSUScripter/Services/MsuPcmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,13 @@ private bool RunMsuPcmInternal(string innerCommand, string expectedOutputPath, o
Dither = project.BasicInfo.Dither,
Verbosity = 2,
Keep_temps = standAlone && _settings.RunMsuPcmWithKeepTemps,
First_track = project.Tracks.Min(x => x.TrackNumber),
Last_track = project.Tracks.Max(x => x.TrackNumber)
First_track = singleSong?.TrackNumber ?? project.Tracks.Min(x => x.TrackNumber),
Last_track = singleSong?.TrackNumber ?? project.Tracks.Where(x => !x.IsScratchPad).Max(x => x.TrackNumber)
};
var tracks = new List<Track>();

var songs = singleSong == null
? project.Tracks.SelectMany(x => x.Songs).ToList()
? project.Tracks.Where(x => !x.IsScratchPad).SelectMany(x => x.Songs).ToList()
: new List<MsuSongInfo>() { singleSong };

foreach (var song in songs)
Expand Down
47 changes: 36 additions & 11 deletions MSUScripter/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using DynamicData;
using Microsoft.Extensions.Logging;
using MSURandomizerLibrary.Configs;
using MSURandomizerLibrary.Services;
Expand Down Expand Up @@ -122,6 +123,16 @@ public void SaveMsuProject(MsuProject project, bool isBackup)
}
}

if (!project.Tracks.Any(x => x.IsScratchPad))
{
project.Tracks.Add(new MsuTrackInfo()
{
TrackNumber = 9999,
TrackName = "Scratch Pad",
IsScratchPad = true,
});
}

if (project.MsuType == msuTypeService.GetSMZ3LegacyMSUType() || project.MsuType == msuTypeService.GetSMZ3MsuType())
{
project.BasicInfo.IsSmz3Project = true;
Expand Down Expand Up @@ -167,6 +178,13 @@ public MsuProject NewMsuProject(string projectPath, MsuType msuType, string msuP
TrackName = track.Name
});
}

project.Tracks.Add(new MsuTrackInfo()
{
TrackNumber = 9999,
TrackName = "Scratch Pad",
IsScratchPad = true
});

if (!File.Exists(msuPath))
{
Expand Down Expand Up @@ -283,6 +301,12 @@ public void ConvertProjectMsuType(MsuProject project, MsuType newMsuType, bool s
var newTracks = new List<MsuTrackInfo>();
foreach (var oldTrack in project.Tracks)
{
if (oldTrack.IsScratchPad)
{
newTracks.Add(oldTrack);
continue;
}

var newTrackNumber = conversion(oldTrack.TrackNumber);

if (oldTrack.TrackNumber == newTrackNumber)
Expand Down Expand Up @@ -403,6 +427,7 @@ private MsuProject InternalGetSmz3MsuProject(MsuProject project, MsuType msuType
var conversion = msuType.Conversions[project.MsuType];

var trackConversions = project.Tracks
.Where(x => !x.IsScratchPad)
.Select(x => (x.TrackNumber, conversion(x.TrackNumber)))
.Where(x => msuType.ValidTrackNumbers.Contains(x.Item2));

Expand Down Expand Up @@ -689,7 +714,7 @@ public void ExportMsuRandomizerYaml(MsuProject project, out string? error)

var tracks = new List<MSURandomizerLibrary.Configs.Track>();

foreach (var projectTrack in project.Tracks)
foreach (var projectTrack in project.Tracks.Where(x => !x.IsScratchPad))
{
foreach (var projectSong in projectTrack.Songs)
{
Expand Down Expand Up @@ -799,14 +824,14 @@ public bool CreateAltSwapperFile(MsuProject project, ICollection<MsuProject>? ot
{
var sb = new StringBuilder();

var trackCombos = project.Tracks.Where(t => t.Songs.Count > 1)
var trackCombos = project.Tracks.Where(t => t is { IsScratchPad: false, Songs.Count: > 1 })
.Select(t => (t.Songs.First(s => !s.IsAlt), t.Songs.First(s => s.IsAlt))).ToList();

if (otherProjects != null)
{
foreach (var otherProject in otherProjects)
{
trackCombos.AddRange(otherProject.Tracks.Where(t => t.Songs.Count > 1)
trackCombos.AddRange(otherProject.Tracks.Where(t => t is { IsScratchPad: false, Songs.Count: > 1 })
.Select(t => (t.Songs.First(s => !s.IsAlt), t.Songs.First(s => s.IsAlt))));
}
}
Expand Down Expand Up @@ -851,9 +876,9 @@ public bool ValidateProject(MsuProjectViewModel project, out string message)
return false;
}

var projectTracks = project.Tracks.SelectMany(x => x.Songs).ToList();
var projectSongs = project.Tracks.Where(x => !x.IsScratchPad).SelectMany(x => x.Songs).ToList();

var projectTrackNumbers = project.Tracks.SelectMany(x => x.Songs).Select(x => x.TrackNumber).Order().ToList();
var projectTrackNumbers = projectSongs.Select(x => x.TrackNumber).Order().ToList();
var msuTrackNumbers = msu.Tracks.Where(x => !x.IsCopied).Select(x => x.Number).Order().ToList();
if (!projectTrackNumbers.SequenceEqual(msuTrackNumbers))
{
Expand Down Expand Up @@ -885,21 +910,21 @@ public bool ValidateProject(MsuProjectViewModel project, out string message)
return false;
}

foreach (var projectTrack in projectTracks)
foreach (var projectSong in projectSongs)
{
var filename = new FileInfo(projectTrack.OutputPath!).Name;
var filename = new FileInfo(projectSong.OutputPath!).Name;
var msuTrack = msu.Tracks.FirstOrDefault(x => x.Path.EndsWith(filename));

if (msuTrack == null)
{
message = $"Could not find track for song {projectTrack.SongName} in the YAML file.";
message = $"Could not find track for song {projectSong.SongName} in the YAML file.";
statusBarService.UpdateStatusBar("YAML File Validation Failed");
return false;
}
else if ((projectTrack.SongName ?? "") != msuTrack.SongName || (projectTrack.Album ?? "") != (msuTrack.Album ?? "") ||
(projectTrack.Artist ?? "") != (msuTrack.Artist ?? "") || (projectTrack.Url ?? "") != (msuTrack.Url ?? ""))
else if ((projectSong.SongName ?? "") != msuTrack.SongName || (projectSong.Album ?? "") != (msuTrack.Album ?? "") ||
(projectSong.Artist ?? "") != (msuTrack.Artist ?? "") || (projectSong.Url ?? "") != (msuTrack.Url ?? ""))
{
message = $"Detail mismatch for song {projectTrack.SongName} under track #{projectTrack.TrackNumber}.";
message = $"Detail mismatch for song {projectSong.SongName} under track #{projectSong.TrackNumber}.";
statusBarService.UpdateStatusBar("YAML File Validation Failed");
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions MSUScripter/Services/SharedPcmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public async Task<GeneratePcmFileResponse> GeneratePcmFile(MsuSongInfoViewModel
{
return new GeneratePcmFileResponse(false, false, "Currently generating another file", null);
}

if (songInfo.Track.IsScratchPad && songInfo.OutputPath?.StartsWith(Directories.TempFolder) != true)
{
var msuFile = new FileInfo(songInfo.Project.MsuPath);
var pcmFileName = msuFile.Name.Replace(msuFile.Extension, $"-{Guid.NewGuid()}.pcm");
songInfo.OutputPath = Path.Combine(Directories.TempFolder, pcmFileName);
}

await audioPlayerService.StopSongAsync(null, true);

Expand Down
Loading