Skip to main content

Ornament

Struct Ornament 

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

An ornament.

use music21_rs::expressions::{Ornament, OrnamentKind};
use music21_rs::{KeySignature, Note};

let mordent = Ornament::of_kind(OrnamentKind::Mordent);
let played = mordent.realize(&Note::from_name("C4")?, &KeySignature::new(0))?;
let names: Vec<String> = played
    .into_notes()
    .iter()
    .map(|note| {
        let length = note.duration().map_or(1.0, |duration| duration.quarter_length());
        format!("{} {length}", note.pitch().name_with_octave())
    })
    .collect();
assert_eq!(names, ["C4 0.125", "B3 0.125", "C4 0.75"]);

Implementations§

Source§

impl Ornament

Source

pub fn of_kind(kind: OrnamentKind) -> Self

An ornament as music21’s class for kind starts out.

Source

pub fn kind(&self) -> OrnamentKind

The kind of ornament this started as.

Source

pub fn is_a(&self, class: &str) -> bool

Whether this is an ornament of that music21 class or one below it.

Source

pub fn direction(&self) -> Option<IntervalDirection>

Which way a mordent, trill or appoggiatura goes to its ornamental note: music21’s direction. Nothing for a general mordent or appoggiatura that has not said, and for an ornament of another kind.

Source

pub fn name(&self) -> String

music21’s name: the class as lower-case words, with a mordent’s or trill’s accidental, and a turn’s delay and accidentals, beside it.

Source

pub fn quarter_length(&self) -> FloatType

How long each ornamental note lasts, in quarter lengths: music21’s quarterLength.

Source

pub fn set_quarter_length(&mut self, quarter_length: FloatType)

Changes how long each ornamental note lasts.

Source

pub fn auto_scale(&self) -> bool

Whether the ornament shrinks to fit a note too short for it: music21’s autoScale.

Source

pub fn set_auto_scale(&mut self, auto_scale: bool)

Says whether the ornament shrinks to fit.

Source

pub fn placement(&self) -> Option<&str>

Where the sign sits.

Source

pub fn set_placement(&mut self, placement: Option<String>)

Says where the sign sits.

Source

pub fn tie_attach(&self) -> &str

Which part of a note split across a tie keeps the ornament.

Source

pub fn set_tie_attach(&mut self, attach: impl Into<String>)

Changes which part keeps it.

Source

pub fn split_client( &self, stream: &mut Stream, positions: &[usize], ) -> Result<Option<Spanner>>

Carries this trill onto the pieces a trilled note was split into: music21’s splitClient, which its splitAtQuarterLength calls.

The pieces are the leaves of stream at positions, first to last. The trill is written on the first piece alone, and where there is more than one piece they are joined by a trill extension, the spanner answered, unless one of stream’s trill extensions already takes in the first. The spanner is answered rather than added, as music21’s is.

use music21_rs::{
    expressions::{Ornament, OrnamentKind},
    Duration, Note, SpannerKind, Stream,
};

let mut stream = Stream::new();
stream.insert(0.0, Note::from_name("C4")?.with_duration(Duration::new(3.0)?));
stream.insert(3.0, Note::from_name("C4")?);
let trill = Ornament::of_kind(OrnamentKind::Trill);
let extension = trill.split_client(&mut stream, &[0, 1])?.unwrap();
assert_eq!(extension.kind(), SpannerKind::TrillExtension);
assert_eq!(extension.spanned(), [Some(0), Some(1)]);
§Errors

An ornament that is not a trill, which music21 gives no such hook, or a first piece that is not a note, a chord or a rest.

Source

pub fn accidental(&self) -> Option<&Accidental>

A mordent’s or trill’s accidental, which spells its ornamental note instead of the key signature.

Source

pub fn set_accidental(&mut self, accidental: Option<Accidental>) -> Result<()>

Changes the accidental.

§Errors

A half-step or whole-step ornament, whose interval is fixed.

Source

pub fn upper_accidental(&self) -> Option<&Accidental>

A turn’s accidental for its upper note.

Source

pub fn set_upper_accidental(&mut self, accidental: Option<Accidental>)

Changes a turn’s upper accidental.

Source

pub fn lower_accidental(&self) -> Option<&Accidental>

A turn’s accidental for its lower note.

Source

pub fn set_lower_accidental(&mut self, accidental: Option<Accidental>)

Changes a turn’s lower accidental.

Source

pub fn delay(&self) -> OrnamentDelay

When a turn starts.

Source

pub fn set_delay(&mut self, delay: OrnamentDelay)

Changes when a turn starts; a timed delay of nothing is no delay.

Source

pub fn is_delayed(&self) -> bool

Whether a turn waits before starting.

Source

pub fn nachschlag(&self) -> bool

Whether a trill ends on two notes turning back into the next: music21’s nachschlag.

Source

pub fn set_nachschlag(&mut self, nachschlag: bool)

Says whether a trill ends on a nachschlag.

Source

pub fn number_of_marks(&self) -> u8

How many strokes cross a tremolo’s stem, nought to eight.

Source

pub fn set_number_of_marks(&mut self, marks: u8) -> Result<()>

Changes how many strokes cross the stem.

§Errors

More than eight.

Source

pub fn measured(&self) -> bool

Whether a tremolo is measured.

Source

pub fn set_measured(&mut self, measured: bool)

Says whether a tremolo is measured.

Source

pub fn appoggiatura_size(&self) -> Option<&Interval>

An appoggiatura’s size: how far from the main note its first note is.

Source

pub fn set_appoggiatura_size(&mut self, size: Option<Interval>)

Changes an appoggiatura’s size.

Source

pub fn size(&self, source: &Pitch, key: &KeySignature) -> Result<Interval>

The interval from source to a mordent’s or trill’s ornamental note, under key: music21’s getSize.

use music21_rs::expressions::{Ornament, OrnamentKind};
use music21_rs::{KeySignature, Pitch};

let mordent = Ornament::of_kind(OrnamentKind::Mordent);
let g = Pitch::from_name("G4")?;
assert_eq!(mordent.size(&g, &KeySignature::new(0))?.directed_name(), "M-2");
assert_eq!(mordent.size(&g, &KeySignature::new(1))?.directed_name(), "m-2");
§Errors

An ornament that is not a mordent or a trill, or a general mordent that has not said which way it goes.

Source

pub fn turn_size( &self, source: &Pitch, which: TurnNote, key: &KeySignature, ) -> Result<Interval>

The interval from source to a turn’s upper or lower note, under key: music21’s Turn.getSize.

§Errors

An ornament that is not a turn.

Source

pub fn ornamental_pitches( &self, source: &Pitch, key: &KeySignature, ) -> Result<Vec<Pitch>>

The pitches the ornament plays besides source itself, under key: music21’s resolveOrnamentalPitches and ornamentalPitches. A mordent or trill has one, a turn its upper and lower notes in that order, and any other ornament none. An ornament’s own accidental passes its display status on to the pitch it spells.

§Errors

A general mordent that has not said which way it goes.

Source

pub fn update_accidental_display( &self, ornamental: &mut [Pitch], options: &AccidentalDisplayOptions<'_>, )

Decides whether each of this ornament’s ornamental pitches shows its accidental: music21’s updateAccidentalDisplay on an ornament.

ornamental is what Ornament::ornamental_pitches gave, in its order. An accidental the ornament was given with a display status of its own says so outright, adding a natural where the pitch has no accidental; otherwise each pitch is decided as Pitch::update_accidental_display decides one, against options, but never as simultaneous with anything and never tied, since an ornamental note is neither. An ornament with no ornamental pitches leaves them alone.

Source

pub fn realize(&self, note: &Note, key: &KeySignature) -> Result<Realization>

The notes note is played as under this ornament, in key: music21’s realize.

§Errors

A note with no length to steal time from (a tremolo takes one as it is), a note too short for an ornament told not to shrink, or a general mordent or appoggiatura that has not said which way it goes.

Trait Implementations§

Source§

impl Clone for Ornament

Source§

fn clone(&self) -> Self

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 Ornament

Source§

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

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

impl Default for Ornament

Source§

fn default() -> Self

music21’s bare Ornament.

Source§

impl<'de> Deserialize<'de> for Ornament

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 From<Ornament> for Expression

Source§

fn from(value: Ornament) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Ornament

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Ornament

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 StructuralPartialEq for Ornament

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