Skip to main content

Module bundles

Module bundles 

Source
Expand description

The metadata of many scores, searched and cached together: music21’s metadata.bundles.

A MetadataBundle maps a key made from each score’s corpus path to a MetadataEntry: where the score is and its RichMetadata. music21 keeps the bundle of each corpus as a gzipped pickle; [MetadataBundle:: from_cache] reads the pickle music21 writes and [MetadataBundle:: to_cache] writes one music21 reads. Compressing is the caller’s.

use music21::metadata::Metadata;
use music21::metadata::bundles::{MetadataBundle, MetadataEntry};
use music21::metadata::rich::{RichMetadata, RichQuery};

let mut metadata = Metadata::new();
metadata.add_contributor("composer", "Arcangelo Corelli");
let mut bundle = MetadataBundle::new(None);
bundle.insert(MetadataEntry::new("corelli/opus3no1/1grave.xml", None, Some(RichMetadata::of(metadata))));

let found = bundle.search(&RichQuery::Text("corelli"), Some("composer"), &[]);
assert_eq!(found.keys(), ["corelli_opus3no1_1grave_xml"]);

let read = MetadataBundle::from_cache(&bundle.to_cache())?;
assert_eq!(read.len(), 1);

Structs§

MetadataBundle
The metadata of many scores, filed by key in the order they were filed: music21’s MetadataBundle.
MetadataEntry
One score in a bundle: music21’s MetadataEntry.

Enums§

KeySource
How a path was given to corpus_path_to_key: music21 reads a pathlib.Path by its parts and a string by its text.
SetOperation
Which set of keys a combination of two bundles keeps.

Functions§

corpus_path_to_key
The key a score is filed under in a bundle: its corpus path with every separator and dot an underscore, and its number in an opus after it: music21’s MetadataBundle.corpusPathToKey.