Skip to main content

Interval

Struct Interval 

Source
pub struct Interval { /* private fields */ }
Expand description

A directed musical interval with diatonic spelling and chromatic size.

Implementations§

Source§

impl Interval

Source

pub fn from_diatonic_and_chromatic( diatonic: DiatonicInterval, chromatic: ChromaticInterval, ) -> Result<Interval>

Builds an interval from its two halves as given, without checking that they agree: music21’s Interval(diatonic=..., chromatic=...).

Source

pub fn from_diatonic(diatonic: DiatonicInterval) -> Result<Self>

Builds an interval from a diatonic interval alone, deriving the semitone count: music21’s Interval(diatonic=...).

Source

pub fn from_chromatic(chromatic: ChromaticInterval) -> Result<Self>

Builds an interval from a semitone count alone, spelling it the simplest way and marking the spelling as implicit: music21’s Interval(chromatic=...).

Source

pub fn generic(&self) -> &GenericInterval

The generic half of the interval.

Source

pub fn diatonic(&self) -> &DiatonicInterval

The diatonic half of the interval: quality plus generic size.

Source

pub fn chromatic(&self) -> &ChromaticInterval

The chromatic half of the interval: the semitone count.

Source

pub fn specifier(&self) -> Specifier

The quality.

Source

pub fn from_generic_and_chromatic( generic: IntegerType, semitones: IntegerType, ) -> Result<Self>

Builds an interval from a generic size and a semitone count: music21’s intervalFromGenericAndChromatic, so a third of four semitones is a major third and a fifth of six a diminished fifth. Negative values give a descending interval.

Source

pub fn pitch_start(&self) -> Option<&Pitch>

The pitch the interval was measured from, when it was built from two pitches or notes.

Source

pub fn pitch_end(&self) -> Option<&Pitch>

The pitch the interval was measured to, when it was built from two pitches or notes.

Source

pub fn note_start(&self) -> Option<Note>

Self::pitch_start as a note without a duration.

Source

pub fn note_end(&self) -> Option<Note>

Self::pitch_end as a note without a duration.

Source

pub fn from_name(name: impl Into<String>) -> Result<Self>

Parses an interval name such as "M3", "P5", or "-m6".

Source

pub fn from_semitones(semitones: IntegerType) -> Result<Self>

Creates an implicit diatonic interval from a chromatic semitone count.

Source

pub fn between_pitches(start: &Pitch, end: &Pitch) -> Result<Self>

Returns the directed interval from start to end.

Source

pub fn between_notes(start: &Note, end: &Note) -> Result<Self>

Returns the directed interval from start to end.

Source

pub fn semitones(&self) -> FloatType

Returns the directed chromatic size in semitones, fractional for a microtonal interval.

Source

pub fn whole_semitones(&self) -> IntegerType

Returns the directed chromatic size rounded to whole semitones.

Source

pub fn direction(&self) -> IntervalDirection

Returns the directed interval direction.

Source

pub fn name(&self) -> String

Returns the human-readable interval name, such as "Major Third".

Source

pub fn generic_number(&self) -> IntegerType

Returns the simple or compound generic interval number.

Source

pub fn is_implicit_diatonic(&self) -> bool

Returns true when the interval was inferred from semitones only.

Source

pub fn inversion(&self) -> Result<Self>

Returns the complementary interval inversion.

Source

pub fn reversed(&self) -> Result<Self>

Returns the same interval in the opposite direction.

Source

pub fn pythagorean_ratio(&self) -> Result<FractionType>

Returns the Pythagorean tuning ratio for this interval.

The ratio is expressed as a rational fraction built from pure fifths, matching the helper music21 uses for enharmonic scoring.

Source

pub fn transpose_pitch(&self, pitch: &Pitch) -> Result<Pitch>

Transposes a pitch by this interval.

Source

pub fn transpose_note(&self, note: &Note) -> Result<Note>

Transposes a note by this interval.

Source

pub fn short_name(&self) -> String

Returns music21’s compact undirected name, such as "P5" or "m3".

Source

pub fn simple_name(&self) -> String

Returns the compact name folded into one octave, so a ninth is "M2".

Source

pub fn semi_simple_name(&self) -> String

Returns the compact name folded into one octave, except that octaves stay 8 rather than becoming unisons.

Source

pub fn directed_name(&self) -> String

Returns the compact name with music21’s direction sign, such as "m-6".

Source

pub fn is_diatonic_step(&self) -> bool

Returns whether this is a second of any quality.

Source

pub fn is_chromatic_step(&self) -> bool

Returns whether this spans exactly one semitone.

Source

pub fn is_step(&self) -> bool

Returns whether this is a step diatonically or chromatically.

Source

pub fn is_skip(&self) -> bool

Returns whether this is larger than a second. Unisons are neither steps nor skips.

Source

pub fn is_consonant(&self) -> bool

Returns whether this is a common-practice consonance: a perfect unison or fifth, or a major or minor third or sixth, in any octave.

Source

pub fn complement(&self) -> Result<Self>

Returns the interval that completes this one to an octave, so a major third becomes a minor sixth and an octave becomes a unison.

Source

pub fn interval_class(&self) -> IntegerType

Returns the interval class, the smaller of the semitone count within an octave and its complement, from 0 to 6.

Source

pub fn sum<'a>( intervals: impl IntoIterator<Item = &'a Interval>, ) -> Result<Self>

Adds intervals end to end, as music21’s interval.add does.

Direction matters: a perfect fifth followed by a descending perfect fourth is a major second.

Source

pub fn difference<'a>( intervals: impl IntoIterator<Item = &'a Interval>, ) -> Result<Self>

Subtracts every following interval from the first, as music21’s interval.subtract does.

Source

pub fn directed_simple_name(&self) -> String

Returns the compact name folded into one octave but keeping the direction sign, such as "A-6" for a descending augmented thirteenth.

Source

pub fn semi_simple_nice_name(&self) -> String

The spelled-out name with compound intervals folded to an octave at most: music21’s semiSimpleNiceName, so a ninth is Minor Second but an octave stays Perfect Octave.

Source

pub fn simple_nice_name(&self) -> String

The spelled-out name within one octave: music21’s simpleNiceName, so both a ninth and a sixteenth are Major Second and an octave is a Perfect Unison.

Source

pub fn directed_nice_name(&self) -> String

The spelled-out name with its direction: music21’s directedNiceName, Descending Major Third.

Source

pub fn directed_simple_nice_name(&self) -> String

Self::simple_nice_name with its direction: music21’s directedSimpleNiceName.

Source

pub fn directed_semi_simple_nice_name(&self) -> String

Self::semi_simple_nice_name with its direction: music21’s directedSemiSimpleNiceName.

Source

pub fn specific_name(&self) -> String

The specifier spelled out on its own: music21’s specificName, Doubly-Diminished for dd5.

Source

pub fn cents(&self) -> FloatType

The chromatic size in cents, signed.

Source

pub fn diatonic_interval_cent_shift(&self) -> FloatType

How far the chromatic size runs past the diatonic spelling, in cents: music21’s _diatonicIntervalCentShift, -50.0 for the augmented unison between C1 and a C1 half-sharp.

Source

pub fn is_unison(&self) -> bool

Whether the generic interval is a unison, whatever its quality.

Source

pub fn is_perfectable(&self) -> bool

Whether the generic interval takes perfect rather than major and minor qualities: unisons, fourths, fifths and their compounds.

Source

pub fn staff_distance(&self) -> IntegerType

The signed number of staff steps: music21’s generic.staffDistance, 0 for a unison, 2 for a third and -4 for a descending fifth.

Source

pub fn mod7(&self) -> IntegerType

The simple generic size from one to seven, with descending intervals inverted: music21’s generic.mod7, so a descending third is 6.

Source

pub fn mod7_inversion(&self) -> IntegerType

The generic size of the inversion within an octave: music21’s generic.mod7inversion, 6 for a third and 1 for an octave.

Source

pub fn mod12(&self) -> IntegerType

The semitones reduced to a pitch class, 0 to 11: music21’s chromatic.mod12, so a descending major third is 8.

Source

pub fn transpose_pitch_with_options( &self, p: &Pitch, reverse: bool, max_accidental: Option<IntegerType>, ) -> Result<Pitch>

Moves a pitch by the interval the way music21’s transposePitch does, with its keyword arguments: reverse transposes by the reversed interval, and max_accidental respells any result carrying more accidentals than that (music21’s default is Some(4)), None meaning no limit.

Source

pub fn transpose_pitch_in_place(&self, pitch: &mut Pitch) -> Result<()>

Transposes a pitch in place by this interval.

Trait Implementations§

Source§

impl Clone for Interval

Source§

fn clone(&self) -> Interval

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<'de> Deserialize<'de> for Interval

Available on crate feature serde only.
Source§

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

Deserialize this value from the given Serde deserializer. 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 From<Interval> for ParallelRequirement

Source§

fn from(interval: Interval) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Interval

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(value: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Interval

Source§

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

Two intervals are the same when they are the same written distance and the same sounding one, which is music21’s own comparison — the pitches an interval was built between are not part of what it is.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Interval

Available on crate feature serde only.
Source§

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

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

impl TryFrom<&str> for Interval

Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<String> for Interval

Source§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<i32> for Interval

Source§

type Error = Error

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

fn try_from(value: IntegerType) -> Result<Self>

Performs the conversion.

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.