From 77356f8e49d541476cc945c497dfdc0fdad3f544 Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Fri, 24 Mar 2023 21:44:35 +0100 Subject: [PATCH] Configurable to create empty patterns for the live coding environment --- song.go | 9 +++++---- vm/patterns.go | 13 ++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/song.go b/song.go index 335c4e7..4fe93d6 100644 --- a/song.go +++ b/song.go @@ -11,10 +11,11 @@ import ( // playback speed, but this could be changed to a floating point in future if // finer adjustments are necessary. type Song struct { - BPM int - RowsPerBeat int - Score Score - Patch Patch + BPM int + RowsPerBeat int + Score Score + Patch Patch + CreateEmptyPatterns bool } // Copy makes a deep copy of a Score. diff --git a/vm/patterns.go b/vm/patterns.go index 671cbce..28dbd46 100644 --- a/vm/patterns.go +++ b/vm/patterns.go @@ -162,7 +162,18 @@ func ConstructPatterns(song *sointu.Song) ([][]byte, [][]byte, error) { return nil, nil, errors.New("the constructed pattern table would result in > 256 unique patterns; only 256 unique patterns are supported") } } - bytePatterns := make([][]byte, len(patterns)) + + // Determine the length of bytePatterns + bytePatternsLength := len(patterns) + if song.CreateEmptyPatterns { + bytePatternsLength = 256 + } + + bytePatterns := make([][]byte, bytePatternsLength) // Initialize bytePatterns with the specified length + for i := 0; i < bytePatternsLength; i++ { + bytePatterns[i] = make([]byte, song.Score.RowsPerPattern) // Initialize each element with an array of zeros with length RowsPerPattern + } + for i, pat := range patterns { var err error replaceInts(pat, -1, 0) // replace don't cares with releases