Skip to content

Commit

Permalink
add - Added device driver determination to the GUI
Browse files Browse the repository at this point in the history
We've added device driver determination.

---

When both device and driver are null, mpg123 will select an active driver and device to play music.

---

Type: add
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Aug 29, 2023
1 parent 07d5429 commit c40f17d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
4 changes: 2 additions & 2 deletions BassBoom.Basolia/Devices/DeviceTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace BassBoom.Basolia.Devices
/// </summary>
public static class DeviceTools
{
internal static string activeDriver = "";
internal static string activeDevice = "";
internal static string activeDriver;
internal static string activeDevice;

[StructLayout(LayoutKind.Sequential)]
public struct DriverList
Expand Down
5 changes: 4 additions & 1 deletion BassBoom/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@
<Button Grid.Row="2" Grid.Column="1" Name="PlayButton" x:CompileBindings="False" Command="{Binding PlayAsync}" IsEnabled="False">Play</Button>
<Button Grid.Row="2" Grid.Column="2" Name="PauseButton" x:CompileBindings="False" Command="{Binding Pause}" IsEnabled="False">Pause</Button>
<Button Grid.Row="2" Grid.Column="3" Name="StopButton" x:CompileBindings="False" Command="{Binding Stop}" IsEnabled="False">Stop</Button>
<Button Grid.Row="2" Grid.Column="4" Name="SelectDriver" x:CompileBindings="False" Command="{Binding SelectDriver}">Select driver...</Button>
<Button Grid.Row="2" Grid.Column="4" Name="SelectDriver" x:CompileBindings="False" Command="{Binding SelectDriver}" IsEnabled="False">Select driver...</Button>
<Button Grid.Row="2" Grid.Column="5" Name="SelectDevice" x:CompileBindings="False" Command="{Binding SelectDevice}" IsEnabled="False">Select device...</Button>
</Grid>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto" Margin="15">
<CheckBox Grid.Row="1" Name="DetermineDevice" IsChecked="true">Determine device and driver</CheckBox>
</Grid>
</StackPanel>
</UserControl>
74 changes: 51 additions & 23 deletions BassBoom/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ public MainView()
InitializeComponent();
DataContext = new BassBoomData(this);
PathToMp3.TextChanged += CheckPath;
DetermineDevice.IsCheckedChanged += MakeDeviceDeterministic;
}

public void CheckPath(object sender, TextChangedEventArgs e)
internal void EnablePlay()
{
if (File.Exists(PathToMp3.Text) && (!string.IsNullOrEmpty(((BassBoomData)DataContext).selectedDevice)))
if (File.Exists(PathToMp3.Text) &&
((!DetermineDevice.IsChecked.Value && !string.IsNullOrEmpty(((BassBoomData)DataContext).selectedDevice)) ||
DetermineDevice.IsChecked.Value))
{
PlayButton.IsEnabled = true;
GetDuration.IsEnabled = true;
Expand All @@ -58,13 +61,19 @@ public void CheckPath(object sender, TextChangedEventArgs e)
GetDuration.IsEnabled = false;
}
}

private void CheckPath(object sender, TextChangedEventArgs e) =>
EnablePlay();

private void MakeDeviceDeterministic(object sender, RoutedEventArgs e) =>
((BassBoomData)DataContext).HandleDeviceButtons();
}

public class BassBoomData
{
private readonly MainView view;
internal string selectedDriver = "";
internal string selectedDevice = "";
internal string selectedDriver;
internal string selectedDevice;
internal bool paused = false;

public void GetDuration()
Expand Down Expand Up @@ -113,12 +122,6 @@ public async Task PlayAsync()
view.PauseButton.IsEnabled = true;
view.StopButton.IsEnabled = true;
await PlaybackTools.PlayAsync();
view.PlayButton.IsEnabled = true;
view.GetDuration.IsEnabled = true;
view.SelectDevice.IsEnabled = true;
view.SelectDriver.IsEnabled = true;
view.PauseButton.IsEnabled = false;
view.StopButton.IsEnabled = false;
}
catch (BasoliaException bex)
{
Expand All @@ -140,21 +143,19 @@ public async Task PlayAsync()
{
if (FileTools.IsOpened && !paused)
FileTools.CloseFile();
view.PlayButton.IsEnabled = true;
view.GetDuration.IsEnabled = true;
view.PauseButton.IsEnabled = false;
view.StopButton.IsEnabled = false;
HandleDeviceButtons();
}
}

public void Pause()
{
try
{
view.PlayButton.IsEnabled = true;
view.GetDuration.IsEnabled = false;
view.SelectDevice.IsEnabled = false;
view.SelectDriver.IsEnabled = false;
view.PauseButton.IsEnabled = false;
view.StopButton.IsEnabled = true;
PlaybackTools.Pause();
paused = true;
}
catch (BasoliaException bex)
{
Expand All @@ -172,18 +173,22 @@ public void Pause()
$"{ex.Message}", ButtonEnum.Ok);
dialog.ShowAsync();
}
finally
{
view.PlayButton.IsEnabled = true;
view.GetDuration.IsEnabled = false;
view.SelectDevice.IsEnabled = false;
view.SelectDriver.IsEnabled = false;
view.PauseButton.IsEnabled = false;
view.StopButton.IsEnabled = true;
paused = true;
}
}

public void Stop()
{
try
{
view.PlayButton.IsEnabled = true;
view.GetDuration.IsEnabled = true;
view.SelectDevice.IsEnabled = true;
view.SelectDriver.IsEnabled = true;
view.PauseButton.IsEnabled = false;
view.StopButton.IsEnabled = false;
PlaybackTools.Stop();
}
catch (BasoliaException bex)
Expand All @@ -206,6 +211,11 @@ public void Stop()
{
if (FileTools.IsOpened)
FileTools.CloseFile();
view.PlayButton.IsEnabled = true;
view.GetDuration.IsEnabled = true;
view.PauseButton.IsEnabled = false;
view.StopButton.IsEnabled = false;
HandleDeviceButtons();
}
}

Expand Down Expand Up @@ -287,6 +297,24 @@ public void SelectDevice()
}
}

internal void HandleDeviceButtons()
{
if (view.DetermineDevice.IsChecked.Value)
{
selectedDevice = null;
selectedDriver = null;
view.SelectDevice.IsEnabled = false;
view.SelectDriver.IsEnabled = false;
}
else
{
if (!string.IsNullOrEmpty(selectedDriver))
view.SelectDevice.IsEnabled = true;
view.SelectDriver.IsEnabled = true;
}
view.EnablePlay();
}

internal BassBoomData(MainView window)
{
view = window;
Expand Down

0 comments on commit c40f17d

Please sign in to comment.