Skip to main content

FiguredBassLine

Struct FiguredBassLine 

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

A bass line and its figures, in a key and a meter.

use music21_rs::Pitch;
use music21_rs::figuredbass::realizer::FiguredBassLine;
use music21_rs::figuredbass::rules::Rules;

let mut line = FiguredBassLine::default();
line.add_element(Pitch::from_name("C3")?, 1.0, None);
line.add_element(Pitch::from_name("D3")?, 1.0, Some("4,3"));
line.add_element(Pitch::from_name("C3")?, 2.0, None);
let realization = line.realize(&Rules::default(), 4, &Pitch::from_name("B5")?)?;
assert_eq!(realization.num_solutions(), 30);

Implementations§

Source§

impl FiguredBassLine

Source

pub fn new(scale: FiguredBassScale) -> Self

An empty line in common time whose figures are read in scale.

Source

pub fn in_key(key: &Key) -> Result<Self>

An empty line in key and common time. The key must be in one of the five modes a figured bass is read in.

§Errors

A key in another mode.

Source

pub fn in_key_and_time(key: &Key, time: TimeSignature) -> Result<Self>

An empty line in key and time: music21’s FiguredBassLine(inKey, inTime).

§Errors

A key in a mode no figured bass is read in.

Source

pub fn scale(&self) -> &FiguredBassScale

The scale its figures are read in.

Source

pub fn time_signature(&self) -> &TimeSignature

The meter it is written in: music21’s inTime.

Source

pub fn add_element( &mut self, bass: Pitch, quarter_length: FloatType, notation: Option<&str>, )

Adds a bass note lasting quarter_length, with the figures written under it, if any: music21’s addElement of a note.

Source

pub fn add_chord( &mut self, bass: Pitch, quarter_length: FloatType, pitch_names: Vec<String>, )

Adds a bass note with the names of the notes above it rather than figures, as music21 reads a chord symbol or a roman numeral into a line. A chord lasting nothing is realized as lasting a quarter, as music21’s is.

Source

pub fn len(&self) -> usize

How many bass notes it has.

Source

pub fn is_empty(&self) -> bool

Whether it has none.

Source

pub fn overlay_part(&mut self, part: &Stream)

Lays a written part over the line, to be kept as it is by every realization: music21’s overlayPart.

Each note of the part holds one part of the voicing to its pitch while it sounds, the first part laid over being the highest. Where it moves and the bass does not, the line gains a segment of no length, into which only the parts laid over may move. As in music21, the first segment of the line is not held to the parts laid over it.

Only the part’s notes and rests are read, at their offsets from its start.

Source

pub fn generate_bass_line(&self) -> Result<Stream>

The bass line written out as a part: a bass clef, the key signature, the meter and the bass notes one after another, each with its figures under it as lyrics, cut into measures with the notes that run past a barline tied, tuplets completed and bracketed and the notes beamed. music21’s generateBassLine.

use music21_rs::figuredbass::realizer::FiguredBassLine;
use music21_rs::{Key, Pitch, TimeSignature};

let key = Key::from_tonic("B")?;
let mut line = FiguredBassLine::in_key_and_time(&key, TimeSignature::new(3, 4)?)?;
line.add_element(Pitch::from_name("B2")?, 1.0, None);
line.add_element(Pitch::from_name("C#3")?, 1.0, Some("6"));
line.add_element(Pitch::from_name("D#3")?, 2.5, Some("6"));
let written = line.generate_bass_line()?;
assert_eq!(written.measures().len(), 2);
assert_eq!(written.notes().len(), 4);
§Errors

A line holding chords rather than bass notes and figures, figures that cannot be read, or a length no duration has.

Source

pub fn segments( &self, rules: &Rules, num_parts: usize, max_pitch: &Pitch, ) -> Result<Vec<Segment>>

A segment for each bass note as the line is written, voiced in num_parts parts under rules, no part above max_pitch: music21’s retrieveSegments.

A bass note cut by a barline is a segment for each piece, and a part laid over the line holds its part of each segment to its pitch. A line of chords is a segment for each chord.

§Errors

Figures the line’s scale cannot read, or a part laid over the line that sounds something other than a note where a segment needs its pitch.

Source

pub fn realize( &self, rules: &Rules, num_parts: usize, max_pitch: &Pitch, ) -> Result<Realization>

Every way of voicing the line in num_parts parts that keeps rules, no part above max_pitch: music21’s realize.

§Errors

A line with nothing in it, figures its scale cannot read, or a resolution that fails.

Trait Implementations§

Source§

impl Clone for FiguredBassLine

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 FiguredBassLine

Source§

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

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

impl Default for FiguredBassLine

Source§

fn default() -> Self

A line in C major and common time, with nothing in it yet.

Source§

impl PartialEq for FiguredBassLine

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 FiguredBassLine

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.