Fixed rotating layouts; Added Shader layout
This commit is contained in:
13 files changed
+207
-93
No files matched your search
+3
-25
@@ -7,11 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type base struct {
|
||||
name string
|
||||
widgets []app.Widget
|
||||
visible bool
|
||||
onButtonPress func(app.Context)
|
||||
onButtonLongPress func(app.Context)
|
||||
name string
|
||||
widgets []app.Widget
|
||||
visible bool
|
||||
}
|
||||
|
||||
func (l *base) log() *logrus.Entry {
|
||||
@@ -50,23 +48,3 @@ func (l *base) Show(ctx app.Context) {
|
||||
}
|
||||
l.visible = true
|
||||
}
|
||||
|
||||
func (i *base) OnButtonPress(action func(app.Context)) {
|
||||
i.onButtonPress = action
|
||||
}
|
||||
|
||||
func (i *base) OnButtonLongPress(action func(app.Context)) {
|
||||
i.onButtonLongPress = action
|
||||
}
|
||||
|
||||
func (l *base) HandleButtonPress(ctx app.Context) {
|
||||
if l.onButtonPress != nil {
|
||||
l.onButtonPress(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *base) HandleButtonLongPress(ctx app.Context) {
|
||||
if l.onButtonLongPress != nil {
|
||||
l.onButtonLongPress(ctx)
|
||||
}
|
||||
}
|
||||
+42
-48
@@ -44,67 +44,61 @@ func Settings(ctx app.Context) app.Layout {
|
||||
}
|
||||
|
||||
func (l *settings) HandleRotary(ctx app.Context, delta int) {
|
||||
if l.menuWidget.IsVisible() {
|
||||
log := l.log()
|
||||
log.WithField("item", l.index).Debug("menu item changed")
|
||||
l.menu.Change(delta)
|
||||
if l.menu.IsEditing() {
|
||||
// React on changed value, if it's an immediate change.
|
||||
switch item := l.menu.Items[l.menu.Position]; item.Label {
|
||||
case "Display contrast":
|
||||
if err := ctx.Display().SetContrast(*(item.Value.(*uint8))); err != nil {
|
||||
log.WithError(err).Error("error updating contrast")
|
||||
}
|
||||
default:
|
||||
log.WithField("label", item.Label).Debug("no immediate change")
|
||||
log := l.log()
|
||||
log.WithField("item", l.index).Debug("menu item changed")
|
||||
l.menu.Change(delta)
|
||||
if l.menu.IsEditing() {
|
||||
// React on changed value, if it's an immediate change.
|
||||
switch item := l.menu.Items[l.menu.Position]; item.Label {
|
||||
case "Display contrast":
|
||||
if err := ctx.Display().SetContrast(*(item.Value.(*uint8))); err != nil {
|
||||
log.WithError(err).Error("error updating contrast")
|
||||
}
|
||||
default:
|
||||
log.WithField("label", item.Label).Debug("no immediate change")
|
||||
}
|
||||
l.menuWidget.Redraw()
|
||||
}
|
||||
l.menuWidget.Redraw()
|
||||
}
|
||||
|
||||
func (l *settings) HandleButtonPress(ctx app.Context) {
|
||||
if l.menuWidget.IsVisible() {
|
||||
log := l.log()
|
||||
if l.menu.IsEditing() {
|
||||
log.Debug("exit edit mode")
|
||||
l.menu.ToggleEdit()
|
||||
} else if l.menu.IsSubMenu() {
|
||||
log.Debug("enter sub menu")
|
||||
l.menu = l.menu.EnterSubMenu()
|
||||
} else if item := l.menu.ActiveItem(); item.Value == menu.Back {
|
||||
log.Debug("exit sub menu")
|
||||
menu := l.menu.ExitSubMenu()
|
||||
if menu == nil {
|
||||
// Close settings layout, exiting root.
|
||||
ctx.Show(nil)
|
||||
return
|
||||
}
|
||||
l.menu = menu
|
||||
} else {
|
||||
log.Debug("enter edit mode")
|
||||
l.menu.ToggleEdit()
|
||||
log := l.log()
|
||||
if l.menu.IsEditing() {
|
||||
log.Debug("exit edit mode")
|
||||
l.menu.ToggleEdit()
|
||||
} else if l.menu.IsSubMenu() {
|
||||
log.Debug("enter sub menu")
|
||||
l.menu = l.menu.EnterSubMenu()
|
||||
} else if item := l.menu.ActiveItem(); item.Value == menu.Back {
|
||||
log.Debug("exit sub menu")
|
||||
menu := l.menu.ExitSubMenu()
|
||||
if menu == nil {
|
||||
// Close settings layout, exiting root.
|
||||
ctx.Show(nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Trigger re-render.
|
||||
l.menuWidget.Update(l.menu)
|
||||
l.menu = menu
|
||||
} else {
|
||||
log.Debug("enter edit mode")
|
||||
l.menu.ToggleEdit()
|
||||
}
|
||||
|
||||
// Trigger re-render.
|
||||
l.menuWidget.Update(l.menu)
|
||||
}
|
||||
|
||||
func (l *settings) HandleButtonLongPress(ctx app.Context) {
|
||||
if l.menuWidget.IsVisible() {
|
||||
// Rewind to root menu
|
||||
for {
|
||||
parent := l.menu.Parent
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
l.menu = parent
|
||||
// Rewind to root menu
|
||||
for {
|
||||
parent := l.menu.Parent
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
|
||||
// Close settings layout.
|
||||
ctx.Show(nil)
|
||||
l.menu = parent
|
||||
}
|
||||
|
||||
// Close settings layout.
|
||||
ctx.Show(nil)
|
||||
}
|
||||
|
||||
func foreachStructField(v reflect.Value, f func(fv reflect.Value, sf reflect.StructField) (stop bool)) {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
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)
|
||||
)
|
||||
Reference in new issue
Block a user