maiacore 1.10.1
Music analisys library
Measure Class Reference

Represents a musical measure (bar) within a score, containing notes, staves, key/time signatures, and barlines. More...

#include <measure.h>

Public Member Functions

 Measure (const int numStaves=1, const int divisionsPerQuarterNote=256)
 Constructs a Measure with a given number of staves and rhythmic division. More...
 
 ~Measure ()
 Destructor.
 
void setKey (int fifthCircle, bool isMajorMode=true)
 Sets the key signature for the measure. More...
 
Key getKey () const
 Returns the Key object for the measure. More...
 
std::string getKeyName () const
 Returns the key name (e.g., "C major", "G minor"). More...
 
void clear ()
 Removes all notes and resets measure state.
 
void setNumber (const int measureNumber)
 Sets the measure number. More...
 
void setKeySignature (const int fifthCircle, const bool isMajorMode=true)
 Sets the key signature for the measure. More...
 
void setTimeSignature (const int upper, const int lower)
 Sets the time signature for the measure. More...
 
void setMetronome (const int bpm, const RhythmFigure duration=RhythmFigure::QUARTER)
 Sets the metronome mark (BPM and rhythm figure) for the measure. More...
 
void setKeyMode (const bool isMajorKeyMode)
 Sets the key mode (major or minor) for the measure. More...
 
void setIsKeySignatureChanged (bool isKeySignatureChanged=false)
 Sets whether the key signature changes in this measure. More...
 
void setIsTimeSignatureChanged (bool isTimeSignatureChanged=false)
 Sets whether the time signature changes in this measure. More...
 
void setIsMetronomeChanged (bool isMetronomeChanged=false)
 Sets whether the metronome mark changes in this measure. More...
 
void setIsDivisionsPerQuarterNoteChanged (bool isDivisionsPerQuarterNoteChanged=false)
 Sets whether the divisions per quarter note changes in this measure. More...
 
void setNumStaves (const int numStaves)
 Sets the number of staves in the measure. More...
 
void setDivisionsPerQuarterNote (const int divisionsPerQuarterNote)
 Sets the divisions per quarter note for the measure. More...
 
void addNote (const Note &note, const int staveId=0, int position=-1)
 Adds a note to a specific staff and position in the measure. More...
 
void addNote (const std::vector< Note > &noteVec, const int staveId=0, int position=-1)
 Adds multiple notes to a specific staff and position in the measure. More...
 
void addNote (const std::string &pitchClass, const int staveId=0, int position=-1)
 Adds a note by pitch string to a specific staff and position. More...
 
void addNote (const std::vector< std::string > &pitchClassVec, const int staveId=0, int position=-1)
 Adds multiple notes by pitch string to a specific staff and position. More...
 
void removeNote (const int noteId, const int staveId=0)
 Removes a note from a specific staff and position. More...
 
int getNumber () const
 Returns the measure number. More...
 
float getQuarterDuration () const
 Returns the total duration of the measure in quarter notes. More...
 
float getFilledQuarterDuration (const int staveId=0) const
 Returns the filled duration (sum of note durations) in quarter notes for a staff. More...
 
float getFreeQuarterDuration (const int staveId=0) const
 Returns the free (remaining) duration in quarter notes for a staff. More...
 
Fraction getFractionDuration () const
 Returns the duration of the measure as a Fraction object. More...
 
int getDurationTicks () const
 Returns the total duration of the measure in ticks. More...
 
int getFilledDurationTicks (const int staveId=0) const
 Returns the filled duration (sum of note durations) in ticks for a staff. More...
 
int getFreeDurationTicks (const int staveId=0) const
 Returns the free (remaining) duration in ticks for a staff. More...
 
const std::vector< Clef > & getClefs () const
 Returns the clefs for all staves in the measure. More...
 
std::vector< Clef > & getClefs ()
 Returns the clefs for all staves in the measure (modifiable). More...
 
const ClefgetClef (const int clefId=0) const
 Returns the clef for a specific staff. More...
 
ClefgetClef (const int clefId=0)
 Returns the clef for a specific staff (modifiable). More...
 
int getNumStaves () const
 Returns the number of staves in the measure. More...
 
const BarlinegetBarlineLeft () const
 Returns the left barline object. More...
 
BarlinegetBarlineLeft ()
 Returns the left barline object (modifiable). More...
 
const BarlinegetBarlineRight () const
 Returns the right barline object. More...
 
BarlinegetBarlineRight ()
 Returns the right barline object (modifiable). More...
 
void setRepeatStart ()
 Sets the left barline as a repeat start.
 
void setRepeatEnd ()
 Sets the right barline as a repeat end.
 
void removeRepeatStart ()
 Removes the repeat start from the left barline.
 
void removeRepeatEnd ()
 Removes the repeat end from the right barline.
 
bool isClefChanged () const
 Returns true if any clef changes in this measure. More...
 
bool timeSignatureChanged () const
 Returns true if the time signature changes in this measure. More...
 
bool keySignatureChanged () const
 Returns true if the key signature changes in this measure. More...
 
bool metronomeChanged () const
 Returns true if the metronome mark changes in this measure. More...
 
bool divisionsPerQuarterNoteChanged () const
 Returns true if the divisions per quarter note changes in this measure. More...
 
bool isMajorKeyMode () const
 Returns true if the key mode is major. More...
 
const NotegetNote (const int noteId, const int staveId=0) const
 Returns a const reference to a note in a specific staff and position. More...
 
NotegetNote (const int noteId, const int staveId=0)
 Returns a reference to a note in a specific staff and position. More...
 
const NotegetNoteOn (const int noteOnId, const int staveId=0) const
 Returns a const reference to a sounding note (note on) by index and staff. More...
 
NotegetNoteOn (const int noteOnId, const int staveId=0)
 Returns a reference to a sounding note (note on) by index and staff. More...
 
const NotegetNoteOff (const int noteOffId, const int staveId=0) const
 Returns a const reference to a rest note (note off) by index and staff. More...
 
NotegetNoteOff (const int noteOffId, const int staveId=0)
 Returns a reference to a rest note (note off) by index and staff. More...
 
int getNumNotesOn () const
 Returns the number of sounding notes (note on) in the measure (all staves). More...
 
int getNumNotesOn (const int staveId) const
 Returns the number of sounding notes (note on) in a specific staff. More...
 
int getNumNotesOff () const
 Returns the number of rest notes (note off) in the measure (all staves). More...
 
int getNumNotesOff (const int staveId) const
 Returns the number of rest notes (note off) in a specific staff. More...
 
int getNumNotes () const
 Returns the total number of notes in the measure (all staves). More...
 
int getNumNotes (const int staveId) const
 Returns the number of notes in a specific staff. More...
 
int getDivisionsPerQuarterNote () const
 Returns the divisions per quarter note for the measure. More...
 
int getFifthCircle () const
 Returns the number of accidentals in the circle of fifths for the key signature. More...
 
const std::string getKeySignature () const
 Returns the key signature as a string (e.g., "C", "Gm"). More...
 
const TimeSignaturegetTimeSignature () const
 Returns the TimeSignature object for the measure. More...
 
std::pair< std::string, int > getMetronome () const
 Returns the metronome mark as a pair (figure, value). More...
 
void info () const
 Prints summary information about the measure to the log. More...
 
bool isEmpty () const
 Returns true if the measure contains no notes in any staff. More...
 
int getEmptyDurationTicks () const
 Returns the empty (unfilled) duration in ticks for the measure. More...
 
const std::string toXML (const int instrumentId=1, const int identSize=2) const
 Serializes the measure to MusicXML format. More...
 
const std::string toJSON () const
 Serializes the measure to JSON format. More...
 

Detailed Description

Represents a musical measure (bar) within a score, containing notes, staves, key/time signatures, and barlines.

The Measure class provides methods for managing notes, staves, key and time signatures, metronome marks, and barlines. It supports MusicXML serialization and is designed for music analysis, computational musicology, and MusicXML processing.

Constructor & Destructor Documentation

◆ Measure()

Measure::Measure ( const int  numStaves = 1,
const int  divisionsPerQuarterNote = 256 
)

Constructs a Measure with a given number of staves and rhythmic division.

Parameters
numStavesNumber of staves (default: 1).
divisionsPerQuarterNoteDivisions per quarter note (default: 256).

Member Function Documentation

◆ addNote() [1/4]

void Measure::addNote ( const Note note,
const int  staveId = 0,
int  position = -1 
)

Adds a note to a specific staff and position in the measure.

Parameters
noteNote to add.
staveIdStaff index (default: 0).
positionPosition in the staff (-1 for append).

◆ addNote() [2/4]

void Measure::addNote ( const std::string &  pitchClass,
const int  staveId = 0,
int  position = -1 
)

Adds a note by pitch string to a specific staff and position.

Parameters
pitchClassPitch string (e.g., "C4").
staveIdStaff index (default: 0).
positionPosition in the staff (-1 for append).

◆ addNote() [3/4]

void Measure::addNote ( const std::vector< Note > &  noteVec,
const int  staveId = 0,
int  position = -1 
)

Adds multiple notes to a specific staff and position in the measure.

Parameters
noteVecVector of notes to add.
staveIdStaff index (default: 0).
positionPosition in the staff (-1 for append).

◆ addNote() [4/4]

void Measure::addNote ( const std::vector< std::string > &  pitchClassVec,
const int  staveId = 0,
int  position = -1 
)

Adds multiple notes by pitch string to a specific staff and position.

Parameters
pitchClassVecVector of pitch strings.
staveIdStaff index (default: 0).
positionPosition in the staff (-1 for append).

◆ divisionsPerQuarterNoteChanged()

bool Measure::divisionsPerQuarterNoteChanged ( ) const

Returns true if the divisions per quarter note changes in this measure.

Returns
True if divisions changed.

◆ getBarlineLeft() [1/2]

Barline & Measure::getBarlineLeft ( )

Returns the left barline object (modifiable).

Returns
Reference to Barline.

◆ getBarlineLeft() [2/2]

const Barline & Measure::getBarlineLeft ( ) const

Returns the left barline object.

Returns
Const reference to Barline.

◆ getBarlineRight() [1/2]

Barline & Measure::getBarlineRight ( )

Returns the right barline object (modifiable).

Returns
Reference to Barline.

◆ getBarlineRight() [2/2]

const Barline & Measure::getBarlineRight ( ) const

Returns the right barline object.

Returns
Const reference to Barline.

◆ getClef() [1/2]

Clef & Measure::getClef ( const int  clefId = 0)

Returns the clef for a specific staff (modifiable).

Parameters
clefIdClef index (default: 0).
Returns
Reference to Clef object.

◆ getClef() [2/2]

const Clef & Measure::getClef ( const int  clefId = 0) const

Returns the clef for a specific staff.

Parameters
clefIdClef index (default: 0).
Returns
Const reference to Clef object.

◆ getClefs() [1/2]

std::vector< Clef > & Measure::getClefs ( )

Returns the clefs for all staves in the measure (modifiable).

Returns
Reference to vector of Clef objects.

◆ getClefs() [2/2]

const std::vector< Clef > & Measure::getClefs ( ) const

Returns the clefs for all staves in the measure.

Returns
Const reference to vector of Clef objects.

◆ getDivisionsPerQuarterNote()

int Measure::getDivisionsPerQuarterNote ( ) const

Returns the divisions per quarter note for the measure.

Returns
Divisions per quarter note (integer).

◆ getDurationTicks()

int Measure::getDurationTicks ( ) const

Returns the total duration of the measure in ticks.

Returns
Duration in ticks.

◆ getEmptyDurationTicks()

int Measure::getEmptyDurationTicks ( ) const

Returns the empty (unfilled) duration in ticks for the measure.

Returns
Number of ticks representing the empty duration.

◆ getFifthCircle()

int Measure::getFifthCircle ( ) const

Returns the number of accidentals in the circle of fifths for the key signature.

Returns
Integer representing the fifth circle value.

◆ getFilledDurationTicks()

int Measure::getFilledDurationTicks ( const int  staveId = 0) const

Returns the filled duration (sum of note durations) in ticks for a staff.

Parameters
staveIdStaff index (default: 0).
Returns
Filled duration in ticks.

◆ getFilledQuarterDuration()

float Measure::getFilledQuarterDuration ( const int  staveId = 0) const

Returns the filled duration (sum of note durations) in quarter notes for a staff.

Parameters
staveIdStaff index (default: 0).
Returns
Filled duration in quarter notes.

◆ getFractionDuration()

Fraction Measure::getFractionDuration ( ) const

Returns the duration of the measure as a Fraction object.

Returns
Fraction representing the duration.

◆ getFreeDurationTicks()

int Measure::getFreeDurationTicks ( const int  staveId = 0) const

Returns the free (remaining) duration in ticks for a staff.

Parameters
staveIdStaff index (default: 0).
Returns
Free duration in ticks.

◆ getFreeQuarterDuration()

float Measure::getFreeQuarterDuration ( const int  staveId = 0) const

Returns the free (remaining) duration in quarter notes for a staff.

Parameters
staveIdStaff index (default: 0).
Returns
Free duration in quarter notes.

◆ getKey()

Key Measure::getKey ( ) const

Returns the Key object for the measure.

Returns
Key object.

◆ getKeyName()

std::string Measure::getKeyName ( ) const

Returns the key name (e.g., "C major", "G minor").

Returns
Key name string.

◆ getKeySignature()

const std::string Measure::getKeySignature ( ) const

Returns the key signature as a string (e.g., "C", "Gm").

Returns
Key signature string.

◆ getMetronome()

std::pair< std::string, int > Measure::getMetronome ( ) const

Returns the metronome mark as a pair (figure, value).

Returns
Pair of metronome figure (string) and value (BPM).

◆ getNote() [1/2]

Note & Measure::getNote ( const int  noteId,
const int  staveId = 0 
)

Returns a reference to a note in a specific staff and position.

Parameters
noteIdNote index.
staveIdStaff index (default: 0).
Returns
Reference to Note.

◆ getNote() [2/2]

const Note & Measure::getNote ( const int  noteId,
const int  staveId = 0 
) const

Returns a const reference to a note in a specific staff and position.

Parameters
noteIdNote index.
staveIdStaff index (default: 0).
Returns
Const reference to Note.

◆ getNoteOff() [1/2]

Note & Measure::getNoteOff ( const int  noteOffId,
const int  staveId = 0 
)

Returns a reference to a rest note (note off) by index and staff.

Parameters
noteOffIdNote off index.
staveIdStaff index (default: 0).
Returns
Reference to Note.

◆ getNoteOff() [2/2]

const Note & Measure::getNoteOff ( const int  noteOffId,
const int  staveId = 0 
) const

Returns a const reference to a rest note (note off) by index and staff.

Parameters
noteOffIdNote off index.
staveIdStaff index (default: 0).
Returns
Const reference to Note.

◆ getNoteOn() [1/2]

Note & Measure::getNoteOn ( const int  noteOnId,
const int  staveId = 0 
)

Returns a reference to a sounding note (note on) by index and staff.

Parameters
noteOnIdNote on index.
staveIdStaff index (default: 0).
Returns
Reference to Note.

◆ getNoteOn() [2/2]

const Note & Measure::getNoteOn ( const int  noteOnId,
const int  staveId = 0 
) const

Returns a const reference to a sounding note (note on) by index and staff.

Parameters
noteOnIdNote on index.
staveIdStaff index (default: 0).
Returns
Const reference to Note.

◆ getNumber()

int Measure::getNumber ( ) const

Returns the measure number.

Returns
Measure number.

◆ getNumNotes() [1/2]

int Measure::getNumNotes ( ) const

Returns the total number of notes in the measure (all staves).

Returns
Number of notes.

◆ getNumNotes() [2/2]

int Measure::getNumNotes ( const int  staveId) const

Returns the number of notes in a specific staff.

Parameters
staveIdStaff index.
Returns
Number of notes in the specified staff.

◆ getNumNotesOff() [1/2]

int Measure::getNumNotesOff ( ) const

Returns the number of rest notes (note off) in the measure (all staves).

Returns
Number of rest notes.

◆ getNumNotesOff() [2/2]

int Measure::getNumNotesOff ( const int  staveId) const

Returns the number of rest notes (note off) in a specific staff.

Parameters
staveIdStaff index.
Returns
Number of rest notes.

◆ getNumNotesOn() [1/2]

int Measure::getNumNotesOn ( ) const

Returns the number of sounding notes (note on) in the measure (all staves).

Returns
Number of sounding notes.

◆ getNumNotesOn() [2/2]

int Measure::getNumNotesOn ( const int  staveId) const

Returns the number of sounding notes (note on) in a specific staff.

Parameters
staveIdStaff index.
Returns
Number of sounding notes.

◆ getNumStaves()

int Measure::getNumStaves ( ) const

Returns the number of staves in the measure.

Returns
Number of staves.

◆ getQuarterDuration()

float Measure::getQuarterDuration ( ) const

Returns the total duration of the measure in quarter notes.

Returns
Duration in quarter notes.

◆ getTimeSignature()

const TimeSignature & Measure::getTimeSignature ( ) const

Returns the TimeSignature object for the measure.

Returns
Const reference to the TimeSignature.

◆ info()

void Measure::info ( ) const

Prints summary information about the measure to the log.

Includes measure number, key, time signature, and note count.

◆ isClefChanged()

bool Measure::isClefChanged ( ) const

Returns true if any clef changes in this measure.

Returns
True if clef changed.

◆ isEmpty()

bool Measure::isEmpty ( ) const

Returns true if the measure contains no notes in any staff.

Returns
True if the measure is empty.

◆ isMajorKeyMode()

bool Measure::isMajorKeyMode ( ) const

Returns true if the key mode is major.

Returns
True if major mode.

◆ keySignatureChanged()

bool Measure::keySignatureChanged ( ) const

Returns true if the key signature changes in this measure.

Returns
True if key signature changed.

◆ metronomeChanged()

bool Measure::metronomeChanged ( ) const

Returns true if the metronome mark changes in this measure.

Returns
True if metronome changed.

◆ removeNote()

void Measure::removeNote ( const int  noteId,
const int  staveId = 0 
)

Removes a note from a specific staff and position.

Parameters
noteIdNote index.
staveIdStaff index (default: 0).

◆ setDivisionsPerQuarterNote()

void Measure::setDivisionsPerQuarterNote ( const int  divisionsPerQuarterNote)

Sets the divisions per quarter note for the measure.

Parameters
divisionsPerQuarterNoteNew divisions per quarter note.

◆ setIsDivisionsPerQuarterNoteChanged()

void Measure::setIsDivisionsPerQuarterNoteChanged ( bool  isDivisionsPerQuarterNoteChanged = false)

Sets whether the divisions per quarter note changes in this measure.

Parameters
isDivisionsPerQuarterNoteChangedTrue if changed.

◆ setIsKeySignatureChanged()

void Measure::setIsKeySignatureChanged ( bool  isKeySignatureChanged = false)

Sets whether the key signature changes in this measure.

Parameters
isKeySignatureChangedTrue if changed.

◆ setIsMetronomeChanged()

void Measure::setIsMetronomeChanged ( bool  isMetronomeChanged = false)

Sets whether the metronome mark changes in this measure.

Parameters
isMetronomeChangedTrue if changed.

◆ setIsTimeSignatureChanged()

void Measure::setIsTimeSignatureChanged ( bool  isTimeSignatureChanged = false)

Sets whether the time signature changes in this measure.

Parameters
isTimeSignatureChangedTrue if changed.

◆ setKey()

void Measure::setKey ( int  fifthCircle,
bool  isMajorMode = true 
)

Sets the key signature for the measure.

Parameters
fifthCircleNumber of accidentals in the circle of fifths.
isMajorModeTrue for major, false for minor.

◆ setKeyMode()

void Measure::setKeyMode ( const bool  isMajorKeyMode)

Sets the key mode (major or minor) for the measure.

Parameters
isMajorKeyModeTrue for major, false for minor.

◆ setKeySignature()

void Measure::setKeySignature ( const int  fifthCircle,
const bool  isMajorMode = true 
)

Sets the key signature for the measure.

Parameters
fifthCircleNumber of accidentals.
isMajorModeTrue for major, false for minor.

◆ setMetronome()

void Measure::setMetronome ( const int  bpm,
const RhythmFigure  duration = RhythmFigure::QUARTER 
)

Sets the metronome mark (BPM and rhythm figure) for the measure.

Parameters
bpmBeats per minute.
durationRhythm figure (default: QUARTER).

◆ setNumber()

void Measure::setNumber ( const int  measureNumber)

Sets the measure number.

Parameters
measureNumberNew measure number.

◆ setNumStaves()

void Measure::setNumStaves ( const int  numStaves)

Sets the number of staves in the measure.

Parameters
numStavesNew number of staves.

◆ setTimeSignature()

void Measure::setTimeSignature ( const int  upper,
const int  lower 
)

Sets the time signature for the measure.

Parameters
upperNumerator.
lowerDenominator.

◆ timeSignatureChanged()

bool Measure::timeSignatureChanged ( ) const

Returns true if the time signature changes in this measure.

Returns
True if time signature changed.

◆ toJSON()

const std::string Measure::toJSON ( ) const

Serializes the measure to JSON format.

Returns
JSON string for the measure.

◆ toXML()

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

Serializes the measure to MusicXML format.

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

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