maiacore 1.10.1
Music analisys library
Score Class Reference

Represents a complete musical score, including metadata, parts, measures, and notes. More...

#include <score.h>

Public Types

typedef std::tuple< std::string, int, int, std::string, std::string, std::vector< std::string >, std::vector< float >, std::vector< float >, float, float, float > MelodyPatternRow
 Table row type for melodic pattern search results. More...
 
typedef std::vector< MelodyPatternRowMelodyPatternTable
 Table type for melodic pattern search results.
 

Public Member Functions

 Score (const std::initializer_list< std::string > &partsName, const int numMeasures=20)
 Constructs a new blank Score object with specified part names and initial measure count. More...
 
 Score (const std::vector< std::string > &partsName, const int numMeasures=20)
 Constructs a new blank Score object with specified part names and initial measure count. More...
 
 Score (const std::string &filePath)
 Constructs a new Score object by loading a MusicXML file. More...
 
 Score (Score &&)=default
 Move constructor for Score.
 
 ~Score ()
 Destructor. Releases resources associated with the score.
 
void clear ()
 Clears all content from the score, removing parts, measures, and metadata. More...
 
void addPart (const std::string &partName, const int numStaves=1)
 Adds a new part (instrument/voice) to the score. More...
 
void removePart (const int partId)
 Removes a part from the score by its index. More...
 
void addMeasure (const int numMeasures)
 Adds a specified number of measures to all parts in the score. More...
 
void removeMeasure (const int measureStart, const int measureEnd)
 Removes a range of measures from all parts in the score. More...
 
PartgetPart (const int partId)
 Returns a reference to a part by its index. More...
 
PartgetPart (const std::string &partName)
 Returns a reference to a part by its name. More...
 
int getNumParts () const
 Returns the number of parts (instruments/voices) in the score. More...
 
int getNumMeasures () const
 Returns the number of measures in the score. More...
 
int getNumNotes () const
 Returns the total number of notes in the score. More...
 
const std::vector< std::string > getPartsNames () const
 Returns a vector with the names of all parts/instruments. More...
 
std::string getTitle () const
 Returns the title of the score. More...
 
void setTitle (const std::string &scoreTitle)
 Sets the title of the score. More...
 
std::string getComposerName () const
 Returns the composer's name. More...
 
void setComposerName (const std::string &composerName)
 Sets the composer's name. More...
 
void setKeySignature (const int fifthCicle, const bool isMajorMode=true, const int measureId=0)
 Sets the key signature for all parts at a specific measure. More...
 
void setKeySignature (const std::string &key, const int measureId=0)
 Sets the key signature using the key name (e.g., "C", "Gm"). More...
 
void setTimeSignature (const int timeUpper, const int timeLower, const int measureId=-1)
 Sets the time signature for all or part of the measures. More...
 
void setMetronomeMark (int bpm, const RhythmFigure duration=RhythmFigure::QUARTER, int measureStart=0)
 Sets the metronome mark (BPM) for a specific measure. More...
 
const std::string toXML (const int identSize=2) const
 Exports the score to MusicXML format. More...
 
const std::string toJSON () const
 Exports the score to JSON format. More...
 
void toFile (std::string fileName, bool compressedXML=false, const int identSize=2) const
 Saves the score to a file in XML or compressed MXL format. More...
 
void info () const
 Prints summary information about the score to the log. More...
 
void forEachNote (std::function< void(Part *part, Measure *measure, int staveId, Note *note)> callback, int measureStart=0, int measureEnd=-1, std::vector< std::string > partNames={})
 Iterates over all notes in the score, applying a callback function. More...
 
bool isValid (void) const
 Returns true if the score is valid (MusicXML loaded correctly). More...
 
std::string getFilePath () const
 Returns the file path of the loaded MusicXML file. More...
 
std::string getFileName () const
 Returns the file name of the loaded MusicXML file. More...
 
bool haveTypeTag (void) const
 Returns true if the MusicXML file contains <type> tags for notes. More...
 
bool getNote (const int part, const int measure, const int note, std::string &pitch, std::string &step, int &octave, int &duration, int &voice, std::string &type, std::string &steam, int &staff) const
 Retrieves detailed information about a specific note in the score. More...
 
bool getNote (const int part, const int measure, const int note, std::string &pitch, std::string &step, int &octave) const
 Retrieves basic information about a specific note (pitch, step, octave). More...
 
bool getNote (const int part, const int measure, const int note, std::string &pitch) const
 Retrieves only the pitch of a specific note. More...
 
void printPartNames () const
 Prints the names of all parts/instruments in the score to the terminal.
 
int xPathCountNodes (const std::string &xPath) const
 Counts the number of XML nodes matching a given XPath expression. More...
 
const std::string getPartName (const int partId) const
 Returns the name of a part by its index. More...
 
bool getPartIndex (const std::string &partName, int *index) const
 Gets the index of a part by its name. More...
 
bool haveAnacrusisMeasure () const
 Returns true if the score contains an anacrusis (pickup) measure. More...
 
void getNoteNodeData (const pugi::xml_node &node, std::string &partName, int &measure, std::string &pitch, std::string &pitchClass, std::string &alterSymbol, int &alterValue, int &octave, std::string &type, float &duration) const
 Retrieves detailed information from a note XML node. More...
 
void setRepeat (int measureStart, int measureEnd=-1)
 Sets repeat barlines for a range of measures. More...
 
nlohmann::json instrumentFragmentation (nlohmann::json config=nlohmann::json())
 Analyzes instrumental fragmentation patterns across the score timeline. More...
 
 Score (const Score &other)
 Copy constructor for Score. More...
 
Scoreoperator= (const Score &other)
 Assignment operator for Score. More...
 
MelodyPatternTable findMelodyPattern (const std::vector< Note > &melodyPattern, const float totalIntervalsSimilarityThreshold=0.5, const float totalRhythmSimilarityThreshold=0.5, const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)> intervalsSimilarityCallback=nullptr, const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)> rhythmSimilarityCallback=nullptr, const std::function< float(const std::vector< float > &)> totalIntervalSimilarityCallback=nullptr, const std::function< float(const std::vector< float > &)> totalRhythmSimilarityCallback=nullptr, const std::function< float(float, float)> totalSimilarityCallback=nullptr) const
 Searches for a melodic pattern throughout the score, returning detailed results. More...
 
std::vector< MelodyPatternTablefindMelodyPattern (const std::vector< std::vector< Note > > &melodyPatterns, const float totalIntervalsSimilarityThreshold=0.5, const float totalRhythmSimilarityThreshold=0.5, const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)> intervalsSimilarityCallback=nullptr, const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)> rhythmSimilarityCallback=nullptr, const std::function< float(const std::vector< float > &)> totalIntervalSimilarityCallback=nullptr, const std::function< float(const std::vector< float > &)> totalRhythmSimilarityCallback=nullptr, const std::function< float(float, float)> totalSimilarityCallback=nullptr) const
 Searches for multiple melodic patterns in the score, returning a table for each pattern. More...
 
std::vector< MelodyPatternTablefindAnyMelodyPattern (const int patternNumNotes=5, const float totalIntervalsSimilarityThreshold=1.0f, const float totalRhythmSimilarityThreshold=1.0f, const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)> intervalsSimilarityCallback=nullptr, const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)> rhythmSimilarityCallback=nullptr, const std::function< float(const std::vector< float > &)> totalIntervalSimilarityCallback=nullptr, const std::function< float(const std::vector< float > &)> totalRhythmSimilarityCallback=nullptr, const std::function< float(float, float)> totalSimilarityCallback=nullptr) const
 Finds all possible melodic patterns of a given length in the score. More...
 
std::vector< std::tuple< int, float, Key, Chord, bool > > getChords (nlohmann::json config={})
 Extracts vertical chord structures from the score with configurable analysis parameters. More...
 

Detailed Description

Represents a complete musical score, including metadata, parts, measures, and notes.

The Score class provides methods for creating, loading, editing, analyzing, and exporting musical scores. It supports MusicXML import/export, part and measure management, note access, metadata handling, and advanced musicological analysis such as melodic pattern search and chord extraction.

Member Typedef Documentation

◆ MelodyPatternRow

typedef std::tuple<std::string, int, int, std::string, std::string, std::vector<std::string>, std::vector<float>, std::vector<float>, float, float, float> Score::MelodyPatternRow

Table row type for melodic pattern search results.

Contains part name, measure, stave, key, transposition, interval/rhythm differences, and similarity scores.

Constructor & Destructor Documentation

◆ Score() [1/4]

Score::Score ( const std::initializer_list< std::string > &  partsName,
const int  numMeasures = 20 
)
explicit

Constructs a new blank Score object with specified part names and initial measure count.

Parameters
partsNameList of instrument/part names.
numMeasuresInitial number of measures (default: 20).

◆ Score() [2/4]

Score::Score ( const std::vector< std::string > &  partsName,
const int  numMeasures = 20 
)
explicit

Constructs a new blank Score object with specified part names and initial measure count.

Parameters
partsNameVector of instrument/part names.
numMeasuresInitial number of measures (default: 20).

◆ Score() [3/4]

Score::Score ( const std::string &  filePath)
explicit

Constructs a new Score object by loading a MusicXML file.

Supported formats: *.xml, *.musicxml, *.mxl (compressed).

Parameters
filePathPath to the MusicXML file.

◆ Score() [4/4]

Score::Score ( const Score other)
inline

Copy constructor for Score.

Parameters
otherScore to copy.

Member Function Documentation

◆ addMeasure()

void Score::addMeasure ( const int  numMeasures)

Adds a specified number of measures to all parts in the score.

Parameters
numMeasuresNumber of measures to add.

◆ addPart()

void Score::addPart ( const std::string &  partName,
const int  numStaves = 1 
)

Adds a new part (instrument/voice) to the score.

Optionally specify the number of staves for the part.

Parameters
partNameName of the part/instrument.
numStavesNumber of staves (default: 1).

◆ clear()

void Score::clear ( )

Clears all content from the score, removing parts, measures, and metadata.

Useful for reusing the Score object without creating a new one.

◆ findAnyMelodyPattern()

std::vector< MelodyPatternTable > Score::findAnyMelodyPattern ( const int  patternNumNotes = 5,
const float  totalIntervalsSimilarityThreshold = 1.0f,
const float  totalRhythmSimilarityThreshold = 1.0f,
const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)>  intervalsSimilarityCallback = nullptr,
const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)>  rhythmSimilarityCallback = nullptr,
const std::function< float(const std::vector< float > &)>  totalIntervalSimilarityCallback = nullptr,
const std::function< float(const std::vector< float > &)>  totalRhythmSimilarityCallback = nullptr,
const std::function< float(float, float)>  totalSimilarityCallback = nullptr 
) const

Finds all possible melodic patterns of a given length in the score.

Useful for exploratory analysis of motives and recurring melodic cells.

Parameters
patternNumNotesNumber of notes in each pattern.
totalIntervalsSimilarityThresholdMinimum interval similarity threshold.
totalRhythmSimilarityThresholdMinimum rhythm similarity threshold.
intervalsSimilarityCallbackCustom function to calculate interval similarity.
rhythmSimilarityCallbackCustom function to calculate rhythm similarity.
totalIntervalSimilarityCallbackFunction to aggregate interval similarity.
totalRhythmSimilarityCallbackFunction to aggregate rhythm similarity.
totalSimilarityCallbackFunction to combine total similarities.
Returns
Vector of result tables for each found pattern.

◆ findMelodyPattern() [1/2]

MelodyPatternTable Score::findMelodyPattern ( const std::vector< Note > &  melodyPattern,
const float  totalIntervalsSimilarityThreshold = 0.5,
const float  totalRhythmSimilarityThreshold = 0.5,
const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)>  intervalsSimilarityCallback = nullptr,
const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)>  rhythmSimilarityCallback = nullptr,
const std::function< float(const std::vector< float > &)>  totalIntervalSimilarityCallback = nullptr,
const std::function< float(const std::vector< float > &)>  totalRhythmSimilarityCallback = nullptr,
const std::function< float(float, float)>  totalSimilarityCallback = nullptr 
) const

Searches for a melodic pattern throughout the score, returning detailed results.

Parameters
melodyPatternVector of notes representing the pattern to search for.
totalIntervalsSimilarityThresholdMinimum interval similarity threshold (0.0-1.0).
totalRhythmSimilarityThresholdMinimum rhythm similarity threshold (0.0-1.0).
intervalsSimilarityCallbackCustom function to calculate interval similarity.
rhythmSimilarityCallbackCustom function to calculate rhythm similarity.
totalIntervalSimilarityCallbackFunction to aggregate interval similarity.
totalRhythmSimilarityCallbackFunction to aggregate rhythm similarity.
totalSimilarityCallbackFunction to combine total similarities.
Returns
Table of results with detailed information about found patterns.

Performs comprehensive melodic pattern matching across all parts and measures of the score, supporting flexible similarity metrics for both intervallic contour and rhythmic structure. This function enables motivic analysis, thematic transformation studies, and computational detection of melodic recurrence.

Pattern Matching Process:

  1. Sliding window search across all melodic sequences in the score
  2. For each candidate match: a. Compute intervallic similarity (pitch contour matching) b. Compute rhythmic similarity (durational pattern matching) c. Aggregate similarities using custom or default models
  3. Filter results by threshold criteria
  4. Return matches with positional metadata (part, measure, beat)

Similarity Calculation:

  • Default Interval Similarity: Normalized edit distance or contour correlation between semitone interval sequences. Allows approximate matching (transposition, modal mutation, chromatic alteration).
  • Default Rhythm Similarity: Durational ratio comparison with tolerance for rhythmic augmentation/diminution and metric displacement.
  • Custom Callbacks: User-defined similarity models enable:
    • Weighted interval classes (emphasize melodic leaps vs. stepwise motion)
    • Parsons code contour matching (directional contour only)
    • Fuzzy matching with configurable tolerance bands

Threshold Parameters:

  • Values near 1.0: Require near-exact matches (strict motivic repetition)
  • Values near 0.5: Allow moderate variation (thematic transformation, development)
  • Values near 0.0: Detect loose similarity (distant motivic relationships)

Applications:

  • Motivic analysis (leitmotif tracking in Wagner, Brahms developing variation)
  • Thematic cataloging (identifying subject entries in fugues, variation themes)
  • Computational musicology (corpus-wide melodic similarity studies)
  • Plagiarism detection (melodic borrowing, paraphrase identification)
  • Style analysis (characteristic melodic gestures across composers/periods)
Note
Computational complexity is O(n × m) where n = total notes in score, m = pattern length. For large scores, consider restricting search to specific parts or measure ranges.

◆ findMelodyPattern() [2/2]

std::vector< MelodyPatternTable > Score::findMelodyPattern ( const std::vector< std::vector< Note > > &  melodyPatterns,
const float  totalIntervalsSimilarityThreshold = 0.5,
const float  totalRhythmSimilarityThreshold = 0.5,
const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)>  intervalsSimilarityCallback = nullptr,
const std::function< std::vector< float >(const std::vector< Note > &, const std::vector< Note > &)>  rhythmSimilarityCallback = nullptr,
const std::function< float(const std::vector< float > &)>  totalIntervalSimilarityCallback = nullptr,
const std::function< float(const std::vector< float > &)>  totalRhythmSimilarityCallback = nullptr,
const std::function< float(float, float)>  totalSimilarityCallback = nullptr 
) const

Searches for multiple melodic patterns in the score, returning a table for each pattern.

Allows parallel analysis of several patterns, useful for comparative research.

Parameters
melodyPatternsVector of melodic patterns.
totalIntervalsSimilarityThresholdMinimum interval similarity threshold.
totalRhythmSimilarityThresholdMinimum rhythm similarity threshold.
intervalsSimilarityCallbackCustom function to calculate interval similarity.
rhythmSimilarityCallbackCustom function to calculate rhythm similarity.
totalIntervalSimilarityCallbackFunction to aggregate interval similarity.
totalRhythmSimilarityCallbackFunction to aggregate rhythm similarity.
totalSimilarityCallbackFunction to combine total similarities.
Returns
Vector of result tables, one for each pattern.

◆ forEachNote()

void Score::forEachNote ( std::function< void(Part *part, Measure *measure, int staveId, Note *note)>  callback,
int  measureStart = 0,
int  measureEnd = -1,
std::vector< std::string >  partNames = {} 
)

Iterates over all notes in the score, applying a callback function.

Supports optional filtering by measure range and part names.

Parameters
callbackFunction to call for each note.
measureStartStarting measure (default: 0).
measureEndEnding measure (default: -1, until the end).
partNamesList of part names to process (default: all).

◆ getChords()

std::vector< std::tuple< int, float, Key, Chord, bool > > Score::getChords ( nlohmann::json  config = {})

Extracts vertical chord structures from the score with configurable analysis parameters.

Parameters
configOptional JSON configuration object controlling chord extraction criteria.
Returns
Vector of tuples: {measure number, beat position, Key, Chord, homophony flag}.

Performs vertical harmonic analysis by extracting simultaneities (vertical chord slices) from the polyphonic texture, with extensive filtering and processing options for texture analysis, harmonic progression studies, and style-specific chord detection.

Configuration Parameters (all optional):

  • partNames (list of strings): Restrict analysis to specific instrumental parts (e.g., ["Violino", "Viola", "Violoncelo"] for string trio texture)
  • measureStart, measureEnd (integers): Define measure range for analysis
  • minStack, maxStack (integers): Filter by chord cardinality (number of notes)
    • minStack=3, maxStack=4 → only triads and seventh chords
  • minDuration, maxDuration (strings): Filter by note duration (e.g., "quarter", "half", "whole")
  • continuosMode (boolean): Texture analysis mode selector
    • true: Continuous vertical slicing—captures ALL vertical alignments including non-aligned notes (polyphonic/contrapuntal texture analysis)
    • false: Attack-point synchronization—only chords formed by simultaneous note onsets (homophonic texture, block chord analysis)
  • includeDuplicates (boolean): Octave doubling handling
    • true: Preserve pitch-class duplications (["C4", "C4", "E4", "G4"])
    • false: Remove duplicate pitch classes (["C4", "E4", "G4"])
  • includeUnpitched (boolean): Include percussion/unpitched elements

Example Configuration:

{
"partNames": ["Violino", "Viola", "Violoncelo"],
"measureStart": 4,
"measureEnd": 10,
"minDuration": "quarter",
"maxDuration": "whole",
"continuosMode": true,
"includeDuplicates": false,
"includeUnpitched": false
}

Return Value Structure: Each tuple contains:

  1. Measure number (int): Absolute measure position in score
  2. Beat position (float): Fractional beat location within measure
  3. Key (Key object): Prevailing key signature at this position
  4. Chord (Chord object): Extracted vertical sonority
  5. Homophony flag (bool): True if all voices share identical rhythm (homophonic texture indicator)

Applications:

  • Harmonic analysis (chord progression extraction, functional harmony labeling)
  • Texture classification (homophonic vs. polyphonic density analysis)
  • Voice-leading analysis (chord-to-chord motion studies)
  • Statistical harmony studies (chord frequency distributions, bigram models)
  • Dissonance trajectory analysis (tracking harmonic tension across time)
Note
The continuosMode parameter critically affects results:
  • For homophonic textures (hymns, chorales): use continuosMode=false
  • For contrapuntal textures (fugues, inventions): use continuosMode=true

◆ getComposerName()

std::string Score::getComposerName ( ) const

Returns the composer's name.

Returns
Composer name string.

◆ getFileName()

std::string Score::getFileName ( ) const

Returns the file name of the loaded MusicXML file.

Returns
File name string.

◆ getFilePath()

std::string Score::getFilePath ( ) const

Returns the file path of the loaded MusicXML file.

Returns
File path string.

◆ getNote() [1/3]

bool Score::getNote ( const int  part,
const int  measure,
const int  note,
std::string &  pitch 
) const

Retrieves only the pitch of a specific note.

Parameters
partPart index.
measureMeasure index.
noteNote index.
pitchOutput: pitch string.
Returns
True if the note was found.

◆ getNote() [2/3]

bool Score::getNote ( const int  part,
const int  measure,
const int  note,
std::string &  pitch,
std::string &  step,
int &  octave 
) const

Retrieves basic information about a specific note (pitch, step, octave).

Parameters
partPart index.
measureMeasure index.
noteNote index.
pitchOutput: pitch string.
stepOutput: step string.
octaveOutput: octave integer.
Returns
True if the note was found.

◆ getNote() [3/3]

bool Score::getNote ( const int  part,
const int  measure,
const int  note,
std::string &  pitch,
std::string &  step,
int &  octave,
int &  duration,
int &  voice,
std::string &  type,
std::string &  steam,
int &  staff 
) const

Retrieves detailed information about a specific note in the score.

Accesses attributes such as pitch, duration, voice, type, stem, and staff.

Parameters
partPart index.
measureMeasure index.
noteNote index.
pitchOutput: pitch string.
stepOutput: step string.
octaveOutput: octave integer.
durationOutput: duration integer.
voiceOutput: voice integer.
typeOutput: type string.
steamOutput: stem string.
staffOutput: staff integer.
Returns
True if the note was found.

◆ getNoteNodeData()

void Score::getNoteNodeData ( const pugi::xml_node &  node,
std::string &  partName,
int &  measure,
std::string &  pitch,
std::string &  pitchClass,
std::string &  alterSymbol,
int &  alterValue,
int &  octave,
std::string &  type,
float &  duration 
) const

Retrieves detailed information from a note XML node.

Parameters
nodeXML node of the note.
partNameOutput: part name.
measureOutput: measure number.
pitchOutput: pitch string.
pitchClassOutput: pitch class string.
alterSymbolOutput: accidental symbol.
alterValueOutput: accidental value.
octaveOutput: octave.
typeOutput: note type.
durationOutput: note duration.

◆ getNumMeasures()

int Score::getNumMeasures ( ) const

Returns the number of measures in the score.

Returns
Number of measures.

◆ getNumNotes()

int Score::getNumNotes ( ) const

Returns the total number of notes in the score.

Returns
Number of notes.

◆ getNumParts()

int Score::getNumParts ( ) const

Returns the number of parts (instruments/voices) in the score.

Returns
Number of parts.

◆ getPart() [1/2]

Part & Score::getPart ( const int  partId)

Returns a reference to a part by its index.

Parameters
partIdIndex of the part.
Returns
Reference to the Part object.

◆ getPart() [2/2]

Part & Score::getPart ( const std::string &  partName)

Returns a reference to a part by its name.

Parameters
partNameName of the part.
Returns
Reference to the Part object.

◆ getPartIndex()

bool Score::getPartIndex ( const std::string &  partName,
int *  index 
) const

Gets the index of a part by its name.

Parameters
partNameName of the part.
indexOutput: index integer.
Returns
True if the part was found.

◆ getPartName()

const std::string Score::getPartName ( const int  partId) const

Returns the name of a part by its index.

Parameters
partIdPart index.
Returns
Part name string.

◆ getPartsNames()

const std::vector< std::string > Score::getPartsNames ( ) const

Returns a vector with the names of all parts/instruments.

Returns
Vector of part names.

◆ getTitle()

std::string Score::getTitle ( ) const

Returns the title of the score.

Returns
Title string.

◆ haveAnacrusisMeasure()

bool Score::haveAnacrusisMeasure ( ) const

Returns true if the score contains an anacrusis (pickup) measure.

Returns
True if anacrusis is present.

◆ haveTypeTag()

bool Score::haveTypeTag ( void  ) const

Returns true if the MusicXML file contains <type> tags for notes.

Returns
True if <type> tags are present.

◆ info()

void Score::info ( ) const

Prints summary information about the score to the log.

Includes title, composer, key, time signature, note count, measure count, and part names.

◆ instrumentFragmentation()

nlohmann::json Score::instrumentFragmentation ( nlohmann::json  config = nlohmann::json())

Analyzes instrumental fragmentation patterns across the score timeline.

Parameters
configJSON configuration object specifying analysis parameters (parts, measures, etc).
Returns
JSON structure with activation, fragmentation, and execution metrics per instrument.

Performs temporal analysis of instrumental activity distribution, quantifying how melodic lines are fragmented across different instruments over time. This analysis is essential for orchestration studies, texture evolution tracking, and compositional strategy research.

Fragmentation Metrics Computed:

  1. Activation Lines: Temporal intervals where each instrument is active (sounding notes)
  2. Fragmentation Patterns: Transitions of melodic material between instruments (e.g., melody alternating between violin and flute—klangfarbenmelodie analysis)
  3. Execution Density: Proportion of time each instrument participates in texture

Analysis Categories:

  • Continuous Execution: Sustained melodic lines without rests (legato passages)
  • Fragmented Execution: Interrupted melodic lines with rests (staccato, pointillism)
  • Hand-off Patterns: Melodic continuation across instrument changes (orchestral dialogue)
  • Tutti vs. Solo Distributions: Ensemble density fluctuations

Configuration Parameters (config JSON):

  • partNames (list): Restrict analysis to specific instrumental parts
  • measureStart, measureEnd (int): Define temporal analysis window
  • timeResolution (float): Granularity for temporal slicing (e.g., 0.25 = sixteenth note)

Return JSON Structure:

{
"instruments": [
{
"name": "Violin I",
"activationIntervals": [[1.0, 4.5], [8.0, 12.5]],
"fragmentationCount": 3,
"executionDensity": 0.67
},
...
],
"fragmentationEvents": [
{"measure": 4, "fromInstrument": "Violin I", "toInstrument": "Flute"},
...
]
}

Applications:

  • Orchestration analysis (instrument usage patterns in Mahler, Ravel, Stravinsky)
  • Klangfarbenmelodie detection (Schoenberg, Webern timbral melody techniques)
  • Texture evolution studies (gradual thickening/thinning of orchestral fabric)
  • Compositional fingerprinting (characteristic orchestration strategies per composer)
  • Performance part difficulty assessment (rest distribution, endurance requirements)
Note
This function is computationally intensive for large orchestral scores. Consider restricting analysis to specific measure ranges or part subsets.

◆ isValid()

bool Score::isValid ( void  ) const

Returns true if the score is valid (MusicXML loaded correctly).

Returns
True if valid.

◆ operator=()

Score & Score::operator= ( const Score other)
inline

Assignment operator for Score.

Parameters
otherScore to assign from.
Returns
Reference to this Score.

◆ removeMeasure()

void Score::removeMeasure ( const int  measureStart,
const int  measureEnd 
)

Removes a range of measures from all parts in the score.

Parameters
measureStartIndex of the first measure to remove.
measureEndIndex of the last measure to remove.

◆ removePart()

void Score::removePart ( const int  partId)

Removes a part from the score by its index.

Parameters
partIdIndex of the part to remove.

◆ setComposerName()

void Score::setComposerName ( const std::string &  composerName)

Sets the composer's name.

Parameters
composerNameNew composer name.

◆ setKeySignature() [1/2]

void Score::setKeySignature ( const int  fifthCicle,
const bool  isMajorMode = true,
const int  measureId = 0 
)

Sets the key signature for all parts at a specific measure.

Specify the number of accidentals (fifths) and mode (major/minor).

Parameters
fifthCicleNumber of accidentals in the circle of fifths.
isMajorModeTrue for major, false for minor.
measureIdMeasure index (default: 0).

◆ setKeySignature() [2/2]

void Score::setKeySignature ( const std::string &  key,
const int  measureId = 0 
)

Sets the key signature using the key name (e.g., "C", "Gm").

Parameters
keyKey name.
measureIdMeasure index (default: 0).

◆ setMetronomeMark()

void Score::setMetronomeMark ( int  bpm,
const RhythmFigure  duration = RhythmFigure::QUARTER,
int  measureStart = 0 
)

Sets the metronome mark (BPM) for a specific measure.

Parameters
bpmBeats per minute.
durationRhythm figure associated with the BPM (default: QUARTER).
measureStartStarting measure (default: 0).

◆ setRepeat()

void Score::setRepeat ( int  measureStart,
int  measureEnd = -1 
)

Sets repeat barlines for a range of measures.

Parameters
measureStartStarting measure index.
measureEndEnding measure index (-1 for last measure).

◆ setTimeSignature()

void Score::setTimeSignature ( const int  timeUpper,
const int  timeLower,
const int  measureId = -1 
)

Sets the time signature for all or part of the measures.

Can be applied to all measures or from a specific measure onward.

Parameters
timeUpperNumerator of the time signature.
timeLowerDenominator of the time signature.
measureIdStarting measure index (-1 for all).

◆ setTitle()

void Score::setTitle ( const std::string &  scoreTitle)

Sets the title of the score.

Parameters
scoreTitleNew title.

◆ toFile()

void Score::toFile ( std::string  fileName,
bool  compressedXML = false,
const int  identSize = 2 
) const

Saves the score to a file in XML or compressed MXL format.

Parameters
fileNameOutput file name.
compressedXMLTrue to save as .mxl (compressed).
identSizeIndentation size (default: 2).

◆ toJSON()

const std::string Score::toJSON ( ) const

Exports the score to JSON format.

Useful for integration with analysis and visualization tools.

Returns
JSON string representing the score.

◆ toXML()

const std::string Score::toXML ( const int  identSize = 2) const

Exports the score to MusicXML format.

Generates a complete MusicXML string, including metadata and all parts.

Parameters
identSizeIndentation size (default: 2).
Returns
MusicXML string.

◆ xPathCountNodes()

int Score::xPathCountNodes ( const std::string &  xPath) const

Counts the number of XML nodes matching a given XPath expression.

Parameters
xPathXPath expression.
Returns
Number of nodes found.

The documentation for this class was generated from the following file: