fix(gioui): unnamed instruments on tracks with multiple voices crashed.

Closes #62.
This commit is contained in:
vsariola
2021-05-08 16:40:06 +03:00
parent d5f413c5dc
commit e649b9ec54

View File

@ -325,13 +325,27 @@ func (te *TrackEditor) layoutTracks(gtx C, t *Tracker) D {
firstIndex, err := t.Song().Patch.InstrumentForVoice(curVoice) firstIndex, err := t.Song().Patch.InstrumentForVoice(curVoice)
lastIndex, err2 := t.Song().Patch.InstrumentForVoice(curVoice + trk.NumVoices - 1) lastIndex, err2 := t.Song().Patch.InstrumentForVoice(curVoice + trk.NumVoices - 1)
if err == nil && err2 == nil { if err == nil && err2 == nil {
switch lastIndex - firstIndex { switch diff := lastIndex - firstIndex; diff {
case 0: case 0:
instrName = t.Song().Patch[firstIndex].Name instrName = t.Song().Patch[firstIndex].Name
case 1:
instrName = string(t.Song().Patch[firstIndex].Name[0]) + "/" + string(t.Song().Patch[lastIndex].Name[0])
default: default:
instrName = string(t.Song().Patch[firstIndex].Name[0]) + "/" + string(t.Song().Patch[firstIndex+1].Name[0]) + "..." n1 := t.Song().Patch[firstIndex].Name
n2 := t.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 {
instrName = n1 + "/" + n2 + "..."
} else {
instrName = n1 + "/" + n2
}
} }
if len(instrName) > 7 { if len(instrName) > 7 {
instrName = instrName[:7] instrName = instrName[:7]