hydrogen 1.2.3
Timeline Class Reference

Timeline class storing and handling all TempoMarkers and Tags. More...

#include <Timeline.h>

Inheritance diagram for Timeline:
Object< Timeline > Base

Data Structures

struct  Tag
 Tag specifies a note added to a certain position in the Song. More...
 
struct  TagComparator
 
struct  TempoMarker
 TempoMarker specifies a change in speed during the Song. More...
 
struct  TempoMarkerComparator
 

Public Member Functions

 Timeline ()
 
 ~Timeline ()
 
void activate ()
 Registers the current playback tempo to m_fDefaultBpm.
 
void addTag (int nColumn, QString sTag)
 Adds a Tag to the Timeline.
 
void addTempoMarker (int nColumn, float fBpm)
 Adds a TempoMarker to the Timeline.
 
void deactivate ()
 Convencience function in order to create a symmetric pair with activate.
 
void deleteAllTags ()
 
void deleteAllTempoMarkers ()
 Deletes all TempoMarkers set by the user.
 
void deleteTag (int nColumn)
 
void deleteTempoMarker (int nColumn)
 Delete all tempo markers except for the first one and mark the tempo of the Timeline m_bUnset.
 
const std::vector< std::shared_ptr< const Tag > > getAllTags () const
 
const std::vector< std::shared_ptr< const TempoMarker > > getAllTempoMarkers () const
 
const QString getTagAtColumn (int nColumn) const
 Returns the tag of the Song at a given column.
 
float getTempoAtColumn (int nColumn) const
 Returns the tempo of the Song at a given column.
 
std::shared_ptr< const Timeline::TempoMarkergetTempoMarkerAtColumn (int nColumn) const
 
bool hasColumnTag (int nColumn) const
 
bool hasColumnTempoMarker (int nColumn) const
 
bool isFirstTempoMarkerSpecial () const
 Whether there is a TempoMarker introduced by the user at the first column.
 
QString toQString (const QString &sPrefix="", bool bShort=true) const override
 Formatted string version for debugging purposes.
 
- Public Member Functions inherited from Object< Timeline >
 Object ()
 
 Object (const Object< Timeline > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 

Private Member Functions

void sortTags ()
 
void sortTempoMarkers ()
 

Private Attributes

float m_fDefaultBpm
 Tempo used for the special tempo marker.
 
std::vector< std::shared_ptr< const Tag > > m_tags
 
std::vector< std::shared_ptr< const TempoMarker > > m_tempoMarkers
 

Additional Inherited Members

- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 
- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from Object< Timeline >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 

Detailed Description

Timeline class storing and handling all TempoMarkers and Tags.

The design of the Timeline is a little bit involved and needs a couple of words to explain it. As soon as the Timeline is activated, it is required to yield a tempo for each column which solely depends on the TempoMarkers set by the user. Since a TempoMarker determines the tempo for all columns equal or bigger its own, there always needs a be one present at the very beginning of the Song.

For a more convenient UX the user shouldn't bother about the first one too much as a TempoMarker is usually put after the first column to indicate a change in tempo. Therefore, when a TempoMarker is added to an empty Timeline (to any location but the first column), the Timeline pretends to have a tempo marker in the beginning holding the current Song::m_fBpm (the tempo set via the BPM widget). This special first marker can only be "removed" by the user by adding a TempoMarker to the first column. In addition, it's tempo gets updated when toggling the Timeline. This, it does not immediately respond to changes of the song tempo (using the BPM widget or MIDI/OSC commands). The special tempo marker is prepended in the getAllTempoMarkers() functions.

The calling function will not notice any difference between the provided TempoMarkers and has to use isFirstTempoMarkerSpecial() instead.

All methods altering the TempoMarker and Tag are members of this class and the former are added as const structs to m_tempoMarkers or m_tags. To alter one of them, one has to delete it and add a new, altered version.

Definition at line 67 of file Timeline.h.

Constructor & Destructor Documentation

◆ Timeline()

Timeline ( )

Definition at line 32 of file Timeline.cpp.

◆ ~Timeline()

~Timeline ( )

Definition at line 36 of file Timeline.cpp.

Member Function Documentation

◆ activate()

void activate ( )

Registers the current playback tempo to m_fDefaultBpm.

Definition at line 41 of file Timeline.cpp.

◆ addTag()

void addTag ( int nColumn,
QString sTag )

Adds a Tag to the Timeline.

Fails if there is already a #Tag present at nColumn.

Parameters
nColumnPosition of the Timeline to query for a tag.
sTagNew tag in beats per minute.

Definition at line 176 of file Timeline.cpp.

◆ addTempoMarker()

void addTempoMarker ( int nColumn,
float fBpm )

Adds a TempoMarker to the Timeline.

Fails if there is already a #TempoMarker present at nColumn.

Parameters
nColumnPosition of the Timeline to query for a tempo marker.
fBpmNew tempo in beats per minute. All values below 30 and above 500 will be cut.

Definition at line 48 of file Timeline.cpp.

◆ deactivate()

void deactivate ( )

Convencience function in order to create a symmetric pair with activate.

Definition at line 45 of file Timeline.cpp.

◆ deleteAllTags()

void deleteAllTags ( )
inline

Definition at line 237 of file Timeline.h.

◆ deleteAllTempoMarkers()

void deleteAllTempoMarkers ( )
inline

Deletes all TempoMarkers set by the user.

But not the special one.

Definition at line 234 of file Timeline.h.

◆ deleteTag()

void deleteTag ( int nColumn)
Parameters
nColumnPosition of the Timeline to delete the tag at (if one is present).

Definition at line 192 of file Timeline.cpp.

◆ deleteTempoMarker()

void deleteTempoMarker ( int nColumn)

Delete all tempo markers except for the first one and mark the tempo of the Timeline m_bUnset.

Parameters
nColumnPosition of the Timeline to delete the tempo marker at (if one is present).

Definition at line 73 of file Timeline.cpp.

◆ getAllTags()

const std::vector< std::shared_ptr< const Timeline::Tag > > getAllTags ( ) const
inline
Returns
std::vector<std::shared_ptr<const Tag>> Provides read-only access to m_tags.

Definition at line 240 of file Timeline.h.

◆ getAllTempoMarkers()

const std::vector< std::shared_ptr< const Timeline::TempoMarker > > getAllTempoMarkers ( ) const
Returns
std::vector<std::shared_ptr<const TempoMarker>> Provides read-only access to m_tempoMarker.

Definition at line 146 of file Timeline.cpp.

◆ getTagAtColumn()

const QString getTagAtColumn ( int nColumn) const

Returns the tag of the Song at a given column.

Parameters
nColumnPosition of the Timeline to query for a tag.

The function returns "" if the column is positioned before the first tag or none is present at all.

Definition at line 206 of file Timeline.cpp.

◆ getTempoAtColumn()

float getTempoAtColumn ( int nColumn) const

Returns the tempo of the Song at a given column.

There does not have to be a TempoMarker present at nColumn as the function takes all preceding ones into account as well.

Parameters
nColumnPosition of the Timeline to query for a tempo marker.

Definition at line 86 of file Timeline.cpp.

◆ getTempoMarkerAtColumn()

std::shared_ptr< const Timeline::TempoMarker > getTempoMarkerAtColumn ( int nColumn) const

Definition at line 129 of file Timeline.cpp.

◆ hasColumnTag()

bool hasColumnTag ( int nColumn) const

Definition at line 220 of file Timeline.cpp.

◆ hasColumnTempoMarker()

bool hasColumnTempoMarker ( int nColumn) const

Definition at line 120 of file Timeline.cpp.

◆ isFirstTempoMarkerSpecial()

bool isFirstTempoMarkerSpecial ( ) const

Whether there is a TempoMarker introduced by the user at the first column.

If not, the Timeline pretends that there is one by returning the current Song's tempo. The latter is referred to by "special tempo marker".

Definition at line 112 of file Timeline.cpp.

◆ sortTags()

void sortTags ( )
private

Definition at line 229 of file Timeline.cpp.

◆ sortTempoMarkers()

void sortTempoMarkers ( )
private

Definition at line 171 of file Timeline.cpp.

◆ toQString()

QString toQString ( const QString & sPrefix = "",
bool bShort = true ) const
overridevirtual

Formatted string version for debugging purposes.

Parameters
sPrefixString prefix which will be added in front of every new line
bShortInstead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks.
Returns
String presentation of current object.

Reimplemented from Base.

Definition at line 235 of file Timeline.cpp.

Field Documentation

◆ m_fDefaultBpm

float m_fDefaultBpm
private

Tempo used for the special tempo marker.

It's the task of the calling function to ensure this is set to the last Song::m_fBpm when activating the Timeline.

Definition at line 216 of file Timeline.h.

◆ m_tags

std::vector<std::shared_ptr<const Tag> > m_tags
private

Definition at line 208 of file Timeline.h.

◆ m_tempoMarkers

std::vector<std::shared_ptr<const TempoMarker> > m_tempoMarkers
private

Definition at line 207 of file Timeline.h.