mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-21 22:44:50 -04:00
feat: introduce "cache" for derived model information
This commit is contained in:
30
song.go
30
song.go
@ -2,7 +2,6 @@ package sointu
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"iter"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -336,32 +335,3 @@ func TotalVoices[T any, S ~[]T, P NumVoicerPointer[T]](slice S) (ret int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Song) InstrumentForTrack(trackIndex int) (int, bool) {
|
||||
voiceIndex := s.Score.FirstVoiceForTrack(trackIndex)
|
||||
instrument, err := s.Patch.InstrumentForVoice(voiceIndex)
|
||||
return instrument, err == nil
|
||||
}
|
||||
|
||||
func (s *Song) AllTracksWithSameInstrument(trackIndex int) iter.Seq[int] {
|
||||
return func(yield func(int) bool) {
|
||||
|
||||
currentInstrument, currentExists := s.InstrumentForTrack(trackIndex)
|
||||
if !currentExists {
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < len(s.Score.Tracks); i++ {
|
||||
instrument, exists := s.InstrumentForTrack(i)
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
if instrument != currentInstrument {
|
||||
continue
|
||||
}
|
||||
if !yield(i) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user