Skip to main content

Stream

Struct Stream 

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

An ordered stream of music, which may hold other streams.

Implementations§

Source§

impl Stream

Source

pub fn new() -> Self

Creates an empty stream.

Source

pub fn with_kind(kind: StreamKind) -> Self

Creates an empty stream standing for one of music21’s subclasses.

Source

pub fn kind(&self) -> StreamKind

Which of music21’s Stream subclasses this stands for.

Source

pub fn set_kind(&mut self, kind: StreamKind)

Sets which subclass this stands for.

Source

pub fn from_events(events: impl IntoIterator<Item = StreamEvent>) -> Self

Creates a stream from events, sorted by offset.

Source

pub fn insert(&mut self, offset: FloatType, element: impl Into<StreamElement>)

Inserts an element at a quarter-length offset.

Source

pub fn push(&mut self, element: impl Into<StreamElement>)

Appends an element after the current end of the stream.

Source

pub fn events_mut(&mut self) -> &mut [StreamEvent]

Returns immutable events in offset order.

Source

pub fn events(&self) -> &[StreamEvent]

The events in offset order.

Source

pub fn iter(&self) -> impl Iterator<Item = &StreamEvent>

Iterates over events in offset order.

Source

pub fn len(&self) -> usize

How many events this stream holds directly, not counting what any nested stream holds.

Source

pub fn is_empty(&self) -> bool

Whether this stream holds nothing at all.

Source

pub fn flatten(&self) -> Self

One timeline with the nesting dissolved: music21’s flatten.

Each nested stream’s offset is added to its contents’, and the streams themselves are gone; everything else comes through in offset order.

Source

pub fn recurse(&self) -> Vec<(FloatType, &StreamElement)>

Every element at its offset from this stream’s start, nested streams themselves included: music21’s recurse.

Source

pub fn streams_of_kind(&self, kind: StreamKind) -> Vec<&Stream>

The streams of one kind held directly by this one: music21’s .parts on a score, .measures on a part, .voices on a measure.

Source

pub fn parts(&self) -> Vec<&Stream>

The parts this stream holds.

Source

pub fn measures(&self) -> Vec<&Stream>

The measures this stream holds.

Source

pub fn voices(&self) -> Vec<&Stream>

The voices this stream holds.

Source

pub fn notes(&self) -> Vec<(FloatType, StreamElement)>

Every note and chord on the flattened timeline: music21’s flatten().notes, which leaves rests out.

Source

pub fn end_offset(&self) -> FloatType

Returns the maximum event end offset, a nested stream’s own length included.

Source

pub fn pitches(&self) -> Vec<Pitch>

Returns all pitches in timeline order, from nested streams too.

Source

pub fn key_signature_at(&self, offset: FloatType) -> Option<KeySignature>

The key signature in force at an offset: the last one written at or before it, anywhere in the nesting.

This is what music21 answers with getContextByClass(KeySignature), found by looking back along the flattened timeline rather than by walking the sites an object belongs to.

Source

pub fn time_signature_at(&self, offset: FloatType) -> Option<TimeSignature>

The metre in force at an offset, found the same way.

Source

pub fn metronome_mark_at(&self, offset: FloatType) -> Option<MetronomeMark>

The tempo in force at an offset, found the same way.

Source

pub fn transpose(&self, interval: &Interval) -> Result<Self>

Returns a transposed copy, nesting and all.

Trait Implementations§

Source§

impl Clone for Stream

Source§

fn clone(&self) -> Stream

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stream

Source§

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

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

impl Default for Stream

Source§

fn default() -> Stream

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Stream

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Stream> for StreamElement

Source§

fn from(value: Stream) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a Stream

Source§

type Item = &'a StreamEvent

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, StreamEvent>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Serialize for Stream

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.