pub struct ScalaArchive { /* private fields */ }Expand description
A searchable collection of Scala scales, keyed by file name.
This is the runtime counterpart to music21’s scale.scala module, whose
search and getPaths helpers index the Scala scale archive. The archive
itself is not bundled with this crate — see the note below — so the
caller supplies the files and this type indexes whatever it is given, which
also keeps the crate free of file IO and usable from wasm.
use music21_rs::ScalaArchive;
let mut archive = ScalaArchive::new();
archive.insert("mbira_banda.scl", b"Mbira Banda\n 1\n 2/1\n")?;
archive.insert("slendro5_2.scl", b"Slendro\n 1\n 2/1\n")?;
assert_eq!(archive.search("mbira"), ["mbira_banda.scl"]);
assert!(archive.get("slendro5_2.scl").is_some());Implementations§
Source§impl ScalaArchive
impl ScalaArchive
Sourcepub fn insert(
&mut self,
file_name: impl Into<String>,
bytes: &[u8],
) -> Result<Option<ScalaScale>>
pub fn insert( &mut self, file_name: impl Into<String>, bytes: &[u8], ) -> Result<Option<ScalaScale>>
Parses and indexes one .scl file under the given name.
The name is the file name as music21 refers to it, such as
"partch_43.scl". Returns the scale it replaced, if any.
Sourcepub fn insert_scale(
&mut self,
file_name: impl Into<String>,
scale: ScalaScale,
) -> Option<ScalaScale>
pub fn insert_scale( &mut self, file_name: impl Into<String>, scale: ScalaScale, ) -> Option<ScalaScale>
Indexes an already-parsed scale under the given name.
Sourcepub fn get(&self, file_name: &str) -> Option<&ScalaScale>
pub fn get(&self, file_name: &str) -> Option<&ScalaScale>
Returns the scale stored under a file name.
Sourcepub fn names(&self) -> impl Iterator<Item = &str>
pub fn names(&self) -> impl Iterator<Item = &str>
Returns every indexed file name, in sorted order.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &ScalaScale)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &ScalaScale)>
Returns every indexed scale with its file name, in sorted order.
Sourcepub fn bundled() -> Self
pub fn bundled() -> Self
Builds an archive from the .scl files bundled with the crate.
Only available under the non-default scala-archive feature, which adds
roughly a megabyte of scale data to the build. Without it, supply the
files yourself with ScalaArchive::insert.
Use ScalaArchive::bundled_with_failures to see any scale that fails
to load rather than silently dropping it.
Sourcepub fn bundled_with_failures() -> (Self, Vec<(&'static str, Error)>)
pub fn bundled_with_failures() -> (Self, Vec<(&'static str, Error)>)
Builds an archive from the bundled files, reporting the ones that fail.
The failures are a fixed property of the bundled data, so the returned list is the same on every call.
Sourcepub fn bundled_len() -> usize
pub fn bundled_len() -> usize
Returns the number of .scl files bundled with the crate.
Counts files without parsing them, so this includes the one that
ScalaArchive::bundled skips.
Sourcepub fn search(&self, target: &str) -> Vec<&str>
pub fn search(&self, target: &str) -> Vec<&str>
Finds file names matching a search string, as music21’s
scale.scala.search does.
Spaces in the target are ignored, an exact file-name match is preferred,
and the remaining matches are substring hits against the name with its
extension dropped and against a form with _ and - removed. Results
are sorted.
Trait Implementations§
Source§impl Clone for ScalaArchive
impl Clone for ScalaArchive
Source§fn clone(&self) -> ScalaArchive
fn clone(&self) -> ScalaArchive
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScalaArchive
impl Debug for ScalaArchive
Source§impl Default for ScalaArchive
impl Default for ScalaArchive
Source§fn default() -> ScalaArchive
fn default() -> ScalaArchive
Source§impl Extend<(String, ScalaScale)> for ScalaArchive
impl Extend<(String, ScalaScale)> for ScalaArchive
Source§fn extend<T: IntoIterator<Item = (String, ScalaScale)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (String, ScalaScale)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<(String, ScalaScale)> for ScalaArchive
impl FromIterator<(String, ScalaScale)> for ScalaArchive
Source§fn from_iter<T: IntoIterator<Item = (String, ScalaScale)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (String, ScalaScale)>>(iter: T) -> Self
Source§impl PartialEq for ScalaArchive
impl PartialEq for ScalaArchive
Source§fn eq(&self, other: &ScalaArchive) -> bool
fn eq(&self, other: &ScalaArchive) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ScalaArchive
Auto Trait Implementations§
impl Freeze for ScalaArchive
impl RefUnwindSafe for ScalaArchive
impl Send for ScalaArchive
impl Sync for ScalaArchive
impl Unpin for ScalaArchive
impl UnsafeUnpin for ScalaArchive
impl UnwindSafe for ScalaArchive
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,
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