Generate an accompaniement for a given melody
|
Describe a musical bar. More...
#include <Music.hpp>
Public Types | |
using | Position = Fraction |
The Position type is a Fraction of Measure. | |
using | ConstIterator = std::map< Position, Note >::const_iterator |
Allows to iterate on the notes of the measure. | |
Public Member Functions | |
Measure (bool binary=true, unsigned duration=4) | |
Constructor. Creates an empty Measure. More... | |
ConstIterator | begin () const __attribute__((pure)) |
returns an iterator at the beginning of measure More... | |
ConstIterator | end () const __attribute__((pure)) |
returns the end iterator of the measure More... | |
unsigned | getDuration () const __attribute__((pure)) |
Gets the duration of the measure. More... | |
void | changeDuration (unsigned d) |
Resize the measure The resizing operation is not trivial, it changes the balance of the music. More... | |
bool | isBinary () const __attribute__((pure)) |
returns if the measure is binary More... | |
void | setBinary (bool b) |
sets the binary type of the measure More... | |
ConstIterator | getNoteBeingPlayedAt (const Position &p) const __attribute__((pure)) |
Get the note played at a given position of the bar. More... | |
void | addNote (const Position &p, const Note &n) |
Adds note to measure. More... | |
bool | operator== (const Measure &o) const __attribute__((pure)) |
Comparison operator for Measure. More... | |
bool | operator!= (const Measure &o) const __attribute__((pure)) |
Difference operator for Measure. More... | |
Describe a musical bar.
This class can only describe monophonic melodies (at each timestep, there must be at most one note playing). We will assume there is 4 beats per measure
Measure::Measure | ( | bool | binary = true , |
unsigned | duration = 4 |
||
) |
Constructor. Creates an empty Measure.
binary | indicates whether the measure is binary |
duration | the duration of the measure. |
Duration is not 4 | if duration != 4 (we only deal with four beat measures atm) |
Adds note to measure.
p | the position in the measure |
n | the note to add Removed feature : if there is twice the same note right after the other, it combines both notes |
std::runtime_error | "already a note there" |
std::domain_error | "Position invalid" |
ConstIterator Measure::begin | ( | ) | const |
returns an iterator at the beginning of measure
void Measure::changeDuration | ( | unsigned | d | ) |
Resize the measure The resizing operation is not trivial, it changes the balance of the music.
d | the number of beats inside the measure |
std::domain_error | if the resizing is going to cause at least one note to be deleted |
ConstIterator Measure::end | ( | ) | const |
returns the end iterator of the measure
unsigned Measure::getDuration | ( | ) | const |
Gets the duration of the measure.
ConstIterator Measure::getNoteBeingPlayedAt | ( | const Position & | p | ) | const |
Get the note played at a given position of the bar.
By assumption, as we only describe monophonic melodies, this note is unique. Also note that the position is not necessarily the beginning of a note (notes are not ponctual events, thus a note is played for a strictly positive amount of time)
p | The position inside the bar (as a fraction of the bar).We must have 0<=p<=1. [CHANGE WARNING] |
std::domain_error | If no note is played at position p (ie there is only silence) |
std::domain_error | if !(0<=p<=1) |
bool Measure::isBinary | ( | ) | const |
returns if the measure is binary
void Measure::setBinary | ( | bool | b | ) |
sets the binary type of the measure