sc icon indicating copy to clipboard operation
sc copied to clipboard

Get rid of panics in Rate methods

Open briansorahan opened this issue 7 years ago • 0 comments

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.
}

briansorahan avatar Jul 29 '17 12:07 briansorahan