hydrogen 1.2.3
Timeline.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef TIMELINE_H
24#define TIMELINE_H
25
26#include <memory>
27
28#include <core/Object.h>
29
30namespace H2Core
31{
32
67class Timeline : public H2Core::Object<Timeline>
68{
70
71public:
72 Timeline();
73 ~Timeline();
74
80 {
81 int nColumn; // beat position in timeline
82 float fBpm; // tempo in beats per minute
83
91 QString getPrettyString( int nDecimals = 2 ) const;
92 QString toQString( const QString& sPrefix = "", bool bShort = true ) const;
93 };
94
99 struct Tag
100 {
101 int nColumn; // beat position in timeline
102 QString sTag; // tag
103
104 QString toQString( const QString& sPrefix = "", bool bShort = true ) const;
105 };
106
110 void activate();
114 void deactivate();
115
125 void addTempoMarker( int nColumn, float fBpm );
132 void deleteTempoMarker( int nColumn );
145 float getTempoAtColumn( int nColumn ) const;
146
147 bool hasColumnTempoMarker( int nColumn ) const;
148 std::shared_ptr<const Timeline::TempoMarker> getTempoMarkerAtColumn( int nColumn ) const;
153 const std::vector<std::shared_ptr<const TempoMarker>> getAllTempoMarkers() const;
154
159 bool isFirstTempoMarkerSpecial() const;
160
169 void addTag( int nColumn, QString sTag );
174 void deleteTag( int nColumn );
175 void deleteAllTags();
186 const QString getTagAtColumn( int nColumn ) const;
191 const std::vector<std::shared_ptr<const Tag>> getAllTags() const;
192 bool hasColumnTag( int nColumn ) const;
193
202 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
203private:
204 void sortTempoMarkers();
205 void sortTags();
206
207 std::vector<std::shared_ptr<const TempoMarker>> m_tempoMarkers;
208 std::vector<std::shared_ptr<const Tag>> m_tags;
209
217
219 {
220 bool operator()( const std::shared_ptr<const TempoMarker> lhs, const std::shared_ptr<const TempoMarker> rhs)
221 {
222 return lhs->nColumn < rhs->nColumn;
223 }
224 };
226 {
227 bool operator()( const std::shared_ptr<const Tag> lhs, const std::shared_ptr<const Tag> rhs)
228 {
229 return lhs->nColumn < rhs->nColumn;
230 }
231 };
232};
233
235 m_tempoMarkers.clear();
236}
238 m_tags.clear();
239}
240inline const std::vector<std::shared_ptr<const Timeline::Tag>> Timeline::getAllTags() const {
241 return m_tags;
242}
243};
244#endif // TIMELINE_H
#define H2_OBJECT(name)
Definition Object.h:224
Timeline class storing and handling all TempoMarkers and Tags.
Definition Timeline.h:68
void deleteTag(int nColumn)
Definition Timeline.cpp:192
void deleteAllTags()
Definition Timeline.h:237
void deleteTempoMarker(int nColumn)
Delete all tempo markers except for the first one and mark the tempo of the Timeline m_bUnset.
Definition Timeline.cpp:73
void sortTempoMarkers()
Definition Timeline.cpp:171
bool hasColumnTempoMarker(int nColumn) const
Definition Timeline.cpp:120
bool isFirstTempoMarkerSpecial() const
Whether there is a TempoMarker introduced by the user at the first column.
Definition Timeline.cpp:112
float getTempoAtColumn(int nColumn) const
Returns the tempo of the Song at a given column.
Definition Timeline.cpp:86
bool hasColumnTag(int nColumn) const
Definition Timeline.cpp:220
void addTag(int nColumn, QString sTag)
Adds a Tag to the Timeline.
Definition Timeline.cpp:176
std::shared_ptr< const Timeline::TempoMarker > getTempoMarkerAtColumn(int nColumn) const
Definition Timeline.cpp:129
void activate()
Registers the current playback tempo to m_fDefaultBpm.
Definition Timeline.cpp:41
void deactivate()
Convencience function in order to create a symmetric pair with activate.
Definition Timeline.cpp:45
std::vector< std::shared_ptr< const TempoMarker > > m_tempoMarkers
Definition Timeline.h:207
std::vector< std::shared_ptr< const Tag > > m_tags
Definition Timeline.h:208
const std::vector< std::shared_ptr< const TempoMarker > > getAllTempoMarkers() const
Definition Timeline.cpp:146
const QString getTagAtColumn(int nColumn) const
Returns the tag of the Song at a given column.
Definition Timeline.cpp:206
void addTempoMarker(int nColumn, float fBpm)
Adds a TempoMarker to the Timeline.
Definition Timeline.cpp:48
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
Definition Timeline.cpp:235
void deleteAllTempoMarkers()
Deletes all TempoMarkers set by the user.
Definition Timeline.h:234
const std::vector< std::shared_ptr< const Tag > > getAllTags() const
Definition Timeline.h:240
float m_fDefaultBpm
Tempo used for the special tempo marker.
Definition Timeline.h:216
bool operator()(const std::shared_ptr< const Tag > lhs, const std::shared_ptr< const Tag > rhs)
Definition Timeline.h:227
Tag specifies a note added to a certain position in the Song.
Definition Timeline.h:100
QString toQString(const QString &sPrefix="", bool bShort=true) const
Definition Timeline.cpp:304
bool operator()(const std::shared_ptr< const TempoMarker > lhs, const std::shared_ptr< const TempoMarker > rhs)
Definition Timeline.h:220
TempoMarker specifies a change in speed during the Song.
Definition Timeline.h:80
QString toQString(const QString &sPrefix="", bool bShort=true) const
Definition Timeline.cpp:287
QString getPrettyString(int nDecimals=2) const
Definition Timeline.cpp:275