Skip to main content

AbcNote

Struct AbcNote 

Source
pub struct AbcNote {
Show 18 fields pub src: String, pub line: usize, pub is_chord: bool, pub carried_accidental: String, pub chord_symbols: Vec<String>, pub in_grace: bool, pub default_quarter_length: Option<FloatType>, pub broken_rhythm: Option<(String, Side)>, pub key: Option<KeySignature>, pub tuplet: Option<Tuplet>, pub spanners: Vec<usize>, pub tie: Option<TieType>, pub articulations: Vec<String>, pub accidental_display: Option<bool>, pub is_rest: bool, pub pitch_name: Option<String>, pub quarter_length: FloatType, pub sub_tokens: Vec<AbcNote>,
}
Expand description

A note, a rest, or with is_chord a chord: music21’s ABCNote and ABCChord. Its context is filled by Handler::process, its pitch and length by AbcNote::parse.

Fields§

§src: String

The text it was read from.

§line: usize

The line of the text it starts on; nought where unknown.

§is_chord: bool

Whether it is a chord.

§carried_accidental: String

The accidental carried from earlier in the measure.

§chord_symbols: Vec<String>

The chord symbols written over it, quotes kept.

§in_grace: bool

Whether it is a grace note.

§default_quarter_length: Option<FloatType>

The default length in force, in quarter notes.

§broken_rhythm: Option<(String, Side)>

The broken-rhythm mark and the side of it the note stands on.

§key: Option<KeySignature>

The key in force.

§tuplet: Option<Tuplet>

The tuplet it is in.

§spanners: Vec<usize>

The spanners in force, by where they stand among the handler’s.

§tie: Option<TieType>

The tie it starts, continues or stops.

§articulations: Vec<String>

music21’s names: staccato, upbow and the rest.

§accidental_display: Option<bool>

Whether the accidental is shown: nothing where undecided.

§is_rest: bool

Whether it is a rest.

§pitch_name: Option<String>

The pitch as music21 names one; nothing for a rest or a chord.

§quarter_length: FloatType

The length in quarter notes.

§sub_tokens: Vec<AbcNote>

A chord’s notes, once parsed.

Implementations§

Source§

impl AbcNote

Source

pub fn new(src: &str, carried: &str) -> Self

An unread note of src, carrying the accidental carried.

Source

pub fn chord(src: &str) -> Self

An unread chord of src.

Source

pub fn split_chord_symbols(src: &str) -> (Vec<String>, String)

music21’s _splitChordSymbols: the quoted strings, and what is left after the last of them.

use music21::abc::step::AbcNote;

let (symbols, rest) = AbcNote::split_chord_symbols("\"D7\"\"D\"d2");
assert_eq!((symbols, rest.as_str()), (vec!["\"D7\"".to_string(), "\"D\"".to_string()], "d2"));
Source

pub fn pitch_name( &self, src: &str, forced_key: Option<&KeySignature>, ) -> Result<(Option<String>, Option<bool>)>

music21’s getPitchName: the pitch as music21 names one, or nothing for a rest, and whether its accidental is shown. forced_key stands in for the note’s own key.

use music21::abc::step::AbcNote;
use music21::KeySignature;

let note = AbcNote::new("", "");
assert_eq!(note.pitch_name("_g''", None)?, (Some("G-7".to_string()), Some(true)));
let key = KeySignature::new(3);
assert_eq!(note.pitch_name("c", Some(&key))?, (Some("C#5".to_string()), Some(false)));
Source

pub fn quarter_length_of( &self, src: &str, forced_default: Option<FloatType>, ) -> Result<FloatType>

music21’s getQuarterLength: the length src writes, against the default length (or forced_default), stretched by a broken rhythm.

use music21::abc::step::{AbcNote, Side};

let mut note = AbcNote::new("", "");
note.default_quarter_length = Some(0.5);
assert_eq!(note.quarter_length_of("A3/2", None)?, 0.75);
note.broken_rhythm = Some(("<<".to_string(), Side::Right));
assert_eq!(note.quarter_length_of("A", None)?, 0.875);
Source

pub fn parse( &mut self, forced_default: Option<FloatType>, forced_key: Option<&KeySignature>, ) -> Result<()>

music21’s ABCNote.parse and ABCChord.parse: the chord symbols, the pitch and the length, or for a chord its notes and length. forced_default and forced_key stand in for the note’s own.

Trait Implementations§

Source§

impl Clone for AbcNote

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 AbcNote

Source§

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

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

impl Default for AbcNote

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for AbcNote

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

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