Module sequence

Module sequence 

Source
Expand description

An atom containing a sequence of time-stamped events.

These events are atoms again. Atoms passed in a sequence can be handled with frame-perfect timing and therefore is the prefered way to transmit events like MIDI messages. However, MIDI messages are implemented in separate crate.

§Example

use lv2_core::prelude::*;
use lv2_units::prelude::*;
use lv2_atom::prelude::*;
use lv2_atom::sequence::*;
use urid::*;

#[derive(PortCollection)]
struct MyPorts {
    input: InputPort<AtomPort>,
    output: OutputPort<AtomPort>,
}

#[derive(URIDCollection)]
struct MyURIDs {
    atom: AtomURIDCollection,
    units: UnitURIDCollection,
}

/// Something like a plugin's run method.
fn run(ports: &mut MyPorts, urids: &MyURIDs) {
    // Get the read handle to the sequence.
    // The reading method needs the URID of the BPM unit to tell if the time stamp
    // is measured in beats or in frames. If the atom doesn't says that it's measured
    // in beats, it is assumed that it is measured in frames.
    let input_sequence: SequenceIterator = ports.input.read(
        urids.atom.sequence,
        urids.units.beat
    ).unwrap();

    // Get the write handle to the sequence.
    // You have to provide the unit of the time stamps.
    let mut output_sequence: SequenceWriter = ports.output.init(
        urids.atom.sequence,
        TimeStampURID::Frames(urids.units.frame)
    ).unwrap();

    // Iterate through all events in the input sequence.
    //
    // The specifications don't require the time stamps to be monotonic, your algorithms should
    // be able to handle older events written after younger events.
    //
    // The sequence writer, however, assures that the written time stamps are monotonic.
    for event in input_sequence {
        // An event contains a timestamp and an atom.
        let (timestamp, atom): (TimeStamp, UnidentifiedAtom) = event;
        // If the read atom is a 32-bit integer...
        if let Some(integer) = atom.read(urids.atom.int, ()) {
            // Multiply it by two and write it to the sequence.
            output_sequence.init(timestamp, urids.atom.int, integer * 2).unwrap();
        } else {
            // Forward the atom to the sequence without a change.
            output_sequence.forward(timestamp, atom).unwrap();
        }
    }
}

§Specification

http://lv2plug.in/ns/ext/atom/atom.html#Sequence

Structs§

Sequence
An atom containing a sequence of time-stamped events.
SequenceIterator
An iterator over all events in a sequence.
SequenceWriter
The writing handle for sequences.

Enums§

TimeStamp
An event time stamp.
TimeStampURID
The measuring units of time stamps, with their URIDs.
TimeStampUnit
The measuring units of time stamps.