Module simple

Source
Expand description

An opinionated abstraction for the lower level client and player API.

Requires the simple feature. All errors are printed to stderr, and the connection to the tracker will be automatically re-established as long as poll_events is called frequently enough.

§Usage

First, install a rocket tracker (original Qt editor or emoon’s OpenGL-based editor).

The Rocket type in this module compiles to different code depending on crate feature player. When the feature is not enabled, the Rocket type uses RocketClient internally. When player is enabled, the Rocket type uses RocketPlayer internally.

Enable the feature in your production’s Cargo.toml:

[features]
player = ["rust-rocket/player"]

[dependencies]
rust-rocket = { version = "0", features = ["simple"] }

And build your release accordingly:

cargo run                                 # Editing without player feature
cargo build --release --features player   # Release built with player feature

A main loop may look like this:

struct MusicPlayer; // Your music player, not included in this crate

fn main() {
    let mut music = MusicPlayer::new(/* ... */);
    let mut rocket = Rocket::new("tracks.bin", music.get_bpm()).unwrap();

    // Create window, render resources etc...

    loop {
        // Handle events from the rocket tracker
        while let Some(event) = rocket.poll_events().ok().flatten() {
            match event {
                Event::Seek(to) => music.seek(to),
                Event::Pause(state) => music.pause(state),
                Event::NotConnected => break,
            }
        }

        // Get current frame's time and keep the tracker updated
        let time = music.get_time();
        rocket.set_time(&time);

        // Read values with Rocket's get_value function while rendering the frame
        let _ = rocket.get_value("track0");
    }
}

For a more thorough example, see examples/simple.rs.

§Caveats

  • Can’t choose how to handle saving the tracks, this uses std::fs::File and bincode.
  • Sub-optimal performance, the implementation does not support caching tracks (only get_value, no get_track). It’s unlikely that this causes noticeable slowdown unless you have an abnormally large amount of tracks.
  • Caution: reconnection will wipe track state. Make sure to save in the editor before closing and reopening it.

§Benefits

  • Get started quickly!
  • Avoid writing #[cfg(...)]-attributes in your code.
  • Sensible error handling that you may want to write anyway if you’re not size-restricted.

Structs§

Rocket
Provides sync values.

Enums§

Event
An Event type.

Functions§

print_errors
Print an error and its sources to stderr. Prefixed with prefix: .
print_msg
Print a message to stderr. Prefixed with prefix: .