diff --git a/CHANGELOG.md b/CHANGELOG.md index 7df0172..0df68ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmd/sointu-vsti/main.go b/cmd/sointu-vsti/main.go index b89f7dd..287877e 100644 --- a/cmd/sointu-vsti/main.go +++ b/cmd/sointu-vsti/main.go @@ -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) diff --git a/tracker/presets.go b/tracker/presets.go index ce985cb..8b97b87 100644 --- a/tracker/presets.go +++ b/tracker/presets.go @@ -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) }