sc
sc copied to clipboard
Get rid of panics in Rate methods
This is a rough sketch of an idea to avoid all the panic
'ing in the ugen Rate methods.
The idea is to cache an error on the ugen that will get returned when NewSynthdef is called.
sinosc.go:
type SinOsc struct {
Freq Input
Phase Input
}
func (s SinOsc) Rate(rate int8) Input {
var err error
if !supported(rate) {
err = errors.Errorf("unsupported rate: %d", rate)
}
return NewInput("SinOsc", err, ...)
}
...
input.go:
type Input interface {
...
err() error
}
synthdef.go:
func NewSynthdef(name string, f UgenFunc) (*Synthdef, error) {
// Flatten the ugen graph.
// If any ugens return an input that returns a non-nil error from
// the private err() method then return the error.
}