ambilight

package
v0.0.0-...-f2f0a72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2016 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ambilight implements a MPD client that is able to play .mood files generated by the moodbar utility: https://en.wikipedia.org/wiki/Moodbar Those are files that consist of 1000 RGB triples of which each represents the composition of frequencies at a certain point in an audio file.

In other words: An audio file is split in 1000(*) little parts where each part is colored based on the low frequencies (red), mids (green) and highs (blue). The combined color is then saved as RGB triple.

This mpd client can automatically create a dir with a .mood database. When a song is played the respective .mood file is located and loaded and synchronized to the music. Additionally a bit of color correction is done and (linear) fading is done between the individual samples for a smoother look.

The ambilightd can be controlled by a simple, line based network protocol which currently supports the following commands:

off     -- Turn off the payback.
on      -- Turn the playback on.
state   -- Print the state ("1\n" or "0\n" on the socket)
quit    -- Quit ambilightd.
close   -- Terminate the connection.

(*) Fixed number given by the moodbar, okay for most songs today,

not very suitable for e.g. Moonsorrow with their 30+ minute songs.

Index

Constants

View Source
const UseDefaultMoodbar = false

UseDefaultMoodbar enables a builtin default moodbar if none was found

Variables

View Source
var DefaultMoodbar = []timedColor{}/* 1000 elements not displayed */

DefaultMoodbar is played when no other moodbar was found but playback is requested. It's supposed to be a smooth soothing fade.

It was generated by this python session:

>>> import math >>> import colorsys >>> h = [i * (255 / 1000) for i in range(1000)]] >>> s = [1 for i in range(1000)] >>> v = [(+math.sin(i / 7) + 1) / 2 for i in range(1000)] >>> rgb = [tuple([int(v * 255) for v in colorsys.hsv_to_rgb(h, s, v)]) for h,s,v in zip(h, s, v)] >>> print('\n'.join(['{%d, %d, %d, 0},' % (v[0], v[1], v[2]) for v in rgb]))

Functions

func Run

func Run(cfg *Config, ctx context.Context) error

Run starts ambilightd with the settings defined in `cfg`. It will stop execution when `ctx` was canceled. If something show-stopping occurs on startup an error is returned.

func Watcher

func Watcher(server *server) error

Watcher instances and connects via channels the go routines that contain the actual logic. It also triggers the logic by feeding mpd events to the go routine pipe.

func WithClient

func WithClient(host string, port int, fn func(client *Client) error) error

WithClient is a convinience function to execute a code snippet with an ambilight connection.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client connects to a running ambilightd instance and can enable/disable the led playback, check the state or quit the daemon remotely.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient creates a new Client from the cfg.Host and cfg.Port

func (*Client) Close

func (cl *Client) Close() error

Close properly terminates the connection and closes resources.

func (*Client) Enable

func (cl *Client) Enable(enable bool) error

Enable enables or disables the playback of ambilight.

func (*Client) Enabled

func (cl *Client) Enabled() (bool, error)

Enabled checks if ambilightd is currently doing playingback. First return is always false when an error occurred.

func (*Client) Quit

func (cl *Client) Quit() error

Quit attempts to shut down the daemon.

type Config

type Config struct {
	// MPDHost of the mpd server (usually localhost)
	MPDHost string

	// MPDPort of the mpd server (usually 6600)
	MPDPort int

	// Lightd host (usually localhost)
	LightdHost string

	// Lightd port  (usually 3333)
	LightdPort int

	// Host of the ambilight command server
	AmbiHost string

	// Port of the command server
	AmbiPort int

	// MusicDir is the root path of the mpd database
	MusicDir string

	// MoodDir contains all moodfiles for certain files (if any)
	MoodDir string

	// UpdateMoodDatabase makes the client update the db and exit afterwards.
	UpdateMoodDatabase bool

	// Name of the RGB LED driver binary (`catlight` for my desktop)
	BinaryName string
}

Config holds all possible adjusting screws for ambilightd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL