|
hydrogen 1.2.6
|
Object holding most of the information about the transport state of the AudioEngine. More...
#include <TransportPosition.h>
Public Member Functions | |
| TransportPosition (const QString sLabel="") | |
| TransportPosition (std::shared_ptr< TransportPosition > pOther) | |
| ~TransportPosition () | |
| int | getBar () const |
| int | getBeat () const |
| float | getBpm () const |
| int | getColumn () const |
| long long | getFrame () const |
| long long | getFrameOffsetTempo () const |
| const QString | getLabel () const |
| long long | getLastLeadLagFactor () const |
| const PatternList * | getNextPatterns () const |
| int | getPatternSize () const |
| long | getPatternStartTick () const |
| long | getPatternTickPosition () const |
| const PatternList * | getPlayingPatterns () const |
| long | getTick () const |
| Retrieve a rounded version of m_fTick. | |
| double | getTickMismatch () const |
| double | getTickOffsetQueuing () const |
| double | getTickOffsetSongSize () const |
| float | getTickSize () const |
| QString | toQString (const QString &sPrefix="", bool bShort=true) const override |
| Formatted string version for debugging purposes. | |
Public Member Functions inherited from Object< TransportPosition > | |
| Object () | |
| Object (const Object< TransportPosition > &other) | |
Public Member Functions inherited from Base | |
| Base () | |
| Base (const Base &other) | |
| virtual const char * | class_name () const |
| void | logBacktrace () const |
| Print the current stack at point into the debug log. | |
| void | Print (bool bShort=true) const |
| Prints content of toQString() via DEBUGLOG. | |
Static Public Member Functions | |
| static long long | computeFrameFromTick (double fTick, double *fTickMismatch, int nSampleRate=0) |
| Calculates frame equivalent of fTick. | |
| static double | computeTickFromFrame (long long nFrame, int nSampleRate=0) |
| Calculates tick equivalent of nFrame. | |
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 Logger * | logger () |
| 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 | |
Private Member Functions | |
| double | getDoubleTick () const |
| PatternList * | getNextPatterns () |
| PatternList * | getPlayingPatterns () |
| void | reset () |
| void | set (std::shared_ptr< TransportPosition > pOther) |
| Copying the content of one position into the other is a lot cheaper than performing computations, like AudioEngine::updateTransportPosition(), twice. | |
| void | setBar (int nBar) |
| void | setBeat (int nBeat) |
| void | setBpm (float fNewBpm) |
| void | setColumn (int nColumn) |
| void | setFrame (long long nNewFrame) |
| void | setFrameOffsetTempo (long long nFrameOffset) |
| void | setLastLeadLagFactor (long long nValue) |
| void | setNextPatterns (PatternList *pPatternList) |
| void | setPatternSize (int nPatternSize) |
| void | setPatternStartTick (long nPatternStartTick) |
| void | setPatternTickPosition (long nPatternTickPosition) |
| void | setPlayingPatterns (PatternList *pPatternList) |
| void | setTick (double fNewTick) |
| void | setTickOffsetQueuing (double nTickOffset) |
| void | setTickOffsetSongSize (double fTickOffset) |
| void | setTickSize (float fNewTickSize) |
Static Private Member Functions | |
| static long long | computeFrame (double fTick, float fTickSize) |
| Converts ticks into frames under the assumption of a constant fTickSize (sample rate, tempo, and resolution did not change). | |
| static double | computeTick (long long nFrame, float fTickSize) |
| Converts frames into ticks under the assumption of a constant fTickSize (sample rate, tempo, and resolution did not change). | |
Private Attributes | |
| float | m_fBpm |
| Current tempo in beats per minute. | |
| double | m_fTick |
| Current transport position in number of ticks since the beginning of the song. | |
| double | m_fTickMismatch |
| Number of ticks m_nFrame is ahead/behind of m_fTick. | |
| double | m_fTickOffsetQueuing |
| Tick offset introduced when changing the tempo of the song. | |
| double | m_fTickOffsetSongSize |
| Tick offset introduced when changing the size of the song. | |
| float | m_fTickSize |
| Number of frames that make up one tick. | |
| int | m_nBar |
| Last beat (column + 1) passed. | |
| int | m_nBeat |
| Last bar passed since m_nBar. | |
| int | m_nColumn |
| Specifies the column transport is located in and can be used as the index of the current PatternList/column in the Song::m_pPatternGroupSequence. | |
| long long | m_nFrame |
| Current transport position in number of frames since the beginning of the song. | |
| long long | m_nFrameOffsetTempo |
| Frame offset introduced when changing the tempo of the song, switching to Timeline, adding or remove an Tempo Marker while Timeline is active, or encountering an external tempo change by a JACK Timebase controller. | |
| long long | m_nLastLeadLagFactor |
| int | m_nPatternSize |
| Maximum size of all patterns in m_pPlayingPatterns. | |
| long | m_nPatternStartTick |
| Dicstance in ticks between the beginning of the song and the beginning of the current column (m_nColumn). | |
| long | m_nPatternTickPosition |
| Ticks passed since m_nPatternStartTick. | |
| PatternList * | m_pNextPatterns |
| Patterns used to toggle the ones in m_pPlayingPatterns in Song::PatternMode::Stacked. | |
| PatternList * | m_pPlayingPatterns |
| Contains all Patterns currently played back. | |
| const QString | m_sLabel |
| Identifier of the transport position. | |
Friends | |
| class | AudioEngine |
| class | AudioEngineTests |
| class | JackAudioDriver |
| bool | operator!= (std::shared_ptr< TransportPosition > lhs, std::shared_ptr< TransportPosition > rhs) |
| bool | operator== (std::shared_ptr< TransportPosition > lhs, std::shared_ptr< TransportPosition > rhs) |
Additional Inherited Members | |
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< TransportPosition > | |
| ~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 |
| static bool | bLogColors = true |
Object holding most of the information about the transport state of the AudioEngine.
Due to the original design of Hydrogen the fundamental variable to determine the transport position is a tick. Whenever a tempo or song size change is encountered, the tick and frame information are shifted or rescaled. To nevertheless ensure consistency, the amount of compensation required to retrieve the original position is stored in a number of dedicated offset variables.
Definition at line 48 of file TransportPosition.h.
| TransportPosition | ( | const QString | sLabel = "" | ) |
Definition at line 41 of file TransportPosition.cpp.
| TransportPosition | ( | std::shared_ptr< TransportPosition > | pOther | ) |
Definition at line 52 of file TransportPosition.cpp.
| ~TransportPosition | ( | ) |
Definition at line 61 of file TransportPosition.cpp.
|
staticprivate |
Converts ticks into frames under the assumption of a constant fTickSize (sample rate, tempo, and resolution did not change).
As the assumption above does not hold once a tempo marker is introduced, computeFrameFromTick() should be used instead while this function is only meant for internal use.
Definition at line 703 of file TransportPosition.cpp.
|
static |
Calculates frame equivalent of fTick.
In case the Timeline is activated, the function takes all passed tempo markers into account in order to determine the number of frames passed when letting the AudioEngine roll for fTick ticks.
It depends on the sample rate nSampleRate and assumes that it as well as the resolution to be constant over the whole song.
| fTick | Current transport position in ticks. |
| fTickMismatch | Since ticks are stored as doubles and there is some loss in precision, this variable is used report how much @fTick exceeds/is ahead of the resulting frame. |
| nSampleRate | If set to 0, the sample rate provided by the audio driver will be used. |
Definition at line 230 of file TransportPosition.cpp.
|
staticprivate |
Converts frames into ticks under the assumption of a constant fTickSize (sample rate, tempo, and resolution did not change).
As the assumption above does not hold once a tempo marker is introduced, computeFrameFromTick() should be used instead while this function is only meant for internal use.
Definition at line 707 of file TransportPosition.cpp.
|
static |
Calculates tick equivalent of nFrame.
In case the Timeline is activated, the function takes all passed tempo markers into account in order to determine the number of ticks passed when letting the AudioEngine roll for nFrame frames.
It depends on the sample rate nSampleRate and assumes that it as well as the resolution to be constant over the whole song.
| nFrame | Transport position in frame which should be converted into ticks. |
| nSampleRate | If set to 0, the sample rate provided by the audio driver will be used. |
Definition at line 502 of file TransportPosition.cpp.
|
inline |
Definition at line 486 of file TransportPosition.h.
|
inline |
Definition at line 489 of file TransportPosition.h.
|
inline |
Definition at line 432 of file TransportPosition.h.
|
inline |
Definition at line 441 of file TransportPosition.h.
|
inlineprivate |
Definition at line 423 of file TransportPosition.h.
|
inline |
Definition at line 420 of file TransportPosition.h.
|
inline |
Definition at line 447 of file TransportPosition.h.
|
inline |
Definition at line 417 of file TransportPosition.h.
|
inline |
Definition at line 480 of file TransportPosition.h.
|
inlineprivate |
Definition at line 474 of file TransportPosition.h.
|
inline |
Definition at line 471 of file TransportPosition.h.
|
inline |
Definition at line 477 of file TransportPosition.h.
|
inline |
Definition at line 435 of file TransportPosition.h.
|
inline |
Definition at line 438 of file TransportPosition.h.
|
inlineprivate |
Definition at line 468 of file TransportPosition.h.
|
inline |
Definition at line 465 of file TransportPosition.h.
|
inline |
Retrieve a rounded version of m_fTick.
Only within the AudioEngine ticks are handled as doubles. This is required to allow for a seamless transition between frames and ticks without any rounding error. All other parts use integer values (due to historical reasons).
Definition at line 426 of file TransportPosition.h.
|
inline |
Definition at line 444 of file TransportPosition.h.
|
inline |
Definition at line 453 of file TransportPosition.h.
|
inline |
Definition at line 459 of file TransportPosition.h.
|
inline |
Definition at line 429 of file TransportPosition.h.
|
private |
Definition at line 101 of file TransportPosition.cpp.
|
private |
Copying the content of one position into the other is a lot cheaper than performing computations, like AudioEngine::updateTransportPosition(), twice.
Definition at line 70 of file TransportPosition.cpp.
|
private |
Definition at line 210 of file TransportPosition.cpp.
|
private |
Definition at line 219 of file TransportPosition.cpp.
|
private |
Definition at line 122 of file TransportPosition.cpp.
|
private |
Definition at line 190 of file TransportPosition.cpp.
|
private |
Definition at line 140 of file TransportPosition.cpp.
|
inlineprivate |
Definition at line 450 of file TransportPosition.h.
|
inlineprivate |
Definition at line 483 of file TransportPosition.h.
|
private |
|
private |
Definition at line 201 of file TransportPosition.cpp.
|
private |
Definition at line 170 of file TransportPosition.cpp.
|
private |
Definition at line 180 of file TransportPosition.cpp.
|
private |
|
private |
Definition at line 150 of file TransportPosition.cpp.
|
inlineprivate |
Definition at line 456 of file TransportPosition.h.
|
inlineprivate |
Definition at line 462 of file TransportPosition.h.
|
private |
Definition at line 160 of file TransportPosition.cpp.
|
overridevirtual |
Formatted string version for debugging purposes.
| sPrefix | String prefix which will be added in front of every new line |
| bShort | Instead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks. |
Reimplemented from Base.
Definition at line 804 of file TransportPosition.cpp.
|
friend |
Definition at line 141 of file TransportPosition.h.
|
friend |
Definition at line 142 of file TransportPosition.h.
|
friend |
Definition at line 143 of file TransportPosition.h.
|
friend |
Definition at line 757 of file TransportPosition.cpp.
|
friend |
Definition at line 711 of file TransportPosition.cpp.
|
private |
Current tempo in beats per minute.
It can be set through three different mechanisms and the corresponding values are stored in different places.
Definition at line 263 of file TransportPosition.h.
|
private |
Current transport position in number of ticks since the beginning of the song.
A tick is the smallest temporal unit used for transport, navigation, and audio rendering within Hydrogen. (Note that the smallest unit for positioning a Note is a frame due to the humanization capabilities.)
Although the precision of this variable is double, only a version of it rounded to integer is used outside of the AudioEngine.
Float is, unfortunately, not enough. When the engine is running for a long time the high precision digits after decimal point required to keep frames and ticks in sync would be lost.
Definition at line 232 of file TransportPosition.h.
|
private |
Number of ticks m_nFrame is ahead/behind of m_fTick.
This is due to the rounding error introduced when calculating the frame counterpart m_nFrame of m_fTick using computeFrameFromTick(). m_nFrame.
Definition at line 301 of file TransportPosition.h.
|
private |
Tick offset introduced when changing the tempo of the song.
In case the Timeline is deactivate each tempo change does alter m_fTickSize and results in the start of the new tick interval covered for note enqueuing in AudioEngine::updateNoteQueue() to not be consistent with the previous interval end anymore. Holes or overlaps could lead to note misses or double enqueuings. We will handle this by compensating the difference in ticks using m_fTickOffsetQueuing as an additive offset internally.
When locating transport or stopping playback both the tick interval and m_fTickOffsetQueuing get resetted.
Note this is not the tick equivalent of m_nFrameOffsetTempo.
Definition at line 338 of file TransportPosition.h.
|
private |
Tick offset introduced when changing the size of the song.
When altering the size of the song, e.g. by enlarging a pattern prior to the one currently playing, both m_nFrame and m_fTick become invalid. We will handle this by compensating the difference between the old and new tick position using m_fTickOffsetSongSize as an additive offset internally. In addition, m_nFrameOffsetTempo and m_fTickOffsetQueuing will be used to compensate for the change in the current frame position and tick interval end.
When locating transport or stopping playback both m_nFrame and m_fTick become synced again and m_fTickOffsetSongSize gets resetted.
Definition at line 356 of file TransportPosition.h.
|
private |
Number of frames that make up one tick.
Calculated using AudioEngine::computeTickSize().
Definition at line 239 of file TransportPosition.h.
|
private |
Last beat (column + 1) passed.
Note that this variable starts at 1 not at 0.
Definition at line 408 of file TransportPosition.h.
|
private |
Last bar passed since m_nBar.
A bar is composed of 48 ticks.
Note that this variable starts at 1 not at 0.
Definition at line 414 of file TransportPosition.h.
|
private |
Specifies the column transport is located in and can be used as the index of the current PatternList/column in the Song::m_pPatternGroupSequence.
A value of -1 corresponds to "pattern list could not be found" and is used to indicate that transport reached the end of the song (with transport not looped).
Definition at line 291 of file TransportPosition.h.
|
private |
Current transport position in number of frames since the beginning of the song.
A frame is a single sample of an audio signal. Thus, with a sample rate of 48000Hz, 48000 frames will be recorded in one second and, with a buffer size = 1024, 1024 consecutive frames will be accumulated before they are handed over to the audio engine for processing. Internally, the transport is based on ticks. (m_nFrame / m_fTickSize)
Definition at line 213 of file TransportPosition.h.
|
private |
Frame offset introduced when changing the tempo of the song, switching to Timeline, adding or remove an Tempo Marker while Timeline is active, or encountering an external tempo change by a JACK Timebase controller.
Each tempo or Tempo Marker change does alter m_fTickSize and results in m_nFrame and m_fTick to not be consistent anymore. We will handle this by compensating the difference in frames (m_fTick is kept constant during a tempo change while m_nFrame gets rescaled) using m_nFrameOffsetTempo as an additive offset internally.
When locating transport or stopping playback both m_nFrame and m_fTick become synced again and m_nFrameOffsetTempo gets resetted.
Note this is not the frame equivalent of m_fTickOffsetQueuing.
Definition at line 320 of file TransportPosition.h.
|
private |
#AudioEngine::getLeadLagInFrames() calculated for the previous
transport position.
It is required to ensure a smooth update of the queuing position in AudioEngine::updateNoteQueue() without any holes or overlaps in the covered ticks (while using the #Timeline in #Song::Mode::Song).
Definition at line 401 of file TransportPosition.h.
|
private |
Maximum size of all patterns in m_pPlayingPatterns.
If m_pPlayingPatterns is empty, #H2Core::MAX_NOTES will be used as fallback.
Definition at line 390 of file TransportPosition.h.
|
private |
Dicstance in ticks between the beginning of the song and the beginning of the current column (m_nColumn).
The current transport position corresponds to m_fTick = (roughly) m_nPatternStartTick + m_nPatternTickPosition.
Definition at line 273 of file TransportPosition.h.
|
private |
Ticks passed since m_nPatternStartTick.
The current transport position thus corresponds to m_fTick = (roughly) m_nPatternStartTick + m_nPatternTickPosition.
Definition at line 281 of file TransportPosition.h.
|
private |
Patterns used to toggle the ones in m_pPlayingPatterns in Song::PatternMode::Stacked.
If a Pattern is already playing and added to m_pNextPatterns, it will the removed from m_pPlayingPatterns next time transport is looped to the beginning and vice versa.
See AudioEngine::updatePlayingPatterns() for details.
Definition at line 368 of file TransportPosition.h.
|
private |
Contains all Patterns currently played back.
If transport is in H2Core::Song::Mode::Song, it corresponds to the patterns present in column m_nColumn.
Due to performance reasons no virtual patterns will be checked and expanded in this list. Instead, all contained patterns have to be added explicitly.
See AudioEngine::updatePlayingPatterns() for details.
Definition at line 382 of file TransportPosition.h.
|
private |
Identifier of the transport position.
Used to keep different instances apart.
Definition at line 200 of file TransportPosition.h.