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: boolWhether 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
impl StreamSearcher
Sourcepub fn new(search: Vec<SearchTerm>) -> Self
pub fn new(search: Vec<SearchTerm>) -> Self
A search for these terms, of the stream’s own elements, by the wildcard algorithm alone.
Trait Implementations§
Source§impl Clone for StreamSearcher
impl Clone for StreamSearcher
Auto Trait Implementations§
impl Freeze for StreamSearcher
impl RefUnwindSafe for StreamSearcher
impl Send for StreamSearcher
impl Sync for StreamSearcher
impl Unpin for StreamSearcher
impl UnsafeUnpin for StreamSearcher
impl UnwindSafe for StreamSearcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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