Skip to content

Commit

Permalink
Add soundbank audio parameter utility
Browse files Browse the repository at this point in the history
  • Loading branch information
segabl committed Aug 5, 2023
1 parent b4f3ba5 commit b66b2e9
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 169 deletions.
26 changes: 13 additions & 13 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Application x:Class="PD2SoundBankEditor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PD2SoundBankEditor"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
Startup="ApplicationStartup">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Dark.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PD2SoundBankEditor"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
Startup="ApplicationStartup">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Dark.xaml"/>
<ResourceDictionary Source="pack://application:,,,/AdonisUI.ClassicTheme;component/Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
8 changes: 2 additions & 6 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly
)]
Binary file added Icon.ico
Binary file not shown.
186 changes: 92 additions & 94 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,99 +1,97 @@
<adonisControls:AdonisWindow x:Class="PD2SoundBankEditor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
Closed="OnWindowClosed"
Title="PD2 Soundbank Editor"
Height="360"
Width="640">
<Window.Style>
<Style TargetType="Window" BasedOn="{StaticResource {x:Type Window}}"/>
</Window.Style>
<Window.CommandBindings>
<CommandBinding Command="Save" CanExecute="CommandSaveCanExecute" Executed="CommandSaveExecuted" />
<CommandBinding Command="SaveAs" CanExecute="CommandSaveAsCanExecute" Executed="CommandSaveAsExecuted" />
</Window.CommandBindings>
<Grid>
<Grid Name="mainGrid" Margin="8,0,8,32">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
Closed="OnWindowClosed"
Title="PD2 Soundbank Editor"
Height="480"
Width="720">
<Window.Style>
<Style TargetType="Window" BasedOn="{StaticResource {x:Type Window}}"/>
</Window.Style>
<Window.CommandBindings>
<CommandBinding Command="Save" CanExecute="CommandSaveCanExecute" Executed="CommandSaveExecuted" />
<CommandBinding Command="SaveAs" CanExecute="CommandSaveAsCanExecute" Executed="CommandSaveAsExecuted" />
</Window.CommandBindings>
<Grid>
<Grid Name="mainGrid" Margin="8,0,8,32">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Menu IsMainMenu="True" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,0,8" HorizontalAlignment="Stretch">
<MenuItem Header="_File">
<MenuItem Header="_Open..." Click="OnOpenButtonClick"/>
<Separator />
<MenuItem Header="_Save" Command="Save"/>
<MenuItem Header="Save _as..." Command="SaveAs"/>
<Separator />
<MenuItem Header="Recent _files" Name="recentFilesList">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="{Binding}"/>
<EventSetter Event="Click" Handler="OnRecentFileClick"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<Separator />
<MenuItem Header="_Exit" Click="OnExitButtonClick"/>
</MenuItem>
<MenuItem Header="_Tools">
<MenuItem Header="_Convert loose files..." Click="OnConvertLooseFilesClick"/>
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="_Hide unreferenced files" IsCheckable="True" IsChecked="{Binding HideUnreferencedEnabled, Mode=TwoWay}" Checked="OnFilterChanged" Unchecked="OnFilterChanged"/>
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_Suppress playback errors" IsCheckable="True" IsChecked="{Binding SuppressErrorsEnabled, Mode=TwoWay}"/>
<MenuItem Header="Check for _updates on startup" IsCheckable="True" IsChecked="{Binding UpdateCheckEnabled, Mode=TwoWay}"/>
<Separator />
<MenuItem Header="_About..." Click="OnAboutButtonClick"/>
</MenuItem>
</Menu>
<Menu IsMainMenu="True" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="0,0,0,8" HorizontalAlignment="Stretch">
<MenuItem Header="_File">
<MenuItem Header="_Open..." Click="OnOpenButtonClick"/>
<Separator />
<MenuItem Header="_Save" Command="Save"/>
<MenuItem Header="Save _as..." Command="SaveAs"/>
<Separator />
<MenuItem Header="Recent _files" Name="recentFilesList">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="{Binding}"/>
<EventSetter Event="Click" Handler="OnRecentFileClick"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<Separator />
<MenuItem Header="_Exit" Click="OnExitButtonClick"/>
</MenuItem>
<MenuItem Header="_Tools">
<MenuItem Header="_Convert loose files..." Click="OnConvertLooseFilesClick"/>
<MenuItem Name="setAudioPropertiedMenuItem" Header="_Set audio properties..." Click="OnSetAudioPropertiesClick" IsEnabled="False"/>
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="_Hide unreferenced files" IsCheckable="True" IsChecked="{Binding HideUnreferencedEnabled, Mode=TwoWay}" Checked="OnFilterChanged" Unchecked="OnFilterChanged"/>
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_Suppress playback errors" IsCheckable="True" IsChecked="{Binding SuppressErrorsEnabled, Mode=TwoWay}"/>
<MenuItem Header="Check for _updates on startup" IsCheckable="True" IsChecked="{Binding UpdateCheckEnabled, Mode=TwoWay}"/>
<Separator />
<MenuItem Header="_About..." Click="OnAboutButtonClick"/>
</MenuItem>
</Menu>

<DataGrid Name="dataGrid" AutoGenerateColumns="False" Grid.Column="0" Grid.Row="1" SelectionChanged="OnDataGridSelectionChanged" HorizontalScrollBarVisibility="Disabled">
<DataGrid.Columns>
<DataGridTemplateColumn SortMemberPath="Offset" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="" Click="OnPlayButtonClick" Width="20" Height="20" Padding="0,0,0,0"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="ID" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Size" Binding="{Binding Size, StringFormat={}{0:0.0} KB}" IsReadOnly="True"/>
<DataGridTextColumn Width="*" Header="Note" Binding="{Binding Note}" IsReadOnly="False"/>
<DataGridTextColumn Width="*" Header="Replacement" Binding="{Binding ReplacementFile}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="8,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Name="extractAllButton" Content="Extract all" Click="OnExtractButtonClick" IsEnabled="False" Height="24"/>
<Button Grid.Row="1" Name="extractSelectedButton" Content="Extract selected" Click="OnExtractButtonClick" IsEnabled="False" Height="24"/>
<Button Grid.Row="2" Name="replaceSelectedButton" Content="Replace selected..." Click="OnReplaceButtonClick" IsEnabled="False" Height="24" Margin="0,8,0,0"/>
<Button Grid.Row="3" Name="replaceByNamesButton" Content="Replace by ID..." Click="OnReplaceByNamesButtonClick" IsEnabled="False" Height="24" Margin="0,0,0,0"/>
<TextBox Grid.Row="5" Name="filterTextBox" adonisExtensions:WatermarkExtension.Watermark="Filter" TextChanged="OnFilterChanged" Height="24"/>
</Grid>
</Grid>
<ProgressBar Name="progressBar" Margin="8,8,8,8" VerticalAlignment="Bottom" Height="16"/>
</Grid>
<DataGrid Name="dataGrid" AutoGenerateColumns="False" Grid.Column="0" Grid.Row="1" SelectionChanged="OnDataGridSelectionChanged" HorizontalScrollBarVisibility="Disabled">
<DataGrid.Columns>
<DataGridTemplateColumn SortMemberPath="Offset" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="" Click="OnPlayButtonClick" Width="20" Height="20" Padding="0,0,0,0"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="ID" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Size" Binding="{Binding Size, StringFormat={}{0:0.0} KB}" IsReadOnly="True"/>
<DataGridTextColumn Width="*" Header="Note" Binding="{Binding Note}" IsReadOnly="False"/>
<DataGridTextColumn Width="*" Header="Replacement" Binding="{Binding ReplacementFile}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>

<Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="8,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Name="extractAllButton" Content="Extract all" Click="OnExtractButtonClick" IsEnabled="False" Height="24"/>
<Button Grid.Row="1" Name="extractSelectedButton" Content="Extract selected" Click="OnExtractButtonClick" IsEnabled="False" Height="24"/>
<Button Grid.Row="2" Name="replaceSelectedButton" Content="Replace selected..." Click="OnReplaceButtonClick" IsEnabled="False" Height="24" Margin="0,8,0,0"/>
<Button Grid.Row="3" Name="replaceByNamesButton" Content="Replace by ID..." Click="OnReplaceByNamesButtonClick" IsEnabled="False" Height="24" Margin="0,0,0,0"/>
<TextBox Grid.Row="5" Name="filterTextBox" adonisExtensions:WatermarkExtension.Watermark="Filter" TextChanged="OnFilterChanged" Height="24"/>
</Grid>
</Grid>
<ProgressBar Name="progressBar" Margin="8,8,8,8" VerticalAlignment="Bottom" Height="16"/>
</Grid>
</adonisControls:AdonisWindow>
25 changes: 15 additions & 10 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
using MessageBoxResult = AdonisUI.Controls.MessageBoxResult;

namespace PD2SoundBankEditor {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : AdonisWindow {
static readonly string CONVERTER_NAME = "wwise_ima_adpcm.exe";
static readonly string CONVERTER_PATH = Path.Join(AppDomain.CurrentDomain.BaseDirectory, CONVERTER_NAME);
Expand Down Expand Up @@ -122,7 +119,7 @@ private void CommandSaveCanExecute(object sender, System.Windows.Input.CanExecut

private void CommandSaveExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) {
soundBank.Save(soundBank.FilePath);
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}";
UpdateWindowTitle();
}
private void CommandSaveAsCanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) {
e.CanExecute = soundBank != null;
Expand All @@ -138,7 +135,7 @@ private void CommandSaveAsExecuted(object sender, System.Windows.Input.ExecutedR
return;
}
soundBank.Save(diag.FileName);
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}";
UpdateWindowTitle();
}

private void OnOpenButtonClick(object sender, RoutedEventArgs e) {
Expand Down Expand Up @@ -193,7 +190,7 @@ private void OnReplaceButtonClick(object sender, RoutedEventArgs e) {
}
}
soundBank.IsDirty = true;
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}*";
UpdateWindowTitle();
}

private void OnReplaceByNamesButtonClick(object sender, RoutedEventArgs e) {
Expand Down Expand Up @@ -325,6 +322,11 @@ private void OnConvertLooseFilesClick(object sender, RoutedEventArgs e) {
DoGenericProcessing(true, ConvertLooseFiles, OnConvertLooseFilesFinished, diag.FileNames);
}

private void OnSetAudioPropertiesClick(object sender, RoutedEventArgs e) {
var paramsWindow = new ParamsWindow(soundBank) { Owner = this };
paramsWindow.ShowDialog();
}

private void OnDataGridSelectionChanged(object sender, SelectionChangedEventArgs e) {
replaceSelectedButton.IsEnabled = converterAvailable && dataGrid.SelectedItems.Count > 0;
extractSelectedButton.IsEnabled = converterAvailable && dataGrid.SelectedItems.Count > 0;
Expand Down Expand Up @@ -419,16 +421,21 @@ public void OnSoundBankLoaded(object sender, RunWorkerCompletedEventArgs e) {
recentFilesList.ItemsSource = null; //too lazy for proper notify
recentFilesList.ItemsSource = appSettings.recentlyOpenedFiles;

Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}";
UpdateWindowTitle();

extractAllButton.IsEnabled = converterAvailable && soundBank.StreamInfos.Count > 0;
replaceByNamesButton.IsEnabled = converterAvailable && soundBank.StreamInfos.Count > 0;
setAudioPropertiedMenuItem.IsEnabled = ((HircSection)soundBank.Sections.Find(x => x.Name == "HIRC"))?.SoundObjects.Count > 0;

if (!soundBank.StreamInfos.Any(info => info.HasReferences)) {
MessageBox.Show($"This soundbank does not contain any referenced embedded streams. Unreferenced embedded data is usually garbage data.", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}

public void UpdateWindowTitle() {
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}{(soundBank.IsDirty ? "*" : "")}";
}

private void ExtractStreams(object sender, DoWorkEventArgs e) {
var streamDescriptions = (IEnumerable<StreamInfo>)e.Argument;
var soundBankName = soundBank.FilePath;
Expand Down Expand Up @@ -499,9 +506,7 @@ void OnReplaceStreamsFinished(object sender, RunWorkerCompletedEventArgs e) {
} else {
MessageBox.Show($"Sound replacement finished successfully!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
}
if (soundBank.IsDirty) {
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}*";
}
UpdateWindowTitle();
}

private void ConvertLooseFiles(object sender, DoWorkEventArgs e) {
Expand Down
16 changes: 7 additions & 9 deletions PD2SoundBankEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
<UseWPF>true</UseWPF>
<StartupObject></StartupObject>
<AssemblyName>PD2SoundBankEditor</AssemblyName>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
<RollForward>Major</RollForward>
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<Compile Remove="SoundBank\Sections\HircObjects\HierarchyObject.cs\**" />
<EmbeddedResource Remove="SoundBank\Sections\HircObjects\HierarchyObject.cs\**" />
<None Remove="SoundBank\Sections\HircObjects\HierarchyObject.cs\**" />
<Page Remove="SoundBank\Sections\HircObjects\HierarchyObject.cs\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AdonisUI.ClassicTheme" Version="1.17.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<Content Include="Icon.ico">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<PackageReference Include="AdonisUI.ClassicTheme" Version="1.17.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
Loading

0 comments on commit b66b2e9

Please sign in to comment.