Fix pretty names to handle actual ALSA device name formats
This commit is contained in:
1 parent
dd758d3523
commit
23ac19a68f
2 files changed
+82
-79
No files matched your search
@@ -301,6 +301,12 @@
|
||||
try {
|
||||
const devices = await invoke<AudioDevice[]>('get_audio_devices');
|
||||
audioDevices = devices;
|
||||
// Debug: log raw names and their pretty versions
|
||||
console.log('[Audio] Devices loaded:', devices.map(d => ({
|
||||
raw: d.name,
|
||||
pretty: getDevicePrettyName(d.name),
|
||||
isDefault: d.is_default
|
||||
})));
|
||||
} catch (err) {
|
||||
console.error('Failed to load audio devices:', err);
|
||||
}
|
||||
|
||||
@@ -1,98 +1,94 @@
|
||||
/**
|
||||
* Helper to convert ALSA device names to more user-friendly display names.
|
||||
* This is a best-effort mapping - some names may not be recognized.
|
||||
*/
|
||||
|
||||
// Common device name patterns and their friendly names
|
||||
const DEVICE_PATTERNS: [RegExp, string | ((match: RegExpMatchArray) => string)][] = [
|
||||
// PipeWire virtual devices
|
||||
[/^default$/, 'System Default'],
|
||||
[/^pipewire$/i, 'PipeWire'],
|
||||
|
||||
// USB Audio devices - extract product name
|
||||
[/alsa_output\.usb-([^.]+)\.([^.]+)/i, (m) => cleanProductName(m[1], m[2])],
|
||||
[/usb-([^-]+)-([^-]+)/i, (m) => cleanProductName(m[1], m[2])],
|
||||
|
||||
// PCI Audio (Intel HD Audio, etc)
|
||||
[/alsa_output\.pci-.*\.hdmi-stereo/i, 'HDMI Audio Output'],
|
||||
[/alsa_output\.pci-.*\.analog-stereo/i, 'Analog Audio Output'],
|
||||
[/alsa_output\.pci-.*\.iec958-stereo/i, 'S/PDIF Digital Output'],
|
||||
|
||||
// HDMI patterns
|
||||
[/hdmi[:\-_]?(\d+)/i, (m) => `HDMI Output ${parseInt(m[1]) + 1}`],
|
||||
[/DisplayPort/i, 'DisplayPort Audio'],
|
||||
|
||||
// Common audio interfaces
|
||||
[/Focusrite/i, (m) => 'Focusrite Scarlett'],
|
||||
[/Steinberg/i, 'Steinberg Interface'],
|
||||
[/MOTU/i, 'MOTU Interface'],
|
||||
[/PreSonus/i, 'PreSonus Interface'],
|
||||
|
||||
// DACs
|
||||
[/DAC|Topping|SMSL|FiiO|iFi|Schiit|Dragonfly|Modi|Magni/i, (m) => `USB DAC (${m[0]})`],
|
||||
|
||||
// Hardware device patterns (hw:X,Y)
|
||||
[/^hw:(\d+),(\d+)$/, (m) => `Hardware Device ${m[1]}:${m[2]}`],
|
||||
[/^plughw:(\d+),(\d+)$/, (m) => `Hardware Device ${m[1]}:${m[2]} (Plugin)`],
|
||||
|
||||
// Intel/AMD audio
|
||||
[/Intel.*HDA|HDA Intel/i, 'Intel HD Audio'],
|
||||
[/AMD.*Audio|Audio.*AMD/i, 'AMD Audio'],
|
||||
[/Realtek/i, 'Realtek Audio'],
|
||||
|
||||
// Headphones/Headsets
|
||||
[/headphone|headset/i, 'Headphones'],
|
||||
[/speaker/i, 'Speakers'],
|
||||
|
||||
// Bluetooth (if visible through ALSA)
|
||||
[/bluez|bluetooth/i, 'Bluetooth Audio'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Clean up USB product names by removing underscores and fixing case
|
||||
*/
|
||||
function cleanProductName(vendor: string, product: string): string {
|
||||
const clean = (s: string) => s
|
||||
.replace(/_/g, ' ')
|
||||
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
||||
.trim();
|
||||
|
||||
const v = clean(vendor);
|
||||
const p = clean(product);
|
||||
|
||||
// If product contains vendor name, just use product
|
||||
if (p.toLowerCase().includes(v.toLowerCase())) {
|
||||
return p;
|
||||
}
|
||||
|
||||
return `${v} ${p}`.trim();
|
||||
}
|
||||
// Known card names and their friendly versions
|
||||
const CARD_NAMES: Record<string, string> = {
|
||||
'sofhdadsp': 'Intel HD Audio',
|
||||
'NVidia': 'NVIDIA GPU',
|
||||
'CS201': 'USB Audio', // Common USB audio chip
|
||||
'Generic': 'Generic Audio',
|
||||
'PCH': 'Onboard Audio',
|
||||
'HDMI': 'HDMI Audio',
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a user-friendly name for an ALSA device name.
|
||||
* Falls back to the original name if no pattern matches.
|
||||
*/
|
||||
export function getDevicePrettyName(alsaName: string): string {
|
||||
if (!alsaName) return 'Unknown Device';
|
||||
|
||||
for (const [pattern, replacement] of DEVICE_PATTERNS) {
|
||||
const match = alsaName.match(pattern);
|
||||
if (match) {
|
||||
if (typeof replacement === 'function') {
|
||||
return replacement(match);
|
||||
// Exact matches first
|
||||
switch (alsaName) {
|
||||
case 'default':
|
||||
return 'System Default';
|
||||
case 'sysdefault':
|
||||
return 'System Default (Alt)';
|
||||
case 'pipewire':
|
||||
return 'PipeWire';
|
||||
case 'pulse':
|
||||
return 'PulseAudio';
|
||||
case 'jack':
|
||||
return 'JACK Audio';
|
||||
}
|
||||
|
||||
// Pattern: hdmi:CARD=XXX,DEV=N
|
||||
const hdmiMatch = alsaName.match(/^hdmi:CARD=([^,]+),DEV=(\d+)$/);
|
||||
if (hdmiMatch) {
|
||||
const cardName = CARD_NAMES[hdmiMatch[1]] || hdmiMatch[1];
|
||||
const devNum = parseInt(hdmiMatch[2]) + 1;
|
||||
return `HDMI ${devNum} (${cardName})`;
|
||||
}
|
||||
|
||||
// Pattern: default:CARD=XXX or sysdefault:CARD=XXX
|
||||
const cardMatch = alsaName.match(/^(default|sysdefault):CARD=(.+)$/);
|
||||
if (cardMatch) {
|
||||
const prefix = cardMatch[1] === 'sysdefault' ? ' (Alt)' : '';
|
||||
const cardName = CARD_NAMES[cardMatch[2]] || cardMatch[2];
|
||||
return `${cardName}${prefix}`;
|
||||
}
|
||||
|
||||
// Pattern: hw:X,Y or plughw:X,Y
|
||||
const hwMatch = alsaName.match(/^(plug)?hw:(\d+),(\d+)$/);
|
||||
if (hwMatch) {
|
||||
const prefix = hwMatch[1] ? 'Plugin ' : '';
|
||||
return `${prefix}Hardware ${hwMatch[2]}:${hwMatch[3]}`;
|
||||
}
|
||||
|
||||
// Pattern: alsa_output.XXX (PipeWire style)
|
||||
if (alsaName.startsWith('alsa_output.')) {
|
||||
const rest = alsaName.slice('alsa_output.'.length);
|
||||
|
||||
// USB device
|
||||
if (rest.includes('usb-')) {
|
||||
const usbMatch = rest.match(/usb-([^.]+)/);
|
||||
if (usbMatch) {
|
||||
return `USB: ${usbMatch[1].replace(/_/g, ' ')}`;
|
||||
}
|
||||
return replacement;
|
||||
}
|
||||
|
||||
// PCI HDMI
|
||||
if (rest.includes('hdmi')) {
|
||||
return 'HDMI Output';
|
||||
}
|
||||
|
||||
// PCI Analog
|
||||
if (rest.includes('analog')) {
|
||||
return 'Analog Output';
|
||||
}
|
||||
|
||||
// S/PDIF
|
||||
if (rest.includes('iec958')) {
|
||||
return 'S/PDIF Output';
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: clean up the raw name a bit
|
||||
// Fallback: clean up the name a bit
|
||||
return alsaName
|
||||
.replace(/alsa_output\./g, '')
|
||||
.replace(/\./g, ' ')
|
||||
.replace(/_/g, ' ')
|
||||
.replace(/-/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim() || alsaName;
|
||||
.replace(/^(default|sysdefault):/, '')
|
||||
.replace(/CARD=/g, '')
|
||||
.replace(/,DEV=(\d+)/, ' Output $1')
|
||||
.replace(/_/g, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,6 +99,7 @@ export function isExternalDevice(deviceName: string): boolean {
|
||||
const lower = deviceName.toLowerCase();
|
||||
return (
|
||||
lower.includes('usb') ||
|
||||
lower.includes('cs201') || // Common USB audio chip
|
||||
lower.includes('dac') ||
|
||||
lower.includes('interface') ||
|
||||
lower.includes('focusrite') ||
|
||||
|
||||
Reference in new issue
Block a user