Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/test/beatgridtest.cpp

Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <QDebug>
00003 
00004 #include "track/beatgrid.h"
00005 
00006 namespace {
00007 
00008 class BeatGridTest : public testing::Test {
00009   protected:
00010 
00011     BeatGridTest() {
00012     }
00013 
00014     virtual void SetUp() {
00015     }
00016 
00017     virtual void TearDown() {
00018     }
00019 };
00020 
00021 TEST_F(BeatGridTest, TestNthBeatWhenOnBeat) {
00022     TrackPointer pTrack(new TrackInfoObject(), &QObject::deleteLater);
00023 
00024     int sampleRate = 44100;
00025     double bpm = 60.0;
00026     const int kFrameSize = 2;
00027     pTrack->setBpm(bpm);
00028     pTrack->setSampleRate(sampleRate);
00029     double beatLength = (60.0 * sampleRate / bpm) * kFrameSize;
00030 
00031     BeatGrid* pGrid = new BeatGrid(pTrack);
00032     // Pretend we're on the 20th beat;
00033     double position = beatLength * 20;
00034 
00035     // The spec dictates that a value of 0 is always invalid and returns -1
00036     EXPECT_EQ(-1, pGrid->findNthBeat(position, 0));
00037 
00038     // findNthBeat should return exactly the current beat if we ask for 1 or
00039     // -1. For all other values, it should return n times the beat length.
00040     for (int i = 1; i < 20; ++i) {
00041         EXPECT_EQ(position + beatLength*(i-1), pGrid->findNthBeat(position, i));
00042         EXPECT_EQ(position + beatLength*(-i+1), pGrid->findNthBeat(position, -i));
00043     }
00044 }
00045 
00046 
00047 TEST_F(BeatGridTest, TestNthBeatWhenNotOnBeat) {
00048     TrackPointer pTrack(new TrackInfoObject(), &QObject::deleteLater);
00049     int sampleRate = 44100;
00050     double bpm = 60.0;
00051     const int kFrameSize = 2;
00052     pTrack->setBpm(bpm);
00053     pTrack->setSampleRate(sampleRate);
00054     double beatLength = (60.0 * sampleRate / bpm) * kFrameSize;
00055 
00056     BeatGrid* pGrid = new BeatGrid(pTrack);
00057 
00058     // Pretend we're half way between the 20th and 21st beat
00059     double previousBeat = beatLength * 20.0;
00060     double nextBeat = beatLength * 21.0;
00061     double position = (nextBeat + previousBeat) / 2.0;
00062 
00063     // The spec dictates that a value of 0 is always invalid and returns -1
00064     EXPECT_EQ(-1, pGrid->findNthBeat(position, 0));
00065 
00066     // findNthBeat should return multiples of beats starting from the next or
00067     // previous beat, depending on whether N is positive or negative.
00068     for (int i = 1; i < 20; ++i) {
00069         EXPECT_EQ(nextBeat + beatLength*(i-1), pGrid->findNthBeat(position, i));
00070         EXPECT_EQ(previousBeat + beatLength*(-i+1), pGrid->findNthBeat(position, -i));
00071     }
00072 }
00073 
00074 }  // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines