Rust tool/library for the Launchpad MK2
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
src
.gitignore
Cargo.lock
Cargo.toml
LICENSE.md
README.md

README.md

Rust Launchpad

A set of bindings for controlling a Novation Launchpad. Using PortMidi for Midi bindings.

Currently only supports the Launchpad MK2. If you have another Launchpad, please let me know @bitshiftmask!

Eventually, I would like to introduce a Launchpad Trait, so code can be generic across different Launchpad types. I accept pull requests!

Prerequisites

(excerpt from portmidi-rs)

You need to make sure you have the PortMidi library installed.

On Ubuntu / Debian:

apt-get install libportmidi-dev

Arch Linux:

pacman -S portmidi

On OSX (Homebrew):

brew install portmidi

On OSX, if you get a linker error ld: library not found for -lportmidi, either,

  • make sure you have the Xcode Command Line Tools installed, not just Xcode, or

  • make sure you have the PortMidi library in your $LIBRARY_PATH, e.g. for Homebrew:

    export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"

Use

First, add launchpad to your Cargo.toml:

[dependencies]
launchpad = "0.1"

Then, get started!

extern crate launchpad;

use std::time::Duration;
use std::thread;
use launchpad::*;

fn main() {
    let mut lpad = LaunchpadMk2::guess();
    let timeout = Duration::from_millis(1);

    // Output
    println!("Clear screen...");
    lpad.light_all(0);

    println!("Columns on!");
    for i in 0..9 {
        lpad.light_column(&ColorColumn {column: i, color: 5});
        thread::sleep(Duration::from_millis(25));
    }

    thread::sleep(Duration::from_millis(500));
    lpad.light_all(0);

    let mut foo = 0;

    // Input and Output
    loop {
        if let Some(events) = lpad.poll() {
            for press in events {
                if press.message.data2 == 127 {
                    foo += 1;
                    foo %= 128;
                    lpad.pulse_single(&ColorLed {
                        color: foo,
                        position: press.message.data1,
                    });
                }
            }
        }

        // there is no blocking receive method in PortMidi, therefore
        // we have to sleep some time to prevent a busy-wait loop
        thread::sleep(timeout);
    }
}

References

License

This code is licensed under the MIT license.