-
Notifications
You must be signed in to change notification settings - Fork 13
/
grain.go
44 lines (39 loc) · 1.19 KB
/
grain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package instruments
import (
"os"
"path/filepath"
"github.com/bspaans/bleep/generators"
)
type GrainsOptionsDef struct {
File string `json:"file" yaml:"file"`
GrainSize float64 `json:"grain_size" yaml:"grain_size"`
BirthRate float64 `json:"birth_rate" yaml:"birth_rate"`
Gain float64 `json:"gain" yaml:"gain"`
Repeat bool `json:"repeat" yaml:"repeat"`
Density int `json:"density" yaml:"density"`
Spread float64 `json:"spread" yaml:"spread"`
Speed float64 `json:"speed" yaml:"speed"`
RandomPosition float64 `json:"random_position" yaml:"random_position"`
}
func (w *GrainsOptionsDef) Generator(ctx *Context) generators.Generator {
file := ctx.GetPathFor(w.File)
g, err := generators.NewGrainsGeneratorForWavFile(ctx.Config, file, w.GrainSize, w.BirthRate, w.Density, w.Spread, w.Speed, w.RandomPosition, w.Gain, w.Repeat)
if err != nil {
panic(err)
}
return g
}
func (w *GrainsOptionsDef) Validate(ctx *Context) error {
file := w.File
if !filepath.IsAbs(w.File) {
file = filepath.Join(ctx.BaseDir, w.File)
}
_, err := os.Stat(file)
if err != nil {
return err
}
if w.Density == 0 {
w.Density = 1
}
return nil
}