README
¶
launchpad
A package allows you to talk to your Novation Launchpad S or Launchpad MK2 in Go. Light buttons or read your touches.
This library is currently only working with Launchpad S (Green-Red Launchpads) and Launchpad MK2 (RGB)
Usage
Initialize a new Launchpad. If there are no currently connected Launchpad device, initialization will fail with an error. You can fake a device by creating an input and output MIDI device and name them as Launchpad.
Drivers
For "cable" communication you need a Driver to connect with the MIDI system of your OS. Currently there are two multi-platform drivers available:
- package
gitlab.com/gomidi/rtmididrv
based on rtmidi - package
gitlab.com/gomidi/portmididrv
based on portmidi
Portmidi is required to use this package.
$ apt-get install libportmidi-dev
# or
$ brew install portmidi
# or
$ yay -S portmidi
package main
import (
"github.com/rainu/launchpad"
driver "gitlab.com/gomidi/portmididrv"
"log"
)
func main() {
pad, err := launchpad.NewLaunchpad(driver.New())
if err != nil {
log.Fatalf("Error initializing launchpad: %v", err)
}
defer pad.Close()
// turn off all of the lights
pad.Clear()
}
Coordinate system
The coordinate system is illustrated below.
+--------- arrow keys -----------+ +--- mode keys ---+
{0, 8} {1, 8} {2, 8} {3, 8} {4, 8} {5, 8} {6, 8} {7, 8} | ableton
----------------------------------------------------------------
----------------------------------------------------------------
{0, 0} {1, 0} {2, 0} {3, 0} {4, 0} {5, 0} {6, 0} {7, 0} | {8, 0} vol
----------------------------------------------------------------
{0, 1} {1, 1} {2, 1} {3, 1} {4, 1} {5, 1} {6, 1} {7, 1} | {8, 1} pan
----------------------------------------------------------------
{0, 2} {1, 2} {2, 2} {3, 2} {4, 2} {5, 2} {6, 2} {7, 2} | {8, 2} sndA
----------------------------------------------------------------
{0, 3} {1, 3} {2, 3} {3, 3} {4, 3} {5, 3} {6, 3} {7, 3} | {8, 3} sndB
----------------------------------------------------------------
{0, 4} {1, 4} {2, 4} {3, 4} {4, 4} {5, 4} {6, 4} {7, 4} | {8, 4} stop
----------------------------------------------------------------
{0, 5} {1, 5} {2, 5} {3, 5} {4, 5} {5, 5} {6, 5} {7, 5} | {8, 5} trk on
----------------------------------------------------------------
{0, 6} {1, 6} {2, 6} {3, 6} {4, 6} {5, 6} {6, 6} {7, 6} | {8, 6} solo
----------------------------------------------------------------
{0, 7} {1, 7} {2, 7} {3, 7} {4, 7} {5, 7} {6, 7} {7, 7} | {8, 7} arm
----------------------------------------------------------------
Demo: Light your touchs
A simple program to light every touch:
package main
import (
"github.com/rainu/launchpad"
driver "gitlab.com/gomidi/portmididrv"
"log"
)
func main() {
pad, err := launchpad.NewLaunchpad(driver.New())
if err != nil {
log.Fatal(err)
}
defer pad.Close()
pad.Clear()
hits, err := pad.ListenToHits()
if err != nil {
log.Fatal(err)
}
for {
select {
case hit := <-hits:
pad.Light(hit.X, hit.Y, launchpad.ColorS{3, 3})
}
}
}
Demo: Write a scrolling text
A simple program to write text on the launchpad
package main
import (
"github.com/rainu/launchpad"
driver "gitlab.com/gomidi/portmididrv"
"log"
)
func main() {
pad, err := launchpad.NewLaunchpad(driver.New())
if err != nil {
log.Fatal(err)
}
defer pad.Close()
pad.Clear()
// Send Text-Loop
pad.Text(launchpad.ColorS{3, 0}).Add(7, "Hello World!").Perform()
marker, err := pad.ListenToScrollTextEndMarker()
if err != nil {
log.Fatal(err)
}
for {
<-marker
log.Printf("Scrolling text is ended now.")
}
}
Documentation
¶
Index ¶
- type Color
- type ColorMK2
- type ColorMK2RGB
- type ColorS
- type Hit
- type Launchpad
- type LaunchpadMK2
- func (l *LaunchpadMK2) Clear() error
- func (l *LaunchpadMK2) Close() error
- func (l *LaunchpadMK2) In() midi.In
- func (l *LaunchpadMK2) Light(x, y int, color Color) error
- func (l *LaunchpadMK2) ListenToHits() (<-chan Hit, error)
- func (l *LaunchpadMK2) ListenToScrollTextEndMarker() (<-chan interface{}, error)
- func (l *LaunchpadMK2) Out() midi.Out
- func (l *LaunchpadMK2) Text(color Color) ScrollingTextBuilder
- func (l *LaunchpadMK2) TextLoop(color Color) ScrollingTextBuilder
- type LaunchpadS
- func (l *LaunchpadS) Clear() error
- func (l *LaunchpadS) Close() error
- func (l *LaunchpadS) In() midi.In
- func (l *LaunchpadS) Light(x, y int, color Color) error
- func (l *LaunchpadS) ListenToHits() (<-chan Hit, error)
- func (l *LaunchpadS) ListenToScrollTextEndMarker() (<-chan interface{}, error)
- func (l *LaunchpadS) Out() midi.Out
- func (l *LaunchpadS) Text(color Color) ScrollingTextBuilder
- func (l *LaunchpadS) TextLoop(color Color) ScrollingTextBuilder
- type ScrollingTextBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶ added in v1.2.0
type Color interface {
AsBytes() []byte
}
Color can be ColorS for "Launchpad S"-Devices and ColorMK2 or ColorMK2RGB for "Launchpad MK2"-Devices
type ColorMK2 ¶ added in v1.2.0
type ColorMK2 struct { //Code represents the color code of color palette. //It can be from 0 to 127 Code int }
ColorMK2 represents a color from the "Launchpad MK2"s color palette
type ColorMK2RGB ¶ added in v1.2.0
type ColorMK2RGB struct { //Red part of color. It can be from 0 to 63! Red int //Green part of color. It can be from 0 to 63! Green int //Blue part of color. It can be from 0 to 63! Blue int }
ColorMK2RGB represents a rgb-color for the "Launchpad MK2"
func (ColorMK2RGB) AsBytes ¶ added in v1.2.0
func (c ColorMK2RGB) AsBytes() []byte
type ColorS ¶ added in v1.2.0
type ColorS struct { //Red part of color. It can be from 0 to 3! Red int //Green part of color. It can be from 0 to 3! Green int }
ColorS represents a color for the "Launchpad S"
type Launchpad ¶
type Launchpad interface { // ListenToHits listens the input stream for hits. // It will return an error if listening initialisation failed. ListenToHits() (<-chan Hit, error) // ListenToScrollTextEndMarker listens the input stream for text end marker events. // It will return an error if listening initialisation failed. ListenToScrollTextEndMarker() (<-chan interface{}, error) // Light lights the button at x,y with the given color. // x and y are [0, 8] and color can be a ColorS or ColorMK2 / ColorMK2RGB (depends on connected launchpad) // Note that x=8 corresponds to the round scene buttons on the right side of the device, // and y=8 corresponds to the round buttons on the top of the device. Light(x, y int, color Color) error // Text will return a scrolling text builder whether you can build and // perform an text with the given color (for Launchpad MK2 only ColorMK2 will work) which will be scrolled on the launchpad. Text(color Color) ScrollingTextBuilder // TextLoop will return a scrolling text builder whether you can build and // perform an text with the given color (for Launchpad MK2 only ColorMK2 will work) which will be scrolled endless on the launchpad. // If you want to stop an text loop you have to build and execute an empty textLoop! TextLoop(color Color) ScrollingTextBuilder // Clear turns off all the LEDs on the Launchpad. Clear() error // Close will close all underlying resources such like the streams and so on. // It will return an error if any of the underlying resources will return an error // on closing. Close() error // Out will return the underlying midi output stream. Out() midi.Out // In will return the underlying midi input stream. In() midi.In }
Launchpad represents a device with an input and output MIDI stream.
type LaunchpadMK2 ¶ added in v1.2.0
type LaunchpadMK2 struct {
// contains filtered or unexported fields
}
func (*LaunchpadMK2) Clear ¶ added in v1.2.0
func (l *LaunchpadMK2) Clear() error
func (*LaunchpadMK2) Close ¶ added in v1.2.0
func (l *LaunchpadMK2) Close() error
func (*LaunchpadMK2) In ¶ added in v1.2.0
func (l *LaunchpadMK2) In() midi.In
func (*LaunchpadMK2) Light ¶ added in v1.2.0
func (l *LaunchpadMK2) Light(x, y int, color Color) error
func (*LaunchpadMK2) ListenToHits ¶ added in v1.2.0
func (l *LaunchpadMK2) ListenToHits() (<-chan Hit, error)
func (*LaunchpadMK2) ListenToScrollTextEndMarker ¶ added in v1.2.0
func (l *LaunchpadMK2) ListenToScrollTextEndMarker() (<-chan interface{}, error)
func (*LaunchpadMK2) Out ¶ added in v1.2.0
func (l *LaunchpadMK2) Out() midi.Out
func (*LaunchpadMK2) Text ¶ added in v1.2.0
func (l *LaunchpadMK2) Text(color Color) ScrollingTextBuilder
func (*LaunchpadMK2) TextLoop ¶ added in v1.2.0
func (l *LaunchpadMK2) TextLoop(color Color) ScrollingTextBuilder
type LaunchpadS ¶ added in v1.2.0
type LaunchpadS struct {
// contains filtered or unexported fields
}
func (*LaunchpadS) Clear ¶ added in v1.2.0
func (l *LaunchpadS) Clear() error
func (*LaunchpadS) Close ¶ added in v1.2.0
func (l *LaunchpadS) Close() error
func (*LaunchpadS) In ¶ added in v1.2.0
func (l *LaunchpadS) In() midi.In
func (*LaunchpadS) ListenToHits ¶ added in v1.2.0
func (l *LaunchpadS) ListenToHits() (<-chan Hit, error)
func (*LaunchpadS) ListenToScrollTextEndMarker ¶ added in v1.2.0
func (l *LaunchpadS) ListenToScrollTextEndMarker() (<-chan interface{}, error)
func (*LaunchpadS) Out ¶ added in v1.2.0
func (l *LaunchpadS) Out() midi.Out
func (*LaunchpadS) Text ¶ added in v1.2.0
func (l *LaunchpadS) Text(color Color) ScrollingTextBuilder
func (*LaunchpadS) TextLoop ¶ added in v1.2.0
func (l *LaunchpadS) TextLoop(color Color) ScrollingTextBuilder
type ScrollingTextBuilder ¶
type ScrollingTextBuilder interface { // Add adds a text snipped with a given speed to the builder. // The speed can be a value from 1-7. The text must be ASCII // characters! Otherwise the result could be weired. Add(speed byte, text string) ScrollingTextBuilder // Perform sends the pre-built scrolling text to the launchpad. Perform() error }
ScrollingTextBuilder is used to build and display an scrolling text on the Launchpad.