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

source

pub const MAX: Self = _

The biggest valid interval.

source

pub const MIN: Self = _

The smallest valid interval.

source

pub const SEMI: Self = _

One semi tone

source

pub const WHOLE: Self = _

One whole tone

source

pub const FLAT2: Self = _

The interval equivalent of two flats on a note.

source

pub const FLAT: Self = _

The interval equivalent of a flat on a note.

source

pub const NAT: Self = _

The interval equivelant of a natural accidental.

source

pub const SHARP: Self = _

The interval equivelant of a sharp on a note.

source

pub const SHARP2: Self = _

The interval equivalent of two sharps on a note.

source

pub const ROOT: Self = _

The root interval, a distance of zero..

source

pub const MIN2: Self = _

Minor second.

source

pub const MAJ2: Self = _

Major second.

source

pub const MIN3: Self = _

Minor third.

source

pub const MAJ3: Self = _

Major third.

source

pub const PER4: Self = _

Perfect fourth.

source

pub const TRIT: Self = _

Tritone.

source

pub const PER5: Self = _

Perfect fifth.

source

pub const MIN6: Self = _

Minor sixth.

source

pub const MAJ6: Self = _

Major sixth.

source

pub const MIN7: Self = _

Minor seventh.

source

pub const MAJ7: Self = _

Major seventh.

source

pub const OCTAVE: Self = _

Octave.

source

pub const MIN9: Self = _

Minor nineth.

source

pub const MAJ9: Self = _

Major nineth.

source

pub const AUG9: Self = _

Augmented nineth.

source

pub const MIN11: Self = _

Minor eleventh.

source

pub const MAJ11: Self = _

Major eleventh.

source

pub const AUG11: Self = _

Augmented eleventh.

source

pub const PER12: Self = _

Perfect twelve, octave equivalent of a perfect fifth.

source

pub const MIN13: Self = _

Minor thirteenth.

source

pub const MAJ13: Self = _

Major thirteenth.

source

pub const AUG13: Self = _

Augmented thirteenth.

source

pub const DIM2: Self = _

Diminished second, octave equivalent of the root.

source

pub const AUG1: Self = _

Augmented first, octave equivalent of a minor second.

source

pub const DIM3: Self = _

Diminished third, octave equivalent of a major second.

source

pub const AUG2: Self = _

Augmented second, octave equivalent of a minor third.

source

pub const DIM4: Self = _

Diminished fourth, octave equivalent of a major third.

source

pub const AUG3: Self = _

Augmented third, octave equivalent of a perfect fourth.

source

pub const DIM5: Self = _

Diminished fifth, octave equivalent of a tritone.

source

pub const AUG4: Self = _

Augmented fourth, octave equivalent of a tritone.

source

pub const DIM6: Self = _

Diminished sixth, octave equivalent of a perfect fifth.

source

pub const AUG5: Self = _

Augmented fifth, octave equivalent of a minor sixth.

source

pub const DIM7: Self = _

Diminished seventh, octave equivalent of a major sixth.

source

pub const AUG6: Self = _

Augmented sixth, octave equivalent of a minor seventh.

source

pub const DIM8: Self = _

Diminished eight, octave equivalent of a major seventh.

source

pub const AUG7: Self = _

Augmented seventh, octave equivalent of an octave.

source

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));
source

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)
source

pub fn abs(self) -> Self

Returns the absolute value of the interval.

Example:

use music_theory::theory::*;
assert_eq!(Interval::FLAT2.abs(), Interval::SHARP2);
source

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);
source

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 Add for Interval

§

type Output = Interval

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign for Interval

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl AddInterval for Interval

source§

fn add_interval(self, interval: Interval) -> Option<Self>

Add an Interval.
source§

impl Clone for Interval

source§

fn clone(&self) -> Interval

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Interval

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Interval

source§

fn default() -> Interval

Returns the “default value” for a type. Read more
source§

impl Display for Interval

source§

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

Formats the value using the given formatter. Read more
source§

impl GeneratablePartialOrder for Interval

source§

fn next(self) -> Option<Interval>

Generate the next item.
source§

fn prev(self) -> Option<Interval>

Generate the previous item.
source§

impl Hash for Interval

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Neg for Interval

§

type Output = Interval

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl OctaveShiftable for Interval

source§

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

Have the value with everything the same except shift the octave from the current one with the given shift.
source§

impl Ord for Interval

source§

fn cmp(&self, other: &Interval) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Interval

source§

fn eq(&self, other: &Interval) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Interval

source§

fn partial_cmp(&self, other: &Interval) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl RangeBounds<Interval> for Interval

source§

fn start_bound(&self) -> Bound<&Self>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&Self>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl Sub for Interval

§

type Output = Interval

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign for Interval

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl ToNamedInterval for Interval

source§

fn to_named_interval_try(self) -> Option<NamedInterval>

Try to convert to NamedInterval.
source§

fn to_named_interval_mod(self) -> NamedInterval

Convert to NamedInterval with wrapping around the octaves.
source§

impl ToNamedOctaveInterval for Interval

source§

impl Wrapper for Interval

§

type Inner = i32

The type the new type wraps.
source§

fn wrap(interval: Self::Inner) -> Option<Self>

Try to wrap a Self::Inner type into the Self type.
source§

fn unwrap(self) -> Self::Inner

Unwrap a Self type into a Self::Inner type.
source§

impl Copy for Interval

source§

impl Eq for Interval

source§

impl StructuralPartialEq for Interval

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> 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> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.