Monome

Struct Monome 

Source
pub struct Monome { /* private fields */ }
Expand description

The client object for a Monome grid device

Implementations§

Source§

impl Monome

Source

pub fn register_device_change_callback_with_host_and_port( serialosc_addr: IpAddr, serialosc_port: u16, callback: fn(DeviceChangeEvent), )

Register for device added/removed notifications, on a non-standard serialosc port

§Arguments
  • serialosc_port: the port on which serialosc is running
  • callback: a function that is called whenever a device is added or removed.
§Example

Print a message, on a machine where serialosc runs on the machine at 192.168.1.12, on port 1234.

Monome::register_device_change_callback_with_host_and_port("192.168.1.12".parse().unwrap(), 1234, |event| {
    match event {
        DeviceChangeEvent::Added(id) => {
            println!("Device {} added", id);
        }
        DeviceChangeEvent::Removed(id) => {
            println!("Device {} removed", id);
        }
    }
});
Source

pub fn register_device_change_callback(callback: fn(DeviceChangeEvent))

Register for device added/removed notifications, on the default serialosc port, when it runs on localhost.

§Arguments
  • callback: a function that is called whenever a device is added or removed.
§Example
Monome::register_device_change_callback(|event| {
    match event {
        DeviceChangeEvent::Added(id) => {
            println!("Device {} added", id);
        }
        DeviceChangeEvent::Removed(id) => {
            println!("Device {} removed", id);
        }
    }
});
Source

pub fn register_device_change_callback_with_host( addr: IpAddr, callback: fn(DeviceChangeEvent), )

Register for device added/removed notifications, on the default serialosc port, passing in the address at which serialoscd is reachable.

§Arguments
  • addr: the address on which serialoscd is reachable.
  • callback: a function that is called whenever a device is added or removed.
§Example
Monome::register_device_change_callback_with_host("192.168.1.12".parse().unwrap(), |event| {
    match event {
        DeviceChangeEvent::Added(id) => {
            println!("Device {} added", id);
        }
        DeviceChangeEvent::Removed(id) => {
            println!("Device {} removed", id);
        }
    }
});
Source

pub fn register_device_change_callback_with_port( port: u16, callback: fn(DeviceChangeEvent), )

Register for device added/removed notifications, on the specific serialosc port, when serialoscd is running on localhost.

§Arguments
  • port: the port at which serialoscd is.
  • callback: a function that is called whenever a device is added or removed.
§Example
Monome::register_device_change_callback_with_port(12012, |event| {
    match event {
        DeviceChangeEvent::Added(id) => {
            println!("Device {} added", id);
        }
        DeviceChangeEvent::Removed(id) => {
            println!("Device {} removed", id);
        }
    }
});
Source

pub fn enumerate_devices_with_host_and_port( serialosc_addr: IpAddr, serialosc_port: u16, ) -> Result<Vec<MonomeDevice>, String>

Enumerate all monome devices on a non-standard serialosc port, on a specific host.

If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.

§Arguments
  • `serialosc_addr: the address of the host on which serialosc runs
  • serialosc_port: the port on which serialosc is running
§Example

Enumerate and display all monome device on port 1234:

let enumeration = Monome::enumerate_devices_with_host_and_port("192.168.1.12".parse().unwrap(), 1234);
match enumeration {
    Ok(devices) => {
        for device in &devices {
           println!("{}", device);
        }
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}
Source

pub fn enumerate_devices() -> Result<Vec<MonomeDevice>, String>

Enumerate all monome devices on the standard port on which serialosc runs (12002).

If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.

§Arguments
  • serialosc_port: the port on which serialosc is running
§Example

Enumerate and display all monome device on port 1234:

let enumeration = Monome::enumerate_devices();
match enumeration {
    Ok(devices) => {
        for device in &devices {
           println!("{}", device);
        }
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}
Source

pub fn enumerate_devices_with_port( port: u16, ) -> Result<Vec<MonomeDevice>, String>

Enumerate all monome devices on localhost, on a specific port.

If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.

§Arguments
  • port: the port serialoscd is bound to.
§Example

Enumerate and display all monome device running on default port at a specific address.

match enumeration {
    Ok(devices) => {
        for device in &devices {
           println!("{}", device);
        }
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}
Source

pub fn enumerate_devices_on_host( host: IpAddr, ) -> Result<Vec<MonomeDevice>, String>

Enumerate all monome devices on the standard port on which serialosc runs (12002), on a specific address.

If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.

§Arguments
  • `addr: the address at which serialosc is reachable
§Example

Enumerate and display all monome device running on default port at a specific addr.

let enumeration = Monome::enumerate_devices_on_host("192.168.1.12".parse().unwrap());
match enumeration {
    Ok(devices) => {
        for device in &devices {
           println!("{}", device);
        }
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}
Source

pub fn new<S>(prefix: S) -> Result<Monome, String>
where S: Into<String>,

Sets up the “first” monome device, with a particular prefix. When multiple devices are plugged in, it’s unclear which one is activated, however this is rare.

§Arguments
  • prefix - the prefix to use for this device and this application
§Example

Set up a monome, with a prefix of “/prefix”:

let m = Monome::new("/prefix");

match m {
  Ok(monome) => {
    println!("{:?}", monome);
  }
  Err(s) => {
    println!("Could not setup the monome: {}", s);
  }
}
Source

pub fn new_with_port<S>( prefix: S, serialosc_port: u16, ) -> Result<Monome, String>
where S: Into<String>,

Sets up the “first” monome device, with a particular prefix and a non-standard port for serialosc. When multiple devices are plugged in, it’s unclear which one is activated, however this is rare.

§Arguments
  • prefix - the prefix to use for this device and this application
  • serialosc_port - the port at which serialosc can be reached.
§Example

Set up a monome, with a prefix of “/prefix”, and specify an explicit port on which serialosc can be reached (here, the default of 12002):

let m = Monome::new_with_port("/prefix", 12002);

match m {
  Ok(monome) => {
    println!("{:?}", monome);
  }
  Err(s) => {
    println!("Could not setup the monome: {}", s);
  }
}
Source

pub fn from_device<S>( device: &MonomeDevice, prefix: S, ) -> Result<Monome, String>
where S: Into<String>,

Get a monome instance on which to call commands, from a MonomeDevice.

§Arguments
  • device: a MonomeDevice acquired through enumerate_devices.
  • prefix: the prefix to use for this device and this application
§Example
let enumeration = Monome::enumerate_devices();
match enumeration {
    Ok(devices) => {
        for device in &devices {
            println!("{}", device);
            match Monome::from_device(device, "prefix") {
                Ok(m) => {
                    println!("Monome setup:\n{}", m);
                }
                Err(e) => {
                    println!("Error setting up {} ({})", device, e);
                }
            }
        }
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}
Source

pub fn set<'a, A>(&mut self, x: i32, y: i32, arg: A)
where A: IntoAddrAndArgs<'a, OscType>,

Set a single led on a grid on or off.

§Arguments
  • x - the horizontal position of the led to set.
  • y - the vertical positino of the led to set.
  • arg - either a bool, true to set a led On, false to set it Off, or a number between 0 and 16, 0 being led off, 16 being full led brightness.
§Example

Set the led on the second row and second column to On, and also the third row and second column to mid-brightness:

monome.set(1 /* 2nd, 0-indexed */,
           1 /* 2nd, 0-indexed */,
           true);
monome.set(1 /* 2nd, 0-indexed */,
           2 /* 3nd, 0-indexed */,
           8);
Source

pub fn all<'a, A>(&mut self, arg: A)
where A: IntoAddrAndArgs<'a, OscType>,

Set all led of the grid to an intensity

§Arguments
  • intensity - either a bool, true for led On or false for led Off, or a number between 0 and 16, 0 being led off, and 16 being full led brightness.
§Example

On a grid, set all led to medium brightness, then turn it on:

let mut monome = Monome::new("/prefix").unwrap();
monome.all(8);
monome.all(false);
Source

pub fn set_all(&mut self, leds: &[bool])

Set all the leds of a monome in one call.

§Arguments
  • leds - a vector of 64 booleans for a monome 64, 128 elements for a monome 128, and 256 elements for a monome 256, packed in row order.
§Example

One a monome 128, do a checkerboard pattern:

let mut monome = Monome::new("/prefix").unwrap();
let mut grid = [false; 128];
for i in 0..128 {
  grid[i] = (i + 1) % 2 == 0;
}
monome.set_all(&grid);
Source

pub fn set_all_intensity(&mut self, leds: &[u8])

Set all the leds of a monome in one call.

§Arguments
  • leds - a vector of 64 integers in [0, 15] for a monome 64, 128 elements for a monome 128, and 256 elements for a monome 256, packed in row order.
§Example

One a monome 128, do a gradient


let mut m = Monome::new("/prefix").unwrap();
let mut grid: Vec<u8> = vec!(0; 128);
for i in 0..8 {
    for j in 0..16 {
        grid[i * 16 + j] = (2 * i) as u8;
    }
}
m.set_all_intensity(&grid);
Source

pub fn map<'a, A>(&mut self, x_offset: i32, y_offset: i32, masks: A)
where A: IntoAddrAndArgs<'a, Vec<OscType>> + Sized,

Set the value an 8x8 quad of led on a monome grid.

§Arguments
  • x_offset - at which offset, that must be a multiple of 8, to set the quad.
  • y_offset - at which offset, that must be a multiple of 8, to set the quad.
  • masks - a vector of 8 unsigned 8-bit integers that is a mask representing the leds to light up, or a vector of 64 bools, true for led On, false for led Off, packed in row order, or a vector of 64 integers between 0 and 15, for the brightness of each led, packed in row order.
§Example

On a monome 128, draw a triangle in the lower left half of the rightmost half, and a gradient on the leftmost half.

let mut monome = Monome::new("/prefix").unwrap();
let mut v = [0; 64];
for i in 0..64 {
    v[i] = (i / 4) as u8;
}
monome.map(0, 0, &v);
monome.map(8, 0, &[1, 3, 7, 15, 32, 63, 127, 0b11111111]);
Source

pub fn row<'a, A>(&mut self, x_offset: i32, y: i32, leds: &A)
where A: IntoAddrAndArgs<'a, Vec<OscType>>,

Set a full row of a grid, using one or more 8-bit mask(s), or a vector containing booleans or integer intensity values.

§Arguments
  • x_offset - at which 8 button offset to start setting the leds. This is always 0 for a 64, and can be 8 for a 128 or 256.
  • y - which row to set, 0-indexed. This must be lower than the number of rows of the device.
  • leds - either the list of masks that determine the pattern to light on for a particular 8 led long section, or a vector of either int or bool, one element for each led.
§Example

On a monome 128, light up every other led of the right half of the 3rd row:

let mut monome = Monome::new("/prefix").unwrap();
monome.row(8 /* rightmost half */,
           2 /* 3rd row, 0 indexed */,
           &0b01010101u8 /* every other led, 85 in decimal */);
Source

pub fn col<'a, A>(&mut self, x: i32, y_offset: i32, leds: &A)
where A: IntoAddrAndArgs<'a, Vec<OscType>>,

Set a full column of a grid, using one or more 8-bit mask(s), or a vector containing booleans or integer intensity values.

§Arguments
  • x - which column to set 0-indexed. This must be lower than the number of columns of the device.
  • y_offset - at which 8 button offset to start setting the leds. This is always 0 for a 64, and can be 8 for a 128 or 256.
  • leds - either the list of masks that determine the pattern to light on for a particular 8 led long section, or a vector of either int or bool, one element for each led.
§Example

On a monome 256, light up every other led of the bottom half of the 3rd column from the right:

use monome::Monome;
let mut monome = Monome::new("/prefix").unwrap();
monome.col(2 /* 3rd column, 0-indexed */,
           8 /* bottom half */,
           &0b01010101u8 /* every other led, 85 in decimal */);
Source

pub fn ring_set(&mut self, n: usize, index: u32, intensity: u32)

Set a single led, with intensity, on an Arc.

§Arguments
  • n - the encoder to set a led on, 0-indexed.
  • index - which led to set. 0 is the top led, and goes clockwise. This is modulo 64, so passing in 65 is the second led from the top, going clockwise.
  • intensity - the intensity of the led 0 being off, 15 full brightness.
§Example

On an arc, make a circular gradient on the first encoder:

use monome::Monome;
let mut monome = Monome::new("/prefix").unwrap();
for i in 0..64 {
  monome.set(0, i, i / 4);
}
Source

pub fn ring_all(&mut self, n: usize, intensity: u32)

Set all the led on an encoder to a particular intensity.

§Arguments
  • n - the encoder to set the leds on, 0-indexed.
  • intensity - the intensity of the leds: 0 being off, 15 full brightness.
§Example

On an arc, make a gradient accross all four encoders:

use monome::Monome;
let mut monome = Monome::new("/prefix").unwrap();
for i in 0..4 {
  monome.ring_all(i, (i * 4) as u32);
}
Source

pub fn ring_range( &mut self, n: usize, start_offset: usize, end_offset: usize, intensity: u32, )

Set a range of led to a particular intensity.

§Arguments
  • n - the encoder to set the leds on, 0-indexed.
  • start_offset - the encoder to start setting the led from, 0-indexed, modulo 64.
  • end_offset - the encoder to end setting the led at 0-indexed, inclusive, modulo 64.
  • intensity - the intensity of the leds: 0 being off, 15 full brightness.
§Example

On an arc, lit up halves:

use monome::Monome;
let mut monome = Monome::new("/prefix").unwrap();
monome.ring_range(0, 0, 32, 15);
monome.ring_range(1, 32, 64, 15);
monome.ring_range(2, 16, 48, 15);
monome.ring_range(3, 48, 16, 15);
Source

pub fn ring_map(&mut self, n: usize, values: &[u8; 64])

Set all leds on an encoder to specific values.

§Arguments
  • n - the encoder to set the leds on, 0-indexed.
  • values - an array of 64 values between 0 an 16, one for each led.
§Example

On an arc, make a gradient on an encoder.

use monome::Monome;
let mut monome = Monome::new("/prefix").unwrap();
let mut v: [u8; 64] = [0; 64];

for i in 0..64 {
    v[i] = (i / 4) as u8;
}
monome.ring_map(0, &v);
Source

pub fn tilt_all(&mut self, on: bool)

Enable or disable all tilt sensors (usually, there is only one), which allows receiving the /<prefix>/tilt/ events, with the n,x,y,z coordinates as parameters.

Source

pub fn set_rotation(&mut self, rotation: i32)

Set the rotation for this device. This is either 0, 90, 180 or 270

Source

pub fn set_prefix(&mut self, prefix: String)

Set the prefix for this device.

Source

pub fn name(&self) -> String

Get the name of this device.

Source

pub fn device_type(&self) -> MonomeDeviceType

Get the type for this device (for example "monome 128").

Source

pub fn port(&self) -> u16

Get the port for this device.

Source

pub fn host(&self) -> String

Get the host for this device is at.

Source

pub fn id(&self) -> String

Get the id of this device.

Source

pub fn prefix(&self) -> String

Get the current prefix of this device.

Source

pub fn rotation(&self) -> i32

Get the current rotation of this device.

Source

pub fn size(&self) -> (i32, i32)

Get the size of this device, as a (width, height).

Source

pub fn width(&self) -> usize

Get the width of this device.

Source

pub fn height(&self) -> usize

Get the height of this device.

Source

pub fn poll(&mut self) -> Option<MonomeEvent>

Receives a MonomeEvent, from a connected monome, which can be a grid key press, an event from the tilt sensor, or a delta from an encoder, on an Arc. Only the events from the set prefix will be received.

§Example

use monome::{Monome, MonomeEvent, KeyDirection};
let mut m = Monome::new("/prefix").unwrap();

loop {
    match m.poll() {
        Some(MonomeEvent::GridKey{x, y, direction}) => {
            match direction {
                KeyDirection::Down => {
                    println!("Key pressed: {}x{}", x, y);
                }
                KeyDirection::Up => {
                    println!("Key released: {}x{}", x, y);
                }
            }
        }
        Some(MonomeEvent::Tilt{n: _n, x, y, z: _z}) => {
          println!("tilt update: pitch: {}, roll {}", x, y);
        }
        _ => {
          break;
        }
    }
}

Trait Implementations§

Source§

impl Debug for Monome

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Monome

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Monome

§

impl !RefUnwindSafe for Monome

§

impl Send for Monome

§

impl Sync for Monome

§

impl Unpin for Monome

§

impl !UnwindSafe for Monome

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.