catnip

package module
v0.0.0-...-92350c4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: ISC Imports: 15 Imported by: 0

README

catnip-gtk

screenshot

A catnip frontend as a Gtk3 widget.

Usage

Check ./cmd/catnip-gtk.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapExternalWindowFn

func WrapExternalWindowFn(fn func([]float64) []float64) window.Function

WrapExternalWindowFn wraps external (mostly gonum/dsp/window) functions to be compatible with catnip's usage. The implementation will assume that the given function modifies the given slice in its place, which is the case for most gonum functions, but it might not always be the case. If the implementation does not, then the caller should write their own function to copy.

Types

type AllocatedSizeGetter

type AllocatedSizeGetter interface {
	GetAllocatedWidth() int
	GetAllocatedHeight() int
}

AllocatedSizeGetter is any widget that can be obtained dimensions of. This is used for the Draw method.

type Area

type Area struct {
	*gtk.DrawingArea
	*Drawer
}

Area is the area that Catnip draws onto.

func New

func New(cfg Config) *Area

New creates a new Catnip DrawingArea from the given config.

type CairoColor

type CairoColor [4]float64

func ColorFromGDK

func ColorFromGDK(rgba *gdk.RGBA) CairoColor

func (CairoColor) RGBA

func (cc CairoColor) RGBA() (r, g, b, a uint32)

type Colors

type Colors struct {
	Foreground color.Color // use Gtk if nil
	Background color.Color // transparent if nil
}

Colors is the color settings for the Drawer.

type Config

type Config struct {
	// Backend is the backend name from list-backends
	Backend string
	// Device is the device name from list-devices
	Device string

	WindowFn     window.Function // default CosSum, a0 = 0.50
	Scaling      ScalingConfig
	SampleRate   float64
	SampleSize   int
	SmoothFactor float64
	MinimumClamp float64 // height before visible

	DrawOptions

	DrawStyle  DrawStyle
	Monophonic bool
}

Config is the catnip config.

func NewConfig

func NewConfig() Config

func (*Config) InitBackend

func (c *Config) InitBackend() (input.Backend, error)

InitBackend initializes a new input backend.

func (*Config) InitDevice

func (c *Config) InitDevice(b input.Backend) (input.Device, error)

InitDevice initializes an input device with the given initalized backend.

type DrawOffsets

type DrawOffsets struct {
	X, Y float64
}

DrawOffsets controls the offset for the Drawer.

type DrawOptions

type DrawOptions struct {
	LineCap   cairo.LineCap  // default BUTT
	LineJoin  cairo.LineJoin // default MITER
	AntiAlias cairo.Antialias

	FrameRate int

	Colors     Colors
	Offsets    DrawOffsets
	BarWidth   float64 // not really pixels
	SpaceWidth float64 // not really pixels

	// ForceEven will round the width and height to be even. This will force
	// Cairo to always draw the bars sharply.
	ForceEven bool
}

DrawOptions is the option for Cairo draws.

type DrawQueuer

type DrawQueuer interface {
	QueueDraw()
}

DrawQueuer is a custom widget interface that allows draw queueing.

type DrawStyle

type DrawStyle uint8

DrawStyle is the style to draw the bars symmetrically.

const (
	// VerticalBars is drawing the bars vertically mirrored if stereo.
	DrawVerticalBars DrawStyle = iota
	// HorizontalBars is drawing the bars horizontally mirrored if stereo.
	DrawHorizontalBars
	// DrawLines draws the spectrum as lines.
	DrawLines
)

type Drawer

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

Drawer is the separated drawer state without any widget.

func NewDrawer

func NewDrawer(widget gtk.Widgetter, cfg Config) *Drawer

NewDrawer creates a separated drawer state. The given drawQueuer will be called every redrawn frame.

func (*Drawer) Draw

func (d *Drawer) Draw(widget gtk.Widgetter, cr *cairo.Context)

Draw is bound to the draw signal. Although Draw won't crash if Drawer is not started yet, the drawn result is undefined.

func (*Drawer) Process

func (d *Drawer) Process()

Process processes the internal read buffer and analyzes its spectrum.

func (*Drawer) SetBackend

func (d *Drawer) SetBackend(backend input.Backend)

SetBackend overrides the given Backend in the config.

func (*Drawer) SetDevice

func (d *Drawer) SetDevice(device input.Device)

SetDevice overrides the given Device in the config.

func (*Drawer) SetPaused

func (d *Drawer) SetPaused(paused bool)

SetPaused will silent all inputs if true.

func (*Drawer) Start

func (d *Drawer) Start() (err error)

Start starts the area. This function blocks permanently until the audio loop is dead, so it should be called inside a goroutine. This function should not be called more than once, else it will panic.

The loop will automatically close when the DrawingArea is destroyed.

func (*Drawer) Stop

func (d *Drawer) Stop()

Stop signals the event loop to stop. It does not block.

type ScalingConfig

type ScalingConfig struct {
	StaticScale    float64 // 0 for dynamic scale
	SlowWindow     float64
	FastWindow     float64
	DumpPercent    float64
	ResetDeviation float64
}

ScalingConfig is the scaling settings for the visualizer.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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