Checkpoint
This commit is contained in:
160 files changed
+76293
-387
No files matched your search
+43
-7
@@ -1,12 +1,16 @@
|
||||
// Package config contains the configuration structure and parser.
|
||||
package config
|
||||
|
||||
import "image"
|
||||
|
||||
// Config structure.
|
||||
type Config struct {
|
||||
Display Display `hcl:"display,block"`
|
||||
Input Input `hcl:"input,block"`
|
||||
Audio Audio `hcl:"audio,block"`
|
||||
Mixer Mixer `hcl:"mixer,block"`
|
||||
Player Player `hcl:"player,block"`
|
||||
Screen Screen `hcl:"screen,block"`
|
||||
}
|
||||
|
||||
// Display configuration for OLED and TFT screens.
|
||||
@@ -15,7 +19,7 @@ type Display struct {
|
||||
Main *DisplayConfig `hcl:"main,block"`
|
||||
Left *DisplayConfig `hcl:"left,block"`
|
||||
Right *DisplayConfig `hcl:"right,block"`
|
||||
Color *DisplayConfig `hcl:"color,block"`
|
||||
Meta *DisplayConfig `hcl:"meta,block"`
|
||||
}
|
||||
|
||||
// DisplayConfig is the configuration for one display.
|
||||
@@ -84,12 +88,19 @@ type Encoder struct {
|
||||
|
||||
// Audio source provides PCM samples.
|
||||
type Audio struct {
|
||||
Type string `hcl:"type"`
|
||||
Path string `hcl:"path,optional"`
|
||||
Host string `hcl:"host,optional"`
|
||||
Rate float64 `hcl:"rate,optional"`
|
||||
Channels int `hcl:"channels,optional"`
|
||||
Bits int `hcl:"bits,optional"`
|
||||
Type string `hcl:"type"`
|
||||
Path string `hcl:"path,optional"`
|
||||
Host string `hcl:"host,optional"`
|
||||
Rate int `hcl:"rate,optional"`
|
||||
Channels int `hcl:"channels,optional"`
|
||||
Bits int `hcl:"bits,optional"`
|
||||
BigEndian bool `hcl:"be,optional"`
|
||||
Delay string `hcl:"delay,optional"`
|
||||
}
|
||||
|
||||
type Mixer struct {
|
||||
Type string `hcl:"type"`
|
||||
Card int `hcl:"card,optional"`
|
||||
}
|
||||
|
||||
// Player controls the audio.
|
||||
@@ -98,3 +109,28 @@ type Player struct {
|
||||
Host string `hcl:"host,optional"`
|
||||
Password string `hcl:"password,optional"`
|
||||
}
|
||||
|
||||
type Screen struct {
|
||||
Playing *ScreenPlaying `hcl:"playing,block"`
|
||||
Spectrum *ScreenSpectrum `hcl:"spectrum,block"`
|
||||
VUMeter *ScreenVUMeter `hcl:"vumeter,block"`
|
||||
}
|
||||
|
||||
type ScreenPlaying struct {
|
||||
Track *Style `hcl:"track,block"`
|
||||
Format *Style `hcl:"format,block"`
|
||||
Spectrum *ScreenSpectrum `hcl:"spectrum,block"`
|
||||
}
|
||||
type ScreenSpectrum struct {
|
||||
Style *Style `hcl:"style"`
|
||||
MinFrequency int `hcl:"min,optional"`
|
||||
MaxFrequency int `hcl:"max,optional"`
|
||||
Hold int `hcl:"hold,optional"`
|
||||
Window string `hcl:"window,optional"`
|
||||
Waterfall bool `hcl:"waterfall,optional"`
|
||||
Move image.Point
|
||||
}
|
||||
|
||||
type ScreenVUMeter struct {
|
||||
Style *Style `hcl:"style"`
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"strings"
|
||||
|
||||
"github.com/BeatGlow/beatglow/ui"
|
||||
"github.com/BeatGlow/beatglow/ui/font"
|
||||
"github.com/mazznoer/csscolorparser"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Style struct {
|
||||
Color string `hcl:"color,optional"`
|
||||
Font string `hcl:"font,optional"`
|
||||
FontSize float64 `hcl:"font_size,optional"`
|
||||
Hinting string `hcl:"hinting,optional"`
|
||||
DPI float64 `hcl:"dpi,optional"`
|
||||
}
|
||||
|
||||
// Apply styles; errors are logged but don't override styles, so we don't break visuals.
|
||||
func (s Style) Apply(style *ui.Style) {
|
||||
if s.Color != "" {
|
||||
c, err := csscolorparser.Parse(s.Color)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("color", s.Color).Warn("invalid color name")
|
||||
} else {
|
||||
r, g, b, a := c.RGBA255()
|
||||
style.Foreground = color.RGBA{r, g, b, a}
|
||||
}
|
||||
}
|
||||
|
||||
if s.Font != "" {
|
||||
switch s.Font {
|
||||
case "monteserrat":
|
||||
style.Font = font.Montserrat
|
||||
case "monaco":
|
||||
style.Font = font.Monaco
|
||||
case "mairy":
|
||||
style.Font = font.MairyBlackItalic
|
||||
case "microgrotesk":
|
||||
style.Font = font.MicroGrotesk
|
||||
default:
|
||||
f, err := font.New(s.Font)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("font", s.Font).Warn("font failed to load")
|
||||
} else {
|
||||
attr := style.Font.Attr()
|
||||
style.Font = f
|
||||
style.Font.SetDPI(attr.DPI)
|
||||
style.Font.SetHinting(attr.Hinting)
|
||||
style.Font.SetLineSpacing(attr.LineSpacing)
|
||||
style.Font.SetPointSize(attr.PointSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if s.FontSize > 0 {
|
||||
style.Font.SetPointSize(s.FontSize)
|
||||
}
|
||||
|
||||
if s.DPI > 0 {
|
||||
style.Font.SetDPI(s.DPI)
|
||||
}
|
||||
|
||||
switch strings.ToLower(s.Hinting) {
|
||||
case "": // use default
|
||||
case "none", "no", "false":
|
||||
style.Font.SetHinting(font.HintingNone)
|
||||
case "vertical":
|
||||
style.Font.SetHinting(font.HintingVertical)
|
||||
case "full", "yes":
|
||||
style.Font.SetHinting(font.HintingFull)
|
||||
default:
|
||||
logrus.WithField("hinting", s.Hinting).Warn("font hinting invalid")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user