pub struct CanvasLayout<'a> { /* private fields */ }Expand description
Imagine this - you have multiple launchpads, you line them up, and now you use the Launchpads
as if they were a single device?! You can do that, with CanvasLayout.
Create a layout, add Canvases to it at the position where they appear on your table, and
you’re ready to rock!
Example:
let mut canvas_layout = CanvasLayout::new(|msg| println!("Got a message: {:?}", msg));
// Assuming you have a Launchpad MK2 and a Launchpad S lying next to it:
canvas_layout.add_by_guess::<launchy::mk2::Canvas>(0, 0)?;
canvas_layout.add_by_guess::<launchy::s::Canvas>(9, 0)?;
// Light the entire canvas layout red - i.e. both Launchpads will be red
for pad in canvas_layout.iter() {
canvas_layout[pad] = launchy::Color::RED;
}
canvas_layout.flush()?;Implementations§
Source§impl<'a> CanvasLayout<'a>
impl<'a> CanvasLayout<'a>
Sourcepub fn new(callback: impl Fn(CanvasMessage) + Send + Sync + 'static) -> Self
pub fn new(callback: impl Fn(CanvasMessage) + Send + Sync + 'static) -> Self
Create a new CanvasLayout that sends messages to the provided callback. The callback must
implement Fn because it may be called from multiple devices concurrently.
Sourcepub fn new_polling() -> (Self, CanvasLayoutPoller)
pub fn new_polling() -> (Self, CanvasLayoutPoller)
Create a new CanvasLayout, plus an input handler object that you can use to poll messages.
pub fn light_threshold(&self) -> f32
pub fn set_light_threshold(&mut self, value: f32)
Sourcepub fn add<C: 'a + Canvas, F, E>(
&mut self,
x_offset: u32,
y_offset: u32,
rotation: Rotation,
creator: F,
) -> Result<(), E>
pub fn add<C: 'a + Canvas, F, E>( &mut self, x_offset: u32, y_offset: u32, rotation: Rotation, creator: F, ) -> Result<(), E>
Add a new device to this canvas layout, at the specified x and y coordinate.
The usage of this method is a bit awkward out of necessity. You need to provide a closure
which, when called with a message callback, is expected to return a Canvas that is set
up to deliver messsages to the provided message callback.
The Result which the closure returns will be propagated.
Example:
canvas_layout.add(0, 0, Rotation::None, |callback| launchy::mk2::Canvas::guess(callback))?;
// or even nested layouts:
canvas_layout.add(0, 0, Rotation::None, |callback| {
let mut canvas_layout = CanvasLayout::new(callback);
canvas_layout.add(0, 0, Rotation::None, |callback| launchy::mk2::Canvas::guess(callback))?;
Ok::<_, launchy::MidiError>(canvas_layout)
})?;
If you want an easier way to add simple devices, see add_by_guess.
Sourcepub fn add_by_guess<E: 'a + DeviceCanvasTrait>(
&mut self,
x: u32,
y: u32,
) -> Result<(), MidiError>
pub fn add_by_guess<E: 'a + DeviceCanvasTrait>( &mut self, x: u32, y: u32, ) -> Result<(), MidiError>
Add a new device to this canvas, at the specified x and y coordinates. The MIDI
connections used for communication with the underlying hardware are determined by guessing
based on the device name.
Specifiy the type of device using a generic Canvas type parameter.
Example
// Assuming a Launchpad MK2 and a Launchpad S next to it:
canvas_layout.add_by_guess::<launchy::mk2::Canvas>(0, 0)?;
canvas_layout.add_by_guess::<launchy::s::Canvas>(9, 0)?;Trait Implementations§
Source§impl Canvas for CanvasLayout<'_>
impl Canvas for CanvasLayout<'_>
Source§fn lowest_visible_brightness(&self) -> f32
fn lowest_visible_brightness(&self) -> f32
Source§fn bounding_box(&self) -> (u32, u32)
fn bounding_box(&self) -> (u32, u32)
Source§fn low_level_get_pending(&self, x: u32, y: u32) -> Option<&Color>
fn low_level_get_pending(&self, x: u32, y: u32) -> Option<&Color>
Source§fn low_level_get_pending_mut(&mut self, x: u32, y: u32) -> Option<&mut Color>
fn low_level_get_pending_mut(&mut self, x: u32, y: u32) -> Option<&mut Color>
Source§fn low_level_get(&self, x: u32, y: u32) -> Option<&Color>
fn low_level_get(&self, x: u32, y: u32) -> Option<&Color>
Source§fn flush(&mut self) -> Result<(), MidiError>
fn flush(&mut self) -> Result<(), MidiError>
Source§fn get(&self, pad: Pad) -> Option<Color>
fn get(&self, pad: Pad) -> Option<Color>
Source§fn get_pending(&self, pad: Pad) -> Option<Color>
fn get_pending(&self, pad: Pad) -> Option<Color>
Source§fn set(&mut self, pad: Pad, color: Color) -> Option<()>
fn set(&mut self, pad: Pad, color: Color) -> Option<()>
Source§fn iter(&self) -> CanvasIterator ⓘ
fn iter(&self) -> CanvasIterator ⓘ
Source§fn toggle(&mut self, pad: Pad, color: Color) -> Option<()>
fn toggle(&mut self, pad: Pad, color: Color) -> Option<()>
Source§fn clear(&mut self)where
Self: Sized,
fn clear(&mut self)where
Self: Sized,
Source§fn into_padded(self) -> PaddingCanvas<Self>where
Self: Sized,
fn into_padded(self) -> PaddingCanvas<Self>where
Self: Sized,
PaddingCanvas for more details