4 #include "configobject.hh"
33 Rest, C, Cis, D, Dis, E, F, Fis, G, Gis, A, Ais, B
37 Whole, Half, Quarter, Eighth, Sixteenth
59 QPair<double, unsigned int>
toTone(
unsigned int bpm)
const;
64 unsigned int infer(
double frequency,
unsigned int ms,
unsigned int bpm);
77 Melody(
unsigned int bpm=100, QObject *parent =
nullptr);
99 unsigned int bpm()
const;
114 QVector<QPair<double, unsigned int>>
toTones()
const;
116 bool infer(
const QVector<QPair<double, unsigned int>> &tones);
121 const QVector<QPair<double, unsigned int>> &tones,
unsigned int bpm);
Base class for all configuration objects (channels, zones, contacts, etc).
Definition: configobject.hh:40
A config item that encodes a melody.
Definition: melody.hh:20
QVector< Note > _melody
The actual melody.
Definition: melody.hh:127
bool copy(const ConfigItem &other)
Copies the given item into this one.
Definition: melody.cc:27
QString toLilypond() const
Serializes the melody into Lilypond notation.
Definition: melody.cc:101
iterator end()
Returns an iterator pointing right after the last note.
Definition: melody.cc:44
void setBPM(unsigned int bpm)
Sets the BPM of the melody.
Definition: melody.cc:77
Melody(unsigned int bpm=100, QObject *parent=nullptr)
Empty constructor.
Definition: melody.cc:10
QVector< QPair< double, unsigned int > > toTones() const
Converts the melody to a series of tones in terms of frequency and duration in ms.
Definition: melody.cc:112
static unsigned int quantizationTimingError(const QVector< QPair< double, unsigned int >> &tones, unsigned int bpm)
Computes the absolute quantization timing error over the given melody for the given BPM.
Definition: melody.cc:144
iterator begin()
Returns an iterator pointing at the first note.
Definition: melody.cc:40
bool fromLilypond(const QString &melody)
Parses the Lilypond notation of the melody.
Definition: melody.cc:85
const Note & operator[](size_t index) const
Element access.
Definition: melody.cc:63
bool infer(const QVector< QPair< double, unsigned int >> &tones)
Infer melody from a vector of frequeny-duration pairs.
Definition: melody.cc:121
unsigned int bpm
The BPM of the melody.
Definition: melody.hh:24
QVector< Note >::const_iterator const_iterator
Const iterator over notes.
Definition: melody.hh:73
QString melody
The melody in LilyPond notation.
Definition: melody.hh:26
unsigned int _bpm
Holds the beats per minute.
Definition: melody.hh:125
QVector< Note >::iterator iterator
Iterator over notes.
Definition: melody.hh:71
size_t count() const
Returns the number of notes (and rests) of this melody.
Definition: melody.cc:58
ConfigItem * clone() const
Clones this item.
Definition: melody.cc:17
Encodes a note, that is tone and duration.
Definition: melody.hh:30
Duration
Note durations as fractions of a bar.
Definition: melody.hh:36
QPair< double, unsigned int > toTone(unsigned int bpm) const
Converts the note to a frequency in Hz and duration in seconds.
Definition: melody.cc:261
QString toLilypond(Duration currentDuration) const
Serializes the note in Lilypond notation.
Definition: melody.cc:221
Duration duration
The note duration.
Definition: melody.hh:43
static unsigned int quantizationTimingError(unsigned int ms, unsigned int bpm)
Computes the quantization timing error for the given duration and BPM.
Definition: melody.cc:356
int octave
The octave of the note, 0 means middle.
Definition: melody.hh:47
bool dotted
If true, the note/rest is dottet.
Definition: melody.hh:45
Note()
Default constructor.
Definition: melody.cc:158
bool fromLilypond(const QString ¬e, Duration currentDuration)
Reads a note in Lilypond notation.
Definition: melody.cc:165
Tone
Possible tone values.
Definition: melody.hh:32
unsigned int infer(double frequency, unsigned int ms, unsigned int bpm)
Infers the note from the given frequency and duration in ms.
Definition: melody.cc:302
Tone tone
The note tone.
Definition: melody.hh:41