Generate an accompaniement for a given melody
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Music.hpp File Reference

This file defines all the data structures related to music objects. More...

#include <map>
#include <vector>
#include <climits>
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <functional>
#include <boost/rational.hpp>

Go to the source code of this file.

Classes

struct  CompleteNoteName
 Fully describes a note (name + accidental) More...
 
struct  Pitch
 Describe a note with its absolute pitch. More...
 
struct  Note
 Describe a note as a musical event (pitch + duration) More...
 
class  Measure
 Describe a musical bar. More...
 
struct  Key
 Describe the key of a melody. More...
 
struct  Chord
 Describe a chord. More...
 
class  Melody
 Describes a melody. More...
 

Typedefs

using Octave = unsigned
 Octave 4 is A 440Hz.
 
using Fraction = boost::rational< int >
 Fraction class to easily manipulate fractions of beats, measures,...
 
using ChordProgression = std::vector< Chord >
 ChordProgression is the class used to give the set of chords used.
 

Enumerations

enum  NoteName {
  C, D, E, F,
  G, A, B
}
 Describe the name of the note. More...
 
enum  Accidental { Accidental::Flat, Accidental::Sharp, Accidental::None }
 Describe the accidental of the note. More...
 

Functions

std::ostream & operator<< (std::ostream &o, NoteName n)
 output operator for NoteName The format is capital letters for the NoteName More...
 
std::istream & operator>> (std::istream &i, NoteName &n)
 input operator for NoteName The format is capital or small letters for the NoteName More...
 
std::ostream & operator<< (std::ostream &o, Accidental a)
 output operator for Accidental The format is ^ for sharp, _ for flat and nothing for none More...
 
std::istream & operator>> (std::istream &i, Accidental &a)
 input operator for Accidental The format is ^ for sharp, _ for flat and nothing or = for none More...
 
std::ostream & operator<< (std::ostream &o, const CompleteNoteName &n)
 output operator for CompleteNoteName The format is as follow : the modifier (if any) followed by the NoteName More...
 
std::istream & operator>> (std::istream &i, CompleteNoteName &n)
 input operator for CompleteNoteName The format is as follow : the modifier (if any) followed by the NoteName More...
 
std::ostream & operator<< (std::ostream &o, const Pitch &n)
 output operator for Pitch The format is as follow : the CompleteNoteName followed by (Octave-4) ' or (4-Octave) , Without specification, a note is assumed to be in the forth octave. The string "A" thus refer to a A 440Hz. From this reference, one can add or subtract octave. The character "'" corresponds to the addition of one octave, and "," to the subtraction. For example, "_G,," represents a G flat in the second octave (4-2) and "B'''" represents a B in the seventh octave (4+3) More...
 
std::istream & operator>> (std::istream &i, Pitch &n)
 input operator for Pitch The format is as follow : the CompleteNoteName followed by (Octave-4) ' or (4-Octave) , Without specification, a note is assumed to be in the forth octave. The string "A" thus refer to a A 440Hz. From this reference, one can add or subtract octave. The character "'" corresponds to the addition of one octave, and "," to the subtraction. For example, "_G,," represents a G flat in the second octave (4-2) and "B'''" represents a G in the seventh octave (4+3) If the pitch is A,,,,,, which does not exist, the parsing stops at A,,,, as any standard operator >> behaves More...
 
std::ostream & operator<< (std::ostream &o, const Note &n)
 output operator for Note The format is as follow : the Pitch followed by num/denom where num/denom is the fraction of beat. If num or denum is 1, they do not appear. More...
 
std::istream & operator>> (std::istream &i, Note &n)
 input operator for Note The format is as follow : the Pitch followed by the fraction of beat. If the denominator is not given, it is supposed to be 2. The details of the possibilities are given in the ABC notations. The web page of the examples is http://abcnotation.com/examples#Note-lengths More...
 
std::ostream & operator<< (std::ostream &o, const Measure &m)
 output operator for Measure The format is as follows : The notes, separated by spaces. Silences are written zFractionofbeat More...
 
std::istream & operator>> (std::istream &i, Measure &m)
 input operator for Measure The format is as follows : The notes, separated by spaces (or not). Silences are written zFractionofbeat More...
 
std::ostream & operator<< (std::ostream &o, const Key &k)
 output operator for Key The format is as shown in ABC notation Link is : http://abcnotation.com/wiki/abc:standard:v2.1#kkey More...
 
Key readKey (const std::string &str)
 input parser for Key The format is as shown in ABC notation Link is : http://abcnotation.com/wiki/abc:standard:v2.1#kkey More...
 
std::ostream & operator<< (std::ostream &o, const Chord &c)
 output operator for Chord More...
 
Chord readChord (const std::string &s)
 parser for chord The format follows the guitar chord format More...
 
std::ostream & operator<< (std::ostream &o, const ChordProgression &c)
 output operator for ChordProgression The format is as follows : Chord1;Chord2;...LastChord; More...
 
ChordProgression readChordProgression (const std::string &str)
 parser for ChordProgression The format is as follows : Chord1;Chord2;...LastChord; More...
 
ChordProgression moveCP (const ChordProgression &cp, int i, const Key &k)
 change the base notes of a chord progression More...
 
std::ostream & operator<< (std::ostream &o, const Melody &m)
 output operator for Melody The format is as follows : M : 4/4 if binary, M : 12/8 if not K : Key L : 1/4 Measure1 | Measure2 | ... More...
 
Melody readMelody (const std::string &str)
 parser for Melody The format is the ABC format. We ignore |, :, >, ... when reading something that is not a header More...
 

Detailed Description

This file defines all the data structures related to music objects.

Date
Mon Oct 6 00:26:17 2014

Enumeration Type Documentation

enum Accidental
strong

Describe the accidental of the note.

The accidental changes the tone of the note by up to half a tone (called a semitone).

Enumerator
Flat 

Means that we add a semitone.

Sharp 

Means that we subtract a semitone.

None 

Means that we use the natural note (no accidental)

enum NoteName
strong

Describe the name of the note.

The name is given in the english notation, where C == Do

Function Documentation

ChordProgression moveCP ( const ChordProgression cp,
int  i,
const Key k 
)

change the base notes of a chord progression

Parameters
iis the number of half tones to add
cpis the chordprogression to change
kis the key in which we transpose the chord progression
Returns
the transposed ChordProgression
std::ostream& operator<< ( std::ostream &  o,
NoteName  n 
)

output operator for NoteName The format is capital letters for the NoteName

Parameters
othe stream to write in
nthe NoteName to write
Returns
o
std::ostream& operator<< ( std::ostream &  o,
Accidental  a 
)

output operator for Accidental The format is ^ for sharp, _ for flat and nothing for none

Parameters
othe stream to write in
athe Accidental to write
Returns
o
std::ostream& operator<< ( std::ostream &  o,
const CompleteNoteName n 
)

output operator for CompleteNoteName The format is as follow : the modifier (if any) followed by the NoteName

Parameters
othe stream to write in
nthe CompleteNoteName to write
Returns
o
std::ostream& operator<< ( std::ostream &  o,
const Pitch n 
)

output operator for Pitch The format is as follow : the CompleteNoteName followed by (Octave-4) ' or (4-Octave) , Without specification, a note is assumed to be in the forth octave. The string "A" thus refer to a A 440Hz. From this reference, one can add or subtract octave. The character "'" corresponds to the addition of one octave, and "," to the subtraction. For example, "_G,," represents a G flat in the second octave (4-2) and "B'''" represents a B in the seventh octave (4+3)

Parameters
othe stream to write in
nthe Pitch to write
Returns
o
std::ostream& operator<< ( std::ostream &  o,
const Note n 
)

output operator for Note The format is as follow : the Pitch followed by num/denom where num/denom is the fraction of beat. If num or denum is 1, they do not appear.

Parameters
othe stream to write in
nthe Note to write
Returns
o
Note
done
std::ostream& operator<< ( std::ostream &  o,
const Measure m 
)

output operator for Measure The format is as follows : The notes, separated by spaces. Silences are written zFractionofbeat

Parameters
othe stream to write in
mthe Measure to write
Returns
o
Note
done
std::ostream& operator<< ( std::ostream &  o,
const Key k 
)

output operator for Key The format is as shown in ABC notation Link is : http://abcnotation.com/wiki/abc:standard:v2.1#kkey

Parameters
othe stream to write in
kthe Key to write
Returns
o
std::ostream& operator<< ( std::ostream &  o,
const Chord c 
)

output operator for Chord

Parameters
othe stream to write in
cthe Chord to write The format follows the guitar chord format
Returns
o
std::ostream& operator<< ( std::ostream &  o,
const ChordProgression c 
)

output operator for ChordProgression The format is as follows : Chord1;Chord2;...LastChord;

Parameters
othe stream to write in
cthe ChordProgression to write
Returns
o
std::ostream& operator<< ( std::ostream &  o,
const Melody m 
)

output operator for Melody The format is as follows : M : 4/4 if binary, M : 12/8 if not K : Key L : 1/4 Measure1 | Measure2 | ...

Parameters
othe stream to write in
mthe Melody to write
Returns
o
std::istream& operator>> ( std::istream &  i,
NoteName n 
)

input operator for NoteName The format is capital or small letters for the NoteName

Parameters
ithe stream to read from
nthe NoteName to write in
Exceptions
std::domain_errorif not a NoteName
Returns
i
std::istream& operator>> ( std::istream &  i,
Accidental a 
)

input operator for Accidental The format is ^ for sharp, _ for flat and nothing or = for none

Parameters
ithe stream to read from
athe Accidental to write in
Returns
i
std::istream& operator>> ( std::istream &  i,
CompleteNoteName n 
)

input operator for CompleteNoteName The format is as follow : the modifier (if any) followed by the NoteName

Parameters
ithe stream to read from
nthe CompleteNoteName to write in
Returns
i
std::istream& operator>> ( std::istream &  i,
Pitch n 
)

input operator for Pitch The format is as follow : the CompleteNoteName followed by (Octave-4) ' or (4-Octave) , Without specification, a note is assumed to be in the forth octave. The string "A" thus refer to a A 440Hz. From this reference, one can add or subtract octave. The character "'" corresponds to the addition of one octave, and "," to the subtraction. For example, "_G,," represents a G flat in the second octave (4-2) and "B'''" represents a G in the seventh octave (4+3) If the pitch is A,,,,,, which does not exist, the parsing stops at A,,,, as any standard operator >> behaves

Parameters
ithe stream to read from
nthe Pitch to write in
Returns
i
std::istream& operator>> ( std::istream &  i,
Note n 
)

input operator for Note The format is as follow : the Pitch followed by the fraction of beat. If the denominator is not given, it is supposed to be 2. The details of the possibilities are given in the ABC notations. The web page of the examples is http://abcnotation.com/examples#Note-lengths

Parameters
ithe stream to read from
nthe Note to write in
Returns
i
Note
done
std::istream& operator>> ( std::istream &  i,
Measure m 
)

input operator for Measure The format is as follows : The notes, separated by spaces (or not). Silences are written zFractionofbeat

Parameters
iis the stream to read from
mthe Measure to write in
Returns
i
Note
done
Chord readChord ( const std::string &  s)

parser for chord The format follows the guitar chord format

Parameters
sthe string to parse
Returns
the chord read
Exceptions
std::runtime_error
ChordProgression readChordProgression ( const std::string &  str)

parser for ChordProgression The format is as follows : Chord1;Chord2;...LastChord;

Parameters
strthe string to read from
Returns
the ChordProgression
Exceptions
std::runtime_error
Key readKey ( const std::string &  str)

input parser for Key The format is as shown in ABC notation Link is : http://abcnotation.com/wiki/abc:standard:v2.1#kkey

Parameters
strthe string to read from
Returns
the Key to write in
Exceptions
std::runtime_error
Note
Replaces operator >> for key
Melody readMelody ( const std::string &  str)

parser for Melody The format is the ABC format. We ignore |, :, >, ... when reading something that is not a header

Parameters
strthe string to read from
Returns
the melody read