pub struct Clef { /* private fields */ }Expand description
A clef: its sign, the line it sits on, the octaves it transposes and the note written on its lowest line.
use music21_rs::clef::{Clef, ClefKind};
let alto = Clef::from_string("C3", 0)?;
assert_eq!(alto.kind(), ClefKind::AltoClef);
assert_eq!(alto.lowest_line(), Some(25));
assert_eq!(alto.name(), "alto");Implementations§
Source§impl Clef
impl Clef
Sourcepub fn color(&self) -> Option<&str>
pub fn color(&self) -> Option<&str>
The colour the clef is drawn in, if one was said. Two clefs differing only in colour are equal.
Sourcepub fn is_a(&self, class: &str) -> bool
pub fn is_a(&self, class: &str) -> bool
Whether this is a clef of that music21 class or one below it:
is_a("GClef") holds for a treble clef.
Sourcepub fn places_pitches(&self) -> bool
pub fn places_pitches(&self) -> bool
Whether the clef places pitches, as every one below music21’s
PitchClef does.
Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
music21’s name: the class name without Clef, first letter lower
case, so a treble clef an octave down is "treble8vb".
Sourcepub fn octave_change(&self) -> IntegerType
pub fn octave_change(&self) -> IntegerType
How many octaves the clef transposes what is written: music21’s
octaveChange.
Sourcepub fn set_octave_change(&mut self, octave_change: IntegerType)
pub fn set_octave_change(&mut self, octave_change: IntegerType)
Changes how many octaves the clef transposes. On a clef that places pitches this moves its lowest line by the octaves it changed by, as music21’s does; setting the lowest line moves nothing.
use music21_rs::clef::Clef;
let mut treble = Clef::treble();
treble.set_octave_change(1);
assert_eq!(treble.lowest_line(), Some(38));Sourcepub fn lowest_line(&self) -> Option<IntegerType>
pub fn lowest_line(&self) -> Option<IntegerType>
The diatonic note number of the note on the lowest line: music21’s
lowestLine.
Sourcepub fn set_lowest_line(&mut self, lowest_line: Option<IntegerType>)
pub fn set_lowest_line(&mut self, lowest_line: Option<IntegerType>)
Changes the note on the lowest line.
Sourcepub fn stem_direction_for_pitches(
&self,
pitches: &[Pitch],
first_last_only: bool,
extreme_pitch_only: bool,
) -> Result<StemDirection>
pub fn stem_direction_for_pitches( &self, pitches: &[Pitch], first_last_only: bool, extreme_pitch_only: bool, ) -> Result<StemDirection>
Which way a stem goes for these pitches under this clef: music21’s
getStemDirectionForPitches. Each pitch counts by how far it sits
from the middle line; with first_last_only, as in a beamed group,
only the first and last count, and with extreme_pitch_only only the
lowest and the highest. Guitar tablature’s stems always go down.
use music21_rs::{clef::Clef, Pitch, StemDirection};
let pitches: Vec<Pitch> = ["C3", "B3", "C3"]
.iter()
.map(|name| Pitch::from_name(name))
.collect::<Result<_, _>>()?;
let bass = Clef::bass();
assert_eq!(bass.stem_direction_for_pitches(&pitches, true, false)?, StemDirection::Up);
assert_eq!(bass.stem_direction_for_pitches(&pitches, false, false)?, StemDirection::Down);§Errors
No pitches at all.
Sourcepub fn from_string(text: &str, octave_shift: IntegerType) -> Result<Self>
pub fn from_string(text: &str, octave_shift: IntegerType) -> Result<Self>
The clef a string like "G2" or "F4" names: music21’s
clefFromString. tab, percussion, none and jianpu name those
clefs, a sign alone takes its usual line, a longer string may be any
clef’s class name with or without Clef, and octave_shift
transposes the result, giving the octave treble and bass clefs their
own kinds. Case does not matter.
§Errors
A string that names no clef, or a line outside one to five.
Sourcepub fn best_for(pitches: &[Pitch], allow_treble_8vb: bool) -> Self
pub fn best_for(pitches: &[Pitch], allow_treble_8vb: bool) -> Self
The clef that best fits these pitches: music21’s bestClef over the
pitches of the notes and chords it finds. Pitches above A4 and below
F3 count a little further out than they are, and with
allow_treble_8vb notes around middle C may take the treble clef an
octave down.
use music21_rs::{clef::{Clef, ClefKind}, Pitch};
let d4 = [Pitch::from_name("D4")?];
assert_eq!(Clef::best_for(&d4, false).kind(), ClefKind::TrebleClef);
assert_eq!(Clef::best_for(&d4, true).kind(), ClefKind::Treble8vbClef);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Clef
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Clef
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<Clef> for StreamElement
impl From<Clef> for StreamElement
impl StructuralPartialEq for Clef
Auto Trait Implementations§
impl Freeze for Clef
impl RefUnwindSafe for Clef
impl Send for Clef
impl Sync for Clef
impl Unpin for Clef
impl UnsafeUnpin for Clef
impl UnwindSafe for Clef
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