6#include "maiacore/constants.h"
7#include "maiacore/note.h"
8#include "nlohmann/json.hpp"
9#include "pugi/pugixml.hpp"
27 static std::vector<std::string>
splitString(
const std::string& s,
char delimiter);
54 int divisionsPerQuarterNote,
55 int actualNotes = 1,
int normalNotes = 1);
66 int divisionsPerQuarterNote,
67 int actualNotes,
int normalNotes);
75 static int noteType2ticks(std::string noteType,
const int divisionsPerQuarterNote = 256);
91 const std::string& accType = MUSIC_XML::ACCIDENT::SHARP);
100 std::function<
int(
float)> modelo =
nullptr);
108 static float midiNote2freq(
const int midiNote,
const float freqA4 = 440.0f);
130 static const std::string
midiNote2pitch(
const int midiNote,
const std::string& accType = {});
146 const bool firstNoteAsReference =
false);
155 const bool firstNoteAsReference =
false);
209 static float noteSimilarity(std::string& pitchClass_A,
int octave_A,
const float duration_A,
210 std::string& pitchClass_B,
int octave_B,
const float duration_B,
211 float& durRatio,
float& pitRatio,
212 const bool enableEnharmonic =
false);
251 const int divisionsPerQuarterNote = 256);
268 const std::string& pitch,
const int semitones,
269 const std::string& accType = MUSIC_XML::ACCIDENT::SHARP);
277 static bool isEnharmonic(
const std::string& pitch_A,
const std::string& pitch_B);
288 static void splitPitch(
const std::string& pitch, std::string& pitchClass,
289 std::string& pitchStep,
int& octave,
float& alterValue,
290 std::string& alterSymbol);
354 std::string& pitchClass, std::string& alterSymbol,
int& alterValue,
355 int& octave, std::string& type,
float& duration);
363 static const pugi::xpath_node_set
getNodeSet(
const pugi::xml_document& doc,
364 const std::string& xPath);
373 const std::vector<float>& desiredPercentiles);
389 const float freq,
const std::string& accType = MUSIC_XML::ACCIDENT::NONE);
397 static float pitchRatio(
const std::string& pitch_A,
const std::string& pitch_B);
404 static std::string
toString(
const RhythmFigure rhythmFigure);
450 const std::vector<Note>& referenceMelody,
const std::vector<Note>& otherMelody);
495 const std::vector<Note>& otherMelody);
511 const std::vector<Note>& referenceRhythm,
const std::vector<Note>& otherRhythm);
520 const std::vector<Note>& otherRhythm);
Helper class with static utility functions for music analysis, pitch/duration conversion,...
Definition: helper.h:19
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.
static const std::vector< std::string > midiNote2pitches(const int midiNote)
Returns all possible pitch spellings for a given MIDI note.
static int rhythmFigure2Ticks(const RhythmFigure rhythmFigure, const int divisionsPerQuarterNote=256)
Converts a RhythmFigure to a duration in ticks.
static int pitch2midiNote(const std::string &pitch)
Converts a pitch string (e.g., "C4") to a MIDI note number.
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.
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.
static float alterSymbol2Value(const std::string &alterSymbol)
Converts an accidental symbol (e.g., "#") to its numeric value.
static std::string toString(const RhythmFigure rhythmFigure)
Converts a RhythmFigure to a string.
static int semitonesBetweenPitches(const std::string &pitch_A, const std::string &pitch_B)
Calculates the number of semitones between two pitch strings.
static const std::string alterName2symbol(const std::string &alterName)
Converts an accidental name (e.g., "sharp") to its symbol (e.g., "#").
static int frequencies2cents(const float freq_A, const float freq_B)
Converts a frequency ratio between two pitches to cents.
static float calculateMelodyEuclideanSimilarity(const std::vector< Note > &melodyPattern, const std::vector< Note > &otherMelody)
Calculates Euclidean distance-based melodic similarity from intervallic contour comparison.
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.
static const std::string alterValue2symbol(const float alterValue)
Converts an accidental value to its symbol (e.g., 1.0 -> "#").
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.
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.
static float pitchRatio(const std::string &pitch_A, const std::string &pitch_B)
Computes the ratio between two pitch strings as a float.
static float calculateRhythmicEuclideanSimilarity(const std::vector< Note > &rhythmPattern, const std::vector< Note > &otherRhythm)
Calculates the Euclidean similarity between two rhythms based on duration differences.
static bool isEnharmonic(const std::string &pitch_A, const std::string &pitch_B)
Checks if two pitch strings are enharmonically equivalent.
static const std::string alterValue2Name(const float alterValue)
Converts an accidental value to its name (e.g., 1.0 -> "sharp").
static float calculateRhythmicEuclideanSimilarity(const std::vector< float > &durationDifferences)
Calculates the Euclidean similarity from a vector of duration differences.
static float calculateMelodyEuclideanSimilarity(const std::vector< float > &semitonesDifference)
Calculates the Euclidean similarity from a vector of semitone differences.
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,...
static const std::string generateIdentation(int identPosition, int identSize=2)
Generates a string of spaces for indentation, useful for pretty-printing MusicXML.
static std::vector< Interval > notes2Intervals(const std::vector< Note > ¬es, const bool firstNoteAsReference=false)
Computes intervals between a sequence of notes.
static std::string formatFloat(float floatValue, int digits)
Formats a floating-point number as a string with a given number of decimal digits.
static float midiNote2freq(const int midiNote, const float freqA4=440.0f)
Converts a MIDI note number to frequency in Hz.
static float freq2equalTemperament(const float freq, const float referenceFreq=440.0f)
Converts a frequency to the nearest equal-tempered frequency.
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.
static int noteType2ticks(std::string noteType, const int divisionsPerQuarterNote=256)
Converts a MusicXML note type string to a duration in ticks.
static float pitch2freq(const std::string &pitch)
Converts a pitch string to its frequency in Hz.
static float durationRatio(float duration_A, float duration_B)
Computes the ratio between two durations.
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.
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.
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.
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.
static std::vector< Interval > notes2Intervals(const std::vector< std::string > &pitches, const bool firstNoteAsReference=false)
Computes intervals between a sequence of pitch strings.
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.
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.
static RhythmFigure noteType2RhythmFigure(const std::string ¬eType)
Converts a MusicXML note type string to a RhythmFigure enum.
static std::string rhythmFigure2noteType(const RhythmFigure rhythmFigure)
Converts a RhythmFigure enum to a MusicXML note type string.
static int midiNote2octave(const int midiNote)
Converts a MIDI note number to its octave number.
static float pitch2number(const std::string &pitch)
Converts a pitch string (e.g., "C4") to a floating-point number representation.
static std::vector< std::string > splitString(const std::string &s, char delimiter)
Splits a string into tokens using a specified delimiter.
Represents a musical interval between two notes, supporting tonal, diatonic, and chromatic analysis.
Definition: interval.h:14