Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Added easier getter for device kind.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Crawford committed Dec 29, 2020
1 parent 519445f commit 9414a5f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type Device interface {
Close()
}

type kindGetter interface {
GetKind() Kind
}

type createOutputDeviceFunc func(settings Settings) (Device, error)

type deviceDetails struct {
Expand All @@ -32,8 +36,8 @@ type deviceDetails struct {

// GetKind returns the kind for the passed in device
func GetKind(d Device) Kind {
if dev, ok := d.(*deviceDetails); ok {
return dev.kind
if dev, ok := d.(kindGetter); ok {
return dev.GetKind()
}
return KindNone
}
Expand All @@ -50,15 +54,14 @@ func CreateOutputDevice(settings Settings) (Device, error) {
if err != nil {
return nil, err
}
dev.(*device).deviceDetails = details
return dev, nil
}

return nil, errors.Wrap(ErrDeviceNotSupported, settings.Name)
}

type device struct {
deviceDetails
Device

onRowOutput DisplayFunc
}
Expand Down
4 changes: 4 additions & 0 deletions device_directsound.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type dsoundDevice struct {
mix mixing.Mixer
}

func (d *dsoundDevice) GetKind() Kind {
return KindSoundCard
}

func newDSoundDevice(settings Settings) (Device, error) {
d := dsoundDevice{
device: device{
Expand Down
4 changes: 4 additions & 0 deletions device_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type fileDevice struct {
device
}

func (d *fileDevice) GetKind() Kind {
return KindFile
}

// Name returns the device name
func (d *fileDevice) Name() string {
return fileName
Expand Down
4 changes: 4 additions & 0 deletions device_pulseaudio.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type pulseaudioDevice struct {
pa *pulseaudio.Client
}

func (d *pulseaudioDevice) GetKind() Kind {
return KindSoundCard
}

func newPulseAudioDevice(settings Settings) (Device, error) {
d := pulseaudioDevice{
device: device{
Expand Down
4 changes: 4 additions & 0 deletions device_winmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type winmmDevice struct {
waveout *winmm.WaveOut
}

func (d *winmmDevice) GetKind() Kind {
return KindSoundCard
}

func newWinMMDevice(settings Settings) (Device, error) {
d := winmmDevice{
device: device{
Expand Down

0 comments on commit 9414a5f

Please sign in to comment.