#usb #hid #reuse

maschine

用于通过USB与Native Instruments Maschine接口交互

1个不稳定版本

0.1.0 2022年7月21日

#21 in #reuse

MIT许可协议

40KB
1K SLoC

Maschine

此crate用于通过USB与Native Instruments Maschine接口交互。

这些设备具有大量按钮、速度敏感垫、旋转编码器和点阵LCD。

目前仅支持Maschine Mikro mk2

用法

示例

extern crate hidapi;

use hidapi::HidApi;
use maschine::{get_device, Canvas, Colour, Controller, Event, EventContext, EventTask};


fn main() {
    let hid_api = HidApi::new().unwrap();
    let mut ctlr = get_device(&hid_api).unwrap();

    loop {
        // Allow controller to do work and update any events
        let mut context = EventContext::new();
        ctlr.tick(&mut context).unwrap();

        // Handle any generated events
        while !context.events.is_empty() {
            let event = context.events.pop_front().unwrap();
            match event {
                Event::Button(button, pressed, shift) => {
                    if pressed {
                        // If button is pressed assign it a random colour
                        ctlr.set_button_led(button, Colour::random());
                        println!("{:?}", button);
                    } else {
                        // Turn the LED off on release.
                        ctlr.set_button_led(button, Colour::BLACK);
                    }
                }
                // Print out other events
                _ => println!("{:?}", event),
            }
        }
    }
}

依赖项

~0.6–1.1MB
~19K SLoC