maiacore 1.10.1
Music analisys library
Part Class Reference

Represents a musical part (instrument or voice) in a score, containing measures, staves, and notes. More...

#include <part.h>

Public Member Functions

 Part (const std::string &partName, const int numStaves=1, const bool isPitched=true, const int divisionsPerQuarterNote=256)
 Constructs a Part with a given name, number of staves, pitch type, and rhythmic division. More...
 
 ~Part ()
 Destructor.
 
void clear ()
 Removes all measures and resets the part.
 
int getPartIndex () const
 Returns the index of the part in the score. More...
 
void setPartIndex (int partIdx)
 Sets the index of the part in the score. More...
 
const std::string & getName () const
 Returns the full name of the part. More...
 
const std::string & getShortName () const
 Returns the short name (abbreviation) of the part. More...
 
void addMidiUnpitched (const int midiUnpitched)
 Adds a MIDI number for an unpitched percussion instrument. More...
 
void append (const std::variant< Note, Chord > &obj, const int position=-1, const int staveId=0)
 Appends a Note or Chord (variant) to the part at a given position and staff. More...
 
void append (const std::vector< std::variant< Note, Chord > > &objs, const int position=-1, const int staveId=0)
 Appends multiple Note or Chord variants to the part at a given position and staff. More...
 
void addMeasure (const int numMeasures)
 Adds a specified number of measures to the part. More...
 
void removeMeasure (const int measureStart, const int measureEnd)
 Removes a range of measures from the part. More...
 
MeasuregetMeasure (const int measureId)
 Returns a reference to a measure by its index. More...
 
const MeasuregetMeasure (const int measureId) const
 Returns a const reference to a measure by its index. More...
 
const std::vector< MeasuregetMeasures () const
 Returns a vector of all measures in the part. More...
 
int getNumMeasures () const
 Returns the number of measures in the part. More...
 
void setNumStaves (const int numStaves)
 Sets the number of staves for the part. More...
 
void setIsPitched (const bool isPitched=true)
 Sets whether the part is pitched (true) or unpitched (false). More...
 
void setStaffLines (const int staffLines=5)
 Sets the number of staff lines for the part. More...
 
void addStaves (const int numStaves=1)
 Adds additional staves to the part. More...
 
void removeStave (const int staveId)
 Removes a staff from the part by its index. More...
 
int getNumStaves () const
 Returns the number of staves in the part. More...
 
std::vector< int > getMidiUnpitched () const
 Returns the MIDI numbers for unpitched percussion instruments. More...
 
bool isPitched () const
 Returns true if the part is pitched (not percussion). More...
 
int getStaffLines () const
 Returns the number of staff lines. More...
 
int getNumNotes (const int staveId=-1)
 Returns the number of notes in the part (optionally for a specific staff). More...
 
int getNumNotesOn (const int staveId=-1)
 Returns the number of sounding notes (note on) in the part (optionally for a specific staff). More...
 
int getNumNotesOff (const int staveId=-1)
 Returns the number of rest notes (note off) in the part (optionally for a specific staff). More...
 
void setShortName (const std::string &shortName)
 Sets the short name (abbreviation) for the part. More...
 
void info () const
 Prints summary information about the part to the log.
 
const std::string toXML (const int instrumentId=1, const int identSize=2) const
 Serializes the part to MusicXML format. More...
 
std::string toJSON () const
 Serializes the part to JSON format. More...
 

Detailed Description

Represents a musical part (instrument or voice) in a score, containing measures, staves, and notes.

The Part class provides methods for managing measures, staves, notes, and chords, as well as for querying and modifying part-level metadata. It supports MusicXML serialization and is designed for music analysis and computational musicology.

Constructor & Destructor Documentation

◆ Part()

Part::Part ( const std::string &  partName,
const int  numStaves = 1,
const bool  isPitched = true,
const int  divisionsPerQuarterNote = 256 
)

Constructs a Part with a given name, number of staves, pitch type, and rhythmic division.

Parameters
partNameName of the part (instrument or voice).
numStavesNumber of staves (default: 1).
isPitchedTrue if pitched (default: true).
divisionsPerQuarterNoteDivisions per quarter note (default: 256).

Member Function Documentation

◆ addMeasure()

void Part::addMeasure ( const int  numMeasures)

Adds a specified number of measures to the part.

Parameters
numMeasuresNumber of measures to add.

◆ addMidiUnpitched()

void Part::addMidiUnpitched ( const int  midiUnpitched)

Adds a MIDI number for an unpitched percussion instrument.

Parameters
midiUnpitchedMIDI number to add.

◆ addStaves()

void Part::addStaves ( const int  numStaves = 1)

Adds additional staves to the part.

Parameters
numStavesNumber of staves to add (default: 1).

◆ append() [1/2]

void Part::append ( const std::variant< Note, Chord > &  obj,
const int  position = -1,
const int  staveId = 0 
)

Appends a Note or Chord (variant) to the part at a given position and staff.

Parameters
objNote or Chord to append.
positionPosition in the measure (-1 for auto).
staveIdStaff index (default: 0).

◆ append() [2/2]

void Part::append ( const std::vector< std::variant< Note, Chord > > &  objs,
const int  position = -1,
const int  staveId = 0 
)

Appends multiple Note or Chord variants to the part at a given position and staff.

Parameters
objsVector of Note or Chord variants.
positionPosition in the measure (-1 for auto).
staveIdStaff index (default: 0).

◆ getMeasure() [1/2]

Measure & Part::getMeasure ( const int  measureId)

Returns a reference to a measure by its index.

Parameters
measureIdMeasure index.
Returns
Reference to the Measure object.

◆ getMeasure() [2/2]

const Measure & Part::getMeasure ( const int  measureId) const

Returns a const reference to a measure by its index.

Parameters
measureIdMeasure index.
Returns
Const reference to the Measure object.

◆ getMeasures()

const std::vector< Measure > Part::getMeasures ( ) const

Returns a vector of all measures in the part.

Returns
Vector of Measure objects.

◆ getMidiUnpitched()

std::vector< int > Part::getMidiUnpitched ( ) const

Returns the MIDI numbers for unpitched percussion instruments.

Returns
Vector of MIDI numbers.

◆ getName()

const std::string & Part::getName ( ) const

Returns the full name of the part.

Returns
Part name string.

◆ getNumMeasures()

int Part::getNumMeasures ( ) const

Returns the number of measures in the part.

Returns
Number of measures.

◆ getNumNotes()

int Part::getNumNotes ( const int  staveId = -1)

Returns the number of notes in the part (optionally for a specific staff).

Parameters
staveIdStaff index (-1 for all staves).
Returns
Number of notes.

◆ getNumNotesOff()

int Part::getNumNotesOff ( const int  staveId = -1)

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

Parameters
staveIdStaff index (-1 for all staves).
Returns
Number of rest notes.

◆ getNumNotesOn()

int Part::getNumNotesOn ( const int  staveId = -1)

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

Parameters
staveIdStaff index (-1 for all staves).
Returns
Number of sounding notes.

◆ getNumStaves()

int Part::getNumStaves ( ) const

Returns the number of staves in the part.

Returns
Number of staves.

◆ getPartIndex()

int Part::getPartIndex ( ) const

Returns the index of the part in the score.

Returns
Part index.

◆ getShortName()

const std::string & Part::getShortName ( ) const

Returns the short name (abbreviation) of the part.

Returns
Short name string.

◆ getStaffLines()

int Part::getStaffLines ( ) const

Returns the number of staff lines.

Returns
Number of staff lines.

◆ isPitched()

bool Part::isPitched ( ) const

Returns true if the part is pitched (not percussion).

Returns
True if pitched.

◆ removeMeasure()

void Part::removeMeasure ( const int  measureStart,
const int  measureEnd 
)

Removes a range of measures from the part.

Parameters
measureStartIndex of the first measure to remove.
measureEndIndex of the last measure to remove.

◆ removeStave()

void Part::removeStave ( const int  staveId)

Removes a staff from the part by its index.

Parameters
staveIdStaff index to remove.

◆ setIsPitched()

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

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

Parameters
isPitchedTrue if pitched.

◆ setNumStaves()

void Part::setNumStaves ( const int  numStaves)

Sets the number of staves for the part.

Parameters
numStavesNew number of staves.

◆ setPartIndex()

void Part::setPartIndex ( int  partIdx)

Sets the index of the part in the score.

Parameters
partIdxNew part index.

◆ setShortName()

void Part::setShortName ( const std::string &  shortName)

Sets the short name (abbreviation) for the part.

Parameters
shortNameShort name string.

◆ setStaffLines()

void Part::setStaffLines ( const int  staffLines = 5)

Sets the number of staff lines for the part.

Parameters
staffLinesNumber of staff lines (default: 5).

◆ toJSON()

std::string Part::toJSON ( ) const

Serializes the part to JSON format.

Returns
JSON string for the part.

◆ toXML()

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

Serializes the part to MusicXML format.

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

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