Skip to content

Commit

Permalink
imp - Better support for changing devices
Browse files Browse the repository at this point in the history
---

DeviceTools' GetDrivers() will no longer list builtin drivers for debugging.

In the player, you can finally query all devices and drivers when not playing.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed May 31, 2024
1 parent de3803a commit 4bd7edb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
13 changes: 12 additions & 1 deletion BassBoom.Basolia/Devices/DeviceTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ public static ReadOnlyDictionary<string, string> GetDrivers()
driverDescs = ArrayVariantLength.GetStringsKnownLength(descr, driverCount);
}

// Iterate through each driver
// Iterate through each driver, but ignore the builtins as they're used for debugging.
for (int i = 0; i < driverCount; i++)
{
string name = driverNames[i];
string description = driverDescs[i];
if (description.Contains("(builtin)"))
continue;
drivers.Add(name, description);
}
return new ReadOnlyDictionary<string, string>(drivers);
Expand Down Expand Up @@ -175,5 +177,14 @@ public static void SetActiveDevice(string driver, string device)
throw new BasoliaException($"Device {device} doesn't exist", mpg123_errors.MPG123_ERR);
activeDevice = device;
}

/// <summary>
/// Resets the driver and the device selection to their initial settings
/// </summary>
public static void Reset()
{
activeDriver = null;
activeDevice = null;
}
}
}
58 changes: 50 additions & 8 deletions BassBoom.Cli/CliBase/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
using SpecProbe.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Terminaux.Base.Buffered;
using Terminaux.Inputs;
using Terminaux.Inputs.Styles.Infobox;

namespace BassBoom.Cli.CliBase
Expand Down Expand Up @@ -86,8 +88,22 @@ internal static void Switch(string musicPath)
internal static void ShowDeviceDriver()
{
var builder = new StringBuilder();
var currentTuple = DeviceTools.GetCurrent();
var currentCachedTuple = DeviceTools.GetCurrentCached();
var currentBuilder = new StringBuilder();
if (PlaybackTools.Playing)
{
var (driver, device) = DeviceTools.GetCurrent();
var cached = DeviceTools.GetCurrentCached();
currentBuilder.AppendLine(
$$"""
Device: {{device}}
Driver: {{driver}}
Device (cached): {{cached.device}}
Driver (cached): {{cached.driver}}
"""
);
}
else
currentBuilder.AppendLine("Can't query current devices while not playing.");
var drivers = DeviceTools.GetDrivers();
string activeDevice = "";
foreach (var driver in drivers)
Expand All @@ -109,10 +125,7 @@ internal static void ShowDeviceDriver()
Device and Driver
=================
Device: {{currentTuple.device}}
Driver: {{currentTuple.driver}}
Device (cached): {{currentCachedTuple.device}}
Driver (cached): {{currentCachedTuple.driver}}
{{currentBuilder}}
Available devices and drivers
=============================
Expand Down Expand Up @@ -182,7 +195,9 @@ [R] Remove current song
[C] Set repeat checkpoint
[SHIFT] + [C] Seek to repeat checkpoint
[E] Opens the equalizer
[D] (when playing) Device and driver info
[D] Device and driver info
[CTRL] + [D] Set device and driver
[SHIFT] + [D] Reset device and driver
[Z] System info
"""
);
Expand All @@ -207,7 +222,9 @@ [N] Next radio station
[R] Remove current radio station
[CTRL] + [R] Remove all radio stations
[E] Opens the equalizer
[D] (when playing) Device and driver info
[D] Device and driver info
[CTRL] + [D] Set device and driver
[SHIFT] + [D] Reset device and driver
[Z] System info
"""
);
Expand Down Expand Up @@ -241,6 +258,31 @@ internal static void HandleKeypressCommon(ConsoleKeyInfo keystroke, Screen playe
case ConsoleKey.L:
enableDisco = !enableDisco;
break;
case ConsoleKey.D:
if (keystroke.Modifiers == ConsoleModifiers.Control)
{
var drivers = DeviceTools.GetDrivers().Select((kvp) => new InputChoiceInfo(kvp.Key, kvp.Value)).ToArray();
int driverIdx = InfoBoxSelectionColor.WriteInfoBoxSelection(drivers, "Select a driver. ESC to quit.");
playerScreen.RequireRefresh();
if (driverIdx < 0)
return;
var driver = drivers[driverIdx];
string active = "";
var devices = DeviceTools.GetDevices(driver.ChoiceName, ref active).Select((kvp) => new InputChoiceInfo(kvp.Key, kvp.Value)).ToArray();
int deviceIdx = InfoBoxSelectionColor.WriteInfoBoxSelection(devices, $"Select a device. Current driver is {active}. ESC to quit.");
playerScreen.RequireRefresh();
if (deviceIdx < 0)
return;
var device = devices[deviceIdx];
DeviceTools.SetActiveDriver(driver.ChoiceName);
DeviceTools.SetActiveDevice(driver.ChoiceName, device.ChoiceName);
}
else if (keystroke.Modifiers == ConsoleModifiers.Shift)
DeviceTools.Reset();
else
ShowDeviceDriver();
playerScreen.RequireRefresh();
break;
case ConsoleKey.Q:
Exit();
break;
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Cli/CliBase/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static void HandleKeypressPlayMode(ConsoleKeyInfo keystroke, Screen play
break;
case ConsoleKey.D:
PlayerControls.Pause();
Common.ShowDeviceDriver();
Common.HandleKeypressCommon(keystroke, playerScreen, false);
playerThread = new(HandlePlay);
PlayerControls.Play();
playerScreen.RequireRefresh();
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Cli/CliBase/Radio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static void HandleKeypressPlayMode(ConsoleKeyInfo keystroke, Screen play
break;
case ConsoleKey.D:
RadioControls.Pause();
Common.ShowDeviceDriver();
Common.HandleKeypressCommon(keystroke, playerScreen, true);
playerThread = new(HandlePlay);
RadioControls.Play();
playerScreen.RequireRefresh();
Expand Down

0 comments on commit 4bd7edb

Please sign in to comment.