From 33afb32a4cc7260e678ab7cf048febd36720414e Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 6 Jul 2021 17:13:21 +0200 Subject: [PATCH] test: Use mixxx::audio::FramePos in AnalyzerSilenceTest --- src/test/analyzersilence_test.cpp | 53 +++++++++++++++++-------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/test/analyzersilence_test.cpp b/src/test/analyzersilence_test.cpp index 92cf84f1767..1a3af6ae731 100644 --- a/src/test/analyzersilence_test.cpp +++ b/src/test/analyzersilence_test.cpp @@ -56,8 +56,8 @@ TEST_F(AnalyzerSilenceTest, SilenceTrack) { analyzeTrack(); - CuePosition cue = pTrack->getCuePoint(); - EXPECT_DOUBLE_EQ(0.0, cue.getPosition()); + const mixxx::audio::FramePos cuePosition = pTrack->getMainCuePosition(); + EXPECT_EQ(mixxx::audio::kStartFramePos, cuePosition); CuePointer pIntroCue = pTrack->findCueByType(mixxx::CueType::Intro); EXPECT_EQ(mixxx::audio::kStartFramePos, pIntroCue->getPosition()); @@ -77,16 +77,16 @@ TEST_F(AnalyzerSilenceTest, EndToEndToneTrack) { analyzeTrack(); - CuePosition cue = pTrack->getCuePoint(); - EXPECT_DOUBLE_EQ(0.0, cue.getPosition()); + const mixxx::audio::FramePos cuePosition = pTrack->getMainCuePosition(); + EXPECT_EQ(mixxx::audio::kStartFramePos, cuePosition); CuePointer pIntroCue = pTrack->findCueByType(mixxx::CueType::Intro); EXPECT_EQ(mixxx::audio::kStartFramePos, pIntroCue->getPosition()); - EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames() * kChannelCount); + EXPECT_DOUBLE_EQ(0.0 / kChannelCount, pIntroCue->getLengthFrames()); CuePointer pOutroCue = pTrack->findCueByType(mixxx::CueType::Outro); EXPECT_EQ(mixxx::audio::kInvalidFramePos, pOutroCue->getPosition()); - EXPECT_DOUBLE_EQ(nTrackSampleDataLength, pOutroCue->getLengthFrames() * kChannelCount); + EXPECT_DOUBLE_EQ(nTrackSampleDataLength / kChannelCount, pOutroCue->getLengthFrames()); } TEST_F(AnalyzerSilenceTest, ToneTrackWithSilence) { @@ -108,16 +108,16 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilence) { analyzeTrack(); - CuePosition cue = pTrack->getCuePoint(); - EXPECT_DOUBLE_EQ(nTrackSampleDataLength / 4, cue.getPosition()); + const mixxx::audio::FramePos cuePosition = pTrack->getMainCuePosition(); + EXPECT_DOUBLE_EQ(nTrackSampleDataLength / 4, cuePosition.toEngineSamplePos()); CuePointer pIntroCue = pTrack->findCueByType(mixxx::CueType::Intro); EXPECT_DOUBLE_EQ(nTrackSampleDataLength / 4, pIntroCue->getPosition().toEngineSamplePos()); - EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames() * kChannelCount); + EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames()); CuePointer pOutroCue = pTrack->findCueByType(mixxx::CueType::Outro); EXPECT_EQ(mixxx::audio::kInvalidFramePos, pOutroCue->getPosition()); - EXPECT_DOUBLE_EQ(3 * nTrackSampleDataLength / 4, pOutroCue->getLengthFrames() * kChannelCount); + EXPECT_DOUBLE_EQ(3 * nTrackSampleDataLength / 4 / kChannelCount, pOutroCue->getLengthFrames()); } TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { @@ -151,12 +151,12 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { analyzeTrack(); - CuePosition cue = pTrack->getCuePoint(); - EXPECT_DOUBLE_EQ(oneFifthOfTrackLength, cue.getPosition()); + const mixxx::audio::FramePos cuePosition = pTrack->getMainCuePosition(); + EXPECT_DOUBLE_EQ(oneFifthOfTrackLength / kChannelCount, cuePosition.value()); CuePointer pIntroCue = pTrack->findCueByType(mixxx::CueType::Intro); EXPECT_DOUBLE_EQ(oneFifthOfTrackLength, pIntroCue->getPosition().toEngineSamplePos()); - EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames() * kChannelCount); + EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames()); CuePointer pOutroCue = pTrack->findCueByType(mixxx::CueType::Outro); EXPECT_EQ(mixxx::audio::kInvalidFramePos, pOutroCue->getPosition()); @@ -165,22 +165,27 @@ TEST_F(AnalyzerSilenceTest, ToneTrackWithSilenceInTheMiddle) { TEST_F(AnalyzerSilenceTest, RespectUserEdits) { // Arbitrary values - const double kManualCuePosition = 0.2 * nTrackSampleDataLength; - const double kManualIntroPosition = 0.1 * nTrackSampleDataLength; - const double kManualOutroPosition = 0.9 * nTrackSampleDataLength; + const auto kManualCuePosition = mixxx::audio::FramePos::fromEngineSamplePos( + 0.2 * nTrackSampleDataLength); + const auto kManualIntroPosition = + mixxx::audio::FramePos::fromEngineSamplePos( + 0.1 * nTrackSampleDataLength); + const auto kManualOutroPosition = + mixxx::audio::FramePos::fromEngineSamplePos( + 0.9 * nTrackSampleDataLength); - pTrack->setCuePoint(CuePosition(kManualCuePosition)); + pTrack->setMainCuePosition(kManualCuePosition); CuePointer pIntroCue = pTrack->createAndAddCue( mixxx::CueType::Intro, Cue::kNoHotCue, kManualIntroPosition, - Cue::kNoPosition); + mixxx::audio::kInvalidFramePos); CuePointer pOutroCue = pTrack->createAndAddCue( mixxx::CueType::Outro, Cue::kNoHotCue, - Cue::kNoPosition, + mixxx::audio::kInvalidFramePos, kManualOutroPosition); // Fill the first half with silence @@ -196,14 +201,14 @@ TEST_F(AnalyzerSilenceTest, RespectUserEdits) { analyzeTrack(); - CuePosition cue = pTrack->getCuePoint(); - EXPECT_DOUBLE_EQ(kManualCuePosition, cue.getPosition()); + mixxx::audio::FramePos cuePosition = pTrack->getMainCuePosition(); + EXPECT_EQ(kManualCuePosition, cuePosition); - EXPECT_DOUBLE_EQ(kManualIntroPosition, pIntroCue->getPosition().toEngineSamplePos()); - EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames() * kChannelCount); + EXPECT_EQ(kManualIntroPosition, pIntroCue->getPosition()); + EXPECT_DOUBLE_EQ(0.0, pIntroCue->getLengthFrames()); EXPECT_EQ(mixxx::audio::kInvalidFramePos, pOutroCue->getPosition()); - EXPECT_DOUBLE_EQ(kManualOutroPosition, pOutroCue->getLengthFrames() * kChannelCount); + EXPECT_DOUBLE_EQ(kManualOutroPosition.value(), pOutroCue->getLengthFrames()); } } // namespace