|
maiacore 1.10.1
Music analisys library
|
Helper class with static utility functions for music analysis, pitch/duration conversion, and MusicXML processing. More...
#include <helper.h>
Static Public Member Functions | |
| static std::vector< std::string > | splitString (const std::string &s, char delimiter) |
| Splits a string into tokens using a specified delimiter. More... | |
| static std::string | formatFloat (float floatValue, int digits) |
| Formats a floating-point number as a string with a given number of decimal digits. More... | |
| static const std::string | generateIdentation (int identPosition, int identSize=2) |
| Generates a string of spaces for indentation, useful for pretty-printing MusicXML. More... | |
| static std::pair< std::string, int > | ticks2noteType (int durationTicks, int divisionsPerQuarterNote, int actualNotes=1, int normalNotes=1) |
| Converts a duration in ticks to a MusicXML note type and dot count. More... | |
| static std::pair< RhythmFigure, int > | ticks2rhythmFigure (int durationTicks, int divisionsPerQuarterNote, int actualNotes, int normalNotes) |
| Converts a duration in ticks to a RhythmFigure and dot count. More... | |
| static int | noteType2ticks (std::string noteType, const int divisionsPerQuarterNote=256) |
| Converts a MusicXML note type string to a duration in ticks. More... | |
| static float | pitch2number (const std::string &pitch) |
| Converts a pitch string (e.g., "C4") to a floating-point number representation. More... | |
| static const std::string | number2pitch (const float number, const std::string &accType=MUSIC_XML::ACCIDENT::SHARP) |
| Converts a floating-point pitch number to a pitch string, with optional accidental type. More... | |
| static std::pair< int, int > | freq2midiNote (const float freq, std::function< int(float)> modelo=nullptr) |
| Converts a frequency in Hz to the closest MIDI note and cents deviation. More... | |
| static float | midiNote2freq (const int midiNote, const float freqA4=440.0f) |
| Converts a MIDI note number to frequency in Hz. More... | |
| static int | midiNote2octave (const int midiNote) |
| Converts a MIDI note number to its octave number. More... | |
| static int | pitch2midiNote (const std::string &pitch) |
| Converts a pitch string (e.g., "C4") to a MIDI note number. More... | |
| static const std::string | midiNote2pitch (const int midiNote, const std::string &accType={}) |
| Converts a MIDI note number to a pitch string, with optional accidental type. More... | |
| static const std::vector< std::string > | midiNote2pitches (const int midiNote) |
| Returns all possible pitch spellings for a given MIDI note. More... | |
| static std::vector< Interval > | notes2Intervals (const std::vector< Note > ¬es, const bool firstNoteAsReference=false) |
| Computes intervals between a sequence of notes. More... | |
| static std::vector< Interval > | notes2Intervals (const std::vector< std::string > &pitches, const bool firstNoteAsReference=false) |
| Computes intervals between a sequence of pitch strings. More... | |
| static int | semitonesBetweenPitches (const std::string &pitch_A, const std::string &pitch_B) |
| Calculates the number of semitones between two pitch strings. More... | |
| static float | noteSimilarity (std::string &pitchClass_A, int octave_A, const float duration_A, std::string &pitchClass_B, int octave_B, const float duration_B, float &durRatio, float &pitRatio, const bool enableEnharmonic=false) |
| Computes multidimensional similarity between two notes using pitch-space and rhythmic metrics. More... | |
| static float | pitch2freq (const std::string &pitch) |
| Converts a pitch string to its frequency in Hz. More... | |
| static int | frequencies2cents (const float freq_A, const float freq_B) |
| Converts a frequency ratio between two pitches to cents. More... | |
| static float | freq2equalTemperament (const float freq, const float referenceFreq=440.0f) |
| Converts a frequency to the nearest equal-tempered frequency. More... | |
| static std::string | rhythmFigure2noteType (const RhythmFigure rhythmFigure) |
| Converts a RhythmFigure enum to a MusicXML note type string. More... | |
| static int | rhythmFigure2Ticks (const RhythmFigure rhythmFigure, const int divisionsPerQuarterNote=256) |
| Converts a RhythmFigure to a duration in ticks. More... | |
| static RhythmFigure | noteType2RhythmFigure (const std::string ¬eType) |
| Converts a MusicXML note type string to a RhythmFigure enum. More... | |
| static const std::string | transposePitch (const std::string &pitch, const int semitones, const std::string &accType=MUSIC_XML::ACCIDENT::SHARP) |
| Transposes a pitch string by a number of semitones. More... | |
| static bool | isEnharmonic (const std::string &pitch_A, const std::string &pitch_B) |
| Checks if two pitch strings are enharmonically equivalent. More... | |
| static void | splitPitch (const std::string &pitch, std::string &pitchClass, std::string &pitchStep, int &octave, float &alterValue, std::string &alterSymbol) |
| Splits a pitch string into its components: pitch class, step, octave, accidental value, and symbol. More... | |
| static float | durationRatio (float duration_A, float duration_B) |
| Computes the ratio between two durations. More... | |
| static const std::string | alterName2symbol (const std::string &alterName) |
| Converts an accidental name (e.g., "sharp") to its symbol (e.g., "#"). More... | |
| static float | alterSymbol2Value (const std::string &alterSymbol) |
| Converts an accidental symbol (e.g., "#") to its numeric value. More... | |
| static const std::string | alterValue2symbol (const float alterValue) |
| Converts an accidental value to its symbol (e.g., 1.0 -> "#"). More... | |
| static const std::string | alterValue2Name (const float alterValue) |
| Converts an accidental value to its name (e.g., 1.0 -> "sharp"). More... | |
| static void | getNoteNodeData (const pugi::xml_node &node, std::string &pitch, std::string &pitchClass, std::string &alterSymbol, int &alterValue, int &octave, std::string &type, float &duration) |
| Retrieves detailed information from a MusicXML note node. More... | |
| static const pugi::xpath_node_set | getNodeSet (const pugi::xml_document &doc, const std::string &xPath) |
| Selects nodes from a MusicXML document using an XPath expression. More... | |
| static const nlohmann::json | getPercentiles (const nlohmann::json &table, const std::vector< float > &desiredPercentiles) |
| Returns a JSON object with percentiles for a given table and desired percentile values. More... | |
| static std::pair< std::string, int > | freq2pitch (const float freq, const std::string &accType=MUSIC_XML::ACCIDENT::NONE) |
| Converts a frequency in Hz to the closest pitch and cents deviation. More... | |
| static float | pitchRatio (const std::string &pitch_A, const std::string &pitch_B) |
| Computes the ratio between two pitch strings as a float. More... | |
| static std::string | toString (const RhythmFigure rhythmFigure) |
| Converts a RhythmFigure to a string. More... | |
| static std::vector< float > | getSemitonesDifferenceBetweenMelodies (const std::vector< Note > &referenceMelody, const std::vector< Note > &otherMelody) |
| Computes the intervallic contour difference vector between two melodic sequences. More... | |
| static float | calculateMelodyEuclideanSimilarity (const std::vector< Note > &melodyPattern, const std::vector< Note > &otherMelody) |
| Calculates Euclidean distance-based melodic similarity from intervallic contour comparison. More... | |
| static float | calculateMelodyEuclideanSimilarity (const std::vector< float > &semitonesDifference) |
| Calculates the Euclidean similarity from a vector of semitone differences. More... | |
| static std::vector< float > | getDurationDifferenceBetweenRhythms (const std::vector< Note > &referenceRhythm, const std::vector< Note > &otherRhythm) |
| Computes the vector of normalized duration differences between two rhythms. More... | |
| static float | calculateRhythmicEuclideanSimilarity (const std::vector< Note > &rhythmPattern, const std::vector< Note > &otherRhythm) |
| Calculates the Euclidean similarity between two rhythms based on duration differences. More... | |
| static float | calculateRhythmicEuclideanSimilarity (const std::vector< float > &durationDifferences) |
| Calculates the Euclidean similarity from a vector of duration differences. More... | |
Helper class with static utility functions for music analysis, pitch/duration conversion, and MusicXML processing.
This class provides a wide range of static methods for manipulating musical data, including pitch and rhythm conversions, MusicXML node handling, similarity calculations, and more. All methods are designed for use in music research and computational musicology.
|
static |
Converts an accidental name (e.g., "sharp") to its symbol (e.g., "#").
| alterName | Accidental name. |
|
static |
Converts an accidental symbol (e.g., "#") to its numeric value.
| alterSymbol | Accidental symbol. |
|
static |
Converts an accidental value to its name (e.g., 1.0 -> "sharp").
| alterValue | Accidental value. |
|
static |
Converts an accidental value to its symbol (e.g., 1.0 -> "#").
| alterValue | Accidental value. |
|
static |
Calculates the Euclidean similarity from a vector of semitone differences.
| semitonesDifference | Vector of semitone differences. |
|
static |
Calculates Euclidean distance-based melodic similarity from intervallic contour comparison.
| melodyPattern | Reference melodic pattern to match against. |
| otherMelody | Candidate melody to compare for similarity. |
Computes global melodic similarity by measuring the Euclidean distance in pitch-space between two melodic sequences, accounting for transposition, intervallic distortion, and contour preservation. This metric is transposition-sensitive, meaning exact transpositions yield high similarity while contour-preserving transformations with interval alterations yield moderate similarity.
Computation Process:
Interpretation of Results:
Transposition Invariance: This metric is NOT fully transposition-invariant. Melodies transposed by a constant interval will have high but not perfect similarity (distance proportional to transposition distance). For exact transposition-invariance, compute interval sequence differences instead.
Applications:
|
static |
Calculates the Euclidean similarity from a vector of duration differences.
| durationDifferences | Vector of duration differences. |
|
static |
Calculates the Euclidean similarity between two rhythms based on duration differences.
| rhythmPattern | Reference rhythm. |
| otherRhythm | Comparison rhythm. |
|
static |
|
static |
Formats a floating-point number as a string with a given number of decimal digits.
| floatValue | The value to format. |
| digits | Number of decimal digits. |
|
static |
Converts a frequency to the nearest equal-tempered frequency.
| freq | Input frequency. |
| referenceFreq | Reference frequency (default: 440.0 Hz). |
|
static |
Converts a frequency in Hz to the closest MIDI note and cents deviation.
| freq | Frequency in Hz. |
| modelo | Optional custom mapping function. |
|
static |
Converts a frequency in Hz to the closest pitch and cents deviation.
| freq | Frequency in Hz. |
| accType | Accidental type for output pitch. |
|
static |
Converts a frequency ratio between two pitches to cents.
| freq_A | Frequency of the first pitch. |
| freq_B | Frequency of the second pitch. |
|
static |
Generates a string of spaces for indentation, useful for pretty-printing MusicXML.
| identPosition | Indentation level. |
| identSize | Number of spaces per level (default: 2). |
|
static |
Computes the vector of normalized duration differences between two rhythms.
| referenceRhythm | Vector of reference notes. |
| otherRhythm | Vector of comparison notes. |
|
static |
Selects nodes from a MusicXML document using an XPath expression.
| doc | XML document. |
| xPath | XPath query string. |
|
static |
Retrieves detailed information from a MusicXML note node.
| node | XML node of the note. |
| pitch | Output: pitch string. |
| pitchClass | Output: pitch class. |
| alterSymbol | Output: accidental symbol. |
| alterValue | Output: accidental value. |
| octave | Output: octave. |
| type | Output: note type. |
| duration | Output: duration. |
|
static |
Returns a JSON object with percentiles for a given table and desired percentile values.
| table | Input JSON table. |
| desiredPercentiles | Vector of percentiles (0.0 to 1.0). |
|
static |
Computes the intervallic contour difference vector between two melodic sequences.
| referenceMelody | Vector of notes representing the reference melodic pattern. |
| otherMelody | Vector of notes to compare against the reference melody. |
Calculates the interval-by-interval pitch displacement between two melodies of equal length, producing a difference vector that quantifies melodic transposition, contour divergence, and pitch-space transformation. This function is fundamental for melodic similarity analysis, thematic variation studies, and computational pattern matching.
Computation Process: For each aligned note pair (referenceMelody[i], otherMelody[i]):
Example:
Interpretation of Results:
Applications:
|
static |
Checks if two pitch strings are enharmonically equivalent.
| pitch_A | First pitch string. |
| pitch_B | Second pitch string. |
|
static |
Converts a MIDI note number to frequency in Hz.
| midiNote | MIDI note number. |
| freqA4 | Reference frequency for A4 (default: 440.0 Hz). |
|
static |
Converts a MIDI note number to its octave number.
| midiNote | MIDI note number. |
|
static |
Converts a MIDI note number to a pitch string, with optional accidental type.
| midiNote | MIDI note number. |
| accType | Accidental type (e.g., "#", "b"). |
|
static |
Returns all possible pitch spellings for a given MIDI note.
| midiNote | MIDI note number. |
|
static |
Computes intervals between a sequence of pitch strings.
| pitches | Vector of pitch strings. |
| firstNoteAsReference | If true, intervals are from the first note to each subsequent note. |
|
static |
Computes multidimensional similarity between two notes using pitch-space and rhythmic metrics.
| pitchClass_A | Pitch class of note A (e.g., "C", "F#", "Bb"). |
| octave_A | Octave register of note A (MIDI octave numbering: A4=440Hz). |
| duration_A | Duration of note A in quarter-note units (1.0 = quarter, 0.5 = eighth). |
| pitchClass_B | Pitch class of note B. |
| octave_B | Octave register of note B. |
| duration_B | Duration of note B in quarter-note units. |
| durRatio | Output parameter: rhythmic similarity ratio in [0,1]. |
| pitRatio | Output parameter: pitch proximity ratio in [0,1]. |
| enableEnharmonic | If true, treats enharmonic equivalents as identical (C# ≡ Db). |
Calculates composite similarity by combining pitch-space distance and rhythmic congruence, enabling flexible note-matching for melodic pattern recognition, variation analysis, and approximate music information retrieval.
Similarity Components:
Applications:
|
static |
Converts a MusicXML note type string to a RhythmFigure enum.
| noteType | Note type string (e.g., "quarter"). |
|
static |
|
static |
Converts a floating-point pitch number to a pitch string, with optional accidental type.
| number | Numeric pitch representation. |
| accType | Accidental type (e.g., "#", "b"). |
|
static |
Converts a pitch string to its frequency in Hz.
| pitch | Pitch string (e.g., "A4"). |
|
static |
Converts a pitch string (e.g., "C4") to a MIDI note number.
| pitch | Pitch string. |
|
static |
Converts a pitch string (e.g., "C4") to a floating-point number representation.
| pitch | Pitch string. |
|
static |
Computes the ratio between two pitch strings as a float.
| pitch_A | First pitch string. |
| pitch_B | Second pitch string. |
|
static |
Converts a RhythmFigure enum to a MusicXML note type string.
| rhythmFigure | RhythmFigure value. |
|
static |
Converts a RhythmFigure to a duration in ticks.
| rhythmFigure | RhythmFigure value. |
| divisionsPerQuarterNote | Divisions per quarter note (default: 256). |
|
static |
Calculates the number of semitones between two pitch strings.
| pitch_A | First pitch string. |
| pitch_B | Second pitch string. |
|
static |
Splits a pitch string into its components: pitch class, step, octave, accidental value, and symbol.
| pitch | Input pitch string. |
| pitchClass | Output: pitch class (e.g., "C#", "Bb"). |
| pitchStep | Output: step (e.g., "C", "D"). |
| octave | Output: octave number. |
| alterValue | Output: accidental value as float. |
| alterSymbol | Output: accidental symbol (e.g., "#", "b"). |
|
static |
Splits a string into tokens using a specified delimiter.
| s | The input string. |
| delimiter | The character used to split the string. |
|
static |
Converts a duration in ticks to a MusicXML note type and dot count.
| durationTicks | Duration in ticks. |
| divisionsPerQuarterNote | Divisions per quarter note. |
| actualNotes | Tuplet numerator (default: 1). |
| normalNotes | Tuplet denominator (default: 1). |
|
static |
Converts a duration in ticks to a RhythmFigure and dot count.
| durationTicks | Duration in ticks. |
| divisionsPerQuarterNote | Divisions per quarter note. |
| actualNotes | Tuplet numerator. |
| normalNotes | Tuplet denominator. |
|
static |
Converts a RhythmFigure to a string.
| rhythmFigure | RhythmFigure value. |
|
static |
Transposes a pitch string by a number of semitones.
| pitch | Input pitch string. |
| semitones | Number of semitones to transpose. |
| accType | Accidental type for output pitch (default: "#"). |