Add new settings

- Play data tracks like audio
- Generate missing TOC
This commit is contained in:
Matt Nadareski
2021-06-06 21:34:33 -07:00
parent 8316c6982f
commit e79b5719ca
3 changed files with 74 additions and 30 deletions

View File

@@ -6,18 +6,55 @@ namespace RedBookPlayer
{
public class Settings
{
string filePath;
/// <summary>
/// Indicates if discs should start playing on load
/// </summary>
public bool AutoPlay { get; set; } = false;
/// <summary>
/// Indicates if an index change can trigger a track change
/// </summary>
public bool IndexButtonChangeTrack { get; set; } = false;
/// <summary>
/// Indicates if the index 0 of track 1 is treated like a hidden track
/// </summary>
public bool AllowSkipHiddenTrack { get; set; } = false;
/// <summary>
/// Indicates if data tracks should be played like old, non-compliant players
/// </summary>
public bool PlayDataTracks { get; set; } = false;
/// <summary>
/// Generate a TOC if the disc is missing one
/// </summary>
public bool GenerateMissingTOC { get; set; } = true;
/// <summary>
/// Indicates the default playback volume
/// </summary>
public int Volume { get; set; } = 100;
/// <summary>
/// Indicates the currently selected theme
/// </summary>
public string SelectedTheme { get; set; } = "default";
/// <summary>
/// Path to the settings file
/// </summary>
private string _filePath;
public Settings() {}
public Settings(string filePath) => this.filePath = filePath;
public bool AutoPlay { get; set; }
public bool IndexButtonChangeTrack { get; set; }
public bool AllowSkipHiddenTrack { get; set; }
public int Volume { get; set; } = 100;
public string SelectedTheme { get; set; } = "default";
public Settings(string filePath) => _filePath = filePath;
/// <summary>
/// Load settings from a file
/// </summary>
/// <param name="filePath">Path to the settings JSON file</param>
/// <returns>Settings derived from the input file, if possible</returns>
public static Settings Load(string filePath)
{
if(File.Exists(filePath))
@@ -25,7 +62,7 @@ namespace RedBookPlayer
try
{
Settings settings = JsonSerializer.Deserialize<Settings>(File.ReadAllText(filePath));
settings.filePath = filePath;
settings._filePath = filePath;
MainWindow.ApplyTheme(settings.SelectedTheme);
@@ -42,6 +79,9 @@ namespace RedBookPlayer
return new Settings(filePath);
}
/// <summary>
/// Save settings to a file
/// </summary>
public void Save()
{
var options = new JsonSerializerOptions
@@ -50,7 +90,7 @@ namespace RedBookPlayer
};
string json = JsonSerializer.Serialize(this, options);
File.WriteAllText(filePath, json);
File.WriteAllText(_filePath, json);
}
}
}

View File

@@ -17,6 +17,14 @@
<CheckBox IsChecked="{Binding AllowSkipHiddenTrack}" Margin="0,0,8,0" />
<TextBlock VerticalAlignment="Center">Treat index 0 of track 1 as track 0 (hidden track)</TextBlock>
</WrapPanel>
<WrapPanel Margin="0,0,0,16">
<CheckBox IsChecked="{Binding PlayDataTracks}" Margin="0,0,8,0"/>
<TextBlock VerticalAlignment="Center">Play data tracks like old, non-compliant players</TextBlock>
</WrapPanel>
<WrapPanel Margin="0,0,0,16">
<CheckBox IsChecked="{Binding GenerateMissingTOC}" Margin="0,0,8,0"/>
<TextBlock VerticalAlignment="Center">Generate a TOC if the disc is missing one</TextBlock>
</WrapPanel>
<DockPanel Margin="0,0,0,16">
<TextBlock VerticalAlignment="Center" Margin="0,0,8,0" DockPanel.Dock="Left">Volume</TextBlock>
<TextBlock VerticalAlignment="Center" DockPanel.Dock="Right" Text="%" />

View File

@@ -8,49 +8,47 @@ namespace RedBookPlayer
{
public class SettingsWindow : Window
{
readonly Settings settings;
string selectedTheme;
ListBox themeList;
private readonly Settings _settings;
private string _selectedTheme;
private ListBox _themeList;
public SettingsWindow() {}
public SettingsWindow(Settings settings)
{
DataContext = this.settings = settings;
DataContext = _settings = settings;
InitializeComponent();
}
public void ThemeList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(e.AddedItems.Count == 0)
{
if (e.AddedItems.Count == 0)
return;
}
selectedTheme = (string)e.AddedItems[0];
_selectedTheme = (string)e.AddedItems[0];
}
public void ApplySettings(object sender, RoutedEventArgs e)
{
if((selectedTheme ?? "") != "")
if (!string.IsNullOrWhiteSpace(_selectedTheme))
{
settings.SelectedTheme = selectedTheme;
MainWindow.ApplyTheme(selectedTheme);
_settings.SelectedTheme = _selectedTheme;
MainWindow.ApplyTheme(_selectedTheme);
}
PlayerView.Player.Volume = settings.Volume;
PlayerView.Player.Volume = _settings.Volume;
settings.Save();
_settings.Save();
}
public void UpdateView() => this.FindControl<TextBlock>("VolumeLabel").Text = settings.Volume.ToString();
public void UpdateView() => this.FindControl<TextBlock>("VolumeLabel").Text = _settings.Volume.ToString();
void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
themeList = this.FindControl<ListBox>("ThemeList");
themeList.SelectionChanged += ThemeList_SelectionChanged;
_themeList = this.FindControl<ListBox>("ThemeList");
_themeList.SelectionChanged += ThemeList_SelectionChanged;
List<string> items = new List<string>();
items.Add("default");
@@ -61,16 +59,14 @@ namespace RedBookPlayer
{
string themeName = dir.Split('/')[1];
if(!File.Exists($"themes/{themeName}/view.xaml"))
{
if (!File.Exists($"themes/{themeName}/view.xaml"))
continue;
}
items.Add(themeName);
}
}
themeList.Items = items;
_themeList.Items = items;
this.FindControl<Button>("ApplyButton").Click += ApplySettings;
this.FindControl<Slider>("VolumeSlider").PropertyChanged += (s, e) => UpdateView();