Struct redact_composer_musical::Interval

source ·
pub struct Interval(pub u8);
Expand description

A pitch difference, measured in half-steps/semitones.

Tuple Fields§

§0: u8

Implementations§

source§

impl Interval

source

pub const P1: Interval = _

Perfect Unison (0 semitones)

source

pub const m2: Interval = _

Minor 2nd (1 semitone)

source

pub const M2: Interval = _

Major 2nd (2 semitones)

source

pub const m3: Interval = _

Minor 3rd (3 semitones)

source

pub const M3: Interval = _

Major 3rd (4 semitones)

source

pub const P4: Interval = _

Perfect 4th (5 semitones)

source

pub const TT: Interval = _

Tritone (6 semitones)

source

pub const A4: Interval = _

Augmented 4th (6 semitones)

source

pub const d5: Interval = _

Diminished 5th (6 semitones)

source

pub const P5: Interval = _

Perfect 5th (7 semitones)

source

pub const m6: Interval = _

Minor 6th (8 semitones)

source

pub const A5: Interval = _

Augmented 5th (8 semitones)

source

pub const M6: Interval = _

Major 6th (9 semitones)

source

pub const d7: Interval = _

Diminished 7th (9 semitones)

source

pub const m7: Interval = _

Minor 7th (10 semitones)

source

pub const M7: Interval = _

Major 7th (11 semitones)

source

pub const P8: Interval = _

Perfect 8th (12 semitones)

source

pub const Octave: Interval = Self::P8

Octave (12 semitones)

source

pub const m9: Interval = _

Minor 9th (13 semitones)

source

pub const M9: Interval = _

Major 9th (13 semitones)

source

pub const m10: Interval = _

Minor 10th (15 semitones)

source

pub const M10: Interval = _

Major 10th (16 semitones)

source

pub const P11: Interval = _

Perfect 11th (17 semitones)

source

pub const P12: Interval = _

Perfect 12th (19 semitones)

source

pub const m13: Interval = _

Minor 13th (20 semitones)

source

pub const M13: Interval = _

Major 13th (21 semitones)

source

pub fn is_simple(&self) -> bool

Returns true if this is a simple interval (up to one octave).

assert!(Interval::P5.is_simple());
source

pub fn to_simple(self) -> Interval

Return the simple interval counterpart. Note: This function will reduce Interval::Octave to Interval::P1.

assert_eq!(Interval::m9.to_simple(), Interval::m2);
source

pub fn is_compound(&self) -> bool

Returns true if this is a compound interval (larger than one octave).

assert!(Interval::m9.is_compound());
source

pub fn to_compound(self) -> Interval

Return the compound interval counterpart (added octave). Does nothing if the interval is already compound.

assert_eq!(Interval::m2.to_compound(), Interval::m9);
source

pub fn inversion(&self) -> Interval

Returns the interval’s inversion.

assert_eq!(Interval::P5.inversion(), Interval::P4);

Trait Implementations§

source§

impl Add<Interval> for Note

source§

fn add(self, rhs: Interval) -> Self::Output

Adds an interval to this note, resulting in another note.

use redact_composer_musical::{Interval as I, Note, NoteName::{C, G}};

let c3 = Note::from((C, 4));
assert_eq!(c3, Note(60));
assert_eq!(c3 + I::P5, Note::from((G, 4)));
§

type Output = Note

The resulting type after applying the + operator.
source§

impl Add<Interval> for PitchClass

source§

fn add(self, rhs: Interval) -> Self::Output

Returns the pitch class a given interval above this.

use redact_composer_musical::{Interval as I, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(C) + I::P5, PitchClass::from(G));
assert_eq!(PitchClass::from(C) + I::Octave, PitchClass::from(C));
§

type Output = PitchClass

The resulting type after applying the + operator.
source§

impl Add for Interval

§

type Output = Interval

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<Interval> for Note

source§

fn add_assign(&mut self, rhs: Interval)

Performs the += operation. Read more
source§

impl AddAssign<Interval> for PitchClass

source§

fn add_assign(&mut self, rhs: Interval)

Performs the += operation. Read more
source§

impl AddAssign for Interval

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
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 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 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 Sub<Interval> for Note

source§

fn sub(self, rhs: Interval) -> Self::Output

Subtracts an interval from this note, resulting in another note.

use redact_composer_musical::{Interval as I, Note, NoteName::{C, G}};

let c3 = Note::from((C, 3));
assert_eq!(c3 - I::P4, Note::from((G, 2)));
§

type Output = Note

The resulting type after applying the - operator.
source§

impl Sub<Interval> for PitchClass

source§

fn sub(self, rhs: Interval) -> Self::Output

Returns the pitch class a given interval below this.

use redact_composer_musical::{Interval as I, NoteName::{C, F}, PitchClass};

assert_eq!(PitchClass::from(C) - I::P5, PitchClass::from(F));
assert_eq!(PitchClass::from(C) - I::Octave, PitchClass::from(C));
§

type Output = PitchClass

The resulting type after applying the - operator.
source§

impl SubAssign<Interval> for Note

source§

fn sub_assign(&mut self, rhs: Interval)

Performs the -= operation. Read more
source§

impl SubAssign<Interval> for PitchClass

source§

fn sub_assign(&mut self, rhs: Interval)

Performs the -= operation. Read more
source§

impl Sum for Interval

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
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, 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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V