Skip to content

Commit

Permalink
- Improve event matching and support dumping.
Browse files Browse the repository at this point in the history
- GUI improvments.
- Bug fixes and improvments.
  • Loading branch information
Razmoth committed Nov 3, 2024
1 parent 4c69f05 commit 8c69e69
Show file tree
Hide file tree
Showing 43 changed files with 873 additions and 758 deletions.
16 changes: 8 additions & 8 deletions Audio.CLI/Components/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static RootCommand RegisterOptions()
public record Options
{
public bool Tags { get; set; }
public bool Playlist { get; set; }
public bool Hierarchy { get; set; }
public bool Info { get; set; }
public bool Event { get; set; }
public bool Bank { get; set; }
public bool Audio { get; set; }
public bool Convert { get; set; }
Expand All @@ -36,8 +36,8 @@ public record Options
public class OptionsBinder : BinderBase<Options>
{
private readonly Option<bool> _tags;
private readonly Option<bool> _playlist;
private readonly Option<bool> _hierarchy;
private readonly Option<bool> _info;
private readonly Option<bool> _event;
private readonly Option<bool> _bank;
private readonly Option<bool> _audio;
private readonly Option<bool> _convert;
Expand All @@ -49,8 +49,8 @@ public class OptionsBinder : BinderBase<Options>
public OptionsBinder(RootCommand rootCommand)
{
rootCommand.Add(_tags = new("--tags", "Enable resolving events and matching tags."));
rootCommand.Add(_playlist = new("--playlist", "Enable dumping playlist.xspf."));
rootCommand.Add(_hierarchy = new("--hierarchy", "Enable dumping hierarchy structures as json files."));
rootCommand.Add(_info = new("--info", "Enable dumping structures as json files."));
rootCommand.Add(_event = new("--event", "Enable dumping events as json file."));
rootCommand.Add(_bank = new("--bank", "Enable dumping raw bank files."));
rootCommand.Add(_audio = new("--audio", "Enable dumping audio files."));
rootCommand.Add(_convert = new("--convert", "Enable conversion while dumping audio files."));
Expand All @@ -63,8 +63,8 @@ public OptionsBinder(RootCommand rootCommand)
protected override Options GetBoundValue(BindingContext bindingContext) => new()
{
Tags = bindingContext.ParseResult.GetValueForOption(_tags),
Playlist = bindingContext.ParseResult.GetValueForOption(_playlist),
Hierarchy = bindingContext.ParseResult.GetValueForOption(_hierarchy),
Info = bindingContext.ParseResult.GetValueForOption(_info),
Event = bindingContext.ParseResult.GetValueForOption(_event),
Bank = bindingContext.ParseResult.GetValueForOption(_bank),
Audio = bindingContext.ParseResult.GetValueForOption(_audio),
Convert = bindingContext.ParseResult.GetValueForOption(_convert),
Expand Down
11 changes: 8 additions & 3 deletions Audio.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Run(Options o)
{
Logger.TryRegister(new ConsoleLogger());

AudioManager manager = new() { Convert = o.Convert, Playlist = o.Playlist };
AudioManager manager = new() { Convert = o.Convert };

List<string> files = [];
if (Directory.Exists(o.Input))
Expand Down Expand Up @@ -44,9 +44,14 @@ public static void Run(Options o)
{
o.Output.Create();

if (o.Hierarchy)
if (o.Info && Directory.Exists(o.Input))
{
manager.DumpHierarchies(o.Output.FullName);
manager.DumpInfos(o.Input, o.Output.FullName);
}

if (o.Event)
{
manager.DumpEvents(o.Output.FullName);
}

if (o.Bank || o.Audio)
Expand Down
49 changes: 25 additions & 24 deletions Audio.GUI.Desktop/Audio.GUI.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
One for Windows with net8.0-windows TFM, one for MacOS with net8.0-macos and one with net8.0 TFM for Linux.-->
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand All @@ -14,33 +15,33 @@
</ItemGroup>

<ItemGroup Condition="$(RuntimeIdentifier.StartsWith('win'))">
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />

<VlcWindowsX64IncludeFiles Include="libvlc.dll" />
<VlcWindowsX64IncludeFiles Include="libvlccore.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\access\libimem_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_filter\libaudio_format_plugin.dll" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.21" />
<VlcWindowsX64IncludeFiles Include="libvlc.dll" />
<VlcWindowsX64IncludeFiles Include="libvlccore.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\access\libimem_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_filter\libaudio_format_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_filter\libugly_resampler_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_filter\libtrivial_channel_mixer_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_output\libmmdevice_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_output\libwasapi_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\codec\libadpcm_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\codec\libavcodec_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\codec\liboggspots_plugin.dll" />

<VlcWindowsX86IncludeFiles Include="libvlc.dll" />
<VlcWindowsX86IncludeFiles Include="libvlccore.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\access\libimem_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_filter\libaudio_format_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_filter\libtrivial_channel_mixer_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_output\libmmdevice_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\audio_output\libwasapi_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\codec\libadpcm_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\codec\libavcodec_plugin.dll" />
<VlcWindowsX64IncludeFiles Include="plugins\codec\liboggspots_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="libvlc.dll" />
<VlcWindowsX86IncludeFiles Include="libvlccore.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\access\libimem_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_filter\libaudio_format_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_filter\libugly_resampler_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_filter\libtrivial_channel_mixer_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_output\libmmdevice_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_output\libwasapi_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\codec\libadpcm_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\codec\libavcodec_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\codec\liboggspots_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_filter\libtrivial_channel_mixer_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_output\libmmdevice_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\audio_output\libwasapi_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\codec\libadpcm_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\codec\libavcodec_plugin.dll" />
<VlcWindowsX86IncludeFiles Include="plugins\codec\liboggspots_plugin.dll" />
</ItemGroup>

<ItemGroup Condition="$(RuntimeIdentifier.Contains('osx'))">
<PackageReference Include="VideoLAN.LibVLC.Mac" Version="3.1.3.1" />
</ItemGroup>
Expand Down
38 changes: 17 additions & 21 deletions Audio.GUI/Models/EntryTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Audio.Entries;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Audio.GUI.Models;
Expand All @@ -9,6 +9,9 @@ public partial class EntryTreeNode : TreeNode
[ObservableProperty]
private Entry entry;

[ObservableProperty]
private EventInfo? eventInfo;

public EntryTreeNode(Entry entry)
{
this.entry = entry;
Expand All @@ -24,32 +27,25 @@ public override bool HasMatch(string? searchText)
Regex regex = new(searchText, RegexOptions.IgnoreCase);

bool match = base.HasMatch(searchText);
if (Entry is TaggedEntry<uint> uintTag)
match |= regex.IsMatch(Entry.ID.ToString());
match |= regex.IsMatch(Entry.Type.ToString());
match |= regex.IsMatch(Entry.Location ?? "");
match |= regex.IsMatch(Entry.Source ?? "");
match |= regex.IsMatch(Entry.Offset.ToString());
match |= regex.IsMatch(Entry.Size.ToString());

if (EventInfo != null)
{
match |= regex.IsMatch(uintTag.ID.ToString());
if (uintTag.Events.Count > 0)
match |= regex.IsMatch(EventInfo.ID.ToString());
foreach (IGrouping<FNVID<uint>, EventTag> group in EventInfo.GetGroupsByID((uint)Entry.ID))
{
foreach (KeyValuePair<FNVID<uint>, HashSet<EventTag>> evt in uintTag.Events)
match |= regex.IsMatch(group.Key.ToString());
foreach (EventTag tag in group)
{
match |= regex.IsMatch(evt.Key.ToString());
foreach (EventTag tag in evt.Value)
{
match |= regex.IsMatch(tag.Type.ToString());
match |= regex.IsMatch(tag.Value.ToString());
}
match |= regex.IsMatch(tag.Value.ToString());
}
}
}
else if (Entry is TaggedEntry<ulong> ulongTag)
{
match |= regex.IsMatch(ulongTag.ID.ToString());
}

match |= regex.IsMatch(Entry.Type.ToString());
match |= regex.IsMatch(Entry.Location ?? "");
match |= regex.IsMatch(Entry.Source);
match |= regex.IsMatch(Entry.Offset.ToString());
match |= regex.IsMatch(Entry.Size.ToString());

return match;
}
Expand Down
3 changes: 1 addition & 2 deletions Audio.GUI/Models/TreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;

namespace Audio.GUI.Models;
Expand All @@ -16,7 +15,7 @@ public partial class TreeNode : ObservableObject
private string name = "";

[ObservableProperty]
private ObservableCollection<TreeNode> nodes = [];
private List<TreeNode> nodes = [];

public IEnumerable<TreeNode> Checked
{
Expand Down
39 changes: 22 additions & 17 deletions Audio.GUI/ViewModels/EntryViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Audio.Entries;
using Audio.GUI.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -9,46 +9,51 @@ namespace Audio.GUI.ViewModels;

public partial class EntryViewModel : ViewModelBase
{
private readonly AudioManager _audioManager;
private readonly PlayerViewModel _playerViewModel;

[ObservableProperty]
private string infoText = "";

[ObservableProperty]
private Entry? entry;
private EntryTreeNode? entry;

public PlayerViewModel PlayerViewModel => _playerViewModel;

public EntryViewModel()
public EntryViewModel(AudioManager audioManager)
{
_audioManager = audioManager;
_playerViewModel = new();
}
partial void OnEntryChanged(Entry? value)
partial void OnEntryChanged(EntryTreeNode? value)
{
if (value != null)
{
StringBuilder sb = new();
sb.AppendLine($"Name: {value.Name}");
sb.AppendLine($"Type: {value.Type}");
sb.AppendLine($"Offset: {value.Offset}");
sb.AppendLine($"Size: {value.Size}");
sb.AppendLine($"Location: {value.Location}");
sb.AppendLine($"Source: {value.Source}");
if (value is TaggedEntry<uint> taggedEntry && taggedEntry.Events.Count > 0)
sb.AppendLine($"Name: {value.Entry.Name}");
sb.AppendLine($"Type: {value.Entry.Type}");
sb.AppendLine($"Offset: {value.Entry.Offset}");
sb.AppendLine($"Size: {value.Entry.Size}");
sb.AppendLine($"Location: {value.Entry.Location}");
sb.AppendLine($"Source: {value.Entry.Source}");
if (value.EventInfo != null && value.EventInfo.Groups.Any(x => x.Key.Count > 0))
{
sb.AppendLine($"Events: ");
foreach(KeyValuePair<FNVID<uint>, HashSet<EventTag>> evt in taggedEntry.Events)
sb.AppendLine($"Tags: ");
foreach (IGrouping<FNVID<uint>, EventTag> group in value.EventInfo.GetGroupsByID((uint)value.Entry.ID))
{
sb.AppendLine($"\t{evt.Key}:");
foreach(IGrouping<FNVID<uint>, EventTag> group in evt.Value.GroupBy(x => x.Type))
sb.AppendLine($"\t{group.Key}:");
foreach(EventTag tag in group)
{
sb.AppendLine($"\t\t{group.Key}: [{string.Join(',', group.Select(x => x.Value))}]");
sb.AppendLine($"\t\t{tag.Value}");
}
}
}

InfoText = sb.ToString();
Task.Run(() => _playerViewModel.LoadAudio(value));
if (value.Entry is AudioEntry audioEntry)
{
Task.Run(() => _playerViewModel.LoadAudio(audioEntry));
}
}
}
}
16 changes: 10 additions & 6 deletions Audio.GUI/ViewModels/LogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
Expand All @@ -10,12 +12,13 @@ namespace Audio.GUI.ViewModels;

public partial class LogViewModel : ViewModelBase, ILogger, IDisposable
{
private bool _scrolling = false;
private readonly object _logLock = new();

[ObservableProperty]
private bool isScrolling;
[ObservableProperty]
private ObservableCollection<string> logs = [];


public LogViewModel()
{
Logger.TryRegister(this);
Expand All @@ -29,16 +32,17 @@ public void Clear()
[RelayCommand]
public async Task ScrollToEnd(ScrollChangedEventArgs e)
{
if (!_scrolling && e.Source is ScrollViewer scrollViewer && e.ExtentDelta != Avalonia.Vector.Zero)
if (!IsScrolling && e.Source is ScrollViewer scrollViewer && e.ExtentDelta != Avalonia.Vector.Zero)
{
_scrolling = true;
await Dispatcher.UIThread.InvokeAsync(scrollViewer.ScrollToEnd);
_scrolling = false;
}
}
public void Log(LogLevel logLevel, string message)
{
Logs.Add($"[{logLevel}]: {message}");
lock (_logLock)
{
Logs.Add($"[{logLevel}]: {message}");
}
}
public void Dispose()
{
Expand Down
Loading

0 comments on commit 8c69e69

Please sign in to comment.