Generate an accompaniement for a given melody
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Measure Class Reference

Describe a musical bar. More...

#include <Music.hpp>

Inheritance diagram for Measure:
ObsMeasure ObsPresenceStats

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...
 

Detailed Description

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

Constructor & Destructor Documentation

Measure::Measure ( bool  binary = true,
unsigned  duration = 4 
)

Constructor. Creates an empty Measure.

Parameters
binaryindicates whether the measure is binary
durationthe duration of the measure.
Exceptions
Duration is not 4if duration != 4 (we only deal with four beat measures atm)
Note
done without exception

Member Function Documentation

void Measure::addNote ( const Position p,
const Note n 
)

Adds note to measure.

Parameters
pthe position in the measure
nthe note to add Removed feature : if there is twice the same note right after the other, it combines both notes
Exceptions
std::runtime_error"already a note there"
std::domain_error"Position invalid"
Note
done
ConstIterator Measure::begin ( ) const

returns an iterator at the beginning of measure

Note
done
void Measure::changeDuration ( unsigned  d)

Resize the measure The resizing operation is not trivial, it changes the balance of the music.

Parameters
dthe number of beats inside the measure
Exceptions
std::domain_errorif the resizing is going to cause at least one note to be deleted
Note
ignore this function we only have 4 beat measures
ConstIterator Measure::end ( ) const

returns the end iterator of the measure

Note
done
unsigned Measure::getDuration ( ) const

Gets the duration of the measure.

Note
done
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)

Parameters
pThe position inside the bar (as a fraction of the bar).We must have 0<=p<=1. [CHANGE WARNING]
Returns
The note being played at position p.
Exceptions
std::domain_errorIf no note is played at position p (ie there is only silence)
std::domain_errorif !(0<=p<=1)
bool Measure::isBinary ( ) const

returns if the measure is binary

Note
done
bool Measure::operator!= ( const Measure o) const

Difference operator for Measure.

Note
done
bool Measure::operator== ( const Measure o) const

Comparison operator for Measure.

Note
done
void Measure::setBinary ( bool  b)

sets the binary type of the measure

Note
I do not see the use for this function
done

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