padx

package module
v0.0.0-...-23f226a Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2018 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Launchpadx is a package which helps you write text / color on your Novation Launchpad Mini.

This package uses https://github.com/rakyll/launchpad

Usage

Character


package main

import (
	"fmt"
	"math/rand"

	"github.com/rakyll/launchpad"

	padx "github.com/yesnault/launchpadx"
)


func main() {
	pad, err := launchpad.Open()
	if err != nil {
		fmt.Printf("error while openning connection to launchpad: %v", err)
	}
	defer pad.Close()

	fmt.Println("Press a button a-h (vertical) or 1-8 (horizontal) on the launchpad")

	pad.Clear()
	f := padx.Widgets8x8()
	ch := pad.Listen()
	for {
		hit := <-ch
		pad.Clear()

		// check if the key is a menu button : a-h, 1-8
		if btn := buttons.Get(hit); btn != nil {
			// it's a 'button'

			// get a random color
			color := padx.Colors[rand.Intn(len(padx.Colors))]

			// display the key pressed
			fmt.Println("pressed:", hit, "with color:", color.Name)

			f.Widgets[btn.Name].Paint(pad, color, 0)
		} else {
			fmt.Println("pressed (not a button):", hit)
		}
	}
}

Draw a Text

[...]

text := padx.Text("foobar", padx.DirectionLeftToRight, padx.Widgets8x8())
text.Move(pad, -text.Width, 0, padx.ColorRedFull, 500*time.Millisecond)

[...]

Draw a character

// initialize the font
f := padx.Widgets8x8()

// paint a character
f.Widgets["a"].Paint(pad, padx.ColorGreenFull)

// blink a character, 100ms transition, 15 repeats between two colors
f.Widgets["b"].Blink(pad, padx.ColorRedFull, padx.ColorOff, 100*time.Millisecond, 15)

// Move a character, 500ms transition
c := f.Widgets["c"]
c.Move(pad, -text.Width, 0, padx.ColorRedFull, 500*time.Millisecond)

Draw a point

padx.Point(5, 3).Paint(pad, padx.ColorRedFull, 0)

Draw a rectangle

r := padx.Rectangle(0, 0, 8, 8)
r.Paint(pad, padx.ColorGreenFull, 10*time.Millisecond)

fmt.Println("Then clear rectangle with 15ms transition between each pixel")
r.Clear(pad, 15*time.Millisecond)

r2 := padx.Rectangle(0, 0, 2, 2)
r2.Paint(pad, padx.ColorGreenFull, 10*time.Millisecond)
r2.Move(pad, 6, 6, padx.ColorGreenFull, 300*time.Millisecond)

Custom Draw

c := padx.NewCustom([]string{
	"--0--",
	"--0--",
	"00000",
	"--0--",
	"-0-0-",
	"0---0",
})

c.Paint(pad, padx.ColorRedFull, 0)
time.Sleep(100*time.Millisecond)

c.Move(pad, 2, 1, padx.ColorGreenFull, 100*time.Millisecond)

License

3-clause BSD

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	A  = Button{Name: 'a', Hit: launchpad.Hit{X: 8, Y: 0}}
	B  = Button{Name: 'b', Hit: launchpad.Hit{X: 8, Y: 1}}
	C  = Button{Name: 'c', Hit: launchpad.Hit{X: 8, Y: 2}}
	D  = Button{Name: 'd', Hit: launchpad.Hit{X: 8, Y: 3}}
	E  = Button{Name: 'e', Hit: launchpad.Hit{X: 8, Y: 4}}
	F  = Button{Name: 'f', Hit: launchpad.Hit{X: 8, Y: 5}}
	G  = Button{Name: 'g', Hit: launchpad.Hit{X: 8, Y: 6}}
	H  = Button{Name: 'h', Hit: launchpad.Hit{X: 8, Y: 7}}
	N1 = Button{Name: '1', Hit: launchpad.Hit{X: 0, Y: 8}}
	N2 = Button{Name: '2', Hit: launchpad.Hit{X: 1, Y: 8}}
	N3 = Button{Name: '3', Hit: launchpad.Hit{X: 2, Y: 8}}
	N4 = Button{Name: '4', Hit: launchpad.Hit{X: 3, Y: 8}}
	N5 = Button{Name: '5', Hit: launchpad.Hit{X: 4, Y: 8}}
	N7 = Button{Name: '6', Hit: launchpad.Hit{X: 5, Y: 8}}
	N6 = Button{Name: '7', Hit: launchpad.Hit{X: 6, Y: 8}}
	N8 = Button{Name: '8', Hit: launchpad.Hit{X: 7, Y: 8}}
)

Buttons around the launchpad

View Source
var (
	ColorOff         = Color{Name: "off", Green: 0, Red: 0}
	ColorGreenLow    = Color{Name: "greenLow", Green: 1, Red: 0}
	ColorGreenMedium = Color{Name: "greenMedium", Green: 2, Red: 0}
	ColorGreenFull   = Color{Name: "greenFull", Green: 3, Red: 0}
	ColorYellowFull  = Color{Name: "yellowFull", Green: 3, Red: 1}
	ColorRedLight    = Color{Name: "redLight", Green: 1, Red: 2}
	ColorOrangeLight = Color{Name: "orangeLight", Green: 3, Red: 2}
	ColorRedFull     = Color{Name: "redFull", Green: 0, Red: 3}
	ColorAmberFull   = Color{Name: "amberFull", Green: 2, Red: 3}
	ColorOrangeFull  = Color{Name: "orangeFull", Green: 3, Red: 3}

	Colors = []Color{
		ColorGreenLow,
		ColorGreenMedium,
		ColorGreenFull,
		ColorYellowFull,
		ColorRedLight,
		ColorOrangeLight,
		ColorRedFull,
		ColorAmberFull,
		ColorOrangeFull,
	}
)

Colors

Functions

This section is empty.

Types

type Button

type Button struct {
	Name rune
	Hit  launchpad.Hit
}

Button represents a button aroune the launchpad

func Get

func Get(hit launchpad.Hit) *Button

Get returns a button (button a-h, 1-8), nil otherwise

func (Button) Equals

func (b Button) Equals(hit launchpad.Hit) bool

Equals return true if button matches with hit

type Color

type Color struct {
	Name  string
	Green int
	Red   int
}

Color represent a color on launchpad mini: green and red

type Custom

type Custom struct {
	OffsetX int
	OffsetY int
	Width   int
	Height  int
	Hits    []launchpad.Hit
}

Custom represents a custom widget and all its hits (x, y) for behing paint

func NewCustom

func NewCustom(lines []string) Custom

NewCustom initializes a custom widget

func Point

func Point(posX, posY int) Custom

Point returns a new custom widget

func Rectangle

func Rectangle(posX, posY, width, height int) Custom

Rectangle returns a new custom widget

func Text

func Text(text string, direction Direction, font Font, offsetX, offsetY int) Custom

Text returns a new text

func (c Custom) Blink(pad *launchpad.Launchpad, colorA, colorB Color, duration time.Duration, repeats int)

Blink blinks a custom widget with two colors duration int Duration of transition between colorA and colorB repeats int Number of repetitions

func (Custom) Clear

func (c Custom) Clear(pad *launchpad.Launchpad, d time.Duration)

Clear paint a custom widget with colorOff

func (*Custom) Move

func (c *Custom) Move(pad *launchpad.Launchpad, toX, toY int, color Color, d time.Duration)

Move moves a custom widget to another position

func (Custom) Paint

func (c Custom) Paint(pad *launchpad.Launchpad, color Color, d time.Duration) []launchpad.Hit

Paint colors a custom widget on launchpad

type Direction

type Direction int

Direction represents a direction for scrolling

const (
	DirectionRightToLeft Direction = iota
	DirectionLeftToRight
	DirectionTopToBottom
	DirectionBottomToTop
)

direction for scroll

type Font

type Font struct {
	Widgets map[rune]Custom
}

Font represents a set of widgets

func Widgets4x4

func Widgets4x4() Font

Widgets4x4 return a 8 per 8 pixels widgets

func Widgets8x8

func Widgets8x8() Font

Widgets8x8 return a 8 per 8 pixels font

type Widget

type Widget interface {
	Paint(pad *launchpad.Launchpad, color Color, d time.Duration)
	Clear(pad *launchpad.Launchpad, d time.Duration)
	Move(pad *launchpad.Launchpad, to launchpad.Hit, color Color, d time.Duration)
}

Widget have to be implemented by widget

Jump to

Keyboard shortcuts

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