77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package layout
|
|
|
|
import (
|
|
"image/color"
|
|
"sync"
|
|
|
|
"github.com/BeatGlow/audio"
|
|
"github.com/BeatGlow/beatglow/app"
|
|
"github.com/BeatGlow/beatglow/app/shader"
|
|
"github.com/BeatGlow/beatglow/app/widget"
|
|
)
|
|
|
|
type shaderLayout struct {
|
|
base
|
|
model color.Model
|
|
effects []shader.Effect
|
|
index int
|
|
mu sync.RWMutex
|
|
shader *shader.Shader
|
|
widget *widget.Canvas
|
|
}
|
|
|
|
func Shader(ctx app.Context) app.Layout {
|
|
display := ctx.Display()
|
|
layout := &shaderLayout{
|
|
model: display.ColorModel(),
|
|
shader: shader.New(display.ColorModel(), display.Bounds().Size()),
|
|
effects: []shader.Effect{
|
|
&shader.AudioIntensityBarsEffect{},
|
|
&shader.AudioNoiseEffect{},
|
|
&shader.AudioRipplesEffect{},
|
|
&shader.ChannelSeparationEffect{},
|
|
&shader.MoireRotatingZoomerEffect{},
|
|
&shader.PulsatingCirclesEffect{},
|
|
&shader.RadialAudioIntensityEffect{},
|
|
&shader.StereoMirrorEffect{},
|
|
&shader.StereoPulseEffect{},
|
|
&shader.StereoRadialEffect{},
|
|
&shader.StereoRippleEffect{},
|
|
&shader.StereoSpectrumEffect{},
|
|
&shader.StereoSwirlEffect{},
|
|
&shader.StereoWaveformEffect{},
|
|
},
|
|
widget: widget.NewCanvas(display.Bounds().Size(), display.ColorModel()),
|
|
}
|
|
layout.shader.Effects = []shader.Effect{layout.effects[0]}
|
|
layout.widgets = []app.Widget{layout.widget}
|
|
return layout
|
|
}
|
|
|
|
func (l *shaderLayout) ProcessBuffer(buffer audio.Buffer[float64]) {
|
|
if l.visible {
|
|
l.mu.Lock()
|
|
l.shader.ProcessBuffer(buffer)
|
|
app.ImageCopy(l.widget.Buffer(), l.shader.Render())
|
|
//l.widget.Update(l.shader.Render(), l.model)
|
|
l.mu.Unlock()
|
|
}
|
|
}
|
|
|
|
func (l *shaderLayout) HandleRotary(_ app.Context, delta int) {
|
|
l.index += delta
|
|
for l.index < 0 {
|
|
l.index = len(l.effects) + l.index
|
|
}
|
|
for l.index >= len(l.effects) {
|
|
l.index = l.index - len(l.effects)
|
|
}
|
|
l.shader.Effects[0] = l.effects[l.index]
|
|
}
|
|
|
|
var (
|
|
_ app.Layout = (*shaderLayout)(nil)
|
|
_ app.BufferProcessor = (*shaderLayout)(nil)
|
|
_ app.RotaryInputHandler = (*shaderLayout)(nil)
|
|
)
|