From fa163b3884b1d7d418affe51ae83d4e9a8c91e76 Mon Sep 17 00:00:00 2001 From: Veikko Sariola Date: Mon, 7 Dec 2020 11:43:14 +0200 Subject: [PATCH] feat(sointu-cli): Add ability to adjust HOLD value of the patterns --- go4k/cmd/sointu-cli/main.go | 7 +++++++ go4k/song.go | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/go4k/cmd/sointu-cli/main.go b/go4k/cmd/sointu-cli/main.go index 4f62f1f..05375c9 100644 --- a/go4k/cmd/sointu-cli/main.go +++ b/go4k/cmd/sointu-cli/main.go @@ -27,6 +27,7 @@ func main() { exactLength := flag.Bool("e", false, "When outputting the C header file, calculate the exact length of song by rendering it once. Only useful when using SPEED opcodes.") rawOut := flag.Bool("r", false, "Output the rendered song as .raw stereo float32 buffer, to standard output unless otherwise specified.") directory := flag.String("d", "", "Directory where to output all files. The directory and its parents are created if needed. By default, everything is placed in the same directory where the original song file is.") + hold := flag.Int("o", -1, "New value to be used as the hold value") flag.Usage = printUsage flag.Parse() if flag.NArg() == 0 || *help { @@ -105,6 +106,12 @@ func main() { return fmt.Errorf("Error playing: %v", err) } } + if *hold > -1 { + err = song.UpdateHold(byte(*hold)) + if err != nil { + return fmt.Errorf("error updating the hold value of the song: %v", err) + } + } if *headerOut { maxSamples := 0 // 0 means it is calculated automatically if *exactLength { diff --git a/go4k/song.go b/go4k/song.go index 6688a71..5f07143 100644 --- a/go4k/song.go +++ b/go4k/song.go @@ -112,3 +112,25 @@ func Play(synth Synth, song Song) ([]float32, error) { } return buffer, nil } + +func (s *Song) UpdateHold(newHold byte) error { + if newHold == 0 { + return errors.New("hold value cannot be 0, 0 is reserved for release") + } + for _, pat := range s.Patterns { + for _, v := range pat { + if v > s.Hold && v <= newHold { + return errors.New("song uses note values greater or equal to the new hold value") + } + } + } + for _, pat := range s.Patterns { + for i, v := range pat { + if v > 0 && v <= s.Hold { + pat[i] = newHold + } + } + } + s.Hold = newHold + return nil +}