maiacore 1.10.1
Music analisys library
measure.h
1#pragma once
2#include <ctype.h>
3
4#include <string>
5#include <vector>
6
7#include "maiacore/barline.h"
8#include "maiacore/clef.h"
9#include "maiacore/constants.h"
10#include "maiacore/key.h"
11#include "maiacore/time-signature.h"
12
13class Note;
14class Barline;
15class Fraction;
16
23class Measure {
24 private:
25 int _number;
26 Key _key;
27 std::string _metronomeFigure;
28 int _metronomeValue;
29 bool _isKeySignatureChanged;
30 bool _isTimeSignatureChanged;
31 bool _isMetronomeChanged;
32 bool _isDivisionsPerQuarterNoteChanged;
33 int _numStaves;
34 int _divisionsPerQuarterNote;
35 TimeSignature _timeSignature;
36
37 std::vector<std::vector<Note>> _note;
38 std::vector<Clef> _clef;
39 Barline _barlineLeft;
40 Barline _barlineRight;
41
42 public:
48 Measure(const int numStaves = 1, const int divisionsPerQuarterNote = 256);
49
54
60 void setKey(int fifthCircle, bool isMajorMode = true);
61
66 Key getKey() const;
67
72 std::string getKeyName() const;
73
77 void clear();
78
83 void setNumber(const int measureNumber);
84
90 void setKeySignature(const int fifthCircle, const bool isMajorMode = true);
91
97 void setTimeSignature(const int upper, const int lower);
98
104 void setMetronome(const int bpm, const RhythmFigure duration = RhythmFigure::QUARTER);
105
110 void setKeyMode(const bool isMajorKeyMode);
111
116 void setIsKeySignatureChanged(bool isKeySignatureChanged = false);
117
122 void setIsTimeSignatureChanged(bool isTimeSignatureChanged = false);
123
124 // void setIsClefChanged(bool isClefChanged = false);
125
130 void setIsMetronomeChanged(bool isMetronomeChanged = false);
131
136 void setIsDivisionsPerQuarterNoteChanged(bool isDivisionsPerQuarterNoteChanged = false);
137
142 void setNumStaves(const int numStaves);
143
148 void setDivisionsPerQuarterNote(const int divisionsPerQuarterNote);
149
156 void addNote(const Note& note, const int staveId = 0, int position = -1);
157
164 void addNote(const std::vector<Note>& noteVec, const int staveId = 0, int position = -1);
165
172 void addNote(const std::string& pitchClass, const int staveId = 0, int position = -1);
173
180 void addNote(const std::vector<std::string>& pitchClassVec, const int staveId = 0,
181 int position = -1);
182
188 void removeNote(const int noteId, const int staveId = 0);
189
194 int getNumber() const;
195
200 float getQuarterDuration() const;
201
207 float getFilledQuarterDuration(const int staveId = 0) const;
208
214 float getFreeQuarterDuration(const int staveId = 0) const;
215
220 Fraction getFractionDuration() const;
221
226 int getDurationTicks() const;
227
233 int getFilledDurationTicks(const int staveId = 0) const;
234
240 int getFreeDurationTicks(const int staveId = 0) const;
241
246 const std::vector<Clef>& getClefs() const;
247
252 std::vector<Clef>& getClefs();
253
259 const Clef& getClef(const int clefId = 0) const;
260
266 Clef& getClef(const int clefId = 0);
267
272 int getNumStaves() const;
273
278 const Barline& getBarlineLeft() const;
279
285
290 const Barline& getBarlineRight() const;
291
297
302
307
312
317
322 bool isClefChanged() const;
323
329
335
340 bool metronomeChanged() const;
341
347
352 bool isMajorKeyMode() const;
353
360 const Note& getNote(const int noteId, const int staveId = 0) const;
361
368 Note& getNote(const int noteId, const int staveId = 0);
369
376 const Note& getNoteOn(const int noteOnId, const int staveId = 0) const;
377
384 Note& getNoteOn(const int noteOnId, const int staveId = 0);
385
392 const Note& getNoteOff(const int noteOffId, const int staveId = 0) const;
393
400 Note& getNoteOff(const int noteOffId, const int staveId = 0);
401
406 int getNumNotesOn() const;
407
413 int getNumNotesOn(const int staveId) const;
414
419 int getNumNotesOff() const;
420
426 int getNumNotesOff(const int staveId) const;
427
432 int getNumNotes() const;
433
439 int getNumNotes(const int staveId) const;
440
446
451 int getFifthCircle() const;
452
457 const std::string getKeySignature() const;
458
464
469 std::pair<std::string, int> getMetronome() const;
470
475 void info() const;
476
481 bool isEmpty() const;
482
488
495 const std::string toXML(const int instrumentId = 1, const int identSize = 2) const;
496
501 const std::string toJSON() const;
502};
Represents a barline in a musical score, including style, direction, and location.
Definition: barline.h:12
Represents a musical clef for a staff, including sign, line, and change status.
Definition: clef.h:19
Represents a musical key signature (tonality), including circle of fifths and mode (major/minor).
Definition: key.h:11
Represents a musical measure (bar) within a score, containing notes, staves, key/time signatures,...
Definition: measure.h:23
int getFreeDurationTicks(const int staveId=0) const
Returns the free (remaining) duration in ticks for a staff.
void removeRepeatStart()
Removes the repeat start from the left barline.
void removeRepeatEnd()
Removes the repeat end from the right barline.
int getDurationTicks() const
Returns the total duration of the measure in ticks.
int getNumNotesOff(const int staveId) const
Returns the number of rest notes (note off) in a specific staff.
bool timeSignatureChanged() const
Returns true if the time signature changes in this measure.
bool isClefChanged() const
Returns true if any clef changes in this measure.
bool metronomeChanged() const
Returns true if the metronome mark changes in this measure.
const Note & getNoteOn(const int noteOnId, const int staveId=0) const
Returns a const reference to a sounding note (note on) by index and staff.
void setRepeatEnd()
Sets the right barline as a repeat end.
void setRepeatStart()
Sets the left barline as a repeat start.
void clear()
Removes all notes and resets measure state.
bool keySignatureChanged() const
Returns true if the key signature changes in this measure.
bool isMajorKeyMode() const
Returns true if the key mode is major.
bool isEmpty() const
Returns true if the measure contains no notes in any staff.
void setIsDivisionsPerQuarterNoteChanged(bool isDivisionsPerQuarterNoteChanged=false)
Sets whether the divisions per quarter note changes in this measure.
const std::string getKeySignature() const
Returns the key signature as a string (e.g., "C", "Gm").
const std::string toJSON() const
Serializes the measure to JSON format.
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.
void setIsKeySignatureChanged(bool isKeySignatureChanged=false)
Sets whether the key signature changes in this measure.
void setKeyMode(const bool isMajorKeyMode)
Sets the key mode (major or minor) for the measure.
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.
const Note & getNote(const int noteId, const int staveId=0) const
Returns a const reference to a note in a specific staff and position.
int getNumNotesOff() const
Returns the number of rest notes (note off) in the measure (all staves).
void addNote(const Note &note, const int staveId=0, int position=-1)
Adds a note to a specific staff and position in the measure.
Measure(const int numStaves=1, const int divisionsPerQuarterNote=256)
Constructs a Measure with a given number of staves and rhythmic division.
void setTimeSignature(const int upper, const int lower)
Sets the time signature for the measure.
void setNumStaves(const int numStaves)
Sets the number of staves in the measure.
Clef & getClef(const int clefId=0)
Returns the clef for a specific staff (modifiable).
void setKeySignature(const int fifthCircle, const bool isMajorMode=true)
Sets the key signature for the measure.
const std::string toXML(const int instrumentId=1, const int identSize=2) const
Serializes the measure to MusicXML format.
const Barline & getBarlineLeft() const
Returns the left barline object.
Barline & getBarlineRight()
Returns the right barline object (modifiable).
Fraction getFractionDuration() const
Returns the duration of the measure as a Fraction object.
void info() const
Prints summary information about the measure to the log.
int getFilledDurationTicks(const int staveId=0) const
Returns the filled duration (sum of note durations) in ticks for a staff.
void setDivisionsPerQuarterNote(const int divisionsPerQuarterNote)
Sets the divisions per quarter note for the measure.
const TimeSignature & getTimeSignature() const
Returns the TimeSignature object for the measure.
Key getKey() const
Returns the Key object for the measure.
Note & getNoteOff(const int noteOffId, const int staveId=0)
Returns a reference to a rest note (note off) by index and staff.
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.
void setIsMetronomeChanged(bool isMetronomeChanged=false)
Sets whether the metronome mark changes in this measure.
int getEmptyDurationTicks() const
Returns the empty (unfilled) duration in ticks for the measure.
int getNumNotesOn() const
Returns the number of sounding notes (note on) in the measure (all staves).
int getNumNotesOn(const int staveId) const
Returns the number of sounding notes (note on) in a specific staff.
void setKey(int fifthCircle, bool isMajorMode=true)
Sets the key signature for the measure.
int getNumber() const
Returns the measure number.
int getNumNotes() const
Returns the total number of notes in the measure (all staves).
void setNumber(const int measureNumber)
Sets the measure number.
const Clef & getClef(const int clefId=0) const
Returns the clef for a specific staff.
void setMetronome(const int bpm, const RhythmFigure duration=RhythmFigure::QUARTER)
Sets the metronome mark (BPM and rhythm figure) for the measure.
const Note & getNoteOff(const int noteOffId, const int staveId=0) const
Returns a const reference to a rest note (note off) by index and staff.
int getNumStaves() const
Returns the number of staves in the measure.
std::vector< Clef > & getClefs()
Returns the clefs for all staves in the measure (modifiable).
int getFifthCircle() const
Returns the number of accidentals in the circle of fifths for the key signature.
int getDivisionsPerQuarterNote() const
Returns the divisions per quarter note for the measure.
Note & getNoteOn(const int noteOnId, const int staveId=0)
Returns a reference to a sounding note (note on) by index and staff.
const std::vector< Clef > & getClefs() const
Returns the clefs for all staves in the measure.
const Barline & getBarlineRight() const
Returns the right barline object.
Note & getNote(const int noteId, const int staveId=0)
Returns a reference to a note in a specific staff and position.
void setIsTimeSignatureChanged(bool isTimeSignatureChanged=false)
Sets whether the time signature changes in this measure.
float getFilledQuarterDuration(const int staveId=0) const
Returns the filled duration (sum of note durations) in quarter notes for a staff.
Barline & getBarlineLeft()
Returns the left barline object (modifiable).
void removeNote(const int noteId, const int staveId=0)
Removes a note from a specific staff and position.
float getQuarterDuration() const
Returns the total duration of the measure in quarter notes.
~Measure()
Destructor.
int getNumNotes(const int staveId) const
Returns the number of notes in a specific staff.
float getFreeQuarterDuration(const int staveId=0) const
Returns the free (remaining) duration in quarter notes for a staff.
bool divisionsPerQuarterNoteChanged() const
Returns true if the divisions per quarter note changes in this measure.
std::string getKeyName() const
Returns the key name (e.g., "C major", "G minor").
std::pair< std::string, int > getMetronome() const
Returns the metronome mark as a pair (figure, value).
Represents a musical note, including pitch, duration, articulation, and MusicXML-related attributes.
Definition: note.h:19
Represents a musical time signature (meter) for a measure.
Definition: time-signature.h:20