libdrmconf  0.11.3
A library to program DMR radios.
Classes | Public Types | Public Member Functions | Static Protected Member Functions | Protected Attributes | Properties | List of all members
Melody Class Reference

A config item that encodes a melody. More...

#include <melody.hh>

Inheritance diagram for Melody:
Inheritance graph
[legend]
Collaboration diagram for Melody:
Collaboration graph
[legend]

Classes

struct  Note
 Encodes a note, that is tone and duration. More...
 

Public Types

typedef QVector< Note >::iterator iterator
 Iterator over notes.
 
typedef QVector< Note >::const_iterator const_iterator
 Const iterator over notes.
 

Public Member Functions

 Melody (unsigned int bpm=100, QObject *parent=nullptr)
 Empty constructor.
 
ConfigItemclone () const
 Clones this item.
 
bool copy (const ConfigItem &other)
 Copies the given item into this one. More...
 
iterator begin ()
 Returns an iterator pointing at the first note.
 
iterator end ()
 Returns an iterator pointing right after the last note.
 
const_iterator begin () const
 Returns a const-iterator pointing at the first note.
 
const_iterator end () const
 Returns a const-iterator pointing right after the last note.
 
size_t count () const
 Returns the number of notes (and rests) of this melody.
 
const Noteoperator[] (size_t index) const
 Element access.
 
Noteoperator[] (size_t index)
 Element access.
 
unsigned int bpm () const
 Returns the BPM of the melody.
 
void setBPM (unsigned int bpm)
 Sets the BPM of the melody.
 
bool fromLilypond (const QString &melody)
 Parses the Lilypond notation of the melody. More...
 
QString toLilypond () const
 Serializes the melody into Lilypond notation.
 
QVector< QPair< double, unsigned int > > toTones () const
 Converts the melody to a series of tones in terms of frequency and duration in ms.
 
bool infer (const QVector< QPair< double, unsigned int >> &tones)
 Infer melody from a vector of frequeny-duration pairs.
 
- Public Member Functions inherited from ConfigItem
virtual int compare (const ConfigItem &other) const
 Compares the items. More...
 
virtual bool label (Context &context, const ErrorStack &err=ErrorStack())
 Recursively labels the config object. More...
 
virtual YAML::Node serialize (const Context &context, const ErrorStack &err=ErrorStack())
 Recursively serializes the configuration to YAML nodes. More...
 
virtual ConfigItemallocateChild (QMetaProperty &prop, const YAML::Node &node, const Context &ctx, const ErrorStack &err=ErrorStack())
 Allocates an instance for the given property on the given YAML node. More...
 
virtual bool parse (const YAML::Node &node, Context &ctx, const ErrorStack &err=ErrorStack())
 Parses the given YAML node, updates the given object and updates the given context (IDs). More...
 
virtual bool link (const YAML::Node &node, const Context &ctx, const ErrorStack &err=ErrorStack())
 Links the given object to the rest of the codeplug using the given context.
 
virtual void clear ()
 Clears the config object.
 
virtual const Configconfig () const
 Returns the config, the item belongs to or nullptr if not part of a config.
 
virtual void findItemsOfTypes (const QStringList &typeNames, QSet< ConfigItem * > &items) const
 Searches the config tree to find all instances of the given type names.
 
template<class Object >
bool is () const
 Returns true if this object is of class Object.
 
template<class Object >
const Object * as () const
 Casts this object to the given type.
 
template<class Object >
Object * as ()
 Casts this object to the given type.
 
bool hasDescription () const
 Returns true if there is a class info "description" for this instance.
 
bool hasLongDescription () const
 Returns true if there is a class info "longDescription" for this instance.
 
bool hasDescription (const QMetaProperty &prop) const
 Returns true if there is a class info "[PropertyName]Description" for the given property.
 
bool hasLongDescription (const QMetaProperty &prop) const
 Returns true if there is a class info "[PropertyName]LongDescription" for the given property.
 
QString description () const
 Returns the description of this instance if set by a class info.
 
QString longDescription () const
 Returns the long description of this instance if set by a class info.
 
QString description (const QMetaProperty &prop) const
 Returns the description of property if set by a class info.
 
QString longDescription (const QMetaProperty &prop) const
 Returns the long description of property if set by a class info.
 

Static Protected Member Functions

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.
 

Protected Attributes

unsigned int _bpm
 Holds the beats per minute.
 
QVector< Note_melody
 The actual melody.
 

Properties

unsigned int bpm
 The BPM of the melody.
 
QString melody
 The melody in LilyPond notation.
 

Additional Inherited Members

- Signals inherited from ConfigItem
void modified (ConfigItem *obj)
 Gets emitted once the config object is modified. More...
 
void beginClear ()
 Gets emitted before clearing the item.
 
void endClear ()
 Gets emitted after clearing the item.
 
- Protected Member Functions inherited from ConfigItem
 ConfigItem (QObject *parent=nullptr)
 Hidden constructor. More...
 
virtual bool populate (YAML::Node &node, const Context &context, const ErrorStack &err=ErrorStack())
 Recursively serializes the configuration to YAML nodes. More...
 

Detailed Description

A config item that encodes a melody.

This can be used to configure several melodies like ring tones and boot-up melodies. Have fun with it. In contrast to the common manufacturer CPSs, qdmr uses a proper musical notation for that.

This however, comes with some difficulties. While the translation from musical notation to tone frequencies and durations is easy, the reverse direction is not. The note duration is the most difficult. In musical notation, durations are expressed in terms of fractions of a bar, implicitly defined by the beat frequency. This additional information must be inferred. To achieve this, this class searches for the BPM, that minimizes the quantization error in the duration while keeping the BPM as close as possible to 100 BPM. Yes, this is utterly over-engineered.

Member Function Documentation

◆ copy()

bool Melody::copy ( const ConfigItem other)
virtual

Copies the given item into this one.

Returns
true if copying was successful and false otherwise. The two items must be of the same type (obviously).

Reimplemented from ConfigItem.

◆ fromLilypond()

bool Melody::fromLilypond ( const QString &  melody)

Parses the Lilypond notation of the melody.

For example,

a8 b e2 des4 d

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