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
impl Metadata
Sourcepub fn new() -> Self
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.
Sourcepub fn add(&mut self, unique_name: impl Into<String>, value: MetadataValue)
pub fn add(&mut self, unique_name: impl Into<String>, value: MetadataValue)
Adds a value under a unique name, after any it already has.
Sourcepub fn add_text(
&mut self,
unique_name: impl Into<String>,
text: impl Into<String>,
)
pub fn add_text( &mut self, unique_name: impl Into<String>, text: impl Into<String>, )
Adds a value that is only text.
Sourcepub fn add_contributor(
&mut self,
role: impl Into<String>,
name: impl Into<String>,
)
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.
Sourcepub fn set(
&mut self,
unique_name: impl Into<String>,
values: Vec<MetadataValue>,
)
pub fn set( &mut self, unique_name: impl Into<String>, values: Vec<MetadataValue>, )
Replaces every value under a unique name.
Sourcepub fn get(&self, unique_name: &str) -> &[MetadataValue]
pub fn get(&self, unique_name: &str) -> &[MetadataValue]
Every value under a unique name, in the order they were added.
Sourcepub fn first_text(&self, unique_name: &str) -> Option<&str>
pub fn first_text(&self, unique_name: &str) -> Option<&str>
The text of the first value under a unique name.
Sourcepub fn all(&self) -> impl Iterator<Item = (&str, &MetadataValue)>
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.
Sourcepub fn contributors(&self) -> impl Iterator<Item = (&str, &MetadataValue)>
pub fn contributors(&self) -> impl Iterator<Item = (&str, &MetadataValue)>
The contributors alone, in the same order.
Sourcepub fn string_value(&self, unique_name: &str) -> Option<String>
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.
Sourcepub fn title(&self) -> Option<String>
pub fn title(&self) -> Option<String>
The title, as Self::string_value reads it: music21’s title.
Sourcepub fn best_title(&self) -> Option<String>
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);Sourcepub fn contributors_by_role(&self, role: Option<&str>) -> Vec<&MetadataValue>
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.
Sourcepub fn all_sorted(&self) -> Vec<(&str, &MetadataValue)>
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.
Sourcepub fn search(
&self,
query: &MetadataQuery<'_>,
field: Option<&str>,
) -> Option<MetadataMatch<'_>>
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<'de> Deserialize<'de> for Metadata
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Metadata
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Metadata
impl StructuralPartialEq for Metadata
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnsafeUnpin for Metadata
impl UnwindSafe for Metadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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