Skip to main content

Crate clasp_client

Crate clasp_client 

Source
Expand description

§CLASP Client Library

High-level async client for the CLASP (Creative Low-Latency Application Streaming Protocol).

This crate provides a Rust client for connecting to CLASP routers, enabling real-time communication between creative applications such as lighting controllers, audio mixers, VJ software, and more.

§Features

  • Async/await: Built on Tokio for efficient async I/O
  • Builder pattern: Flexible client configuration
  • Subscriptions: Pattern-based subscriptions with callbacks
  • Parameters: Get/set persistent values with caching
  • Events: Fire-and-forget event emission
  • Streams: High-rate data streaming (QoS fire)
  • Bundles: Atomic multi-message operations
  • Time sync: Automatic clock synchronization with server

§Quick Start

use clasp_client::Clasp;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Connect using builder pattern
    let client = Clasp::builder("ws://localhost:7330")
        .name("my-app")
        .features(vec!["param", "event", "stream"])
        .connect()
        .await?;

    println!("Connected! Session: {:?}", client.session_id());

    // Subscribe to changes with wildcard patterns
    client.subscribe("/lumen/scene/*/layer/*/opacity", |value, address| {
        println!("{} = {:?}", address, value);
    }).await?;

    // Set a parameter value
    client.set("/lumen/scene/0/layer/0/opacity", 0.75).await?;

    // Emit an event (with map value)
    client.emit("/cue/trigger", clasp_core::Value::Map(Default::default())).await?;

    // Stream high-rate data
    for i in 0..100 {
        let value = (i as f64 / 100.0).sin();
        client.stream("/sensor/value", value).await?;
        tokio::time::sleep(std::time::Duration::from_millis(10)).await;
    }

    Ok(())
}

§Address Patterns

CLASP uses hierarchical addresses similar to OSC:

  • /namespace/category/instance/property
  • /lumen/scene/0/layer/3/opacity
  • /midi/launchpad/cc/74

Wildcard patterns for subscriptions:

  • * - matches exactly one segment: /path/*/value matches /path/foo/value
  • ** - matches any number of segments: /path/** matches /path/a/b/c

§Signal Types

TypeUse CasePersistenceQoS
set()Parameters with statePersistedConfirm
emit()One-shot eventsNot persistedConfirm
stream()High-rate sensor dataNot persistedFire
gesture()Touch/pen/motion inputPhase onlyFire

§Error Handling

All async methods return Result<T, ClientError>. Common errors:

  • ClientError::NotConnected - Operation requires active connection
  • ClientError::SendFailed - Message could not be sent
  • ClientError::Timeout - Operation timed out

§Crate Features

  • p2p - Enable peer-to-peer mesh networking support

Re-exports§

pub use builder::ClaspBuilder;
pub use client::Clasp;
pub use error::ClientError;
pub use error::Result;

Modules§

builder
Client builder pattern
client
Main Clasp client implementation
error
Client error types
prelude
Prelude for convenient imports

Structs§

TimelineData
Timeline automation message Immutable once published - to modify, publish a new timeline
TimelineKeyframe
A keyframe in a timeline

Enums§

EasingType
Easing functions for timeline interpolation
GesturePhase
Gesture phases