From e887fdba8e7ceee20dde858f09a7791e1c14762b Mon Sep 17 00:00:00 2001 From: Wijnand Modderman-Lenstra Date: Thu, 29 Oct 2026 17:28:13 +0100 Subject: [PATCH] Adapt playback layout and fonts for displays and add contrast fading --- app/app.go | 3 ++ app/font/asset/unifont-16.0.02.bdf | 3 ++ app/font/embed.go | 3 ++ app/font/font_bdf.go | 1 + app/layout/playing.go | 68 +++++++++++++++++++++--------- app/style.go | 3 +- config/settings.go | 16 ++++--- context.go | 6 +++ controller.go | 29 +++++++++++-- 9 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 app/font/asset/unifont-16.0.02.bdf diff --git a/app/app.go b/app/app.go index 97027ac..936fca1 100644 --- a/app/app.go +++ b/app/app.go @@ -41,6 +41,9 @@ type Context interface { // Settings are the user settings. Settings() *config.Settings + + // SetContrast updates all screen's contrast. + SetContrast(level uint8) } type Widget interface { diff --git a/app/font/asset/unifont-16.0.02.bdf b/app/font/asset/unifont-16.0.02.bdf new file mode 100644 index 0000000..1010e8c --- /dev/null +++ b/app/font/asset/unifont-16.0.02.bdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f4c7ae19e2219e54ee88778f850fac5680fab5cb84bfcc75d2f4b508163558b +size 9384069 diff --git a/app/font/embed.go b/app/font/embed.go index bad032b..4a81344 100644 --- a/app/font/embed.go +++ b/app/font/embed.go @@ -17,6 +17,9 @@ var ( //go:embed asset/spleen-8x16.bdf spleen8x16BDF []byte + + //go:embed asset/unifont-16.0.02.bdf + unifontBDF []byte ) var ( diff --git a/app/font/font_bdf.go b/app/font/font_bdf.go index ef8ee59..8118ef1 100644 --- a/app/font/font_bdf.go +++ b/app/font/font_bdf.go @@ -16,6 +16,7 @@ var ( Spleen5x8 = Must(NewFromBytes(spleen5x8BDF)) Spleen6x12 = Must(NewFromBytes(spleen6x12BDF)) Spleen8x16 = Must(NewFromBytes(spleen8x16BDF)) + Unifont = Must(NewFromBytes(unifontBDF)) ) // Icons mapped in SM4TIK diff --git a/app/layout/playing.go b/app/layout/playing.go index afcc1bb..19d6fae 100644 --- a/app/layout/playing.go +++ b/app/layout/playing.go @@ -11,6 +11,7 @@ import ( "periph.io/x/conn/v3/physic" "github.com/BeatGlow/audio" + "github.com/BeatGlow/display/pixel" "github.com/BeatGlow/beatglow/app" "github.com/BeatGlow/beatglow/app/font" @@ -48,11 +49,20 @@ type playing struct { spectrumWidget *widget.Spectrum } -const playingWaterfallHeight = 32 - func Playing(ctx app.Context) app.Layout { - bounds := ctx.Display().Bounds() - styles := app.StylesFor(ctx.Display().ColorModel()) + var ( + config = ctx.Settings() + bounds = ctx.Display().Bounds() + cmodel = ctx.Display().ColorModel() + styles = app.StylesFor(cmodel) + playingWaterfallHeight = bounds.Dy() - 32 + maxWidth = bounds.Dx() - bounds.Dy() + ) + + if !config.Player.ShowArt { + maxWidth = bounds.Dx() + } + layout := &playing{ base: base{name: "playing"}, settings: ctx.Settings(), @@ -62,21 +72,29 @@ func Playing(ctx app.Context) app.Layout { durationText: durationTextPlaceholder, durationWidget: widget.NewText(image.Pt(2+len(durationTextPlaceholder)*9, 12)), trackText: trackTextPlaceholder, - trackWidget: widget.NewText(image.Pt(bounds.Dx()-bounds.Dy(), bounds.Dy()-12-playingWaterfallHeight)), + trackWidget: widget.NewText(image.Pt(maxWidth, bounds.Dy()-12-playingWaterfallHeight)), iconText: iconTextPlaceholder, iconWidget: widget.NewText(image.Pt(10, 12)), - artWidget: widget.NewImage(image.Pt(bounds.Dy(), bounds.Dy())), - spectrumWidget: widget.NewSpectrum(image.Pt(bounds.Dx()-bounds.Dy(), playingWaterfallHeight)), + spectrumWidget: widget.NewSpectrum(image.Pt(maxWidth, playingWaterfallHeight)), + } + if config.Player.ShowArt { + layout.artWidget = widget.NewImage(image.Pt(bounds.Dy(), bounds.Dy())) } var ( formatStyle = styles.Text.WithFont(font.Spleen6x12) - iconStyle = styles.Text.WithFont(font.SM4TIK).WithForegroundColor(color.Gray{0x3f}) + iconStyle = styles.Text.WithFont(font.SM4TIK).WithForegroundColor(color.Gray{0x80}) durationStyle = formatStyle titleStyle = styles.Text.WithFont(font.Montserrat.WithPointSize(20)) offset int ) + switch cmodel { + case pixel.MonoModel: + titleFont := font.Unifont + titleStyle = styles.Text.WithFont(titleFont) + } + layout.phonesWidget. SetStyle(iconStyle). Update(string(font.IconNote)). @@ -110,8 +128,10 @@ func Playing(ctx app.Context) app.Layout { Bind(&layout.trackText). Move(image.Pt(0, 12)) - layout.artWidget. - Move(image.Pt(bounds.Dx()-bounds.Dy(), 0)) + if config.Player.ShowArt { + layout.artWidget. + Move(image.Pt(bounds.Dx()-bounds.Dy(), 0)) + } layout.spectrumWidget. SetWaterfall(false). @@ -125,9 +145,11 @@ func Playing(ctx app.Context) app.Layout { layout.iconWidget, layout.durationWidget, layout.trackWidget, - layout.artWidget, layout.spectrumWidget, } + if config.Player.ShowArt { + layout.widgets = append(layout.widgets, layout.artWidget) + } return layout } @@ -160,8 +182,10 @@ func (l *playing) TrackChanged(ctx app.Context, track *player.Track) { if !track.Eq(l.track) { l.track = track - l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel()) - go l.updateArt(ctx, track) + if ctx.Settings().Player.ShowArt { + l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel()) + go l.updateArt(ctx, track) + } } } @@ -175,6 +199,7 @@ func (l *playing) updateArt(ctx app.Context, track *player.Track) { } } log.Debug("updating album art failed: unavailable") + } func (l *playing) StatusChanged(ctx app.Context, status *player.Status) { @@ -188,10 +213,13 @@ func (l *playing) StatusChanged(ctx app.Context, status *player.Status) { if status.Paused { l.iconText = string(font.IconPause) + ctx.SetContrast(ctx.Settings().Display.Contrast) } else if status.Playing { l.iconText = string(font.IconPlay) + ctx.SetContrast(ctx.Settings().Display.Contrast) } else { l.iconText = string(font.IconStop) + ctx.SetContrast(1) } if status.Duration > 0 { @@ -199,12 +227,14 @@ func (l *playing) StatusChanged(ctx app.Context, status *player.Status) { } if status.Track != nil { - if l.formatRate { - l.formatText = fmt.Sprintf("%04d@%s", status.Format.BitRate, formatRate(status.Format.SampleRate)) - } else { - l.formatText = fmt.Sprintf("%-4s@%s", strings.ToUpper(status.Track.Format), formatRate(status.Format.SampleRate)) - } - l.formatRate = !l.formatRate + //if l.formatRate { + // l.formatText = fmt.Sprintf("%04d@%s", status.Format.BitRate, formatRate(status.Format.SampleRate)) + //} else { + l.formatText = fmt.Sprintf("%-4s@%s", strings.ToUpper(status.Track.Format), formatRate(status.Format.SampleRate)) + //} + //l.formatRate = !l.formatRate + } else { + l.formatText = formatTextPlaceholder } } diff --git a/app/style.go b/app/style.go index 60c6f8d..0139456 100644 --- a/app/style.go +++ b/app/style.go @@ -24,6 +24,7 @@ var ( var ( defaultMonoObjectStyle = ObjectStyle{ + BackgroundImage: image.Black, BackgroundColor: pixel.Off, ForegroundColor: pixel.On, BorderColor: pixel.On, @@ -35,7 +36,7 @@ var ( Graph: defaultMonoObjectStyle, Text: TextStyle{ ObjectStyle: defaultMonoObjectStyle, - Font: font.SmoochSans, + Font: font.Spleen5x8, }, } diff --git a/config/settings.go b/config/settings.go index d7bee1b..c6d6042 100644 --- a/config/settings.go +++ b/config/settings.go @@ -22,12 +22,14 @@ type Settings struct { } type DisplaySettings struct { - Contrast uint8 `hcl:"contrast" menu:"Display contrast" icon:"md_contrast_box"` - Sleep string `hcl:"sleep" menu:"Display sleep time" options:"5min,15min,hour,day" icon:"md_power"` + Contrast uint8 `hcl:"contrast" menu:"Display contrast" icon:"md_contrast_box"` + Sleep string `hcl:"sleep" menu:"Display sleep time" options:"5min,15min,hour,day" icon:"md_power"` + Brightness uint8 `hcl:"brightness" menu:"Display brightness" icon:"md_brightness_6"` } type PlayerSettings struct { - Pause bool + Pause bool `hcl:"pause" menu:"Pause" icon:"md_pause"` + ShowArt bool `hcl:"show_art" menu:"Show album art" icon:"md_image"` } type SpectrumSettings struct { @@ -45,8 +47,12 @@ type SystemSettings struct { var DefaultSettings = Settings{ Display: DisplaySettings{ - Contrast: 0x80, - Sleep: "hour", + Contrast: 0x80, + Sleep: "hour", + Brightness: 0x7F, + }, + Player: PlayerSettings{ + ShowArt: true, }, Spectrum: SpectrumSettings{ Hold: 10, diff --git a/context.go b/context.go index 1ec43bc..708729f 100644 --- a/context.go +++ b/context.go @@ -26,6 +26,8 @@ type controllerContext struct { previous app.Layout settingsLayout app.Layout settings *config.Settings + contrast uint8 + contrastTarget uint8 } func (c controllerContext) Display() display.Display { @@ -240,4 +242,8 @@ func (c *controllerContext) handleRotaryLongPress() { c.Show(c.settingsLayout) } +func (c *controllerContext) SetContrast(level uint8) { + c.contrastTarget = level +} + var _ app.Context = (*controllerContext)(nil) diff --git a/controller.go b/controller.go index 60e9bd7..f32bdd6 100644 --- a/controller.go +++ b/controller.go @@ -87,6 +87,13 @@ func (c *Controller) configureDisplay(log *logrus.Entry, settings *config.Displa } else if err = c.ctx.display.Refresh(); err != nil { return } + + userSettings := c.ctx.Settings() + c.ctx.contrast = userSettings.Display.Contrast + if err = c.ctx.display.SetContrast(userSettings.Display.Contrast); err != nil { + return + } + log.WithField("display", c.ctx.display).Debug("setup display done") return } @@ -181,6 +188,8 @@ func (c *Controller) Run(ctx context.Context) error { } func (c *Controller) onFrame(now time.Time) { + log := logrus.WithField("component", "controller") + var refresh bool for _, layout := range c.ctx.layouts { for _, widget := range layout.Widgets() { @@ -195,7 +204,7 @@ func (c *Controller) onFrame(now time.Time) { if refresh { logrus.Trace("display refresh required") if err := c.ctx.display.Refresh(); err != nil { - logrus.WithError(err).Warn("display refresh failed") + log.WithError(err).Warn("display refresh failed") } if c.recorder != nil { @@ -205,12 +214,26 @@ func (c *Controller) onFrame(now time.Time) { go c.recorderSave() } } else if now.After(c.recorderStart) { - logrus.Info("recorder starting") + log.Info("recorder starting") c.recorder = new(gif.GIF) } } else { - logrus.Trace("display refresh skipped, widgets not changed") + log.Trace("display refresh skipped, widgets not changed") + } + + if c.ctx.contrast < c.ctx.contrastTarget { + c.ctx.contrast++ + log.Debugf("increasing contrast %d to reach %d", c.ctx.contrast, c.ctx.contrastTarget) + if err := c.ctx.display.SetContrast(c.ctx.contrast); err != nil { + log.WithError(err).Warn("can't set display contrast") + } + } else if c.ctx.contrast > c.ctx.contrastTarget { + c.ctx.contrast-- + log.Debugf("decreasing contrast %d to reach %d", c.ctx.contrast, c.ctx.contrastTarget) + if err := c.ctx.display.SetContrast(c.ctx.contrast); err != nil { + log.WithError(err).Warn("can't set display contrast") + } } }