monome

package module
v0.0.0-...-2acc1f6 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package monome implements an OSC interfaces to monome devices from monome.org

Example
keyEvents := make(chan KeyEvent)
device, err := Connect("/hello", keyEvents)
if err != nil {
	log.Fatal(err)
}
defer device.Close()
fmt.Printf("Connected to monome id: %s, prefix: %s, width: %d, height: %d, rotation: %d\n",
	device.Id(), device.Prefix(), device.Width(), device.Height(), device.Rotation())

for e := range keyEvents {
	fmt.Printf("%+v\n", e)
	device.LEDSet(e.X, e.Y, e.State)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ConnectTimeout sets the timeout used by the Connect function.
	// It should not need to be changed in most cases.
	ConnectTimeout = 5 * time.Second

	// ErrTimeout is returned when the connection to a device cannot be established.
	ErrTimeout = errors.New("connection timed out")
)

Functions

This section is empty.

Types

type DeviceEvent

type DeviceEvent struct {
	Id      string
	Type    string
	Port    int
	Removed bool // True if the device is being disconnected, otherwise false.
}

A DeviceEvent is a Monome device connection or disconnection event.

type Grid

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

Grid represents a connection to a Monome device via SerialOsc.

func Connect

func Connect(prefix string, keyEvents chan KeyEvent) (*Grid, error)

Connect is a utility method that establishes a connection to the first monome device it finds. The device sends key events to the given channel. It returns ErrTimeout if it can't connec to a device.

func DialGrid

func DialGrid(address, prefix string, events chan KeyEvent) (*Grid, error)

DialGrid connects to a Monome device using the given address. The address is obtained from SerialOsc running on the local machine. prefix is the OSC address prefix to be used by the local OSC server. If an empty prefix is given, it defaults to /gopher. KeyEvents which are received will be sent in to the given events channel.

func (Grid) Close

func (c Grid) Close() error

Close terminates the OSC connection.

func (*Grid) Height

func (g *Grid) Height() int

Height returns the height of the connected Monome device.

func (Grid) HostPort

func (c Grid) HostPort() (string, int)

HostPort returns the local OSC server host and port.

func (*Grid) Id

func (g *Grid) Id() string

Id returns the id of the connected Monome device.

func (*Grid) LEDAll

func (g *Grid) LEDAll(state int) error

LEDAll sets all LEDs to the given state. State must be 1 for on or 0 for off.

func (*Grid) LEDCol

func (g *Grid) LEDCol(x, yOffset int, states ...byte) error

LEDCol sets a 1x8 col based on a y offset, an x row and an 8 bit bitmask. (0-255) The states bitmask represents the on/off states of the items in the column

func (*Grid) LEDIntensity

func (g *Grid) LEDIntensity(i int) error

LEDIntensity sets the intensity of the grid LEDs.

func (*Grid) LEDLevelAll

func (g *Grid) LEDLevelAll(level int) error

LEDLevelAll sets the level of all LEDs.

func (*Grid) LEDLevelCol

func (g *Grid) LEDLevelCol(x, yOffset int, levels []int) error

LEDLevelRow is like LEDCol but with control over the level.

func (*Grid) LEDLevelMap

func (g *Grid) LEDLevelMap(xOffset, yOffset int, levels [64]int) error

LEDLevelMap is like LEDMap but with control over the level.

func (*Grid) LEDLevelRow

func (g *Grid) LEDLevelRow(xOffset, y int, levels []int) error

LEDLevelRow is like LEDRow but with control over the level.

func (*Grid) LEDLevelSet

func (g *Grid) LEDLevelSet(x, y, level int) error

LEDLevel sets the level of the LED at coordinates x, y. The value of level must be in the range [0, 15].

func (*Grid) LEDMap

func (g *Grid) LEDMap(xOffset, yOffset int, states [8]byte) error

LEDMap sets an 8x8 grid of LEDs on the monome to the given states. The states are a bitmask with each byte representing one row and each bit representing the state of an LED in that row. xOffset and yOffset must be multiples of 8.

func (*Grid) LEDRow

func (g *Grid) LEDRow(xOffset, y int, states ...byte) error

LEDRow sets a 8x1 row based on an x offset, a y row and a bitmask. (0-255) The states bitmask represents the on/off states of the items in the row

func (*Grid) LEDSet

func (g *Grid) LEDSet(x, y, state int) error

LEDSet sets the LED at (x, y) to the given state. State must be 1 for on or 0 for off.

func (*Grid) Prefix

func (g *Grid) Prefix() string

Prefix returns the OSC prefinx being used in communication with the connected Monome device.

func (*Grid) Rotation

func (g *Grid) Rotation() int

Rotation returns the rotation of the connected Monome device.

func (*Grid) Width

func (g *Grid) Width() int

Width returns the width of the connected Monome device.

type KeyEvent

type KeyEvent struct {
	X     int
	Y     int
	State int // 1 for down, 0 for up.
}

A KeyEvent is received for every key down or key up on a Monome device.

type LEDBuffer

type LEDBuffer struct {
	Buf []int
	// contains filtered or unexported fields
}

LEDBuffer can be used to buffer LED changes to a grid. It supports all the same LED operations as a Grid, but doesn't send anything until buffer.Render() is called.

func NewLEDBuffer

func NewLEDBuffer(width, height int) *LEDBuffer

Creates a new LEDBuffer with exposed .Buf value for direct manipulation. Requires width and height to calculate size.

func (*LEDBuffer) GetIndexFromXY

func (b *LEDBuffer) GetIndexFromXY(x, y int) int

Returns the index of the LEDBuffer given x and y coordinates

func (*LEDBuffer) GetXYFromIndex

func (b *LEDBuffer) GetXYFromIndex(i int) []int

Returns the x and y coortinate values given an LEDBuffer index

func (*LEDBuffer) LEDAll

func (b *LEDBuffer) LEDAll(state int) error

Sets all leds in an LEDBuffer, either on (1) or off (0)

func (*LEDBuffer) LEDCol

func (b *LEDBuffer) LEDCol(x, yOffset int, states ...byte) error

Writes a column of values to an LEDBuffer, states is a bitmask of values

func (*LEDBuffer) LEDLevelAll

func (b *LEDBuffer) LEDLevelAll(level int) error

Writes a single varibright level values 0-15 to an LEDBuffer

func (*LEDBuffer) LEDLevelCol

func (b *LEDBuffer) LEDLevelCol(x, yOffset int, levels []int) error

Writes a column of data to a LEDBuffer, uses varibright levels 0-15

func (*LEDBuffer) LEDLevelMap

func (b *LEDBuffer) LEDLevelMap(xOffset, yOffset int, levels [64]int) error

Writes an 8x8 quadrant of varibright values to an LEDBuffer, values 0-15

func (*LEDBuffer) LEDLevelMapAll

func (b *LEDBuffer) LEDLevelMapAll(levels []int) error

Similar to LEDLevelMap but can map LEDBuffer to arbitrary size of device, sice should contain enough values for target grid takes varibright level values 0-15

func (*LEDBuffer) LEDLevelRow

func (b *LEDBuffer) LEDLevelRow(xOffset, y int, levels []int) error

Writes a row of data to a LEDBuffer, uses varibright levels 0-15

func (*LEDBuffer) LEDLevelSet

func (b *LEDBuffer) LEDLevelSet(x, y, level int) error

Writes a single led value at x,y with varibright level values 0-15 to an LEDBuffer

func (*LEDBuffer) LEDMap

func (b *LEDBuffer) LEDMap(xOffset, yOffset int, states [8]byte) error

Writes an 8x8 quadrant of grid values to an LEDBuffer states accepts a bitmask for each row of the quadrant

func (*LEDBuffer) LEDRow

func (b *LEDBuffer) LEDRow(xOffset, y int, states ...byte) error

Writes a Row of values to an LEDBuffer, states is a bitmask of values

func (*LEDBuffer) LEDSet

func (b *LEDBuffer) LEDSet(x, y, state int) error

Sets a single led in an LEDBuffer, either on (1) or off (0)

func (*LEDBuffer) Render

func (b *LEDBuffer) Render(g *Grid) error

Renders a LEDBuffer using LEDLevelMap which only requires one osc message per 8x8 quadrant.

type SerialOsc

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

SerialOsc represents an OSC connection to the monome "serialosc" application.

func DialSerialOsc

func DialSerialOsc(address string, events chan DeviceEvent) (*SerialOsc, error)

DialSerialOsc creates a connection to a serialosc instance at the given address. If an empty address is given it defaults to localhost:12002 Device add and remove events are sent to the given channel.

func (SerialOsc) Close

func (c SerialOsc) Close() error

Close terminates the OSC connection.

func (SerialOsc) HostPort

func (c SerialOsc) HostPort() (string, int)

HostPort returns the local OSC server host and port.

func (*SerialOsc) List

func (s *SerialOsc) List() error

List requests a list of all monome devices serialosc is aware of. The results are sent to the DeviceEvent channel the connetion was initialized with.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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