pub struct PitchClassMask(/* private fields */);Expand description
A bitmask over the twelve pitch classes, with bit n set when pitch class n
is present.
The low twelve bits represent pitch classes C through B.
§Examples
use sim_lib_pitch_core::PitchClass;
use sim_lib_pitch_set::PitchClassMask;
let triad = PitchClassMask::from_pitch_classes(&[PitchClass::C, PitchClass::E, PitchClass::G]);
assert_eq!(triad.count_bits(), 3);Implementations§
Source§impl PitchClassMask
impl PitchClassMask
Sourcepub fn new(bits: u16) -> Result<Self, PitchSetError>
pub fn new(bits: u16) -> Result<Self, PitchSetError>
Builds a pitch-class mask, rejecting any bits outside the low twelve.
Sourcepub fn from_pitch_classes(pitch_classes: &[PitchClass]) -> Self
pub fn from_pitch_classes(pitch_classes: &[PitchClass]) -> Self
Builds a mask from a slice of pitch classes; duplicates collapse to one bit.
Sourcepub fn pitch_classes(self) -> Vec<PitchClass>
pub fn pitch_classes(self) -> Vec<PitchClass>
Returns the set pitch classes in ascending order.
Sourcepub fn rotate(self, semitones: i32) -> Self
pub fn rotate(self, semitones: i32) -> Self
Returns this mask transposed by semitones, wrapping within the octave.
Sourcepub fn invert(self, axis: PitchClass) -> Self
pub fn invert(self, axis: PitchClass) -> Self
Returns this mask inverted about axis.
Sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Returns the rotation of this mask with the smallest numeric value, a transposition-invariant normal form.
Sourcepub fn count_bits(self) -> u32
pub fn count_bits(self) -> u32
Returns the number of pitch classes in the set (the population count).
Sourcepub fn interval_vector(self) -> IntervalVector
pub fn interval_vector(self) -> IntervalVector
Returns the IntervalVector tallying interval classes among the set’s
pitch classes.
Trait Implementations§
Source§impl Clone for PitchClassMask
impl Clone for PitchClassMask
Source§fn clone(&self) -> PitchClassMask
fn clone(&self) -> PitchClassMask
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for PitchClassMask
Source§impl Debug for PitchClassMask
impl Debug for PitchClassMask
Source§impl Default for PitchClassMask
impl Default for PitchClassMask
Source§fn default() -> PitchClassMask
fn default() -> PitchClassMask
Returns the “default value” for a type. Read more
impl Eq for PitchClassMask
Source§impl Hash for PitchClassMask
impl Hash for PitchClassMask
Source§impl PartialEq for PitchClassMask
impl PartialEq for PitchClassMask
impl StructuralPartialEq for PitchClassMask
Auto Trait Implementations§
impl Freeze for PitchClassMask
impl RefUnwindSafe for PitchClassMask
impl Send for PitchClassMask
impl Sync for PitchClassMask
impl Unpin for PitchClassMask
impl UnsafeUnpin for PitchClassMask
impl UnwindSafe for PitchClassMask
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