refactor level methods for strip/bus types

This commit is contained in:
onyx-and-iris 2022-12-09 00:54:40 +00:00
parent 134d016e10
commit 26765f554c
2 changed files with 18 additions and 18 deletions

18
bus.go
View File

@ -26,9 +26,9 @@ type iBus interface {
// bus represents a bus channel // bus represents a bus channel
type bus struct { type bus struct {
iRemote iRemote
eQ *eQ eQ *eQ
mode *busMode mode *busMode
levels levels *levels
} }
// Mute returns the value of the Mute parameter // Mute returns the value of the Mute parameter
@ -83,7 +83,7 @@ func (b *bus) Mode() *busMode {
// Levels returns the levels field // Levels returns the levels field
func (b *bus) Levels() *levels { func (b *bus) Levels() *levels {
return &b.levels return b.levels
} }
// FadeTo sets the value of gain to target over at time interval of time_ // FadeTo sets the value of gain to target over at time interval of time_
@ -268,16 +268,16 @@ func (bm *busMode) SetRearOnly(val bool) {
} }
// newBusLevels represents the levels field for a channel // newBusLevels represents the levels field for a channel
func newBusLevels(i int, k *kind) levels { func newBusLevels(i int, k *kind) *levels {
init := i * 8 init := i * 8
return levels{iRemote{fmt.Sprintf("bus[%d]", i), i}, k, init, 8, "bus"} return &levels{iRemote{fmt.Sprintf("bus[%d]", i), i}, k, init, 8, "bus"}
} }
// All returns the level values for a bus // All returns the level values for a bus
func (l *levels) All() []float64 { func (l *levels) All() []float64 {
var levels []float64 levels := make([]float64, l.offset)
for i := l.init; i < l.init+l.offset; i++ { for i := range levels {
levels = append(levels, convertLevel(_levelCache.busLevels[i])) levels[i] = convertLevel(_levelCache.busLevels[i+l.init])
} }
return levels return levels
} }

View File

@ -598,9 +598,9 @@ func newStripLevels(i int, k *kind) *levels {
// PreFader returns the level values for this strip, PREFADER mode // PreFader returns the level values for this strip, PREFADER mode
func (l *levels) PreFader() []float64 { func (l *levels) PreFader() []float64 {
_levelCache.stripMode = 0 _levelCache.stripMode = 0
var levels []float64 levels := make([]float64, l.offset)
for i := l.init; i < l.init+l.offset; i++ { for i := range levels {
levels = append(levels, convertLevel(_levelCache.stripLevels[i])) levels[i] = convertLevel(_levelCache.stripLevels[i+l.init])
} }
return levels return levels
} }
@ -608,9 +608,9 @@ func (l *levels) PreFader() []float64 {
// PostFader returns the level values for this strip, POSTFADER mode // PostFader returns the level values for this strip, POSTFADER mode
func (l *levels) PostFader() []float64 { func (l *levels) PostFader() []float64 {
_levelCache.stripMode = 1 _levelCache.stripMode = 1
var levels []float64 levels := make([]float64, l.offset)
for i := l.init; i < l.init+l.offset; i++ { for i := range levels {
levels = append(levels, convertLevel(_levelCache.stripLevels[i])) levels[i] = convertLevel(_levelCache.stripLevels[i+l.init])
} }
return levels return levels
} }
@ -618,9 +618,9 @@ func (l *levels) PostFader() []float64 {
// PostMute returns the level values for this strip, POSTMUTE mode // PostMute returns the level values for this strip, POSTMUTE mode
func (l *levels) PostMute() []float64 { func (l *levels) PostMute() []float64 {
_levelCache.stripMode = 2 _levelCache.stripMode = 2
var levels []float64 levels := make([]float64, l.offset)
for i := l.init; i < l.init+l.offset; i++ { for i := range levels {
levels = append(levels, convertLevel(_levelCache.stripLevels[i])) levels[i] = convertLevel(_levelCache.stripLevels[i+l.init])
} }
return levels return levels
} }