feat(tracker): load presets from os.UserConfigDir()/sointu/presets/

This is related to #125, but is very crude way of implementing it.
This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-02-20 20:17:59 +02:00
parent b70db4d394
commit edee3452f4
3 changed files with 29 additions and 4 deletions

View File

@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased
### Added
- User can drop preset instruments into `os.UserConfigDir()/sointu/presets/` and
they appear in the list of presets next time sointu is started.
([#125][i125])
- Ability to loop certain section of the song when playing. The loop can be set
by using the toggle button in the song panel, or by hitting Ctrl+L.
([#128][i128])
@ -142,6 +145,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[i120]: https://github.com/vsariola/sointu/issues/120
[i121]: https://github.com/vsariola/sointu/issues/121
[i122]: https://github.com/vsariola/sointu/issues/122
[i125]: https://github.com/vsariola/sointu/issues/125
[i128]: https://github.com/vsariola/sointu/issues/128
[i129]: https://github.com/vsariola/sointu/issues/129
[i130]: https://github.com/vsariola/sointu/issues/130

View File

@ -61,7 +61,7 @@ func init() {
if configDir, err := os.UserConfigDir(); err == nil {
randBytes := make([]byte, 16)
rand.Read(randBytes)
recoveryFile = filepath.Join(configDir, "Sointu", "sointu-vsti-recovery-"+hex.EncodeToString(randBytes))
recoveryFile = filepath.Join(configDir, "sointu", "sointu-vsti-recovery-"+hex.EncodeToString(randBytes))
}
model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile)
t := gioui.NewTracker(model)

View File

@ -3,6 +3,8 @@ package tracker
import (
"embed"
"io/fs"
"os"
"path/filepath"
"sort"
"github.com/vsariola/sointu"
@ -168,12 +170,31 @@ func init() {
return nil
}
var instr sointu.Instrument
if yaml.Unmarshal(data, &instr) != nil {
return nil
if yaml.Unmarshal(data, &instr) == nil {
instrumentPresets = append(instrumentPresets, instr)
}
instrumentPresets = append(instrumentPresets, instr)
return nil
})
if configDir, err := os.UserConfigDir(); err == nil {
userPresets := filepath.Join(configDir, "sointu", "presets")
filepath.WalkDir(userPresets, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
data, err := os.ReadFile(path)
if err != nil {
return nil
}
var instr sointu.Instrument
if yaml.Unmarshal(data, &instr) == nil {
instrumentPresets = append(instrumentPresets, instr)
}
return nil
})
}
sort.Sort(instrumentPresets)
}