67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package layout
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"github.com/BeatGlow/audio"
|
|
"github.com/BeatGlow/beatglow/app"
|
|
"github.com/BeatGlow/beatglow/app/widget"
|
|
"github.com/BeatGlow/beatglow/config"
|
|
)
|
|
|
|
type analyzerLayout struct {
|
|
base
|
|
model color.Model
|
|
widget *widget.Spectrum
|
|
settings *config.Settings
|
|
index int
|
|
}
|
|
|
|
func Analyzer(ctx app.Context) app.Layout {
|
|
var (
|
|
display = ctx.Display()
|
|
bounds = display.Bounds()
|
|
settings = ctx.Settings()
|
|
styles = app.StylesFor(display.ColorModel())
|
|
layout = &analyzerLayout{
|
|
base: base{name: "analyzer"},
|
|
widget: widget.NewSpectrum(bounds.Size()),
|
|
settings: settings,
|
|
}
|
|
)
|
|
|
|
layout.widget.SetStyles(*styles)
|
|
layout.widgets = []app.Widget{layout.widget}
|
|
|
|
return layout
|
|
}
|
|
|
|
func (l *analyzerLayout) Show(ctx app.Context) {
|
|
channels := 2
|
|
if l.settings.Spectrum.Mono {
|
|
channels = 1
|
|
}
|
|
|
|
l.widget.
|
|
SetWaterfall(l.settings.Spectrum.Waterfall).
|
|
SetChannels(channels).
|
|
SetRange(l.settings.Spectrum.MinFrequency, l.settings.Spectrum.MaxFrequency).
|
|
SetHold(int(l.settings.Spectrum.Hold))
|
|
|
|
l.base.Show(ctx)
|
|
}
|
|
|
|
func (l *analyzerLayout) ProcessBuffer(buffer audio.Buffer[float64]) {
|
|
l.widget.ProcessBuffer(buffer)
|
|
}
|
|
|
|
func (l *analyzerLayout) HandleRotary(ctx app.Context, delta int) {
|
|
l.settings.Spectrum.Waterfall = !l.settings.Spectrum.Waterfall
|
|
l.widget.SetWaterfall(l.settings.Spectrum.Waterfall)
|
|
}
|
|
|
|
var (
|
|
_ app.Layout = (*analyzerLayout)(nil)
|
|
_ app.BufferProcessor = (*analyzerLayout)(nil)
|
|
)
|