Interval

Struct 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) -> <Note as Add<Interval>>::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)));
Source§

type Output = Note

The resulting type after applying the + operator.
Source§

impl Add<Interval> for PitchClass

Source§

fn add(self, rhs: Interval) -> <PitchClass as Add<Interval>>::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));
Source§

type Output = PitchClass

The resulting type after applying the + operator.
Source§

impl Add for Interval

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Interval) -> <Interval as Add>::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: Interval)

Performs the += operation. Read more
Source§

impl Clone for Interval

Source§

fn clone(&self) -> Interval

Returns a duplicate 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<(), Error>

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<'de> Deserialize<'de> for Interval

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Interval, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Element for Interval

Source§

fn wrapped_element(&self) -> Option<&(dyn Element + 'static)>

None.
Source§

impl Hash for Interval

Source§

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

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,

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

impl PartialEq for Interval

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Interval

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<Interval> for Note

Source§

fn sub(self, rhs: Interval) -> <Note as Sub<Interval>>::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)));
Source§

type Output = Note

The resulting type after applying the - operator.
Source§

impl Sub<Interval> for PitchClass

Source§

fn sub(self, rhs: Interval) -> <PitchClass as Sub<Interval>>::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));
Source§

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>(iter: I) -> Interval
where I: Iterator<Item = Interval>,

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> AsAny for T
where T: Element,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts this to a [&dyn Any].
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoSegment for T
where T: Element,

Source§

fn into_segment(self, timing: impl Into<Timing>) -> Segment

Creates a Segment from this element, spanning the given time range.

Source§

fn over(self, timing: impl Into<Timing>) -> Segment

Creates a Segment from this element, spanning the given time range.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,