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
impl Ornament
Sourcepub fn of_kind(kind: OrnamentKind) -> Self
pub fn of_kind(kind: OrnamentKind) -> Self
An ornament as music21’s class for kind starts out.
Sourcepub fn kind(&self) -> OrnamentKind
pub fn kind(&self) -> OrnamentKind
The kind of ornament this started as.
Sourcepub fn is_a(&self, class: &str) -> bool
pub fn is_a(&self, class: &str) -> bool
Whether this is an ornament of that music21 class or one below it.
Sourcepub fn direction(&self) -> Option<IntervalDirection>
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.
Sourcepub fn name(&self) -> String
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.
Sourcepub fn quarter_length(&self) -> FloatType
pub fn quarter_length(&self) -> FloatType
How long each ornamental note lasts, in quarter lengths: music21’s
quarterLength.
Sourcepub fn set_quarter_length(&mut self, quarter_length: FloatType)
pub fn set_quarter_length(&mut self, quarter_length: FloatType)
Changes how long each ornamental note lasts.
Sourcepub fn auto_scale(&self) -> bool
pub fn auto_scale(&self) -> bool
Whether the ornament shrinks to fit a note too short for it: music21’s
autoScale.
Sourcepub fn set_auto_scale(&mut self, auto_scale: bool)
pub fn set_auto_scale(&mut self, auto_scale: bool)
Says whether the ornament shrinks to fit.
Sourcepub fn set_placement(&mut self, placement: Option<String>)
pub fn set_placement(&mut self, placement: Option<String>)
Says where the sign sits.
Sourcepub fn tie_attach(&self) -> &str
pub fn tie_attach(&self) -> &str
Which part of a note split across a tie keeps the ornament.
Sourcepub fn set_tie_attach(&mut self, attach: impl Into<String>)
pub fn set_tie_attach(&mut self, attach: impl Into<String>)
Changes which part keeps it.
Sourcepub fn split_client(
&self,
stream: &mut Stream,
positions: &[usize],
) -> Result<Option<Spanner>>
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.
Sourcepub fn accidental(&self) -> Option<&Accidental>
pub fn accidental(&self) -> Option<&Accidental>
A mordent’s or trill’s accidental, which spells its ornamental note instead of the key signature.
Sourcepub fn set_accidental(&mut self, accidental: Option<Accidental>) -> Result<()>
pub fn set_accidental(&mut self, accidental: Option<Accidental>) -> Result<()>
Sourcepub fn upper_accidental(&self) -> Option<&Accidental>
pub fn upper_accidental(&self) -> Option<&Accidental>
A turn’s accidental for its upper note.
Sourcepub fn set_upper_accidental(&mut self, accidental: Option<Accidental>)
pub fn set_upper_accidental(&mut self, accidental: Option<Accidental>)
Changes a turn’s upper accidental.
Sourcepub fn lower_accidental(&self) -> Option<&Accidental>
pub fn lower_accidental(&self) -> Option<&Accidental>
A turn’s accidental for its lower note.
Sourcepub fn set_lower_accidental(&mut self, accidental: Option<Accidental>)
pub fn set_lower_accidental(&mut self, accidental: Option<Accidental>)
Changes a turn’s lower accidental.
Sourcepub fn delay(&self) -> OrnamentDelay
pub fn delay(&self) -> OrnamentDelay
When a turn starts.
Sourcepub fn set_delay(&mut self, delay: OrnamentDelay)
pub fn set_delay(&mut self, delay: OrnamentDelay)
Changes when a turn starts; a timed delay of nothing is no delay.
Sourcepub fn is_delayed(&self) -> bool
pub fn is_delayed(&self) -> bool
Whether a turn waits before starting.
Sourcepub fn nachschlag(&self) -> bool
pub fn nachschlag(&self) -> bool
Whether a trill ends on two notes turning back into the next:
music21’s nachschlag.
Sourcepub fn set_nachschlag(&mut self, nachschlag: bool)
pub fn set_nachschlag(&mut self, nachschlag: bool)
Says whether a trill ends on a nachschlag.
Sourcepub fn number_of_marks(&self) -> u8
pub fn number_of_marks(&self) -> u8
How many strokes cross a tremolo’s stem, nought to eight.
Sourcepub fn set_number_of_marks(&mut self, marks: u8) -> Result<()>
pub fn set_number_of_marks(&mut self, marks: u8) -> Result<()>
Sourcepub fn set_measured(&mut self, measured: bool)
pub fn set_measured(&mut self, measured: bool)
Says whether a tremolo is measured.
Sourcepub fn appoggiatura_size(&self) -> Option<&Interval>
pub fn appoggiatura_size(&self) -> Option<&Interval>
An appoggiatura’s size: how far from the main note its first note is.
Sourcepub fn set_appoggiatura_size(&mut self, size: Option<Interval>)
pub fn set_appoggiatura_size(&mut self, size: Option<Interval>)
Changes an appoggiatura’s size.
Sourcepub fn size(&self, source: &Pitch, key: &KeySignature) -> Result<Interval>
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.
Sourcepub fn turn_size(
&self,
source: &Pitch,
which: TurnNote,
key: &KeySignature,
) -> Result<Interval>
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.
Sourcepub fn ornamental_pitches(
&self,
source: &Pitch,
key: &KeySignature,
) -> Result<Vec<Pitch>>
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.
Sourcepub fn update_accidental_display(
&self,
ornamental: &mut [Pitch],
options: &AccidentalDisplayOptions<'_>,
)
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.
Sourcepub fn realize(&self, note: &Note, key: &KeySignature) -> Result<Realization>
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<'de> Deserialize<'de> for Ornament
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Ornament
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<Ornament> for Expression
impl From<Ornament> for Expression
impl StructuralPartialEq for Ornament
Auto Trait Implementations§
impl Freeze for Ornament
impl RefUnwindSafe for Ornament
impl Send for Ornament
impl Sync for Ornament
impl Unpin for Ornament
impl UnsafeUnpin for Ornament
impl UnwindSafe for Ornament
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