Checkpoint
This commit is contained in:
160 files changed
+76293
-387
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package sound
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BeatGlow/beatglow/config"
|
||||
)
|
||||
|
||||
type Opener = func(config.Audio) (Source, error)
|
||||
|
||||
var drivers = make(map[string]Opener)
|
||||
|
||||
func Register(name string, opener Opener) {
|
||||
if _, dupe := drivers[name]; dupe {
|
||||
panic(fmt.Sprintf("sound source %q already registered", name))
|
||||
}
|
||||
drivers[name] = opener
|
||||
}
|
||||
|
||||
func New(config config.Audio) (Source, error) {
|
||||
opener, ok := drivers[config.Type]
|
||||
if ok {
|
||||
return opener(config)
|
||||
}
|
||||
return nil, fmt.Errorf("sound: no %q driver was found", config.Type)
|
||||
}
|
||||
Reference in new issue
Block a user