mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-14 02:54:37 -04:00
feat(tracker): add menu to load instrument presets
The presets are embedded in the executable, so there's no additional files. Closes #91
This commit is contained in:
parent
b65d11cbb7
commit
ce7c8a0d3e
51
tracker/presets.go
Normal file
51
tracker/presets.go
Normal file
@ -0,0 +1,51 @@
|
||||
package tracker
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"sort"
|
||||
|
||||
"github.com/vsariola/sointu"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type PresetList []sointu.Instrument
|
||||
|
||||
//go:embed presets/*
|
||||
var presetFS embed.FS
|
||||
|
||||
var Presets PresetList
|
||||
|
||||
func init() {
|
||||
fs.WalkDir(presetFS, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
data, err := fs.ReadFile(presetFS, path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var instr sointu.Instrument
|
||||
if yaml.Unmarshal(data, &instr) != nil {
|
||||
return nil
|
||||
}
|
||||
Presets = append(Presets, instr)
|
||||
return nil
|
||||
})
|
||||
sort.Sort(Presets)
|
||||
}
|
||||
|
||||
func (p PresetList) Len() int {
|
||||
return len(p)
|
||||
}
|
||||
|
||||
func (p PresetList) Less(i, j int) bool {
|
||||
return p[i].Name < p[j].Name
|
||||
}
|
||||
|
||||
func (p PresetList) Swap(i, j int) {
|
||||
p[i], p[j] = p[j], p[i]
|
||||
}
|
Reference in New Issue
Block a user