Struct music_theory::theory::interval::Interval
source · pub struct Interval(/* private fields */);
Expand description
An interval is a distance between notes.
Example:
use music_theory::theory::*;
assert_eq!(Note::C2 - Note::A2, Interval::new(3));
Implementations§
source§impl Interval
impl Interval
sourcepub fn new(i: i32) -> Self
pub fn new(i: i32) -> Self
Create a new interval from an integer. Will be clamped if needed to ensure the interval is valid.
Example:
use music_theory::theory::*;
assert_eq!(Note::B2 - Note::A2, Interval::new(2));
sourcepub fn new_try(i: i32) -> Option<Self>
pub fn new_try(i: i32) -> Option<Self>
Create a new interval from an integer.
If the integer is out of range of valid intervals, it will return None
.
Example:
use music_theory::theory::*;
assert_eq!(Interval::new_try(7), Some(Interval::PER5));
assert_eq!(Interval::new_try((1 << 30) + 1), None)
sourcepub fn abs(self) -> Self
pub fn abs(self) -> Self
Returns the absolute value of the interval.
Example:
use music_theory::theory::*;
assert_eq!(Interval::FLAT2.abs(), Interval::SHARP2);
sourcepub fn abs_note(self) -> Note
pub fn abs_note(self) -> Note
Returns the absolute value of the interval inside a Note type.
Example:
use music_theory::theory::*;
assert_eq!(Interval::MIN3.abs_note(), note_interval::MIN3);
sourcepub fn to_string_nat(&self) -> String
pub fn to_string_nat(&self) -> String
Returns the interval spelled out in accidentals. Will spell the zero interval with a natural accidental.
Example:
use music_theory::theory::*;
assert_eq!(&Interval::FLAT2.to_string_nat(), "♭♭");
assert_eq!(&Interval::ROOT.to_string_nat(), "♮");
Trait Implementations§
source§impl AddAssign for Interval
impl AddAssign for Interval
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+=
operation. Read moresource§impl AddInterval for Interval
impl AddInterval for Interval
source§impl GeneratablePartialOrder for Interval
impl GeneratablePartialOrder for Interval
source§impl OctaveShiftable for Interval
impl OctaveShiftable for Interval
source§fn with_octave(self, octave: Octave) -> Self
fn with_octave(self, octave: Octave) -> Self
Have the value with everything the same except change the octave to the given one.
source§fn shift_octave(self, shift: OctaveShift) -> Self
fn shift_octave(self, shift: OctaveShift) -> Self
Have the value with everything the same except shift the octave from the current one with
the given shift.
source§impl Ord for Interval
impl Ord for Interval
source§impl PartialEq for Interval
impl PartialEq for Interval
source§impl PartialOrd for Interval
impl PartialOrd for Interval
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl RangeBounds<Interval> for Interval
impl RangeBounds<Interval> for Interval
source§impl SubAssign for Interval
impl SubAssign for Interval
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-=
operation. Read moresource§impl ToNamedInterval for Interval
impl ToNamedInterval for Interval
source§fn to_named_interval_try(self) -> Option<NamedInterval>
fn to_named_interval_try(self) -> Option<NamedInterval>
Try to convert to NamedInterval.
source§fn to_named_interval_mod(self) -> NamedInterval
fn to_named_interval_mod(self) -> NamedInterval
Convert to NamedInterval with wrapping around the octaves.
source§impl ToNamedOctaveInterval for Interval
impl ToNamedOctaveInterval for Interval
source§fn to_named_octave_interval_try(self) -> Option<NamedOctaveInterval>
fn to_named_octave_interval_try(self) -> Option<NamedOctaveInterval>
Try to convert to NamedOctaveInterval.
source§fn to_named_octave_interval_mod(self) -> NamedOctaveInterval
fn to_named_octave_interval_mod(self) -> NamedOctaveInterval
Convert to NamedOctaveInterval with wrapping around the octave.
impl Copy for Interval
impl Eq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl Freeze for Interval
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnwindSafe for Interval
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