pub struct Interval { /* private fields */ }Expand description
A directed musical interval with diatonic spelling and chromatic size.
Implementations§
Source§impl Interval
impl Interval
Sourcepub fn from_diatonic_and_chromatic(
diatonic: DiatonicInterval,
chromatic: ChromaticInterval,
) -> Result<Interval>
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=...).
Sourcepub fn from_diatonic(diatonic: DiatonicInterval) -> Result<Self>
pub fn from_diatonic(diatonic: DiatonicInterval) -> Result<Self>
Builds an interval from a diatonic interval alone, deriving the
semitone count: music21’s Interval(diatonic=...).
Sourcepub fn from_chromatic(chromatic: ChromaticInterval) -> Result<Self>
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=...).
Sourcepub fn generic(&self) -> &GenericInterval
pub fn generic(&self) -> &GenericInterval
The generic half of the interval.
Sourcepub fn diatonic(&self) -> &DiatonicInterval
pub fn diatonic(&self) -> &DiatonicInterval
The diatonic half of the interval: quality plus generic size.
Sourcepub fn chromatic(&self) -> &ChromaticInterval
pub fn chromatic(&self) -> &ChromaticInterval
The chromatic half of the interval: the semitone count.
Sourcepub fn from_generic_and_chromatic(
generic: IntegerType,
semitones: IntegerType,
) -> Result<Self>
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.
Sourcepub fn pitch_start(&self) -> Option<&Pitch>
pub fn pitch_start(&self) -> Option<&Pitch>
The pitch the interval was measured from, when it was built from two pitches or notes.
Sourcepub fn pitch_end(&self) -> Option<&Pitch>
pub fn pitch_end(&self) -> Option<&Pitch>
The pitch the interval was measured to, when it was built from two pitches or notes.
Sourcepub fn note_start(&self) -> Option<Note>
pub fn note_start(&self) -> Option<Note>
Self::pitch_start as a note without a duration.
Sourcepub fn note_end(&self) -> Option<Note>
pub fn note_end(&self) -> Option<Note>
Self::pitch_end as a note without a duration.
Sourcepub fn from_name(name: impl Into<String>) -> Result<Self>
pub fn from_name(name: impl Into<String>) -> Result<Self>
Parses an interval name such as "M3", "P5", or "-m6".
Sourcepub fn from_semitones(semitones: IntegerType) -> Result<Self>
pub fn from_semitones(semitones: IntegerType) -> Result<Self>
Creates an implicit diatonic interval from a chromatic semitone count.
Sourcepub fn between_pitches(start: &Pitch, end: &Pitch) -> Result<Self>
pub fn between_pitches(start: &Pitch, end: &Pitch) -> Result<Self>
Returns the directed interval from start to end.
Sourcepub fn between_notes(start: &Note, end: &Note) -> Result<Self>
pub fn between_notes(start: &Note, end: &Note) -> Result<Self>
Returns the directed interval from start to end.
Sourcepub fn semitones(&self) -> FloatType
pub fn semitones(&self) -> FloatType
Returns the directed chromatic size in semitones, fractional for a microtonal interval.
Sourcepub fn whole_semitones(&self) -> IntegerType
pub fn whole_semitones(&self) -> IntegerType
Returns the directed chromatic size rounded to whole semitones.
Sourcepub fn direction(&self) -> IntervalDirection
pub fn direction(&self) -> IntervalDirection
Returns the directed interval direction.
Sourcepub fn generic_number(&self) -> IntegerType
pub fn generic_number(&self) -> IntegerType
Returns the simple or compound generic interval number.
Sourcepub fn is_implicit_diatonic(&self) -> bool
pub fn is_implicit_diatonic(&self) -> bool
Returns true when the interval was inferred from semitones only.
Sourcepub fn pythagorean_ratio(&self) -> Result<FractionType>
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.
Sourcepub fn transpose_pitch(&self, pitch: &Pitch) -> Result<Pitch>
pub fn transpose_pitch(&self, pitch: &Pitch) -> Result<Pitch>
Transposes a pitch by this interval.
Sourcepub fn transpose_note(&self, note: &Note) -> Result<Note>
pub fn transpose_note(&self, note: &Note) -> Result<Note>
Transposes a note by this interval.
Sourcepub fn short_name(&self) -> String
pub fn short_name(&self) -> String
Returns music21’s compact undirected name, such as "P5" or "m3".
Sourcepub fn simple_name(&self) -> String
pub fn simple_name(&self) -> String
Returns the compact name folded into one octave, so a ninth is "M2".
Sourcepub fn semi_simple_name(&self) -> String
pub fn semi_simple_name(&self) -> String
Returns the compact name folded into one octave, except that octaves
stay 8 rather than becoming unisons.
Sourcepub fn directed_name(&self) -> String
pub fn directed_name(&self) -> String
Returns the compact name with music21’s direction sign, such as "m-6".
Sourcepub fn is_diatonic_step(&self) -> bool
pub fn is_diatonic_step(&self) -> bool
Returns whether this is a second of any quality.
Sourcepub fn is_chromatic_step(&self) -> bool
pub fn is_chromatic_step(&self) -> bool
Returns whether this spans exactly one semitone.
Sourcepub fn is_skip(&self) -> bool
pub fn is_skip(&self) -> bool
Returns whether this is larger than a second. Unisons are neither steps nor skips.
Sourcepub fn is_consonant(&self) -> bool
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.
Sourcepub fn complement(&self) -> Result<Self>
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.
Sourcepub fn interval_class(&self) -> IntegerType
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.
Sourcepub fn sum<'a>(
intervals: impl IntoIterator<Item = &'a Interval>,
) -> Result<Self>
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.
Sourcepub fn difference<'a>(
intervals: impl IntoIterator<Item = &'a Interval>,
) -> Result<Self>
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.
Sourcepub fn directed_simple_name(&self) -> String
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.
Sourcepub fn semi_simple_nice_name(&self) -> String
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.
Sourcepub fn simple_nice_name(&self) -> String
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.
Sourcepub fn directed_nice_name(&self) -> String
pub fn directed_nice_name(&self) -> String
The spelled-out name with its direction: music21’s directedNiceName,
Descending Major Third.
Sourcepub fn directed_simple_nice_name(&self) -> String
pub fn directed_simple_nice_name(&self) -> String
Self::simple_nice_name with its direction: music21’s
directedSimpleNiceName.
Sourcepub fn directed_semi_simple_nice_name(&self) -> String
pub fn directed_semi_simple_nice_name(&self) -> String
Self::semi_simple_nice_name with its direction: music21’s
directedSemiSimpleNiceName.
Sourcepub fn specific_name(&self) -> String
pub fn specific_name(&self) -> String
The specifier spelled out on its own: music21’s specificName,
Doubly-Diminished for dd5.
Sourcepub fn diatonic_interval_cent_shift(&self) -> FloatType
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.
Sourcepub fn is_unison(&self) -> bool
pub fn is_unison(&self) -> bool
Whether the generic interval is a unison, whatever its quality.
Sourcepub fn is_perfectable(&self) -> bool
pub fn is_perfectable(&self) -> bool
Whether the generic interval takes perfect rather than major and minor qualities: unisons, fourths, fifths and their compounds.
Sourcepub fn staff_distance(&self) -> IntegerType
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.
Sourcepub fn mod7(&self) -> IntegerType
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.
Sourcepub fn mod7_inversion(&self) -> IntegerType
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.
Sourcepub fn mod12(&self) -> IntegerType
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.
Sourcepub fn transpose_pitch_with_options(
&self,
p: &Pitch,
reverse: bool,
max_accidental: Option<IntegerType>,
) -> Result<Pitch>
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.
Sourcepub fn transpose_pitch_in_place(&self, pitch: &mut Pitch) -> Result<()>
pub fn transpose_pitch_in_place(&self, pitch: &mut Pitch) -> Result<()>
Transposes a pitch in place by this interval.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Interval
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Interval
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Interval> for ParallelRequirement
impl From<Interval> for ParallelRequirement
Source§impl PartialEq for Interval
impl PartialEq 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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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