From 32f99d26155f490329d6007d8b4edcc0c94adea0 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 6 May 2021 12:20:34 +0100 Subject: [PATCH] AudioPlayHead: Tidy up implementation --- .../audio_play_head/juce_AudioPlayHead.h | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/modules/juce_audio_basics/audio_play_head/juce_AudioPlayHead.h b/modules/juce_audio_basics/audio_play_head/juce_AudioPlayHead.h index ebbb68d931..37a3d53783 100644 --- a/modules/juce_audio_basics/audio_play_head/juce_AudioPlayHead.h +++ b/modules/juce_audio_basics/audio_play_head/juce_AudioPlayHead.h @@ -66,23 +66,23 @@ public: struct JUCE_API CurrentPositionInfo { /** The tempo in BPM */ - double bpm; + double bpm = 120.0; /** Time signature numerator, e.g. the 3 of a 3/4 time sig */ - int timeSigNumerator; + int timeSigNumerator = 4; /** Time signature denominator, e.g. the 4 of a 3/4 time sig */ - int timeSigDenominator; + int timeSigDenominator = 4; /** The current play position, in samples from the start of the timeline. */ - int64 timeInSamples; + int64 timeInSamples = 0; /** The current play position, in seconds from the start of the timeline. */ - double timeInSeconds; + double timeInSeconds = 0; /** For timecode, the position of the start of the timeline, in seconds from 00:00:00:00. */ - double editOriginTime; + double editOriginTime = 0; /** The current play position, in units of quarter-notes. */ - double ppqPosition; + double ppqPosition = 0; /** The position of the start of the last bar, in units of quarter-notes. @@ -92,51 +92,56 @@ public: Note - this value may be unavailable on some hosts, e.g. Pro-Tools. If it's not available, the value will be 0. */ - double ppqPositionOfLastBarStart; + double ppqPositionOfLastBarStart = 0; /** The video frame rate, if applicable. */ - FrameRateType frameRate; + FrameRateType frameRate = FrameRateType::fps23976; /** True if the transport is currently playing. */ - bool isPlaying; + bool isPlaying = false; /** True if the transport is currently recording. (When isRecording is true, then isPlaying will also be true). */ - bool isRecording; + bool isRecording = false; /** The current cycle start position in units of quarter-notes. Note that not all hosts or plugin formats may provide this value. @see isLooping */ - double ppqLoopStart; + double ppqLoopStart = 0; /** The current cycle end position in units of quarter-notes. Note that not all hosts or plugin formats may provide this value. @see isLooping */ - double ppqLoopEnd; + double ppqLoopEnd = 0; /** True if the transport is currently looping. */ - bool isLooping; + bool isLooping = false; //============================================================================== bool operator== (const CurrentPositionInfo& other) const noexcept { - return timeInSamples == other.timeInSamples - && ppqPosition == other.ppqPosition - && editOriginTime == other.editOriginTime - && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart - && frameRate == other.frameRate - && isPlaying == other.isPlaying - && isRecording == other.isRecording - && bpm == other.bpm - && timeSigNumerator == other.timeSigNumerator - && timeSigDenominator == other.timeSigDenominator - && ppqLoopStart == other.ppqLoopStart - && ppqLoopEnd == other.ppqLoopEnd - && isLooping == other.isLooping; + auto tie = [] (const CurrentPositionInfo& i) + { + return std::tie (i.timeInSamples, + i.ppqPosition, + i.editOriginTime, + i.ppqPositionOfLastBarStart, + i.frameRate, + i.isPlaying, + i.isRecording, + i.bpm, + i.timeSigNumerator, + i.timeSigDenominator, + i.ppqLoopStart, + i.ppqLoopEnd, + i.isLooping); + }; + + return tie (*this) == tie (other); } bool operator!= (const CurrentPositionInfo& other) const noexcept @@ -146,10 +151,7 @@ public: void resetToDefault() { - zerostruct (*this); - timeSigNumerator = 4; - timeSigDenominator = 4; - bpm = 120; + *this = CurrentPositionInfo{}; } };