Skip to main content

Module features

Module features 

Source
Expand description

Features of a piece for machine learning: music21’s features. Features of a piece of music, extracted for machine learning and corpus study: music21’s features package.

A DataInstance prepares a stream once – ties stripped, every part and voice prepared on its own – and works out each representation an extractor asks for the first time one does: its pitches, its pitch and interval histograms, its melodic contour. An Extractor reads those and answers a Feature, a vector of numbers of a fixed length, each a Value that is a whole number or a measurement as music21’s is. jsymbolic::JSYMBOLIC holds the extractors music21 ports from Cory McKay’s jSymbolic, and native::NATIVE those music21 adds of its own; extractors_by_id finds them by id. A DataSet reads features of many pieces into one table and writes it for a machine-learning tool.

use music21_rs::features::{DataInstance, jsymbolic};
use music21_rs::tinynotation::from_tiny_notation;

let line = from_tiny_notation("4/4 c4 d e f g a b c'")?;
let data = DataInstance::new(&line)?;
let range = jsymbolic::extractor("P10").expect("the range extractor");
assert_eq!(range.extract(&data)?.vector(), [12.0]);

Modules§

jsymbolic
The features music21 ports from Cory McKay’s jSymbolic: music21’s features.jSymbolic. Each is an Extractor in JSYMBOLIC, found by its id with extractor.
languagelanguage-detection
Which language a text is in: music21’s LanguageDetector, with the language-detection feature. Which language a text is in, by the letters that follow each pair of letters: music21’s text.LanguageDetector and text.Trigram.
native
The features music21 adds of its own: music21’s features.native. Each is an Extractor in NATIVE, found by its id with extractor.

Structs§

DataInstance
A piece prepared for feature extraction, with each representation of it worked out once: music21’s DataInstance and the StreamForms it keeps.
DataSet
Features of many pieces in one table: music21’s DataSet. Each piece is a row, labelled with an id and a value of the class the set is about – its composer, say – and each extractor gives it as many columns as it has values. DataSet::process reads every feature of every piece, and DataSet::to_text writes the table for a machine-learning tool.
Extractor
One way of reading a feature out of a piece: music21’s FeatureExtractor, with what its class says about the feature.
Failure
An extractor that could not read its feature from a piece, so that the data set stands a blank feature in for it.
Feature
What an Extractor answers: its name and the vector it found.
Seconds
Where a note sounds in time, in seconds at the tempi of the piece: music21’s secondsMap entry.

Enums§

Cell
One cell of a DataSet’s table: a piece’s id or class, or a value.
Library
Where an extractor comes from: music21’s jSymbolic ports or its own.
OutputFormat
A file format a DataSet is written in: music21’s OutputFormat.
Value
One value of a Feature: a whole number, as a count or an index is, or a float, as a share or a measurement is. music21 keeps the two apart, a vector starting as whole noughts, and writes them apart – 4 and 4.0 – in a data set.

Functions§

all_features_as_list
Every feature of a piece, jSymbolic’s and then music21’s own, each a blank one where it cannot be read: music21’s allFeaturesAsList, but for its language feature.
extractor_by_id
The first extractor extractors_by_id finds for an id: music21’s extractorById.
extractors_by_id
The extractors with any of these ids, from these libraries, in the libraries’ own order: music21’s extractorsById. An id is read without regard to case, hyphens or spaces, so p-20 finds P20; the id all, first, finds every extractor. Both libraries have a P22, so asking for it in both finds two.
index_of
Where the extractor of a feature named so sits in its library, and which library, looking through jSymbolic first unless one is given: music21’s getIndex, as (61, JSymbolic) for Range. Nothing for a name no extractor has.
vector_by_id
The values of the first extractor with an id, read from a piece: music21’s vectorById. Nothing for an id no extractor has.