Added standalone analyzer layout
This commit is contained in:
5 files changed
+110
-13
No files matched your search
@@ -0,0 +1,66 @@
|
||||
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)
|
||||
)
|
||||
@@ -23,6 +23,7 @@ type shaderLayout struct {
|
||||
func Shader(ctx app.Context) app.Layout {
|
||||
display := ctx.Display()
|
||||
layout := &shaderLayout{
|
||||
base: base{name: "shader"},
|
||||
model: display.ColorModel(),
|
||||
shader: shader.New(display.ColorModel(), display.Bounds().Size()),
|
||||
effects: []shader.Effect{
|
||||
|
||||
Reference in new issue
Block a user