mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
feat(tracker): preset names include their directories
This commit is contained in:
parent
5ee7e44ed7
commit
46a9c7dab3
@ -77,6 +77,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
([#156][i156])
|
||||
|
||||
### Changed
|
||||
- Presets get their name by concatenating their subdirectory path (with path
|
||||
separators replaced with spaces) to their filename
|
||||
- The keyboard shortcuts are now again closer to what they were old trackers
|
||||
([#151][i151])
|
||||
- The stand-alone apps now output floating point sound, as made possible by
|
||||
|
@ -5,7 +5,9 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/vsariola/sointu"
|
||||
"github.com/vsariola/sointu/vm"
|
||||
@ -179,6 +181,10 @@ func init() {
|
||||
}
|
||||
var instr sointu.Instrument
|
||||
if yaml.Unmarshal(data, &instr) == nil {
|
||||
noExt := path[:len(path)-len(filepath.Ext(path))]
|
||||
splitted := splitPath(noExt)
|
||||
splitted = splitted[1:] // remove "presets" from the path
|
||||
instr.Name = strings.Join(splitted, " ")
|
||||
instrumentPresets = append(instrumentPresets, instr)
|
||||
}
|
||||
return nil
|
||||
@ -198,6 +204,13 @@ func init() {
|
||||
}
|
||||
var instr sointu.Instrument
|
||||
if yaml.Unmarshal(data, &instr) == nil {
|
||||
if len(userPresets)+1 > len(path) {
|
||||
return nil
|
||||
}
|
||||
subPath := path[len(userPresets)+1:]
|
||||
noExt := subPath[:len(subPath)-len(filepath.Ext(subPath))]
|
||||
splitted := splitPath(noExt)
|
||||
instr.Name = strings.Join(splitted, " ")
|
||||
instrumentPresets = append(instrumentPresets, instr)
|
||||
}
|
||||
return nil
|
||||
@ -206,6 +219,31 @@ func init() {
|
||||
sort.Sort(instrumentPresets)
|
||||
}
|
||||
|
||||
func splitPath(path string) []string {
|
||||
subPath := path
|
||||
var result []string
|
||||
for {
|
||||
subPath = filepath.Clean(subPath) // Amongst others, removes trailing slashes (except for the root directory).
|
||||
|
||||
dir, last := filepath.Split(subPath)
|
||||
if last == "" {
|
||||
if dir != "" { // Root directory.
|
||||
result = append(result, dir)
|
||||
}
|
||||
break
|
||||
}
|
||||
result = append(result, last)
|
||||
|
||||
if dir == "" { // Nothing to split anymore.
|
||||
break
|
||||
}
|
||||
subPath = dir
|
||||
}
|
||||
|
||||
slices.Reverse(result)
|
||||
return result
|
||||
}
|
||||
|
||||
func (p instrumentPresetsSlice) Len() int { return len(p) }
|
||||
func (p instrumentPresetsSlice) Less(i, j int) bool { return p[i].Name < p[j].Name }
|
||||
func (p instrumentPresetsSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||
|
Loading…
Reference in New Issue
Block a user