Skip to main content

Spanner

Struct Spanner 

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

A mark joining several notes: music21’s Spanner.

Implementations§

Source§

impl Spanner

Source

pub fn new(kind: SpannerKind, spanned: Vec<usize>) -> Self

A spanner of a kind joining the elements at these positions.

use music21::{Spanner, SpannerKind};

let line = Spanner::new(SpannerKind::Line, vec![2, 5]);
assert_eq!(line.len(), 2);
assert_eq!(line.spanned(), [Some(2), Some(5)]);
Source

pub fn with_unplaced(kind: SpannerKind, spanned: Vec<Option<usize>>) -> Self

A spanner of a kind joining elements some of which stand nowhere: a score read from a file may leave a spanner holding a note no stream holds. It still counts that note among its own, so the ends and the length are those of the whole list.

Source

pub fn multi_measure_rest(spanned: Vec<usize>) -> Self

One rest of several measures over the rests at these positions, drawn with symbols as music21’s starts out.

Source

pub fn multi_rest(&self) -> Option<MultiRest>

How a rest of several measures is drawn and counted.

Source

pub fn set_multi_rest(&mut self, multi_rest: Option<MultiRest>)

Says how a rest of several measures is drawn and counted.

Source

pub fn num_rests(&self) -> usize

How many measures a rest of several lasts: the count it was given, or else how many rests it joins. music21’s numRests.

Source

pub fn glissando(spanned: Vec<usize>) -> Self

A glissando over the elements at these positions, drawn as a wavy line and played chromatically, as music21’s starts out.

Source

pub fn glissando_details(&self) -> Option<&Glissando>

How a glissando is played and what is written along it.

Source

pub fn set_glissando_details(&mut self, glissando: Option<Glissando>)

Says how a glissando is played and what is written along it.

Source

pub fn tremolo(marks: u8, spanned: Vec<usize>) -> Result<Self>

A tremolo alternating between the elements at these positions, with so many strokes through the stems.

§Errors

More than eight strokes, as music21’s TremoloException.

Source

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

How many strokes a tremolo between notes is written with: music21’s numberOfMarks.

Source

pub fn set_number_of_marks(&mut self, marks: Option<u8>) -> Result<()>

Says how many strokes a tremolo between notes is written with.

§Errors

More than eight, as music21’s TremoloException.

Source

pub fn offset(&self) -> FloatType

Where the spanner itself stands in the stream holding it: nought for one a score is read with. A pedal mark drawn as a sign and a line says where its line resumes by it.

Source

pub fn set_offset(&mut self, offset: FloatType)

Says where the spanner itself stands in the stream holding it.

Source

pub fn arpeggio_mark(arpeggio: ArpeggioType, spanned: Vec<usize>) -> Self

One arpeggio across the chords at these positions.

Source

pub fn arpeggio(&self) -> ArpeggioType

Which way an arpeggio across several chords is spread.

Source

pub fn set_arpeggio(&mut self, arpeggio: ArpeggioType)

Says which way an arpeggio across several chords is spread.

Source

pub fn line(spanned: Vec<usize>) -> Self

A line over the elements at these positions, solid with a tick down at each end, as music21’s starts out.

Source

pub fn ends(&self) -> LineEnds

How a line’s ends are drawn.

Source

pub fn set_ends(&mut self, ends: LineEnds)

Says how a line’s ends are drawn.

Source

pub fn pedal_mark(pedal: Pedal, spanned: Vec<usize>) -> Self

A pedal held under the elements at these positions.

Source

pub fn pedal(&self) -> Option<Pedal>

Which pedal a pedal mark holds and how it is drawn.

Source

pub fn set_pedal(&mut self, pedal: Option<Pedal>)

Says which pedal a pedal mark holds and how it is drawn.

Source

pub fn ottava(shift: OctaveShift, spanned: Vec<usize>) -> Self

An octave line over the elements at these positions, drawn above them as music21’s starts out.

use music21::{OctaveShift, Spanner};

let ottava = Spanner::ottava(OctaveShift::from_name("8va", true)?, vec![0, 1]);
let shift = ottava.shift().expect("an ottava shifts");
assert_eq!(shift.name(), "8va");
assert!(shift.up());
Source

pub fn shift(&self) -> Option<OctaveShift>

How far and which way an octave line moves its notes.

Source

pub fn set_shift(&mut self, shift: Option<OctaveShift>)

Says how far and which way an octave line moves its notes.

Source

pub fn slur(spanned: Vec<usize>) -> Self

A slur over the elements at these positions.

use music21::{Note, Spanner, SpannerKind, Stream};

let mut stream = Stream::new();
for name in ["C4", "D4", "E4"] {
    stream.push(Note::from_name(name)?);
}
// The slur names its notes by their places in `Stream::leaves`.
stream.add_spanner(Spanner::slur(vec![0, 1, 2]));
let slur = &stream.spanners()[0];
assert_eq!(slur.kind(), SpannerKind::Slur);
assert!(slur.is_first(0) && slur.is_last(2));
Source

pub fn wedge(kind: SpannerKind, spanned: Vec<usize>) -> Self

A hairpin over the elements at these positions, drawn below them and opening fifteen tenths wide, as music21’s starts out.

use music21::{Spanner, SpannerKind};

let hairpin = Spanner::wedge(SpannerKind::Crescendo, vec![0, 3]);
assert!(hairpin.kind().is_wedge());
assert_eq!(hairpin.kind().class_name(), "Crescendo");
Source

pub fn spread(&self) -> Option<FloatType>

How wide a hairpin opens, in tenths of a staff space: music21’s spread.

Source

pub fn set_spread(&mut self, spread: Option<FloatType>)

Says how wide a hairpin opens.

Source

pub fn kind(&self) -> SpannerKind

Which kind of spanner this is.

Source

pub fn spanned(&self) -> &[Option<usize>]

The positions of the elements it joins, first to last, nothing for one that stands in no stream.

use music21::Spanner;

let slur = Spanner::slur(vec![4, 5, 6]);
assert_eq!(slur.spanned(), [Some(4), Some(5), Some(6)]);
Source

pub fn len(&self) -> usize

How many elements it joins, those standing nowhere included.

Source

pub fn is_empty(&self) -> bool

Whether it joins nothing at all.

Source

pub fn is_first(&self, position: usize) -> bool

Whether the element at a position is the first it joins: music21’s isFirst.

Source

pub fn is_last(&self, position: usize) -> bool

Whether the element at a position is the last it joins: music21’s isLast.

Source

pub fn has_spanned_element(&self, position: usize) -> bool

Whether the element at a position is among those it joins: music21’s hasSpannedElement.

Source

pub fn add_spanned_elements( &mut self, positions: impl IntoIterator<Item = usize>, )

Joins the elements at these positions too, after those it joins already, in the order given: music21’s addSpannedElements, which joins an element once however often it is added.

use music21::Spanner;

let mut slur = Spanner::slur(vec![1]);
slur.add_spanned_elements([2, 3, 1]);
assert_eq!(slur.spanned(), [Some(1), Some(2), Some(3)]);
Source

pub fn insert_first_spanned_element(&mut self, position: usize)

Joins the element at a position first, before the rest: music21’s insertFirstSpannedElement. One it joins already stays where it is.

Source

pub fn replace_spanned_element(&mut self, old: usize, new: usize)

Joins the element at new where it joined the one at old: music21’s replaceSpannedElement. Where it joins new already it just lets old go, and where it does not join old nothing changes.

use music21::Spanner;

let mut slur = Spanner::slur(vec![1, 2, 3]);
slur.replace_spanned_element(3, 4);
assert_eq!(slur.spanned(), [Some(1), Some(2), Some(4)]);
Source

pub fn placement(&self) -> Option<Placement>

Which side of the notes it is drawn on, where the score says.

Source

pub fn set_placement(&mut self, placement: Option<Placement>)

Says which side of the notes it is drawn on.

Source

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

The number a score tells it from others of its kind by: music21’s idLocal.

Source

pub fn set_id_local(&mut self, id_local: Option<String>)

Sets the number it is told apart by, or clears it.

Source

pub fn unplaced_elements(&self) -> &[(usize, StreamElement)]

What it joins that no stream holds, each by its place among what it joins, where Spanner::spanned says nothing.

Source

pub fn set_unplaced_element(&mut self, place: usize, element: StreamElement)

Says what it joins at place that no stream holds.

Source

pub fn stands_in_score(&self) -> bool

Whether the reader put it in the score itself, after its last measure, rather than in the part holding what it joins: music21’s MEI reader appends its slurs to the score.

Source

pub fn set_stands_in_score(&mut self, in_score: bool)

Says whether it stands in the score itself.

Source

pub fn complete(&self) -> bool

Whether the reader that made it saw it to its end: music21’s completeStatus.

Source

pub fn set_complete(&mut self, complete: bool)

Says whether it was seen to its end.

Source

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

How its line is drawn where that is not solid, dashed or dotted: music21’s style.lineType.

Source

pub fn set_line_type(&mut self, line_type: Option<String>)

Says how its line is drawn.

Trait Implementations§

Source§

impl Clone for Spanner

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 Spanner

Source§

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

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

impl<'de> Deserialize<'de> for Spanner

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 Eq for Spanner

Source§

impl PartialEq for Spanner

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 Spanner

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 Spanner

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