pub struct Sieve { /* private fields */ }Expand description
A parsed Xenakis sieve.
use music21_rs::Sieve;
// Every third semitone: a cycle of minor thirds.
let sieve = Sieve::parse("3@0")?;
assert_eq!(sieve.period(), 3);
assert_eq!(sieve.interval_widths()?, [3]);
// The major scale, as Xenakis would write it.
let major = Sieve::parse("(-3@2 & 4) | (-3@1 & 4@1) | (3@2 & 4@2) | (-3 & 4@3)")?;
assert_eq!(major.interval_widths()?, [2, 2, 1, 2, 2, 2, 1]);Implementations§
Source§impl Sieve
impl Sieve
Sourcepub fn parse(expression: &str) -> Result<Self>
pub fn parse(expression: &str) -> Result<Self>
Parses a sieve expression such as "3@0|4@1".
A bare modulus means a shift of zero, so "5" is "5@0". Whitespace is
ignored, {} and () both group, and & binds tighter than ^, which
binds tighter than | — matching music21, where 3@0|4@0&6@0 parses as
3@0|{4@0&6@0}.
Sourcepub fn contains(&self, z: IntegerType) -> bool
pub fn contains(&self, z: IntegerType) -> bool
Returns whether an integer is in the sieve.
Sourcepub fn period(&self) -> UnsignedIntegerType
pub fn period(&self) -> UnsignedIntegerType
Returns the period: the least common multiple of every modulus.
The sieve’s membership pattern repeats with this length.
Sourcepub fn segment(&self, low: IntegerType, high: IntegerType) -> Vec<IntegerType> ⓘ
pub fn segment(&self, low: IntegerType, high: IntegerType) -> Vec<IntegerType> ⓘ
Returns the members of the sieve in low..=high.
Sourcepub fn interval_widths(&self) -> Result<Vec<IntegerType>>
pub fn interval_widths(&self) -> Result<Vec<IntegerType>>
Returns the widths between consecutive members of one period.
This is music21’s PitchSieve.getIntervalSequence, in semitones: the
sieve is evaluated over 0..=period and the consecutive differences
taken. A sieve with fewer than two members in that window has no widths
and is an error, exactly as music21 raises for 3@1.
Trait Implementations§
impl Eq for Sieve
impl StructuralPartialEq for Sieve
Auto Trait Implementations§
impl Freeze for Sieve
impl RefUnwindSafe for Sieve
impl Send for Sieve
impl Sync for Sieve
impl Unpin for Sieve
impl UnsafeUnpin for Sieve
impl UnwindSafe for Sieve
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
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>
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>
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