pyampact.symbolic.Score
- class pyampact.symbolic.Score(score_path)[source]
A class to import a score via music21 and expose pyAMPACT’s analysis utilities.
The analysis utilities are generally formatted as pandas dataframes. This class also ports over some matlab code to help with alignment of scores in symbolic notation and audio analysis of recordings of those scores. Score objects can insert analysis into an MEI file, and can export any type of file to a kern format, optionally also including analysis from a JSON file. Similarly, Score objects can serve clickable URLs of short excerpts of their associated score in symbolic notation. These links open in the Verovio Humdrum Viewer.
- Parameters:
score_path – A string representing the path to the score file.
- Returns:
A Score object.
Example
url_or_path = 'https://github.com/pyampact/pyAMPACTtutorials/blob/main/test_files/M025_00_01a_a.krn' piece = Score(url_or_path)
Methods
__init__
(score_path)cdata
([snap_to, filler, output])Get the cdata records from **cdata spines in a kern file if there are any and return it as a pandas DataFrame. This is similar to the .harm, .functions, .chords, and .keys methods, with the exception that this method defaults to returning a dataframe since there are often more than one cdata spine in a kern score. If want to get the results of a different spine type (i.e. not one of the ones listed above), see
getSpines()
.chords
([snap_to, filler, output])Get the chord labels from the **chord spine in a kern file if there is one and return it as an array or a time-aligned pandas Series. This is similar to the .functions, .harm, .keys, and .cdata methods. The default is for the results to be returned as a 1-d array, but you can set output='series' for a pandas series instead. If want to get the results of a different spine type (i.e. not one of the ones listed above), see
getSpines()
.contextualize
(df[, offsets, measures, beats])Add measure and beat numbers to a DataFrame.
dez
([path])Get the labels data from a .dez file/url and return it as a dataframe.
durations
([multi_index, df])Return a DataFrame of durations of note and rest objects in the piece.
dynamics
()Extract the dynamics from the score.
form
([snap_to, filler, output, dez_path])Get the "Structure" labels from a .dez file/url and return it as an array or a time-aligned pandas Series.
functions
([snap_to, filler, output])Get the harmonic function labels from a **function spine in a kern file if there is one and return it as an array or a time-aligned pandas Series. This is similar to the .harm, .keys, .chords, and .cdata methods. The default is for the results to be returned as a 1-d array, but you can set output='series' for a pandas series instead. If want to get the results of a different spine type (i.e. not one of the ones listed above), see
getSpines()
.getSpines
(spineType)Return a pandas DataFrame of a less common spine type.
harm
([snap_to, filler, output])Get the harmonic analysis portion of the **harm spine in a kern file if there is one and return it as an array or a time-aligned pandas Series. The prevailing key signature information is not included here from the harm spine, but that key information is available in the .keys method. This is similar to the .keys, .functions, .chords, and .cdata methods. The default is for the results to be returned as a 1-d array, but you can set output='series' for a pandas series instead which is helpful if you're going to concatenate the results to a dataframe. If want to get the results of a different spine type (i.e. not one of the ones listed above), see
getSpines()
.insertAudioAnalysis
(output_path, data[, ...])Insert a <performance> element into the MEI score given the analysis data (data) in the format of a json file or an nmat dictionary with audio data already included.
insertScoreDef
(root)Insert a scoreDef element into an MEI (Music Encoding Initiative) document.
jsonCDATA
(json_path)Return a dictionary of pandas DataFrames, one for each voice.
kernNotes
()Return a DataFrame of the notes and rests given in kern notation.
keys
([snap_to, filler, output])Get the key signature portion of the **harm spine in a kern file if there is one and return it as an array or a time-aligned pandas Series. This is similar to the .harm, .functions, .chords, and .cdata methods. The default is for the results to be returned as a 1-d array, but you can set output='series' for a pandas series instead. If want to get the results of a different spine type (i.e. not one of the ones listed above), see
getSpines()
.lyrics
([strip])Extract the lyrics from the score.
mask
([winms, sample_rate, num_harmonics, ...])Construct a mask from the sampled piano roll using width and harmonics.
midiPitches
([multi_index])Return a DataFrame of notes and rests as MIDI pitches.
midi_ticks_durations
([i, df])Replaces the placeholder ONSET_SEC and OFFSET_SEC columns with timing information directly extracted from the music21 stream.
nmats
([json_path, include_cdata])Return a dictionary of DataFrames, one for each voice, with information about the notes and rests in that voice.
notes
([combine_rests, combine_unisons])Return a DataFrame of the notes and rests given in American Standard Pitch Notation where middle C is C4.
pianoRoll
()Construct a MIDI piano roll.
romanNumerals
([snap_to, filler, output, ...])Get the roman numeral labels from a .dez file/url or **harm spine and return it as an array or a time-aligned pandas Series. The default is for the results to be returned as a 1-d array, but you can set output='series' for a pandas series instead. If you want to align these results so that they match the columnar (time) axis of the pianoRoll, sampled, or mask results, you can pass the pianoRoll or mask that you want to align to as the snap_to parameter. Doing that makes it easier to combine these results with any of the pianoRoll, sampled, or mask tables to have both in a single table which can make data analysis easier. This example shows how to get the roman numeral analysis from a kern score that has a **harm spine.
sampled
([bpm, obs])Sample the score according to the given beats per minute (bpm) and the desired observations per second (obs).
show
([start, stop])Print a VerovioHumdrumViewer link to the score in between the start and stop measures (inclusive).
toKern
([path_name, data, lyrics, dynamics])Create a kern representation of the score.
toMEI
([file_name, indentation, data, start, ...])Write or return an MEI score optionally including analysis data.
xmlIDs
()Return xml ids per part in a pandas.DataFrame time-aligned with the objects offset.