hydrogen 1.2.3
TransportPosition.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#ifndef TRANSPORT_POSITION_H
23#define TRANSPORT_POSITION_H
24
25#include <memory>
26
27#include <core/Object.h>
30
31namespace H2Core
32{
33
34class PatternList;
35
47class TransportPosition : public H2Core::Object<TransportPosition>
48{
50public:
51
52 TransportPosition( const QString sLabel = "" );
54
55 const QString getLabel() const;
56 long long getFrame() const;
65 long getTick() const;
66 float getTickSize() const;
67 float getBpm() const;
68 long getPatternStartTick() const;
69 long getPatternTickPosition() const;
70 int getColumn() const;
71 double getTickMismatch() const;
72 long long getFrameOffsetTempo() const;
73 double getTickOffsetQueuing() const;
74 double getTickOffsetSongSize() const;
75 const PatternList* getPlayingPatterns() const;
76 const PatternList* getNextPatterns() const;
77 int getPatternSize() const;
78 long long getLastLeadLagFactor() const;
79 int getBar() const;
80 int getBeat() const;
81
99 static double computeTickFromFrame( long long nFrame, int nSampleRate = 0 );
100
122 static long long computeFrameFromTick( double fTick, double* fTickMismatch, int nSampleRate = 0 );
123
132 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
133
134 friend class AudioEngine;
135 friend class AudioEngineTests;
136
137private:
143 void set( std::shared_ptr<TransportPosition> pOther );
144 void reset();
145
146 void setFrame( long long nNewFrame );
147 void setTick( double fNewTick );
148 void setTickSize( float fNewTickSize );
149 void setBpm( float fNewBpm );
150 void setPatternStartTick( long nPatternStartTick );
151 void setPatternTickPosition( long nPatternTickPosition );
152 void setColumn( int nColumn );
153 void setFrameOffsetTempo( long long nFrameOffset );
154 void setTickOffsetQueuing( double nTickOffset );
155 void setTickOffsetSongSize( double fTickOffset );
156 void setPlayingPatterns( PatternList* pPatternList );
157 void setNextPatterns( PatternList* pPatternList );
158 void setPatternSize( int nPatternSize );
159 void setLastLeadLagFactor( long long nValue );
160 void setBar( int nBar );
161 void setBeat( int nBeat );
162
165
175 static long long computeFrame( double fTick, float fTickSize );
185 static double computeTick( long long nFrame, float fTickSize );
186
187 double getDoubleTick() const;
188
192 const QString m_sLabel;
193
205 long long m_nFrame;
206
224 double m_fTick;
225
255 float m_fBpm;
256
284
294
330
348
360
374
382
393
406};
407
408inline const QString TransportPosition::getLabel() const {
409 return m_sLabel;
410}
411inline long long TransportPosition::getFrame() const {
412 return m_nFrame;
413}
414inline double TransportPosition::getDoubleTick() const {
415 return m_fTick;
416}
417inline long TransportPosition::getTick() const {
418 return static_cast<long>(std::floor( m_fTick ));
419}
420inline float TransportPosition::getTickSize() const {
421 return m_fTickSize;
422}
423inline float TransportPosition::getBpm() const {
424 return m_fBpm;
425}
427 return m_nPatternStartTick;
428}
433 return m_nColumn;
434}
436 return m_fTickMismatch;
437}
439 return m_nFrameOffsetTempo;
440}
441inline void TransportPosition::setFrameOffsetTempo( long long nFrameOffset ) {
442 m_nFrameOffsetTempo = nFrameOffset;
443}
446}
447inline void TransportPosition::setTickOffsetQueuing( double fTickOffset ) {
448 m_fTickOffsetQueuing = fTickOffset;
449}
453inline void TransportPosition::setTickOffsetSongSize( double fTickOffset ) {
454 m_fTickOffsetSongSize = fTickOffset;
455}
463 return m_pNextPatterns;
464}
469 return m_nPatternSize;
470}
473}
474inline void TransportPosition::setLastLeadLagFactor( long long nValue ) {
475 m_nLastLeadLagFactor = nValue;
476}
477inline int TransportPosition::getBar() const {
478 return m_nBar;
479}
480inline int TransportPosition::getBeat() const {
481 return m_nBeat;
482}
483};
484
485#endif
486
#define H2_OBJECT(name)
Definition Object.h:224
Defined in here since it requires access to methods and variables private to the #AudioEngine class.
The audio engine deals with two distinct #TransportPosition.
Definition AudioEngine.h:97
PatternList is a collection of patterns.
Definition PatternList.h:43
Object holding most of the information about the transport state of the AudioEngine.
double m_fTickOffsetQueuing
Tick offset introduced when changing the tempo of the song.
long long m_nFrameOffsetTempo
Frame offset introduced when changing the tempo of the song.
TransportPosition(const QString sLabel="")
void setPatternStartTick(long nPatternStartTick)
const PatternList * getNextPatterns() const
long m_nPatternTickPosition
Ticks passed since m_nPatternStartTick.
double m_fTickMismatch
Number of ticks m_nFrame is ahead/behind of m_fTick.
int m_nColumn
Specifies the column transport is located in and can be used as the index of the current PatternList/...
long m_nPatternStartTick
Dicstance in ticks between the beginning of the song and the beginning of the current column (m_nColu...
static double computeTick(long long nFrame, float fTickSize)
Converts frames into ticks under the assumption of a constant fTickSize (sample rate,...
static long long computeFrameFromTick(double fTick, double *fTickMismatch, int nSampleRate=0)
Calculates frame equivalent of fTick.
float m_fBpm
Current tempo in beats per minute.
int m_nBeat
Last bar passed since m_nBar.
void setTickOffsetSongSize(double fTickOffset)
long getTick() const
Retrieve a rounded version of m_fTick.
void setNextPatterns(PatternList *pPatternList)
void setTick(double fNewTick)
const QString getLabel() const
void setPatternTickPosition(long nPatternTickPosition)
void set(std::shared_ptr< TransportPosition > pOther)
Copying the content of one position into the other is a lot cheaper than performing computations,...
void setFrame(long long nNewFrame)
void setTickOffsetQueuing(double nTickOffset)
const PatternList * getPlayingPatterns() const
int m_nPatternSize
Maximum size of all patterns in m_pPlayingPatterns.
int m_nBar
Last beat (column + 1) passed.
PatternList * m_pPlayingPatterns
Contains all Patterns currently played back.
void setFrameOffsetTempo(long long nFrameOffset)
void setTickSize(float fNewTickSize)
static double computeTickFromFrame(long long nFrame, int nSampleRate=0)
Calculates tick equivalent of nFrame.
void setLastLeadLagFactor(long long nValue)
long long m_nFrame
Current transport position in number of frames since the beginning of the song.
double m_fTickOffsetSongSize
Tick offset introduced when changing the size of the song.
long long getLastLeadLagFactor() const
float m_fTickSize
Number of frames that make up one tick.
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
void setPlayingPatterns(PatternList *pPatternList)
double m_fTick
Current transport position in number of ticks since the beginning of the song.
void setPatternSize(int nPatternSize)
static long long computeFrame(double fTick, float fTickSize)
Converts ticks into frames under the assumption of a constant fTickSize (sample rate,...
PatternList * m_pNextPatterns
Patterns used to toggle the ones in m_pPlayingPatterns in Song::PatternMode::Stacked.
long long getFrameOffsetTempo() const
const QString m_sLabel
Identifier of the transport position.