Adapt playback layout and fonts for displays and add contrast fading
This commit is contained in:
9 files changed
+95
-19
No files matched your search
@@ -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 {
|
||||
|
||||
Binary file not shown.
@@ -17,6 +17,9 @@ var (
|
||||
|
||||
//go:embed asset/spleen-8x16.bdf
|
||||
spleen8x16BDF []byte
|
||||
|
||||
//go:embed asset/unifont-16.0.02.bdf
|
||||
unifontBDF []byte
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -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
|
||||
|
||||
+44
-14
@@ -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))
|
||||
|
||||
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,9 +182,11 @@ func (l *playing) TrackChanged(ctx app.Context, track *player.Track) {
|
||||
|
||||
if !track.Eq(l.track) {
|
||||
l.track = track
|
||||
if ctx.Settings().Player.ShowArt {
|
||||
l.artWidget.Update(beatglowLogo, ctx.Display().ColorModel())
|
||||
go l.updateArt(ctx, track)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *playing) updateArt(ctx app.Context, track *player.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 {
|
||||
//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
|
||||
//}
|
||||
//l.formatRate = !l.formatRate
|
||||
} else {
|
||||
l.formatText = formatTextPlaceholder
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -24,10 +24,12 @@ 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"`
|
||||
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 {
|
||||
@@ -47,6 +49,10 @@ var DefaultSettings = Settings{
|
||||
Display: DisplaySettings{
|
||||
Contrast: 0x80,
|
||||
Sleep: "hour",
|
||||
Brightness: 0x7F,
|
||||
},
|
||||
Player: PlayerSettings{
|
||||
ShowArt: true,
|
||||
},
|
||||
Spectrum: SpectrumSettings{
|
||||
Hold: 10,
|
||||
|
||||
@@ -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)
|
||||
+26
-3
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user