Skip to main content

Metadata

Struct Metadata 

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

A score’s metadata: named values in the order the names were first given.

use music21_rs::metadata::Metadata;

let mut md = Metadata::new();
md.add_text("title", "Wer nur den lieben Gott");
md.add_contributor("composer", "J. S. Bach");
assert_eq!(md.first_text("title"), Some("Wer nur den lieben Gott"));
assert_eq!(md.contributors().next().map(|(_, value)| value.text()), Some("J. S. Bach"));

Implementations§

Source§

impl Metadata

Source

pub fn new() -> Self

Metadata with nothing in it.

music21’s own constructor starts with its version under software; this one starts empty, and a caller who wants a software line adds it.

Source

pub fn add(&mut self, unique_name: impl Into<String>, value: MetadataValue)

Adds a value under a unique name, after any it already has.

Source

pub fn add_text( &mut self, unique_name: impl Into<String>, text: impl Into<String>, )

Adds a value that is only text.

Source

pub fn add_contributor( &mut self, role: impl Into<String>, name: impl Into<String>, )

Adds a contributor in a role: under the role itself where it is one of the vocabulary’s contributor names, and under otherContributor where it is not, as music21’s addContributor files one.

Source

pub fn set( &mut self, unique_name: impl Into<String>, values: Vec<MetadataValue>, )

Replaces every value under a unique name.

Source

pub fn get(&self, unique_name: &str) -> &[MetadataValue]

Every value under a unique name, in the order they were added.

Source

pub fn first_text(&self, unique_name: &str) -> Option<&str>

The text of the first value under a unique name.

Source

pub fn all(&self) -> impl Iterator<Item = (&str, &MetadataValue)>

Every name and value in order, names in the order they were first given and each name’s values together: music21’s all with returnSorted=False.

Source

pub fn contributors(&self) -> impl Iterator<Item = (&str, &MetadataValue)>

The contributors alone, in the same order.

Source

pub fn string_value(&self, unique_name: &str) -> Option<String>

Every value under a unique name as one piece of text, as music21’s attribute of that name reads it – title, composer, movementName: one contributor by name, two joined with and, more as the first and how many others; a title’s values each with an article written after a comma put back in front; anything else the values joined with commas. Nothing for a name outside the vocabulary, or with no value.

Source

pub fn title(&self) -> Option<String>

The title, as Self::string_value reads it: music21’s title.

Source

pub fn best_title(&self) -> Option<String>

The title, or the next best thing the score says: music21’s bestTitle, which takes the first of title, popularTitle, alternativeTitle and movementName that says anything.

use music21_rs::metadata::Metadata;

let mut said = Metadata::new();
said.add_text("popularTitle", "Eroica");
assert_eq!(said.best_title().as_deref(), Some("Eroica"));
said.add_text("title", "Third Symphony");
assert_eq!(said.best_title().as_deref(), Some("Third Symphony"));
assert_eq!(Metadata::new().best_title(), None);
Source

pub fn contributors_by_role(&self, role: Option<&str>) -> Vec<&MetadataValue>

The contributors in a role, or the ones with no role of their own where none is asked for: music21’s getContributorsByRole, which a MusicXML file needs because some of them name a contributor and no role.

Source

pub fn is_empty(&self) -> bool

Whether nothing is in it.

Source

pub fn all_sorted(&self) -> Vec<(&str, &MetadataValue)>

Every name and value sorted by name and then by text, as music21’s all reads them by default and Self::search walks them.

Source

pub fn search( &self, query: &MetadataQuery<'_>, field: Option<&str>, ) -> Option<MetadataMatch<'_>>

The first value a query matches, and the field it was found under: music21’s search.

With no field, every standard name is searched, sorted by name, and then every contributor in the order they were added, under its role rather than its unique name so that a made-up role can be searched for.

A field names where to look, and need not be the whole name: music21 takes a unique name, one of its four grandfathered work ids (date, volume, dedication, commission), one of its twenty Humdrum abbreviations (otl, ode), or any piece of a name – compos finds composer. A field naming nothing finds nothing.

use music21_rs::metadata::{Metadata, MetadataQuery};

let mut md = Metadata::new();
md.add_contributor("composer", "Joplin, Scott");
md.add_text("title", "Maple Leaf Rag");

let joplin = MetadataQuery::Text("joplin");
assert_eq!(
    md.search(&joplin, Some("composer")).unwrap().field(),
    Some("composer")
);
assert_eq!(
    md.search(&joplin, Some("compos")).unwrap().field(),
    Some("composer")
);
assert!(md.search(&joplin, Some("title")).is_none());

let found = md.search(&MetadataQuery::Text("leaf"), None).unwrap();
assert_eq!((found.field(), found.text()), (Some("title"), "Maple Leaf Rag"));

Trait Implementations§

Source§

impl Clone for Metadata

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 Metadata

Source§

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

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

impl Default for Metadata

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Metadata

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 Metadata

Source§

impl PartialEq for Metadata

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 Metadata

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 Metadata

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.