mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-20 05:54:34 -04:00
feat: introduce "cache" for derived model information
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package tracker
|
||||
|
||||
import (
|
||||
"iter"
|
||||
"math"
|
||||
|
||||
"github.com/vsariola/sointu"
|
||||
@ -367,71 +366,6 @@ func (m *Order) SetValue(p Point, val int) {
|
||||
m.d.Song.Score.Tracks[p.X].Order.Set(p.Y, val)
|
||||
}
|
||||
|
||||
func (e *Order) Title(x int) (title string) {
|
||||
title = "?"
|
||||
if x < 0 || x >= len(e.d.Song.Score.Tracks) {
|
||||
return
|
||||
}
|
||||
firstIndex, lastIndex, err := e.instrumentListFor(x)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch diff := lastIndex - firstIndex; diff {
|
||||
case 0:
|
||||
title = e.d.Song.Patch[firstIndex].Name
|
||||
default:
|
||||
n1 := e.d.Song.Patch[firstIndex].Name
|
||||
n2 := e.d.Song.Patch[firstIndex+1].Name
|
||||
if len(n1) > 0 {
|
||||
n1 = string(n1[0])
|
||||
} else {
|
||||
n1 = "?"
|
||||
}
|
||||
if len(n2) > 0 {
|
||||
n2 = string(n2[0])
|
||||
} else {
|
||||
n2 = "?"
|
||||
}
|
||||
if diff > 1 {
|
||||
title = n1 + "/" + n2 + "..."
|
||||
} else {
|
||||
title = n1 + "/" + n2
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Order) instrumentListFor(trackIndex int) (int, int, error) {
|
||||
track := e.d.Song.Score.Tracks[trackIndex]
|
||||
firstVoice := e.d.Song.Score.FirstVoiceForTrack(trackIndex)
|
||||
lastVoice := firstVoice + track.NumVoices - 1
|
||||
firstIndex, err1 := e.d.Song.Patch.InstrumentForVoice(firstVoice)
|
||||
if err1 != nil {
|
||||
return trackIndex, trackIndex, err1
|
||||
}
|
||||
lastIndex, err2 := e.d.Song.Patch.InstrumentForVoice(lastVoice)
|
||||
if err2 != nil {
|
||||
return trackIndex, trackIndex, err2
|
||||
}
|
||||
return firstIndex, lastIndex, nil
|
||||
}
|
||||
|
||||
func (e *Order) TrackIndicesForCurrentInstrument() iter.Seq[int] {
|
||||
currentTrack := e.d.Cursor.Track
|
||||
return e.d.Song.AllTracksWithSameInstrument(currentTrack)
|
||||
}
|
||||
|
||||
func (e *Order) CountNextTracksForCurrentInstrument() int {
|
||||
currentTrack := e.d.Cursor.Track
|
||||
count := 0
|
||||
for t := range e.TrackIndicesForCurrentInstrument() {
|
||||
if t > currentTrack {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// NoteTable
|
||||
|
||||
func (v *Notes) Table() Table {
|
||||
|
Reference in New Issue
Block a user