feat(sointu): make patterns local to track

The global pattern table is constructed only during compilation. At this point, we can do also all sorts of optimizations / changes e.g. remove unnecessary releases and reuse patterns if there's a pattern already that could be used.
This commit is contained in:
vsariola
2021-01-03 01:06:59 +02:00
parent 06c006086b
commit 5dd81430b7
100 changed files with 395 additions and 150 deletions

View File

@ -4,15 +4,9 @@ import "github.com/vsariola/sointu"
var defaultSong = sointu.Song{
BPM: 100,
Patterns: [][]byte{
{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0},
{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 75, 0, 75, 0, 80, 0},
{0, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0},
{32, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 68, 0, 68, 0},
},
Tracks: []sointu.Track{
{NumVoices: 2, Sequence: []byte{0, 0, 0, 1}},
{NumVoices: 2, Sequence: []byte{2, 2, 2, 3}},
{NumVoices: 2, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}, {64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 75, 0, 75, 0, 80, 0}}},
{NumVoices: 2, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{0, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0}, {32, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 68, 0, 68, 0}}},
},
Patch: sointu.Patch{
Instruments: []sointu.Instrument{{NumVoices: 4, Units: []sointu.Unit{

View File

@ -117,12 +117,12 @@ func (t *Tracker) KeyEvent(e key.Event) bool {
// setCurrent sets the (note) value in current pattern under cursor to iv
func (t *Tracker) setCurrent(iv byte) {
t.song.Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow] = iv
t.song.Tracks[t.ActiveTrack].Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow] = iv
}
// getCurrent returns the current (note) value in current pattern under the cursor
func (t *Tracker) getCurrent() byte {
return t.song.Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow]
return t.song.Tracks[t.ActiveTrack].Patterns[t.song.Tracks[t.ActiveTrack].Sequence[t.DisplayPattern]][t.CursorRow]
}
// NotePressed handles incoming key presses while in the note column

View File

@ -30,7 +30,7 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
}
for i, trk := range t.song.Tracks {
flexTracks[i] = layout.Rigid(Lowered(t.layoutTrack(
t.song.Patterns[trk.Sequence[t.DisplayPattern]],
trk.Patterns[trk.Sequence[t.DisplayPattern]],
t.ActiveTrack == i,
t.CursorRow,
t.CursorColumn,

View File

@ -96,7 +96,7 @@ func (t *Tracker) sequencerLoop(closer <-chan struct{}) {
notes := make([]Note, 0, 32)
for track := range t.song.Tracks {
patternIndex := t.song.Tracks[track].Sequence[t.PlayPattern]
note := t.song.Patterns[patternIndex][t.PlayRow]
note := t.song.Tracks[track].Patterns[patternIndex][t.PlayRow]
if note == 1 { // anything but hold causes an action.
continue
}