Skip to main content

StreamSearcher

Struct StreamSearcher 

Source
pub struct StreamSearcher {
    pub search: Vec<SearchTerm>,
    pub recurse: bool,
    pub filter: Option<Filter>,
    pub algorithms: Vec<Algorithm>,
}
Expand description

Searches a stream for runs of elements matching a list of terms, the terms compared by a list of algorithms: music21’s StreamSearcher. A run matches unless an algorithm says one of its elements does not; with only the wildcard algorithm, as it starts, every run matches.

use music21_rs::duration::Duration;
use music21_rs::note::Note;
use music21_rs::search::{Algorithm, Filter, SearchTerm, StreamSearcher};
use music21_rs::stream::StreamElement;
use music21_rs::tinynotation::from_tiny_notation;

let line = from_tiny_notation("3/4 c4. d8 e4 g4. a8 f4 c'8 d'4.")?;
let mut searcher = StreamSearcher::new(vec![
    SearchTerm::Element(StreamElement::Note(
        Note::from_name("C4")?.with_duration(Duration::new(1.5)?),
    )),
    SearchTerm::Element(StreamElement::Note(
        Note::from_name("C4")?.with_duration(Duration::new(0.5)?),
    )),
]);
searcher.recurse = true;
searcher.filter = Some(Filter::Notes);
searcher.algorithms.push(Algorithm::Rhythm);
let found = searcher.run(&line)?;
assert_eq!(found.iter().map(|found| found.index).collect::<Vec<_>>(), [0, 3]);

Fields§

§search: Vec<SearchTerm>

What to look for, in order.

§recurse: bool

Whether to look inside the streams the stream holds.

§filter: Option<Filter>

Which elements to look at; all of them for none.

§algorithms: Vec<Algorithm>

How to compare, in order, each asked until one answers.

Implementations§

Source§

impl StreamSearcher

Source

pub fn new(search: Vec<SearchTerm>) -> Self

A search for these terms, of the stream’s own elements, by the wildcard algorithm alone.

Source

pub fn run<'a>(&self, stream: &'a Stream) -> Result<Vec<SearchMatch<'a>>>

The runs of a stream’s elements that match: music21’s run.

§Errors

Nothing to search for.

Source

pub fn run_over<'a>( &self, elements: &[Searched<'a>], ) -> Result<Vec<SearchMatch<'a>>>

The runs of these elements that match: music21’s run of a stream iterator.

§Errors

Nothing to search for.

Trait Implementations§

Source§

impl Clone for StreamSearcher

Source§

fn clone(&self) -> Self

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 StreamSearcher

Source§

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

Formats the value using the given formatter. 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> 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.