maiacore 1.10.1
Music analisys library
Helper Class Reference

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< Intervalnotes2Intervals (const std::vector< Note > &notes, const bool firstNoteAsReference=false)
 Computes intervals between a sequence of notes. More...
 
static std::vector< Intervalnotes2Intervals (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 &noteType)
 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...
 

Detailed Description

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.

Member Function Documentation

◆ alterName2symbol()

static const std::string Helper::alterName2symbol ( const std::string &  alterName)
static

Converts an accidental name (e.g., "sharp") to its symbol (e.g., "#").

Parameters
alterNameAccidental name.
Returns
Accidental symbol.

◆ alterSymbol2Value()

static float Helper::alterSymbol2Value ( const std::string &  alterSymbol)
static

Converts an accidental symbol (e.g., "#") to its numeric value.

Parameters
alterSymbolAccidental symbol.
Returns
Numeric value (e.g., 1.0 for "#").

◆ alterValue2Name()

static const std::string Helper::alterValue2Name ( const float  alterValue)
static

Converts an accidental value to its name (e.g., 1.0 -> "sharp").

Parameters
alterValueAccidental value.
Returns
Accidental name.

◆ alterValue2symbol()

static const std::string Helper::alterValue2symbol ( const float  alterValue)
static

Converts an accidental value to its symbol (e.g., 1.0 -> "#").

Parameters
alterValueAccidental value.
Returns
Accidental symbol.

◆ calculateMelodyEuclideanSimilarity() [1/2]

static float Helper::calculateMelodyEuclideanSimilarity ( const std::vector< float > &  semitonesDifference)
static

Calculates the Euclidean similarity from a vector of semitone differences.

Parameters
semitonesDifferenceVector of semitone differences.
Returns
Similarity value in [0,1].

◆ calculateMelodyEuclideanSimilarity() [2/2]

static float Helper::calculateMelodyEuclideanSimilarity ( const std::vector< Note > &  melodyPattern,
const std::vector< Note > &  otherMelody 
)
static

Calculates Euclidean distance-based melodic similarity from intervallic contour comparison.

Parameters
melodyPatternReference melodic pattern to match against.
otherMelodyCandidate melody to compare for similarity.
Returns
Normalized similarity score in [0,1] where 1.0 = identical contour, 0.0 = maximal divergence.

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:

  1. Extract semitone difference vector: getSemitonesDifferenceBetweenMelodies(melodyPattern, otherMelody)
  2. Compute Euclidean distance: sqrt(Σ(difference[i]²))
  3. Normalize to [0,1] similarity: similarity = 1 / (1 + distance/scaling_factor)

Interpretation of Results:

  • similarity ≈ 1.0 (0.95-1.0): Near-identical melodies, possibly exact transposition
  • similarity ≈ 0.7-0.9: High similarity with minor intervallic variations (e.g., chromatic alterations, octave displacements in 1-2 notes)
  • similarity ≈ 0.4-0.7: Moderate similarity, recognizable contour with significant transformations (e.g., modal transposition, rhythmic variation, ornamentation)
  • similarity < 0.4: Low similarity, different melodic material or inverted contours

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:

  • Melodic pattern matching in thematic analysis (identifying motivic recurrence)
  • Theme-and-variation studies (quantifying melodic transformation degree)
  • Plagiarism detection (measuring melodic borrowing/paraphrase)
  • Music information retrieval (query-by-example melodic search)
  • Corpus analysis (clustering melodies by contour similarity)
Note
Both melodies must have the same length for meaningful comparison. If lengths differ, the function processes min(melodyPattern.size(), otherMelody.size()) notes.
Warning
This metric emphasizes pitch contour over rhythmic structure. For combined pitch+rhythm similarity, use findMelodyPattern() with custom similarity callbacks.

◆ calculateRhythmicEuclideanSimilarity() [1/2]

static float Helper::calculateRhythmicEuclideanSimilarity ( const std::vector< float > &  durationDifferences)
static

Calculates the Euclidean similarity from a vector of duration differences.

Parameters
durationDifferencesVector of duration differences.
Returns
Similarity value in [0,1].

◆ calculateRhythmicEuclideanSimilarity() [2/2]

static float Helper::calculateRhythmicEuclideanSimilarity ( const std::vector< Note > &  rhythmPattern,
const std::vector< Note > &  otherRhythm 
)
static

Calculates the Euclidean similarity between two rhythms based on duration differences.

Parameters
rhythmPatternReference rhythm.
otherRhythmComparison rhythm.
Returns
Similarity value in [0,1].

◆ durationRatio()

static float Helper::durationRatio ( float  duration_A,
float  duration_B 
)
static

Computes the ratio between two durations.

Parameters
duration_ADuration of note A.
duration_BDuration of note B.
Returns
Ratio in [0,1], where 1 means identical durations.

◆ formatFloat()

static std::string Helper::formatFloat ( float  floatValue,
int  digits 
)
static

Formats a floating-point number as a string with a given number of decimal digits.

Parameters
floatValueThe value to format.
digitsNumber of decimal digits.
Returns
Formatted string.

◆ freq2equalTemperament()

static float Helper::freq2equalTemperament ( const float  freq,
const float  referenceFreq = 440.0f 
)
static

Converts a frequency to the nearest equal-tempered frequency.

Parameters
freqInput frequency.
referenceFreqReference frequency (default: 440.0 Hz).
Returns
Nearest equal-tempered frequency.

◆ freq2midiNote()

static std::pair< int, int > Helper::freq2midiNote ( const float  freq,
std::function< int(float)>  modelo = nullptr 
)
static

Converts a frequency in Hz to the closest MIDI note and cents deviation.

Parameters
freqFrequency in Hz.
modeloOptional custom mapping function.
Returns
Pair of MIDI note number and cents deviation.

◆ freq2pitch()

static std::pair< std::string, int > Helper::freq2pitch ( const float  freq,
const std::string &  accType = MUSIC_XML::ACCIDENT::NONE 
)
static

Converts a frequency in Hz to the closest pitch and cents deviation.

Parameters
freqFrequency in Hz.
accTypeAccidental type for output pitch.
Returns
Pair of pitch string and cents deviation.

◆ frequencies2cents()

static int Helper::frequencies2cents ( const float  freq_A,
const float  freq_B 
)
static

Converts a frequency ratio between two pitches to cents.

Parameters
freq_AFrequency of the first pitch.
freq_BFrequency of the second pitch.
Returns
Interval in cents.

◆ generateIdentation()

static const std::string Helper::generateIdentation ( int  identPosition,
int  identSize = 2 
)
static

Generates a string of spaces for indentation, useful for pretty-printing MusicXML.

Parameters
identPositionIndentation level.
identSizeNumber of spaces per level (default: 2).
Returns
String with the requested indentation.

◆ getDurationDifferenceBetweenRhythms()

static std::vector< float > Helper::getDurationDifferenceBetweenRhythms ( const std::vector< Note > &  referenceRhythm,
const std::vector< Note > &  otherRhythm 
)
static

Computes the vector of normalized duration differences between two rhythms.

Parameters
referenceRhythmVector of reference notes.
otherRhythmVector of comparison notes.
Returns
Vector of duration differences.

◆ getNodeSet()

static const pugi::xpath_node_set Helper::getNodeSet ( const pugi::xml_document &  doc,
const std::string &  xPath 
)
static

Selects nodes from a MusicXML document using an XPath expression.

Parameters
docXML document.
xPathXPath query string.
Returns
Set of matching XML nodes.

◆ getNoteNodeData()

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

Retrieves detailed information from a MusicXML note node.

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

◆ getPercentiles()

static const nlohmann::json Helper::getPercentiles ( const nlohmann::json &  table,
const std::vector< float > &  desiredPercentiles 
)
static

Returns a JSON object with percentiles for a given table and desired percentile values.

Parameters
tableInput JSON table.
desiredPercentilesVector of percentiles (0.0 to 1.0).
Returns
JSON object with percentile values.

◆ getSemitonesDifferenceBetweenMelodies()

static std::vector< float > Helper::getSemitonesDifferenceBetweenMelodies ( const std::vector< Note > &  referenceMelody,
const std::vector< Note > &  otherMelody 
)
static

Computes the intervallic contour difference vector between two melodic sequences.

Parameters
referenceMelodyVector of notes representing the reference melodic pattern.
otherMelodyVector of notes to compare against the reference melody.
Returns
Vector of signed semitone differences (positive = upward transposition, negative = downward).

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]):

  • Compute signed semitone distance: otherMelody[i].pitch - referenceMelody[i].pitch
  • Positive values indicate upward transposition (otherMelody higher than reference)
  • Negative values indicate downward transposition (otherMelody lower than reference)
  • Zero values indicate exact pitch match at that position

Example:

referenceMelody: C4-E4-G4 (semitone sequence: 60-64-67)
otherMelody: D4-F#4-A4 (semitone sequence: 62-66-69)
Difference vector: [+2, +2, +2] → uniform transposition up by major second

Interpretation of Results:

  • Constant difference vector (e.g., [+5, +5, +5]): Exact transposition
  • Zero-centered fluctuations (e.g., [-1, 0, +1]): Approximate contour match with chromatic variation
  • Large absolute values (e.g., [+12, +7, -3]): Significant contour divergence, octave displacements
  • Alternating signs: Contour inversion or melodic inversion transformation

Applications:

  • Melodic variation analysis (identifying theme-and-variation relationships)
  • Fugue analysis (detecting transposed subject entries at different pitch levels)
  • Melodic similarity scoring (input to calculateMelodyEuclideanSimilarity)
  • Contour analysis (studying intervallic contour preservation vs. transformation)
  • Computational musicology (corpus-wide melodic relationship detection)
Note
Both melodies must have the same length. If lengths differ, the function processes min(referenceMelody.size(), otherMelody.size()) notes and ignores excess notes.
Warning
This function compares absolute pitch, not pitch-class. C4 and C5 differ by 12 semitones. For pitch-class comparison (octave-invariant), reduce results modulo 12.

◆ isEnharmonic()

static bool Helper::isEnharmonic ( const std::string &  pitch_A,
const std::string &  pitch_B 
)
static

Checks if two pitch strings are enharmonically equivalent.

Parameters
pitch_AFirst pitch string.
pitch_BSecond pitch string.
Returns
True if pitches are enharmonic.

◆ midiNote2freq()

static float Helper::midiNote2freq ( const int  midiNote,
const float  freqA4 = 440.0f 
)
static

Converts a MIDI note number to frequency in Hz.

Parameters
midiNoteMIDI note number.
freqA4Reference frequency for A4 (default: 440.0 Hz).
Returns
Frequency in Hz.

◆ midiNote2octave()

static int Helper::midiNote2octave ( const int  midiNote)
static

Converts a MIDI note number to its octave number.

Parameters
midiNoteMIDI note number.
Returns
Octave number.

◆ midiNote2pitch()

static const std::string Helper::midiNote2pitch ( const int  midiNote,
const std::string &  accType = {} 
)
static

Converts a MIDI note number to a pitch string, with optional accidental type.

Parameters
midiNoteMIDI note number.
accTypeAccidental type (e.g., "#", "b").
Returns
Pitch string.

◆ midiNote2pitches()

static const std::vector< std::string > Helper::midiNote2pitches ( const int  midiNote)
static

Returns all possible pitch spellings for a given MIDI note.

Parameters
midiNoteMIDI note number.
Returns
Vector of pitch strings.

◆ notes2Intervals() [1/2]

static std::vector< Interval > Helper::notes2Intervals ( const std::vector< Note > &  notes,
const bool  firstNoteAsReference = false 
)
static

Computes intervals between a sequence of notes.

Parameters
notesVector of Note objects.
firstNoteAsReferenceIf true, intervals are from the first note to each subsequent note.
Returns
Vector of Interval objects.

◆ notes2Intervals() [2/2]

static std::vector< Interval > Helper::notes2Intervals ( const std::vector< std::string > &  pitches,
const bool  firstNoteAsReference = false 
)
static

Computes intervals between a sequence of pitch strings.

Parameters
pitchesVector of pitch strings.
firstNoteAsReferenceIf true, intervals are from the first note to each subsequent note.
Returns
Vector of Interval objects.

◆ noteSimilarity()

static float Helper::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 
)
static

Computes multidimensional similarity between two notes using pitch-space and rhythmic metrics.

Parameters
pitchClass_APitch class of note A (e.g., "C", "F#", "Bb").
octave_AOctave register of note A (MIDI octave numbering: A4=440Hz).
duration_ADuration of note A in quarter-note units (1.0 = quarter, 0.5 = eighth).
pitchClass_BPitch class of note B.
octave_BOctave register of note B.
duration_BDuration of note B in quarter-note units.
durRatioOutput parameter: rhythmic similarity ratio in [0,1].
pitRatioOutput parameter: pitch proximity ratio in [0,1].
enableEnharmonicIf true, treats enharmonic equivalents as identical (C# ≡ Db).
Returns
Overall similarity score in [0,1] where 1.0 = perfect identity, 0.0 = maximal dissimilarity.

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:

  1. Pitch Similarity (pitRatio):
    • Computed as inverse exponential decay function of semitone distance
    • Adjacent semitones (C→C#) → high similarity (≈0.9)
    • Octave displacement (C4→C5) → moderate similarity (≈0.6-0.7)
    • Large intervals (C4→G5) → low similarity (≈0.2-0.4)
    • When enableEnharmonic=true: C# and Db are treated as identical (distance=0)
  2. Rhythmic Similarity (durRatio):
    • Computed as inverse ratio of duration difference
    • Identical durations → durRatio = 1.0
    • Augmentation/diminution by factor of 2 (quarter vs. half) → durRatio ≈ 0.5
    • Large durational differences (whole vs. sixteenth) → durRatio → 0.0
  3. Combined Similarity (return value):
    • Weighted combination: similarity = α × pitRatio + β × durRatio
    • Default weighting emphasizes pitch over rhythm (typical: α=0.7, β=0.3)

Applications:

  • Melodic pattern matching with tolerance for ornamentation and metric variation
  • Variation analysis (comparing theme vs. variations in sonata/rondo forms)
  • Approximate music search (query-by-humming with pitch/rhythm flexibility)
  • Voice-leading analysis (tracking note continuity across harmonic changes)
  • Motivic analysis with rhythmic transformation (augmentation, diminution)
Note
This is a local (note-to-note) similarity metric. For global melodic similarity (entire phrase comparison), use calculateMelodyEuclideanSimilarity() instead.

◆ noteType2RhythmFigure()

static RhythmFigure Helper::noteType2RhythmFigure ( const std::string &  noteType)
static

Converts a MusicXML note type string to a RhythmFigure enum.

Parameters
noteTypeNote type string (e.g., "quarter").
Returns
RhythmFigure value.

◆ noteType2ticks()

static int Helper::noteType2ticks ( std::string  noteType,
const int  divisionsPerQuarterNote = 256 
)
static

Converts a MusicXML note type string to a duration in ticks.

Parameters
noteTypeNote type string (e.g., "quarter").
divisionsPerQuarterNoteDivisions per quarter note (default: 256).
Returns
Duration in ticks.

◆ number2pitch()

static const std::string Helper::number2pitch ( const float  number,
const std::string &  accType = MUSIC_XML::ACCIDENT::SHARP 
)
static

Converts a floating-point pitch number to a pitch string, with optional accidental type.

Parameters
numberNumeric pitch representation.
accTypeAccidental type (e.g., "#", "b").
Returns
Pitch string.

◆ pitch2freq()

static float Helper::pitch2freq ( const std::string &  pitch)
static

Converts a pitch string to its frequency in Hz.

Parameters
pitchPitch string (e.g., "A4").
Returns
Frequency in Hz.

◆ pitch2midiNote()

static int Helper::pitch2midiNote ( const std::string &  pitch)
static

Converts a pitch string (e.g., "C4") to a MIDI note number.

Parameters
pitchPitch string.
Returns
MIDI note number.

◆ pitch2number()

static float Helper::pitch2number ( const std::string &  pitch)
static

Converts a pitch string (e.g., "C4") to a floating-point number representation.

Parameters
pitchPitch string.
Returns
Numeric representation of the pitch.

◆ pitchRatio()

static float Helper::pitchRatio ( const std::string &  pitch_A,
const std::string &  pitch_B 
)
static

Computes the ratio between two pitch strings as a float.

Parameters
pitch_AFirst pitch string.
pitch_BSecond pitch string.
Returns
Ratio in [0,1].

◆ rhythmFigure2noteType()

static std::string Helper::rhythmFigure2noteType ( const RhythmFigure  rhythmFigure)
static

Converts a RhythmFigure enum to a MusicXML note type string.

Parameters
rhythmFigureRhythmFigure value.
Returns
Note type string (e.g., "quarter").

◆ rhythmFigure2Ticks()

static int Helper::rhythmFigure2Ticks ( const RhythmFigure  rhythmFigure,
const int  divisionsPerQuarterNote = 256 
)
static

Converts a RhythmFigure to a duration in ticks.

Parameters
rhythmFigureRhythmFigure value.
divisionsPerQuarterNoteDivisions per quarter note (default: 256).
Returns
Duration in ticks.

◆ semitonesBetweenPitches()

static int Helper::semitonesBetweenPitches ( const std::string &  pitch_A,
const std::string &  pitch_B 
)
static

Calculates the number of semitones between two pitch strings.

Parameters
pitch_AFirst pitch string.
pitch_BSecond pitch string.
Returns
Number of semitones from pitch_A to pitch_B.

◆ splitPitch()

static void Helper::splitPitch ( const std::string &  pitch,
std::string &  pitchClass,
std::string &  pitchStep,
int &  octave,
float &  alterValue,
std::string &  alterSymbol 
)
static

Splits a pitch string into its components: pitch class, step, octave, accidental value, and symbol.

Parameters
pitchInput pitch string.
pitchClassOutput: pitch class (e.g., "C#", "Bb").
pitchStepOutput: step (e.g., "C", "D").
octaveOutput: octave number.
alterValueOutput: accidental value as float.
alterSymbolOutput: accidental symbol (e.g., "#", "b").

◆ splitString()

static std::vector< std::string > Helper::splitString ( const std::string &  s,
char  delimiter 
)
static

Splits a string into tokens using a specified delimiter.

Parameters
sThe input string.
delimiterThe character used to split the string.
Returns
Vector of substrings.

◆ ticks2noteType()

static std::pair< std::string, int > Helper::ticks2noteType ( int  durationTicks,
int  divisionsPerQuarterNote,
int  actualNotes = 1,
int  normalNotes = 1 
)
static

Converts a duration in ticks to a MusicXML note type and dot count.

Parameters
durationTicksDuration in ticks.
divisionsPerQuarterNoteDivisions per quarter note.
actualNotesTuplet numerator (default: 1).
normalNotesTuplet denominator (default: 1).
Returns
Pair of note type string and number of dots.

◆ ticks2rhythmFigure()

static std::pair< RhythmFigure, int > Helper::ticks2rhythmFigure ( int  durationTicks,
int  divisionsPerQuarterNote,
int  actualNotes,
int  normalNotes 
)
static

Converts a duration in ticks to a RhythmFigure and dot count.

Parameters
durationTicksDuration in ticks.
divisionsPerQuarterNoteDivisions per quarter note.
actualNotesTuplet numerator.
normalNotesTuplet denominator.
Returns
Pair of RhythmFigure and number of dots.

◆ toString()

static std::string Helper::toString ( const RhythmFigure  rhythmFigure)
static

Converts a RhythmFigure to a string.

Parameters
rhythmFigureRhythmFigure value.
Returns
String representation.

◆ transposePitch()

static const std::string Helper::transposePitch ( const std::string &  pitch,
const int  semitones,
const std::string &  accType = MUSIC_XML::ACCIDENT::SHARP 
)
static

Transposes a pitch string by a number of semitones.

Parameters
pitchInput pitch string.
semitonesNumber of semitones to transpose.
accTypeAccidental type for output pitch (default: "#").
Returns
Transposed pitch string.

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