60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
// Fenrir console screen reader.
|
|
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
// any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
// more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
|
|
|
package sound
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Options struct {
|
|
Driver string
|
|
Device string
|
|
Volume float64
|
|
}
|
|
|
|
type Driver struct {
|
|
ID, Label string
|
|
open func(*Service, string) error
|
|
}
|
|
|
|
// Drivers is the shared startup, validation and form registry. PipeWire uses
|
|
// its PulseAudio service; explicit selections never switch drivers on failure.
|
|
func Drivers() []Driver {
|
|
return []Driver{{ID: "pulse", Label: "PulseAudio", open: open_pulse}, {ID: "alsa", Label: "ALSA", open: open_alsa}}
|
|
}
|
|
|
|
func Find_driver(id string) (Driver, error) {
|
|
for _, driver := range Drivers() {
|
|
if driver.ID == id {
|
|
return driver, nil
|
|
}
|
|
}
|
|
return Driver{}, fmt.Errorf("unknown sound driver %q", id)
|
|
}
|
|
|
|
func Validate_selection(driver, device string) error {
|
|
if _, err := Find_driver(driver); err != nil {
|
|
return err
|
|
}
|
|
if strings.TrimSpace(device) == "" || strings.ContainsAny(device, "\x00\r\n") {
|
|
return fmt.Errorf("sound device must be a nonempty ALSA PCM name")
|
|
}
|
|
return nil
|
|
}
|