feat(sointu-cli): Add ability to adjust HOLD value of the patterns

This commit is contained in:
Veikko Sariola 2020-12-07 11:43:14 +02:00
parent fee637b02a
commit fa163b3884
2 changed files with 29 additions and 0 deletions

View File

@ -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.") 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.") 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.") 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.Usage = printUsage
flag.Parse() flag.Parse()
if flag.NArg() == 0 || *help { if flag.NArg() == 0 || *help {
@ -105,6 +106,12 @@ func main() {
return fmt.Errorf("Error playing: %v", err) 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 { if *headerOut {
maxSamples := 0 // 0 means it is calculated automatically maxSamples := 0 // 0 means it is calculated automatically
if *exactLength { if *exactLength {

View File

@ -112,3 +112,25 @@ func Play(synth Synth, song Song) ([]float32, error) {
} }
return buffer, nil 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
}