hydrogen 1.2.6
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-2025 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>
31
32namespace H2Core
33{
34
35class PatternList;
36
48class TransportPosition : public H2Core::Object<TransportPosition>
49{
51public:
52
53 TransportPosition( const QString sLabel = "" );
54 TransportPosition( std::shared_ptr<TransportPosition> pOther );
56
57 const QString getLabel() const;
58 long long getFrame() const;
67 long getTick() const;
68 float getTickSize() const;
69 float getBpm() const;
70 long getPatternStartTick() const;
71 long getPatternTickPosition() const;
72 int getColumn() const;
73 double getTickMismatch() const;
74 long long getFrameOffsetTempo() const;
75 double getTickOffsetQueuing() const;
76 double getTickOffsetSongSize() const;
77 const PatternList* getPlayingPatterns() const;
78 const PatternList* getNextPatterns() const;
79 int getPatternSize() const;
80 long long getLastLeadLagFactor() const;
81 int getBar() const;
82 int getBeat() const;
83
101 static double computeTickFromFrame( long long nFrame, int nSampleRate = 0 );
102
124 static long long computeFrameFromTick( double fTick, double* fTickMismatch, int nSampleRate = 0 );
125
126 friend bool operator==( std::shared_ptr<TransportPosition> lhs,
127 std::shared_ptr<TransportPosition> rhs );
128 friend bool operator!=( std::shared_ptr<TransportPosition> lhs,
129 std::shared_ptr<TransportPosition> rhs );
130
139 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
140
141 friend class AudioEngine;
142 friend class AudioEngineTests;
143 friend class JackAudioDriver;
144
145private:
151 void set( std::shared_ptr<TransportPosition> pOther );
152 void reset();
153
154 void setFrame( long long nNewFrame );
155 void setTick( double fNewTick );
156 void setTickSize( float fNewTickSize );
157 void setBpm( float fNewBpm );
158 void setPatternStartTick( long nPatternStartTick );
159 void setPatternTickPosition( long nPatternTickPosition );
160 void setColumn( int nColumn );
161 void setFrameOffsetTempo( long long nFrameOffset );
162 void setTickOffsetQueuing( double nTickOffset );
163 void setTickOffsetSongSize( double fTickOffset );
164 void setPlayingPatterns( PatternList* pPatternList );
165 void setNextPatterns( PatternList* pPatternList );
166 void setPatternSize( int nPatternSize );
167 void setLastLeadLagFactor( long long nValue );
168 void setBar( int nBar );
169 void setBeat( int nBeat );
170
173
183 static long long computeFrame( double fTick, float fTickSize );
193 static double computeTick( long long nFrame, float fTickSize );
194
195 double getDoubleTick() const;
196
200 const QString m_sLabel;
201
213 long long m_nFrame;
214
232 double m_fTick;
233
263 float m_fBpm;
264
292
302
339
357
369
383
391
402
415};
416
417inline const QString TransportPosition::getLabel() const {
418 return m_sLabel;
419}
420inline long long TransportPosition::getFrame() const {
421 return m_nFrame;
422}
423inline double TransportPosition::getDoubleTick() const {
424 return m_fTick;
425}
426inline long TransportPosition::getTick() const {
427 return static_cast<long>(std::floor( m_fTick ));
428}
429inline float TransportPosition::getTickSize() const {
430 return m_fTickSize;
431}
432inline float TransportPosition::getBpm() const {
433 return m_fBpm;
434}
436 return m_nPatternStartTick;
437}
442 return m_nColumn;
443}
445 return m_fTickMismatch;
446}
448 return m_nFrameOffsetTempo;
449}
450inline void TransportPosition::setFrameOffsetTempo( long long nFrameOffset ) {
451 m_nFrameOffsetTempo = nFrameOffset;
452}
455}
456inline void TransportPosition::setTickOffsetQueuing( double fTickOffset ) {
457 m_fTickOffsetQueuing = fTickOffset;
458}
462inline void TransportPosition::setTickOffsetSongSize( double fTickOffset ) {
463 m_fTickOffsetSongSize = fTickOffset;
464}
472 return m_pNextPatterns;
473}
478 return m_nPatternSize;
479}
482}
483inline void TransportPosition::setLastLeadLagFactor( long long nValue ) {
484 m_nLastLeadLagFactor = nValue;
485}
486inline int TransportPosition::getBar() const {
487 return m_nBar;
488}
489inline int TransportPosition::getBeat() const {
490 return m_nBeat;
491}
492};
493
494#endif
495
#define H2_OBJECT(name)
Definition Object.h:227
PatternList is a collection of patterns.
Definition PatternList.h:43
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, switching to Timeline,...
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)
friend bool operator==(std::shared_ptr< TransportPosition > lhs, std::shared_ptr< TransportPosition > rhs)
friend bool operator!=(std::shared_ptr< TransportPosition > lhs, std::shared_ptr< TransportPosition > rhs)
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.