mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-19 05:24:48 -04:00
feat: midi note input for the tracker
This commit is contained in:
30
song.go
30
song.go
@ -2,6 +2,7 @@ package sointu
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"iter"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -331,3 +332,32 @@ 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