mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(vm): make the all empty pattern the zero pattern
Perhaps helps compression
This commit is contained in:
parent
4b90c1c50a
commit
cce99e6508
@ -202,5 +202,33 @@ func ConstructPatterns(song *sointu.Song) ([][]byte, [][]byte, error) {
|
||||
return nil, nil, fmt.Errorf("invalid note in pattern, notes should be 0 .. 255: %v", err)
|
||||
}
|
||||
}
|
||||
allZeroIndex := -1
|
||||
for i, pat := range patterns {
|
||||
match := true
|
||||
for _, note := range pat {
|
||||
if note != 0 {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if match {
|
||||
allZeroIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
// if there's a pattern full of zeros...
|
||||
if allZeroIndex > -1 {
|
||||
// ...swap that into position 0, as it is likely the most common pattern
|
||||
bytePatterns[allZeroIndex], bytePatterns[0] = bytePatterns[0], bytePatterns[allZeroIndex]
|
||||
for _, s := range sequences {
|
||||
for j, n := range s {
|
||||
if n == 0 {
|
||||
s[j] = byte(allZeroIndex)
|
||||
} else if n == byte(allZeroIndex) {
|
||||
s[j] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bytePatterns, sequences, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user