Skip to content

Commit

Permalink
Soundfont manager usability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
khang06 committed Feb 27, 2025
1 parent 9756390 commit 02b6605
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
13 changes: 12 additions & 1 deletion OmniConverter/Extensions/SoundFonts.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Avalonia.Platform.Storage;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;

namespace OmniConverter
{
public class SoundFont
public class SoundFont : INotifyPropertyChanged
{
[JsonProperty("Path")]
public string SoundFontPath { get; private set; }
Expand Down Expand Up @@ -46,6 +47,8 @@ public class SoundFont
[JsonProperty]
public bool NoRampIn { get; private set; }

public string SoundFontDisplayName => $"{(Enabled ? "" : "[OFF] ")}{SoundFontPath}";

public SoundFont()
{
SoundFontPath = string.Empty;
Expand All @@ -70,6 +73,9 @@ public SoundFont(string SFP, short SP, short SB, short DP, short DB, short DBLSB
SetPresetSettings(SP, SB, DP, DB, DBLSB, E);
}

public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

public void ChangePath(string SFP)
{
SoundFontPath = SFP;
Expand All @@ -78,12 +84,17 @@ public void ChangePath(string SFP)

public void SetPresetSettings(short SP, short SB, short DP, short DB, short DBLSB, bool E)
{
bool enabledChanged = Enabled != E;

SourcePreset = (IsSFZ() && SP < 0) ? (short)0: SP;
SourceBank = (IsSFZ() && SB < 0) ? (short)0 : SB;
DestinationPreset = (IsSFZ() && DP < 0) ? (short)0 : DP;
DestinationBank = DB;
DestinationBankLSB = DBLSB;
Enabled = E;

if (enabledChanged)
OnPropertyChanged("SoundFontDisplayName");
}

public void SetGenSettings(bool XGM, bool LAM, bool LDV, bool MF, bool SL, bool NRI)
Expand Down
29 changes: 14 additions & 15 deletions OmniConverter/Forms/SoundFontsManager.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,51 @@
<ListBox Name="SoundFontListView" SelectionMode="Multiple" Grid.Column="0" DragDrop.AllowDrop="True" SelectionChanged="SelectedSFChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="SoundFontTemplate" x:DataType="oc:SoundFont" Text="{Binding SoundFontPath}"/>
<TextBlock Name="SoundFontTemplate" x:DataType="oc:SoundFont" Text="{Binding SoundFontDisplayName}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ctrl:GroupBox Grid.Column="1" Header="Settings" Theme="{StaticResource GroupBoxClassic}" Margin="10, 0, 0, 0">
<Panel>
<StackPanel Name="SettingsArea">
<StackPanel Name="SettingsArea" IsEnabled="false">
<StackPanel Margin="4">
<Label Content="SOURCE" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<Grid ColumnDefinitions="1*, 2*">
<Label Grid.Column="0" Content="Preset:" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<NumericUpDown Name="SourcePreset" Grid.Column="1" Value="-1" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" />
<NumericUpDown Name="SourcePreset" Grid.Column="1" Value="-1" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" ValueChanged="PresetSettingChanged" />
</Grid>
<Grid ColumnDefinitions="1*, 2*">
<Label Grid.Column="0" Content="Bank:" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<NumericUpDown Name="SourceBank" Grid.Column="1" Value="-1" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" />
<NumericUpDown Name="SourceBank" Grid.Column="1" Value="-1" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" ValueChanged="PresetSettingChanged" />
</Grid>
</StackPanel>
<StackPanel Margin="4">
<Label Content="DESTINATION" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<Grid ColumnDefinitions="1*, 2*">
<Label Grid.Column="0" Content="Bank:" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<NumericUpDown Name="DestinationBank" Grid.Column="1" Value="0" Minimum="0" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" />
<NumericUpDown Name="DestinationBank" Grid.Column="1" Value="0" Minimum="0" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" ValueChanged="PresetSettingChanged" />
</Grid>
<Grid ColumnDefinitions="1*, 2*">
<Label Grid.Column="0" Content="LSB:" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<NumericUpDown Name="DestinationBankLSB" Grid.Column="1" Value="0" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" />
<NumericUpDown Name="DestinationBankLSB" Grid.Column="1" Value="0" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" ValueChanged="PresetSettingChanged" />
</Grid>
<Grid ColumnDefinitions="1*, 2*">
<Label Grid.Column="0" Content="Preset:" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontWeight="Bold"/>
<NumericUpDown Name="DestinationPreset" Grid.Column="1" Value="-1" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" />
<NumericUpDown Name="DestinationPreset" Grid.Column="1" Value="-1" Minimum="-1" Maximum="127" HorizontalContentAlignment="Center" FormatString="0" ValueChanged="PresetSettingChanged" />
</Grid>
</StackPanel>
<StackPanel Margin="4">
<Label Content="ADDITIONAL SET." HorizontalContentAlignment="Center" FontWeight="Bold" Padding="4, 4, 4, 8"/>
<CheckBox Name="XGDrums" Content="Load XG bank first" HorizontalAlignment="Left" />
<CheckBox Name="LinAttMod" Content="Use linear attack" HorizontalAlignment="Left" />
<CheckBox Name="LinDecVol" Content="Use linear decay/release" HorizontalAlignment="Left" />
<CheckBox Name="MinFx" Content="Treat reverb/chorus val. as min." HorizontalAlignment="Left" />
<CheckBox Name="EnforceSBLimits" Content="Enforce SoundBlaster gen. limits" HorizontalAlignment="Left" />
<CheckBox Name="NoRampIn" Content="Do not ramp-in start of samples" HorizontalAlignment="Left" />
<CheckBox Name="XGDrums" Content="Load XG bank first" HorizontalAlignment="Left" Click="GenSettingChanged" />
<CheckBox Name="LinAttMod" Content="Use linear attack" HorizontalAlignment="Left" Click="GenSettingChanged" />
<CheckBox Name="LinDecVol" Content="Use linear decay/release" HorizontalAlignment="Left" Click="GenSettingChanged" />
<CheckBox Name="MinFx" Content="Treat reverb/chorus val. as min." HorizontalAlignment="Left" Click="GenSettingChanged" />
<CheckBox Name="EnforceSBLimits" Content="Enforce SoundBlaster gen. limits" HorizontalAlignment="Left" Click="GenSettingChanged" />
<CheckBox Name="NoRampIn" Content="Do not ramp-in start of samples" HorizontalAlignment="Left" Click="GenSettingChanged" />
</StackPanel>
</StackPanel>
<StackPanel VerticalAlignment="Bottom">
<CheckBox Name="Enabled" Content="Enabled" HorizontalAlignment="Center" />
<Button Name="ApplySFSettings" Content="Apply SF settings" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Margin="4" Click="ApplySoundFontSettings" />
<CheckBox Name="Enabled" Content="Enabled" HorizontalAlignment="Center" Click="PresetSettingChanged" IsEnabled="false" />
</StackPanel>
</Panel>
</ctrl:GroupBox>
Expand Down
40 changes: 33 additions & 7 deletions OmniConverter/Forms/SoundFontsManager.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public void SelectedSFChanged(object? sender, SelectionChangedEventArgs e)
DestinationBank.Value = item.DestinationBank;
DestinationBankLSB.Value = item.DestinationBankLSB;
DestinationPreset.Value = item.DestinationPreset;

SettingsArea.IsEnabled = true;
Enabled.IsEnabled = true;
return;
}

Expand All @@ -138,9 +141,22 @@ public void SelectedSFChanged(object? sender, SelectionChangedEventArgs e)
DestinationBank.Value = 0;
DestinationBankLSB.Value = 0;
DestinationPreset.Value = -1;

SettingsArea.IsEnabled = false;
Enabled.IsEnabled = false;
}

private void PresetSettingChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
PresetSettingChanged();
}

private void ApplySoundFontSettings(object? sender, RoutedEventArgs e)
private void PresetSettingChanged(object? sender, RoutedEventArgs e)
{
PresetSettingChanged();
}

private void PresetSettingChanged()
{
int index = SoundFontListView.SelectedIndex;

Expand All @@ -152,16 +168,26 @@ private void ApplySoundFontSettings(object? sender, RoutedEventArgs e)
(short)SourcePreset.Value, (short)SourceBank.Value,
(short)DestinationPreset.Value, (short)DestinationBank.Value, (short)DestinationBankLSB.Value,
(bool)Enabled.IsChecked);
}

RefreshList();
}

private void GenSettingChanged(object? sender, RoutedEventArgs e)
{
int index = SoundFontListView.SelectedIndex;

if (index != -1)
{
var item = (SoundFont)SoundFontListView.Items[index];

item.SetGenSettings(
(bool)XGDrums.IsChecked,
(bool)XGDrums.IsChecked,
(bool)LinAttMod.IsChecked,
(bool)LinDecVol.IsChecked,
(bool)MinFx.IsChecked,
(bool)EnforceSBLimits.IsChecked,
(bool)LinDecVol.IsChecked,
(bool)MinFx.IsChecked,
(bool)EnforceSBLimits.IsChecked,
(bool)NoRampIn.IsChecked);

return;
}

RefreshList();
Expand Down

0 comments on commit 02b6605

Please sign in to comment.