maiacore 1.10.1
Music analisys library
part.h
1#pragma once
2
3#include <iostream>
4#include <variant>
5#include <vector>
6
7class Chord;
8class Measure;
9class Note;
10
17class Part {
18 private:
19 int _partIndex;
20 int _numStaves;
21 int _divisionsPerQuarterNote;
22 bool _isPitched;
23 int _staffLines;
24 std::string _partName;
25 std::string _shortName;
26 std::vector<Measure> _measure;
27 std::vector<int> _midiUnpitched;
28
35 void appendNote(const Note& note, const int position = -1, const int staveId = 0);
36
43 void appendNotes(const std::vector<Note>& notes, const int position = -1,
44 const int staveId = 0);
45
52 void appendChord(const Chord& chord, const int position = -1, const int staveId = 0);
53
60 void appendChords(const std::vector<Chord>& chords, const int position = -1,
61 const int staveId = 0);
62
63 public:
71 Part(const std::string& partName, const int numStaves = 1, const bool isPitched = true,
72 const int divisionsPerQuarterNote = 256);
73
78
82 void clear();
83
88 int getPartIndex() const;
89
94 void setPartIndex(int partIdx);
95
100 const std::string& getName() const;
101
106 const std::string& getShortName() const;
107
112 void addMidiUnpitched(const int midiUnpitched);
113
120 void append(const std::variant<Note, Chord>& obj, const int position = -1,
121 const int staveId = 0);
122
129 void append(const std::vector<std::variant<Note, Chord>>& objs, const int position = -1,
130 const int staveId = 0);
131
136 void addMeasure(const int numMeasures);
137
143 void removeMeasure(const int measureStart, const int measureEnd);
144
150 Measure& getMeasure(const int measureId);
151
157 const Measure& getMeasure(const int measureId) const;
158
163 const std::vector<Measure> getMeasures() const;
164
169 int getNumMeasures() const;
170
175 void setNumStaves(const int numStaves);
176
181 void setIsPitched(const bool isPitched = true);
182
187 void setStaffLines(const int staffLines = 5);
188
193 void addStaves(const int numStaves = 1);
194
199 void removeStave(const int staveId);
200
205 int getNumStaves() const;
206
211 std::vector<int> getMidiUnpitched() const;
212
217 bool isPitched() const;
218
223 int getStaffLines() const;
224
230 int getNumNotes(const int staveId = -1);
231
237 int getNumNotesOn(const int staveId = -1);
238
244 int getNumNotesOff(const int staveId = -1);
245
250 void setShortName(const std::string& shortName);
251
255 void info() const;
256
263 const std::string toXML(const int instrumentId = 1, const int identSize = 2) const;
264
269 std::string toJSON() const;
270};
Represents a musical chord.
Definition: chord.h:70
Represents a musical measure (bar) within a score, containing notes, staves, key/time signatures,...
Definition: measure.h:23
Represents a musical note, including pitch, duration, articulation, and MusicXML-related attributes.
Definition: note.h:19
Represents a musical part (instrument or voice) in a score, containing measures, staves,...
Definition: part.h:17
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.
void removeMeasure(const int measureStart, const int measureEnd)
Removes a range of measures from the part.
void addStaves(const int numStaves=1)
Adds additional staves to the part.
~Part()
Destructor.
Measure & getMeasure(const int measureId)
Returns a reference to a measure by its index.
const std::vector< Measure > getMeasures() const
Returns a vector of all measures in the part.
int getNumNotesOff(const int staveId=-1)
Returns the number of rest notes (note off) in the part (optionally for a specific staff).
std::string toJSON() const
Serializes the part to JSON format.
int getNumNotesOn(const int staveId=-1)
Returns the number of sounding notes (note on) in the part (optionally for a specific staff).
int getNumMeasures() const
Returns the number of measures in the part.
int getStaffLines() const
Returns the number of staff lines.
void setNumStaves(const int numStaves)
Sets the number of staves for the 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.
void removeStave(const int staveId)
Removes a staff from the part by its index.
bool isPitched() const
Returns true if the part is pitched (not percussion).
const std::string toXML(const int instrumentId=1, const int identSize=2) const
Serializes the part to MusicXML format.
const Measure & getMeasure(const int measureId) const
Returns a const reference to a measure by its index.
std::vector< int > getMidiUnpitched() const
Returns the MIDI numbers for unpitched percussion instruments.
void info() const
Prints summary information about the part to the log.
void setStaffLines(const int staffLines=5)
Sets the number of staff lines for the part.
void addMidiUnpitched(const int midiUnpitched)
Adds a MIDI number for an unpitched percussion instrument.
void addMeasure(const int numMeasures)
Adds a specified number of measures to the part.
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.
void clear()
Removes all measures and resets the part.
int getNumStaves() const
Returns the number of staves in the part.
void setShortName(const std::string &shortName)
Sets the short name (abbreviation) for the part.
const std::string & getName() const
Returns the full name of the part.
int getPartIndex() const
Returns the index of the part in the score.
void setIsPitched(const bool isPitched=true)
Sets whether the part is pitched (true) or unpitched (false).
void setPartIndex(int partIdx)
Sets the index of the part in the score.
const std::string & getShortName() const
Returns the short name (abbreviation) of the part.
int getNumNotes(const int staveId=-1)
Returns the number of notes in the part (optionally for a specific staff).