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 ## Unreleased
### Added ### 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 - 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. by using the toggle button in the song panel, or by hitting Ctrl+L.
([#128][i128]) ([#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 [i120]: https://github.com/vsariola/sointu/issues/120
[i121]: https://github.com/vsariola/sointu/issues/121 [i121]: https://github.com/vsariola/sointu/issues/121
[i122]: https://github.com/vsariola/sointu/issues/122 [i122]: https://github.com/vsariola/sointu/issues/122
[i125]: https://github.com/vsariola/sointu/issues/125
[i128]: https://github.com/vsariola/sointu/issues/128 [i128]: https://github.com/vsariola/sointu/issues/128
[i129]: https://github.com/vsariola/sointu/issues/129 [i129]: https://github.com/vsariola/sointu/issues/129
[i130]: https://github.com/vsariola/sointu/issues/130 [i130]: https://github.com/vsariola/sointu/issues/130

View File

@ -61,7 +61,7 @@ func init() {
if configDir, err := os.UserConfigDir(); err == nil { if configDir, err := os.UserConfigDir(); err == nil {
randBytes := make([]byte, 16) randBytes := make([]byte, 16)
rand.Read(randBytes) 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) model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile)
t := gioui.NewTracker(model) t := gioui.NewTracker(model)

View File

@ -3,6 +3,8 @@ package tracker
import ( import (
"embed" "embed"
"io/fs" "io/fs"
"os"
"path/filepath"
"sort" "sort"
"github.com/vsariola/sointu" "github.com/vsariola/sointu"
@ -168,12 +170,31 @@ func init() {
return nil return nil
} }
var instr sointu.Instrument var instr sointu.Instrument
if yaml.Unmarshal(data, &instr) != nil { if yaml.Unmarshal(data, &instr) == nil {
return nil instrumentPresets = append(instrumentPresets, instr)
} }
instrumentPresets = append(instrumentPresets, instr)
return nil 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) sort.Sort(instrumentPresets)
} }