This module contains tools for estimating key signature, time signature,
pitch spelling, voice information, tonal tension, as well as methods for
deriving note-level features and performance encodings.
1) Without arguments this returns a structured array of onsets, offsets,
pitch, and ID information: equivalent to part.note_array()
2) With any of the flag arguments set to true, a column with the specified
information will be added to the array: equivalent t0 part.note_array(*flags)
3) With a list of strings or functions as feature_functions argument,
a column (or multiple columns) with the specified information will
be added to the array.
See also:
>>> make_note_features(part)
For a list of features see:
>>> list_note_feats_functions()
Parameters:
include_pitch_spelling (bool (optional)) – If True, includes pitch spelling information for each
note. Default is False
include_key_signature (bool (optional)) – If True, includes key signature information, i.e.,
the key signature at the onset time of each note (all
notes starting at the same time have the same key signature).
Default is False
include_time_signature (bool (optional)) – If True, includes time signature information, i.e.,
the time signature at the onset time of each note (all
notes starting at the same time have the same time signature).
Default is False
include_metrical_position (bool (optional)) – If True, includes metrical position information, i.e.,
the position of the onset time of each note with respect to its
measure (all notes starting at the same time have the same metrical
position).
Default is False
include_grace_notes (bool (optional)) – If True, includes grace note information, i.e. if a note is a
grace note and the grace type “” for non grace notes).
Default is False
feature_functions (list or str) – A list of feature functions. Elements of the list can be either
the functions themselves or the names of a feature function as
strings (or a mix). The feature functions specified by name are
looked up in the featuremixer.featurefunctions module.
Estimate key of a piece by comparing the pitch statistics of the
note array to key profiles [2], [3].
Parameters:
note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or
as a structured array. If it is a structured array, it has to
contain the fields generated by the note_array properties
of Part or PerformedPart objects. If the array contains
onset and duration information of both score and performance,
(e.g., containing both onset_beat and onset_sec), the score
information will be preferred.
method ({'krumhansl'}) – Method for estimating the key. For now ‘krumhansl’ is the only
supported method.
args – Positional and Keyword arguments for the key estimation method
kwargs – Positional and Keyword arguments for the key estimation method
Returns:
String representing the key name (i.e., Root(alteration)(m if minor)).
See partitura.utils.key_name_to_fifths_mode and
partitura.utils.fifths_mode_to_key_name.
Estimate pitch spelling using the ps13 algorithm [4], [5].
Parameters:
note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or
as a structured array. If it is a structured array, it has to
contain the fields generated by the note_array properties
of Part or PerformedPart objects. If the array contains
onset and duration information of both score and performance,
(e.g., containing both onset_beat and onset_sec), the score
information will be preferred.
method ({'ps13s1'}) – Pitch spelling algorithm. More methods will be added.
**kwargs – Keyword arguments for the algorithm specified in method.
Returns:
spelling – Array with pitch spellings. The fields are ‘step’, ‘alter’ and
‘octave’
Estimate tempo, meter (currently only time signature numerator), and beats
Parameters:
note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or
as a structured array. If it is a structured array, it has to
contain the fields generated by the note_array properties
of Part or PerformedPart objects. If the array contains
onset and duration information of both score and performance,
(e.g., containing both onset_beat and onset_sec), the score
information will be preferred.
note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or
as a structured array. If it is a structured array, it has to
contain the fields generated by the note_array properties
of Part or PerformedPart objects. If the array contains
onset and duration information of both score and performance,
(e.g., containing both onset_beat and onset_sec), the score
information will be preferred. Furthermore, this method requires
pitch spelling and key signature information. If a structured note
array is provided as input, this information can be optionally
provided in fields step, alter, ks_fifths and ks_mode.
If these fields are not found in the input structured array,
they will be estimated using the key and pitch spelling estimation
methods from partitura.musicanalysis.estimate_key and
and partitura.musicanalysis.estimate_spelling, respectively.
ws ({int, float, np.array}, optional) – Window size for computing the tonal tension. If a number, it determines
the size of the window centered at each specified score position (see
ss below). If a numpy array, a 2D array of shape (len(ss), 2)
specifying the left and right distance from each score position in
ss. Default is 1 beat.
ss ({float, int, np.array, 'onset'}, optional.) – Step size or score position for computing the tonal tension features.
If a number, this parameter determines the size of the step (in beats)
starting from the first score position. If an array, it specifies the
score positions at which the tonal tension is estimated. If ‘onset’,
it computes the tension at each unique score position (i.e., all notes
in a chord have the same score position). Default is ‘onset’.
scale_factor (float) – A multiplicative scaling factor.
w (np.ndarray) – Weights for the chords
alpha (float) – Alpha.
beta (float) – Beta.
Returns:
tonal_tension – Array containing the tonal tension features. It contains the fields
cloud_diameter, cloud_momentum, tensile_strain and onset.
note_info (structured array, Part or PerformedPart) – Note information as a Part or PerformedPart instances or
as a structured array. If it is a structured array, it has to
contain the fields generated by the note_array properties
of Part or PerformedPart objects. If the array contains
onset and duration information of both score and performance,
(e.g., containing both onset_beat and onset_sec), the score
information will be preferred.
monophonic_voices (bool) – If True voices are guaranteed to be monophonic. Otherwise
notes with the same onset and duration are treated as a chord
and assigned to the same voice. Defaults to False.
Returns:
voice – Voice for each note in the notearray. (The voices start with 1, as
is the MusicXML convention).
Compute the specified feature functions for a part.
The function returns the computed feature functions as a N x M
array, where N equals len(part.notes_tied) and M equals the
total number of descriptors of all feature functions that occur in
part.
Furthermore the function returns the names of the feature functions.
A list of strings of size M. The names have the name of the
function prepended to the name of the descriptor. For example if a
function named abc_feature returns descriptors a, b, and c,
then the list of names returned by make_feature(part,
[‘abc_feature’]) will be [‘abc_feature.a’, ‘abc_feature.b’,
‘abc_feature.c’].
feature_functions (list or str) – A list of feature functions. Elements of the list can be either
the functions themselves or the names of a feature function as
strings (or a mix), or the keywork “all”. The feature functions specified by name are
looked up in the featuremixer.featurefunctions module.
Compute the specified feature functions for a part.
The function returns the computed feature functions as a N x M
array, where N equals len(part.rests) and M equals the
total number of descriptors of all feature functions that occur in
part.
feature_functions (list or str) – A list of feature functions. Elements of the list can be either
the functions themselves or the names of a feature function as
strings (or a mix), or the keywork “all”. The feature functions specified by name are
looked up in the featuremixer.featurefunctions module.