|
maiacore 1.10.1
Music analisys library
|
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< MelodyPatternRow > | MelodyPatternTable |
| 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... | |
| Part & | getPart (const int partId) |
| Returns a reference to a part by its index. More... | |
| Part & | getPart (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... | |
| Score & | operator= (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< MelodyPatternTable > | 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. More... | |
| std::vector< MelodyPatternTable > | 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. 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... | |
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.
| 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.
|
explicit |
Constructs a new blank Score object with specified part names and initial measure count.
| partsName | List of instrument/part names. |
| numMeasures | Initial number of measures (default: 20). |
|
explicit |
Constructs a new blank Score object with specified part names and initial measure count.
| partsName | Vector of instrument/part names. |
| numMeasures | Initial number of measures (default: 20). |
|
explicit |
Constructs a new Score object by loading a MusicXML file.
Supported formats: *.xml, *.musicxml, *.mxl (compressed).
| filePath | Path to the MusicXML file. |
|
inline |
| void Score::addMeasure | ( | const int | numMeasures | ) |
Adds a specified number of measures to all parts in the score.
| numMeasures | Number of measures to add. |
| 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.
| partName | Name of the part/instrument. |
| numStaves | Number of staves (default: 1). |
| 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.
| 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.
| patternNumNotes | Number of notes in each pattern. |
| totalIntervalsSimilarityThreshold | Minimum interval similarity threshold. |
| totalRhythmSimilarityThreshold | Minimum rhythm similarity threshold. |
| intervalsSimilarityCallback | Custom function to calculate interval similarity. |
| rhythmSimilarityCallback | Custom function to calculate rhythm similarity. |
| totalIntervalSimilarityCallback | Function to aggregate interval similarity. |
| totalRhythmSimilarityCallback | Function to aggregate rhythm similarity. |
| totalSimilarityCallback | Function to combine total similarities. |
| 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.
| melodyPattern | Vector of notes representing the pattern to search for. |
| totalIntervalsSimilarityThreshold | Minimum interval similarity threshold (0.0-1.0). |
| totalRhythmSimilarityThreshold | Minimum rhythm similarity threshold (0.0-1.0). |
| intervalsSimilarityCallback | Custom function to calculate interval similarity. |
| rhythmSimilarityCallback | Custom function to calculate rhythm similarity. |
| totalIntervalSimilarityCallback | Function to aggregate interval similarity. |
| totalRhythmSimilarityCallback | Function to aggregate rhythm similarity. |
| totalSimilarityCallback | Function to combine total similarities. |
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:
Similarity Calculation:
Threshold Parameters:
Applications:
| 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.
| melodyPatterns | Vector of melodic patterns. |
| totalIntervalsSimilarityThreshold | Minimum interval similarity threshold. |
| totalRhythmSimilarityThreshold | Minimum rhythm similarity threshold. |
| intervalsSimilarityCallback | Custom function to calculate interval similarity. |
| rhythmSimilarityCallback | Custom function to calculate rhythm similarity. |
| totalIntervalSimilarityCallback | Function to aggregate interval similarity. |
| totalRhythmSimilarityCallback | Function to aggregate rhythm similarity. |
| totalSimilarityCallback | Function to combine total similarities. |
| 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.
| callback | Function to call for each note. |
| measureStart | Starting measure (default: 0). |
| measureEnd | Ending measure (default: -1, until the end). |
| partNames | List of part names to process (default: all). |
| 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.
| config | Optional JSON configuration object controlling chord extraction criteria. |
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 analysisminStack, maxStack (integers): Filter by chord cardinality (number of notes)minDuration, maxDuration (strings): Filter by note duration (e.g., "quarter", "half", "whole")continuosMode (boolean): Texture analysis mode selectorincludeDuplicates (boolean): Octave doubling handlingincludeUnpitched (boolean): Include percussion/unpitched elementsExample Configuration:
Return Value Structure: Each tuple contains:
Applications:
continuosMode parameter critically affects results:| std::string Score::getComposerName | ( | ) | const |
Returns the composer's name.
| std::string Score::getFileName | ( | ) | const |
Returns the file name of the loaded MusicXML file.
| std::string Score::getFilePath | ( | ) | const |
Returns the file path of the loaded MusicXML file.
| bool Score::getNote | ( | const int | part, |
| const int | measure, | ||
| const int | note, | ||
| std::string & | pitch | ||
| ) | const |
| bool Score::getNote | ( | const int | part, |
| const int | measure, | ||
| const int | note, | ||
| std::string & | pitch, | ||
| std::string & | step, | ||
| int & | octave | ||
| ) | const |
| 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.
| part | Part index. |
| measure | Measure index. |
| note | Note index. |
| pitch | Output: pitch string. |
| step | Output: step string. |
| octave | Output: octave integer. |
| duration | Output: duration integer. |
| voice | Output: voice integer. |
| type | Output: type string. |
| steam | Output: stem string. |
| staff | Output: staff integer. |
| 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.
| node | XML node of the note. |
| partName | Output: part name. |
| measure | Output: measure number. |
| pitch | Output: pitch string. |
| pitchClass | Output: pitch class string. |
| alterSymbol | Output: accidental symbol. |
| alterValue | Output: accidental value. |
| octave | Output: octave. |
| type | Output: note type. |
| duration | Output: note duration. |
| int Score::getNumMeasures | ( | ) | const |
Returns the number of measures in the score.
| int Score::getNumNotes | ( | ) | const |
Returns the total number of notes in the score.
| int Score::getNumParts | ( | ) | const |
Returns the number of parts (instruments/voices) in the score.
| Part & Score::getPart | ( | const int | partId | ) |
Returns a reference to a part by its index.
| partId | Index of the part. |
| Part & Score::getPart | ( | const std::string & | partName | ) |
Returns a reference to a part by its name.
| partName | Name of the part. |
| bool Score::getPartIndex | ( | const std::string & | partName, |
| int * | index | ||
| ) | const |
Gets the index of a part by its name.
| partName | Name of the part. |
| index | Output: index integer. |
| const std::string Score::getPartName | ( | const int | partId | ) | const |
| const std::vector< std::string > Score::getPartsNames | ( | ) | const |
Returns a vector with the names of all parts/instruments.
| std::string Score::getTitle | ( | ) | const |
Returns the title of the score.
| bool Score::haveAnacrusisMeasure | ( | ) | const |
Returns true if the score contains an anacrusis (pickup) measure.
| bool Score::haveTypeTag | ( | void | ) | const |
Returns true if the MusicXML file contains <type> tags for notes.
| 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.
| nlohmann::json Score::instrumentFragmentation | ( | nlohmann::json | config = nlohmann::json() | ) |
Analyzes instrumental fragmentation patterns across the score timeline.
| config | JSON configuration object specifying analysis parameters (parts, measures, etc). |
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:
Analysis Categories:
Configuration Parameters (config JSON):
partNames (list): Restrict analysis to specific instrumental partsmeasureStart, measureEnd (int): Define temporal analysis windowtimeResolution (float): Granularity for temporal slicing (e.g., 0.25 = sixteenth note)Return JSON Structure:
Applications:
| bool Score::isValid | ( | void | ) | const |
Returns true if the score is valid (MusicXML loaded correctly).
| void Score::removeMeasure | ( | const int | measureStart, |
| const int | measureEnd | ||
| ) |
Removes a range of measures from all parts in the score.
| measureStart | Index of the first measure to remove. |
| measureEnd | Index of the last measure to remove. |
| void Score::removePart | ( | const int | partId | ) |
Removes a part from the score by its index.
| partId | Index of the part to remove. |
| void Score::setComposerName | ( | const std::string & | composerName | ) |
Sets the composer's name.
| composerName | New composer name. |
| 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).
| fifthCicle | Number of accidentals in the circle of fifths. |
| isMajorMode | True for major, false for minor. |
| measureId | Measure index (default: 0). |
| void Score::setKeySignature | ( | const std::string & | key, |
| const int | measureId = 0 |
||
| ) |
| void Score::setMetronomeMark | ( | int | bpm, |
| const RhythmFigure | duration = RhythmFigure::QUARTER, |
||
| int | measureStart = 0 |
||
| ) |
Sets the metronome mark (BPM) for a specific measure.
| bpm | Beats per minute. |
| duration | Rhythm figure associated with the BPM (default: QUARTER). |
| measureStart | Starting measure (default: 0). |
| void Score::setRepeat | ( | int | measureStart, |
| int | measureEnd = -1 |
||
| ) |
Sets repeat barlines for a range of measures.
| measureStart | Starting measure index. |
| measureEnd | Ending measure index (-1 for last measure). |
| 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.
| timeUpper | Numerator of the time signature. |
| timeLower | Denominator of the time signature. |
| measureId | Starting measure index (-1 for all). |
| void Score::setTitle | ( | const std::string & | scoreTitle | ) |
Sets the title of the score.
| scoreTitle | New title. |
| 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.
| fileName | Output file name. |
| compressedXML | True to save as .mxl (compressed). |
| identSize | Indentation size (default: 2). |
| const std::string Score::toJSON | ( | ) | const |
Exports the score to JSON format.
Useful for integration with analysis and visualization tools.
| 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.
| identSize | Indentation size (default: 2). |
| int Score::xPathCountNodes | ( | const std::string & | xPath | ) | const |
Counts the number of XML nodes matching a given XPath expression.
| xPath | XPath expression. |