Skip to main content

Clef

Struct Clef 

Source
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

Source

pub fn of_kind(kind: ClefKind) -> Self

A clef as music21’s class for kind starts out.

Source

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.

Source

pub fn set_color(&mut self, color: Option<String>)

Sets the colour the clef is drawn in.

Source

pub fn treble() -> Self

The treble clef.

Source

pub fn bass() -> Self

The bass clef.

Source

pub fn kind(&self) -> ClefKind

The kind of clef this started as.

Source

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.

Source

pub fn places_pitches(&self) -> bool

Whether the clef places pitches, as every one below music21’s PitchClef does.

Source

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

Source

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

The sign: G, F, C, TAB, percussion, none or jianpu.

Source

pub fn set_sign(&mut self, sign: Option<String>)

Changes the sign.

Source

pub fn line(&self) -> Option<u8>

The line the sign sits on, counted from the bottom.

Source

pub fn set_line(&mut self, line: Option<u8>)

Changes the line.

Source

pub fn octave_change(&self) -> IntegerType

How many octaves the clef transposes what is written: music21’s octaveChange.

Source

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));
Source

pub fn lowest_line(&self) -> Option<IntegerType>

The diatonic note number of the note on the lowest line: music21’s lowestLine.

Source

pub fn set_lowest_line(&mut self, lowest_line: Option<IntegerType>)

Changes the note on the lowest line.

Source

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.

Source

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.

Source

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 Clone for Clef

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 Clef

Source§

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

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

impl Default for Clef

Source§

fn default() -> Self

music21’s bare Clef, which says nothing.

Source§

impl<'de> Deserialize<'de> for Clef

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<Clef> for StreamElement

Source§

fn from(value: Clef) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Clef

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 Clef

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