Skip to main content

ScalaArchive

Struct ScalaArchive 

Source
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

Source

pub fn new() -> Self

Creates an empty archive.

Source

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.

Source

pub fn insert_scale( &mut self, file_name: impl Into<String>, scale: ScalaScale, ) -> Option<ScalaScale>

Indexes an already-parsed scale under the given name.

Source

pub fn get(&self, file_name: &str) -> Option<&ScalaScale>

Returns the scale stored under a file name.

Source

pub fn names(&self) -> impl Iterator<Item = &str>

Returns every indexed file name, in sorted order.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &ScalaScale)>

Returns every indexed scale with its file name, in sorted order.

Source

pub fn len(&self) -> usize

Returns the number of indexed scales.

Source

pub fn is_empty(&self) -> bool

Returns whether the archive is empty.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ScalaArchive

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 ScalaArchive

Source§

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

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

impl Default for ScalaArchive

Source§

fn default() -> ScalaArchive

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

impl Extend<(String, ScalaScale)> for ScalaArchive

Source§

fn extend<T: IntoIterator<Item = (String, ScalaScale)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<(String, ScalaScale)> for ScalaArchive

Source§

fn from_iter<T: IntoIterator<Item = (String, ScalaScale)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for ScalaArchive

Source§

fn eq(&self, other: &ScalaArchive) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ScalaArchive

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.