maiacore 1.10.1
Music analisys library
Note Class Reference

Represents a musical note, including pitch, duration, articulation, and MusicXML-related attributes. More...

#include <note.h>

Public Member Functions

 Note ()
 Default constructor. Initializes a note as "A4" (MIDI 69).
 
 Note (const std::string &pitch, const RhythmFigure rhythmFigure=RhythmFigure::QUARTER, bool isNoteOn=true, bool inChord=false, const int transposeDiatonic=0, const int transposeChromatic=0, const int divisionsPerQuarterNote=256)
 Constructs a Note from a pitch string and rhythm figure. More...
 
 Note (const int midiNumber, const std::string &accType="", const RhythmFigure rhythmFigure=RhythmFigure::QUARTER, bool isNoteOn=true, bool inChord=false, const int transposeDiatonic=0, const int transposeChromatic=0, const int divisionsPerQuarterNote=256)
 Constructs a Note from a MIDI number, accidental type, and rhythm figure. More...
 
 ~Note ()
 Destructor.
 
void setPitchClass (const std::string &pitchClass)
 Sets the pitch class (e.g., "C", "D#", "Bb") for the note. More...
 
void setOctave (int octave)
 Sets the octave for the note. More...
 
void setDuration (const Duration &duration)
 Sets the duration for the note. More...
 
void setDuration (const float quarterDuration, const int divisionsPerQuarterNote=256)
 Sets the duration for the note using quarter note value. More...
 
void setDuration (const int durationTicks, const int divisionsPerQuarterNote)
 Sets the duration for the note using tick values. More...
 
void setIsNoteOn (bool isNoteOn)
 Sets whether the note is sounding (note on) or a rest (note off). More...
 
void setPitch (const std::string &pitch)
 Sets the pitch (e.g., "C4", "G#3") for the note. More...
 
void setIsInChord (bool inChord)
 Sets whether the note is part of a chord. More...
 
void setTransposingInterval (const int diatonicInterval, const int chromaticInterval)
 Sets the transposing interval for the note. More...
 
void setVoice (const int voice)
 Sets the voice number for the note. More...
 
void setStaff (const int staff)
 Sets the staff number for the note. More...
 
void setIsGraceNote (const bool isGraceNote=false)
 Sets whether the note is a grace note. More...
 
void setStem (const std::string &stem)
 Sets the stem direction for the note. More...
 
void setIsTuplet (const bool isTuplet=false)
 Sets the note as part of a tuplet. More...
 
void setTupleValues (const int actualNotes, const int normalNotes, const std::string &normalType="eighth")
 Sets the tuplet values for the note. More...
 
void setIsPitched (const bool isPitched=true)
 Sets whether the note is pitched (true) or unpitched (false). More...
 
void setUnpitchedIndex (const int unpitchedIndex)
 Sets the unpitched index for percussion notes. More...
 
void setTieStart ()
 Sets the note as tied at the start.
 
void setTieStop ()
 Sets the note as tied at the stop.
 
void setTieStopStart ()
 Sets the note as tied at both start and stop.
 
void addTie (const std::string &tieType)
 Adds a tie type to the note. More...
 
void addSlur (const std::string &slurType, const std::string &slurOrientation)
 Adds a slur to the note. More...
 
void addArticulation (const std::string &articulation)
 Adds an articulation mark to the note. More...
 
void addBeam (const std::string &beam)
 Adds a beam type to the note. More...
 
const std::string getSoundingPitchClass () const
 Returns the sounding pitch class (after transposition). More...
 
const std::string getSoundingPitch () const
 Returns the full sounding pitch (after transposition). More...
 
const std::string getWrittenPitchClass () const
 Returns the written pitch class (as notated). More...
 
const std::string getWrittenPitch () const
 Returns the full written pitch (as notated). More...
 
const std::string getDiatonicWrittenPitchClass () const
 Returns the diatonic written pitch class (e.g., "C", "D"). More...
 
const std::string getDiatonicSoundingPitchClass () const
 Returns the diatonic sounding pitch class (e.g., "C", "D"). More...
 
int getSoundingOctave () const
 Returns the sounding octave (after transposition). More...
 
int getWrittenOctave () const
 Returns the written octave (as notated). More...
 
int getOctave () const
 Returns the octave (sounding). More...
 
std::string getPitchClass () const
 Returns the pitch class (sounding). More...
 
std::string getWrittenPitchStep () const
 Returns the written pitch step (e.g., "C", "D"). More...
 
std::string getSoundingPitchStep () const
 Returns the sounding pitch step (e.g., "C", "D"). More...
 
std::string getPitchStep () const
 Returns the pitch step (sounding). More...
 
std::string getType () const
 Returns the note type as a string (e.g., "quarter", "eighth-dot"). More...
 
std::string getLongType () const
 Returns the long note type string (e.g., "quarter-dot"). More...
 
std::string getShortType () const
 Returns the short note type string (e.g., "quarter"). More...
 
int getDurationTicks () const
 Returns the duration in ticks. More...
 
int getNumDots () const
 Returns the number of dots for the note. More...
 
bool isDotted () const
 Returns true if the note is dotted. More...
 
bool isDoubleDotted () const
 Returns true if the note is double-dotted. More...
 
int getDivisionsPerQuarterNote () const
 Returns the divisions per quarter note for the note. More...
 
const DurationgetDuration () const
 Returns the Duration object for the note. More...
 
float getQuarterDuration () const
 Returns the duration in quarter notes as a float. More...
 
bool isGraceNote () const
 Returns true if the note is a grace note. More...
 
bool isNoteOn () const
 Returns true if the note is a sounding note (note on). More...
 
bool isNoteOff () const
 Returns true if the note is a rest (note off). More...
 
std::string getPitch () const
 Returns the full pitch string (sounding). More...
 
int getMidiNumber () const
 Returns the MIDI note number. More...
 
int getVoice () const
 Returns the voice number. More...
 
int getStaff () const
 Returns the staff number. More...
 
std::string getStem () const
 Returns the stem direction. More...
 
std::vector< std::string > getTie () const
 Returns the tie types for the note. More...
 
void removeTies ()
 Removes all ties from the note.
 
std::pair< std::string, std::string > getSlur () const
 Returns the slur information (type and orientation). More...
 
std::vector< std::string > getArticulation () const
 Returns the articulation marks for the note. More...
 
std::vector< std::string > getBeam () const
 Returns the beam types for the note. More...
 
bool isTuplet () const
 Returns true if the note is part of a tuplet. More...
 
bool isPitched () const
 Returns true if the note is pitched. More...
 
int getUnpitchedIndex () const
 Returns the unpitched index for percussion notes. More...
 
std::string getAlterSymbol () const
 Returns the accidental symbol for the note (e.g., "#", "b"). More...
 
bool inChord () const
 Returns true if the note is part of a chord. More...
 
int getTransposeDiatonic () const
 Returns the diatonic transposition interval. More...
 
int getTransposeChromatic () const
 Returns the chromatic transposition interval. More...
 
bool isTransposed () const
 Returns true if the note is transposed. More...
 
std::string getEnharmonicPitch (const bool alternativeEnhamonicPitch=false) const
 Returns an enharmonic equivalent pitch string. More...
 
std::vector< std::string > getEnharmonicPitches (const bool includeCurrentPitch=false) const
 Returns all enharmonic pitch strings for the note. More...
 
Note getEnharmonicNote (const bool alternativeEnhamonicPitch=false) const
 Returns an enharmonic equivalent Note object. More...
 
std::vector< NotegetEnharmonicNotes (const bool includeCurrentPitch=false) const
 Returns all enharmonic Note objects for the note. More...
 
int getScaleDegree (const Key &key) const
 Returns the scale degree of the note in a given key. More...
 
void toEnharmonicPitch (const bool alternativeEnhamonicPitch=false)
 Converts the note to its enharmonic equivalent. More...
 
float getFrequency (const float freqA4=440.0f) const
 Returns the frequency of the note in Hz. More...
 
std::pair< std::vector< float >, std::vector< float > > getHarmonicSpectrum (const int numPartials=6, const std::function< std::vector< float >(std::vector< float >)> amplCallback=nullptr, const float partialsDecayExpRate=0.88f, const float freqA4=440.0f) const
 Returns the harmonic spectrum of the note (partials and amplitudes). More...
 
void transpose (const int semitones, const std::string &accType=MUSIC_XML::ACCIDENT::NONE)
 Transposes the note by a number of semitones and optional accidental type. More...
 
const std::string toXML (const size_t instrumentId=1, const int identSize=2) const
 Serializes the note to MusicXML format. More...
 
void info () const
 Prints detailed information about the note to the log.
 
bool operator< (const Note &otherNote) const
 Less-than operator for comparing notes by MIDI number.
 
bool operator> (const Note &otherNote) const
 Greater-than operator for comparing notes by MIDI number.
 
bool operator<= (const Note &otherNote) const
 Less-than-or-equal operator for comparing notes by MIDI number.
 
bool operator>= (const Note &otherNote) const
 Greater-than-or-equal operator for comparing notes by MIDI number.
 
bool operator== (const Note &otherNote) const
 Equality operator for comparing notes by pitch.
 
bool operator!= (const Note &otherNote) const
 Inequality operator for comparing notes by pitch.
 

Detailed Description

Represents a musical note, including pitch, duration, articulation, and MusicXML-related attributes.

The Note class provides methods for manipulating and querying musical notes, including pitch and octave handling, duration and rhythm, articulations, ties, beams, transposition, enharmonic equivalents, and MusicXML serialization. Designed for music analysis, computational musicology, and MusicXML processing.

Examples
C:/Users/nyck/Desktop/maialib/maiacore/include/maiacore/chord.h, and C:/Users/nyck/Desktop/maialib/maiacore/include/maiacore/config.h.

Constructor & Destructor Documentation

◆ Note() [1/2]

Note::Note ( const std::string &  pitch,
const RhythmFigure  rhythmFigure = RhythmFigure::QUARTER,
bool  isNoteOn = true,
bool  inChord = false,
const int  transposeDiatonic = 0,
const int  transposeChromatic = 0,
const int  divisionsPerQuarterNote = 256 
)
explicit

Constructs a Note from a pitch string and rhythm figure.

Parameters
pitchPitch string (e.g., "C4", "G#3").
rhythmFigureRhythm figure (default: QUARTER).
isNoteOnTrue if sounding note, false for rest.
inChordTrue if part of a chord.
transposeDiatonicDiatonic transposition interval.
transposeChromaticChromatic transposition interval.
divisionsPerQuarterNoteDivisions per quarter note (default: 256).

◆ Note() [2/2]

Note::Note ( const int  midiNumber,
const std::string &  accType = "",
const RhythmFigure  rhythmFigure = RhythmFigure::QUARTER,
bool  isNoteOn = true,
bool  inChord = false,
const int  transposeDiatonic = 0,
const int  transposeChromatic = 0,
const int  divisionsPerQuarterNote = 256 
)
explicit

Constructs a Note from a MIDI number, accidental type, and rhythm figure.

Parameters
midiNumberMIDI note number.
accTypeAccidental type (e.g., "#", "b").
rhythmFigureRhythm figure (default: QUARTER).
isNoteOnTrue if sounding note, false for rest.
inChordTrue if part of a chord.
transposeDiatonicDiatonic transposition interval.
transposeChromaticChromatic transposition interval.
divisionsPerQuarterNoteDivisions per quarter note (default: 256).

Member Function Documentation

◆ addArticulation()

void Note::addArticulation ( const std::string &  articulation)

Adds an articulation mark to the note.

Parameters
articulationArticulation string.

◆ addBeam()

void Note::addBeam ( const std::string &  beam)

Adds a beam type to the note.

Parameters
beamBeam type string.

◆ addSlur()

void Note::addSlur ( const std::string &  slurType,
const std::string &  slurOrientation 
)

Adds a slur to the note.

Parameters
slurTypeSlur type ("start", "stop").
slurOrientationSlur orientation ("above", "below").

◆ addTie()

void Note::addTie ( const std::string &  tieType)

Adds a tie type to the note.

Parameters
tieTypeTie type ("start", "stop").

◆ getAlterSymbol()

std::string Note::getAlterSymbol ( ) const

Returns the accidental symbol for the note (e.g., "#", "b").

Returns
Accidental symbol string.

◆ getArticulation()

std::vector< std::string > Note::getArticulation ( ) const

Returns the articulation marks for the note.

Returns
Vector of articulation strings.

◆ getBeam()

std::vector< std::string > Note::getBeam ( ) const

Returns the beam types for the note.

Returns
Vector of beam strings.

◆ getDiatonicSoundingPitchClass()

const std::string Note::getDiatonicSoundingPitchClass ( ) const

Returns the diatonic sounding pitch class (e.g., "C", "D").

Returns
Diatonic sounding pitch class.

◆ getDiatonicWrittenPitchClass()

const std::string Note::getDiatonicWrittenPitchClass ( ) const

Returns the diatonic written pitch class (e.g., "C", "D").

Returns
Diatonic written pitch class.

◆ getDivisionsPerQuarterNote()

int Note::getDivisionsPerQuarterNote ( ) const

Returns the divisions per quarter note for the note.

Returns
Divisions per quarter note.

◆ getDuration()

const Duration & Note::getDuration ( ) const

Returns the Duration object for the note.

Returns
Duration object.

◆ getDurationTicks()

int Note::getDurationTicks ( ) const

Returns the duration in ticks.

Returns
Duration in ticks.

◆ getEnharmonicNote()

Note Note::getEnharmonicNote ( const bool  alternativeEnhamonicPitch = false) const

Returns an enharmonic equivalent Note object.

Parameters
alternativeEnhamonicPitchIf true, returns an alternative enharmonic.
Returns
Enharmonic Note object.

◆ getEnharmonicNotes()

std::vector< Note > Note::getEnharmonicNotes ( const bool  includeCurrentPitch = false) const

Returns all enharmonic Note objects for the note.

Parameters
includeCurrentPitchIf true, includes the current note.
Returns
Vector of enharmonic Note objects.

◆ getEnharmonicPitch()

std::string Note::getEnharmonicPitch ( const bool  alternativeEnhamonicPitch = false) const

Returns an enharmonic equivalent pitch string.

Parameters
alternativeEnhamonicPitchIf true, returns an alternative enharmonic.
Returns
Enharmonic pitch string.

◆ getEnharmonicPitches()

std::vector< std::string > Note::getEnharmonicPitches ( const bool  includeCurrentPitch = false) const

Returns all enharmonic pitch strings for the note.

Parameters
includeCurrentPitchIf true, includes the current pitch.
Returns
Vector of enharmonic pitch strings.

◆ getFrequency()

float Note::getFrequency ( const float  freqA4 = 440.0f) const

Returns the frequency of the note in Hz.

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

◆ getHarmonicSpectrum()

std::pair< std::vector< float >, std::vector< float > > Note::getHarmonicSpectrum ( const int  numPartials = 6,
const std::function< std::vector< float >(std::vector< float >)>  amplCallback = nullptr,
const float  partialsDecayExpRate = 0.88f,
const float  freqA4 = 440.0f 
) const

Returns the harmonic spectrum of the note (partials and amplitudes).

Parameters
numPartialsNumber of partials.
amplCallbackOptional amplitude callback.
partialsDecayExpRateOptional Partials decay exponential rate (default: 0.88).
freqA4Reference frequency for A4 (default: 440.0 Hz).
Returns
Pair of vectors: frequencies and amplitudes.

◆ getLongType()

std::string Note::getLongType ( ) const

Returns the long note type string (e.g., "quarter-dot").

Returns
Long note type string.

◆ getMidiNumber()

int Note::getMidiNumber ( ) const

Returns the MIDI note number.

Returns
MIDI note number.

◆ getNumDots()

int Note::getNumDots ( ) const

Returns the number of dots for the note.

Returns
Number of dots.

◆ getOctave()

int Note::getOctave ( ) const

Returns the octave (sounding).

Returns
Octave number.

◆ getPitch()

std::string Note::getPitch ( ) const

Returns the full pitch string (sounding).

Returns
Pitch string.

◆ getPitchClass()

std::string Note::getPitchClass ( ) const

Returns the pitch class (sounding).

Returns
Pitch class string.

◆ getPitchStep()

std::string Note::getPitchStep ( ) const

Returns the pitch step (sounding).

Returns
Pitch step string.

◆ getQuarterDuration()

float Note::getQuarterDuration ( ) const

Returns the duration in quarter notes as a float.

Returns
Quarter duration.

◆ getScaleDegree()

int Note::getScaleDegree ( const Key key) const

Returns the scale degree of the note in a given key.

Parameters
keyKey object for reference.
Returns
Scale degree as integer.

◆ getShortType()

std::string Note::getShortType ( ) const

Returns the short note type string (e.g., "quarter").

Returns
Short note type string.

◆ getSlur()

std::pair< std::string, std::string > Note::getSlur ( ) const

Returns the slur information (type and orientation).

Returns
Pair of slur type and orientation.

◆ getSoundingOctave()

int Note::getSoundingOctave ( ) const

Returns the sounding octave (after transposition).

Returns
Sounding octave number.

◆ getSoundingPitch()

const std::string Note::getSoundingPitch ( ) const

Returns the full sounding pitch (after transposition).

Returns
Sounding pitch string.

◆ getSoundingPitchClass()

const std::string Note::getSoundingPitchClass ( ) const

Returns the sounding pitch class (after transposition).

Returns
Sounding pitch class string.

◆ getSoundingPitchStep()

std::string Note::getSoundingPitchStep ( ) const

Returns the sounding pitch step (e.g., "C", "D").

Returns
Sounding pitch step.

◆ getStaff()

int Note::getStaff ( ) const

Returns the staff number.

Returns
Staff number.

◆ getStem()

std::string Note::getStem ( ) const

Returns the stem direction.

Returns
Stem string.

◆ getTie()

std::vector< std::string > Note::getTie ( ) const

Returns the tie types for the note.

Returns
Vector of tie strings.

◆ getTransposeChromatic()

int Note::getTransposeChromatic ( ) const

Returns the chromatic transposition interval.

Returns
Chromatic interval.

◆ getTransposeDiatonic()

int Note::getTransposeDiatonic ( ) const

Returns the diatonic transposition interval.

Returns
Diatonic interval.

◆ getType()

std::string Note::getType ( ) const

Returns the note type as a string (e.g., "quarter", "eighth-dot").

Returns
Note type string.

◆ getUnpitchedIndex()

int Note::getUnpitchedIndex ( ) const

Returns the unpitched index for percussion notes.

Returns
Unpitched index.

◆ getVoice()

int Note::getVoice ( ) const

Returns the voice number.

Returns
Voice number.

◆ getWrittenOctave()

int Note::getWrittenOctave ( ) const

Returns the written octave (as notated).

Returns
Written octave number.

◆ getWrittenPitch()

const std::string Note::getWrittenPitch ( ) const

Returns the full written pitch (as notated).

Returns
Written pitch string.

◆ getWrittenPitchClass()

const std::string Note::getWrittenPitchClass ( ) const

Returns the written pitch class (as notated).

Returns
Written pitch class string.

◆ getWrittenPitchStep()

std::string Note::getWrittenPitchStep ( ) const

Returns the written pitch step (e.g., "C", "D").

Returns
Written pitch step.

◆ inChord()

bool Note::inChord ( ) const

Returns true if the note is part of a chord.

Returns
True if in chord.

◆ isDotted()

bool Note::isDotted ( ) const

Returns true if the note is dotted.

Returns
True if dotted.

◆ isDoubleDotted()

bool Note::isDoubleDotted ( ) const

Returns true if the note is double-dotted.

Returns
True if double-dotted.

◆ isGraceNote()

bool Note::isGraceNote ( ) const

Returns true if the note is a grace note.

Returns
True if grace note.

◆ isNoteOff()

bool Note::isNoteOff ( ) const

Returns true if the note is a rest (note off).

Returns
True if note off.

◆ isNoteOn()

bool Note::isNoteOn ( ) const

Returns true if the note is a sounding note (note on).

Returns
True if note on.

◆ isPitched()

bool Note::isPitched ( ) const

Returns true if the note is pitched.

Returns
True if pitched.

◆ isTransposed()

bool Note::isTransposed ( ) const

Returns true if the note is transposed.

Returns
True if transposed.

◆ isTuplet()

bool Note::isTuplet ( ) const

Returns true if the note is part of a tuplet.

Returns
True if tuplet.

◆ setDuration() [1/3]

void Note::setDuration ( const Duration duration)

Sets the duration for the note.

Parameters
durationDuration object.

◆ setDuration() [2/3]

void Note::setDuration ( const float  quarterDuration,
const int  divisionsPerQuarterNote = 256 
)

Sets the duration for the note using quarter note value.

Parameters
quarterDurationDuration in quarter notes.
divisionsPerQuarterNoteDivisions per quarter note (default: 256).

◆ setDuration() [3/3]

void Note::setDuration ( const int  durationTicks,
const int  divisionsPerQuarterNote 
)

Sets the duration for the note using tick values.

Parameters
durationTicksDuration in ticks.
divisionsPerQuarterNoteDivisions per quarter note (default: 256).

◆ setIsGraceNote()

void Note::setIsGraceNote ( const bool  isGraceNote = false)

Sets whether the note is a grace note.

Parameters
isGraceNoteTrue if grace note.

◆ setIsInChord()

void Note::setIsInChord ( bool  inChord)

Sets whether the note is part of a chord.

Parameters
inChordTrue if in chord.

◆ setIsNoteOn()

void Note::setIsNoteOn ( bool  isNoteOn)

Sets whether the note is sounding (note on) or a rest (note off).

Parameters
isNoteOnTrue for sounding note, false for rest.

◆ setIsPitched()

void Note::setIsPitched ( const bool  isPitched = true)

Sets whether the note is pitched (true) or unpitched (false).

Parameters
isPitchedTrue if pitched.

◆ setIsTuplet()

void Note::setIsTuplet ( const bool  isTuplet = false)

Sets the note as part of a tuplet.

Parameters
isTupletTrue if part of a tuplet.

◆ setOctave()

void Note::setOctave ( int  octave)

Sets the octave for the note.

Parameters
octaveOctave number.

◆ setPitch()

void Note::setPitch ( const std::string &  pitch)

Sets the pitch (e.g., "C4", "G#3") for the note.

Parameters
pitchPitch string.

◆ setPitchClass()

void Note::setPitchClass ( const std::string &  pitchClass)

Sets the pitch class (e.g., "C", "D#", "Bb") for the note.

Parameters
pitchClassThe pitch class string.

◆ setStaff()

void Note::setStaff ( const int  staff)

Sets the staff number for the note.

Parameters
staffStaff number.

◆ setStem()

void Note::setStem ( const std::string &  stem)

Sets the stem direction for the note.

Parameters
stemStem direction ("up", "down", etc.).

◆ setTransposingInterval()

void Note::setTransposingInterval ( const int  diatonicInterval,
const int  chromaticInterval 
)

Sets the transposing interval for the note.

Parameters
diatonicIntervalDiatonic interval.
chromaticIntervalChromatic interval.

◆ setTupleValues()

void Note::setTupleValues ( const int  actualNotes,
const int  normalNotes,
const std::string &  normalType = "eighth" 
)

Sets the tuplet values for the note.

Parameters
actualNotesNumber of actual notes in tuplet.
normalNotesNumber of normal notes in tuplet.
normalTypeNote type for normal notes (default: "eighth").

◆ setUnpitchedIndex()

void Note::setUnpitchedIndex ( const int  unpitchedIndex)

Sets the unpitched index for percussion notes.

Parameters
unpitchedIndexIndex for unpitched note.

◆ setVoice()

void Note::setVoice ( const int  voice)

Sets the voice number for the note.

Parameters
voiceVoice number.

◆ toEnharmonicPitch()

void Note::toEnharmonicPitch ( const bool  alternativeEnhamonicPitch = false)

Converts the note to its enharmonic equivalent.

Parameters
alternativeEnhamonicPitchIf true, uses alternative enharmonic.

◆ toXML()

const std::string Note::toXML ( const size_t  instrumentId = 1,
const int  identSize = 2 
) const

Serializes the note to MusicXML format.

Parameters
instrumentIdInstrument index (default: 1).
identSizeIndentation size (default: 2).
Returns
MusicXML string for the note.

◆ transpose()

void Note::transpose ( const int  semitones,
const std::string &  accType = MUSIC_XML::ACCIDENT::NONE 
)

Transposes the note by a number of semitones and optional accidental type.

Parameters
semitonesNumber of semitones.
accTypeAccidental type (e.g., "#", "b").

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