Skip to content

Commit

Permalink
Add automation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-w committed Mar 21, 2017
1 parent 42fcaed commit 4bce488
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ void Song::processAutomations(const TrackList &tracklist, MidiTime timeStart, fp
{
track->getTCOsInRange(tcos, 0, timeEnd);
}
std::remove_if(tcos.begin(), tcos.end(), std::mem_fn(&TrackContentObject::isMuted));

values = automatedValuesAt(tcos, timeStart);
}
Expand Down Expand Up @@ -858,6 +857,9 @@ AutomatedValueMap Song::automatedValuesAt(const Track::tcoVector &tcos, MidiTime

for(TrackContentObject* tco : tcos)
{
if (tco->isMuted() || tco->startPosition() > time) {
continue;
}
AutomationPattern* p = dynamic_cast<AutomationPattern *>(tco);
if (!p) {
qCritical() << "automatedValuesAt: tco passed is not an automation pattern";
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ ADD_EXECUTABLE(tests
$<TARGET_OBJECTS:lmmsobjs>

src/core/ProjectVersionTest.cpp

src/tracks/AutomationTrackTest.cpp
)
TARGET_LINK_LIBRARIES(tests ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY})
TARGET_LINK_LIBRARIES(tests ${LMMS_REQUIRED_LIBS})
5 changes: 5 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

#include <QDebug>

#include "Engine.h"

int main(int argc, char* argv[])
{
new QCoreApplication(argc, argv);
Engine::init(true);

int numsuites = QTestSuite::suites().size();
qDebug() << ">> Will run" << numsuites << "test suites";
int failed = 0;
Expand Down
101 changes: 101 additions & 0 deletions tests/src/tracks/AutomationTrackTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* AutomationTrackTest.cpp
*
* Copyright (c) 2017 Lukas W <lukaswhl/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#include "QTestSuite.h"

#include "QCoreApplication"

#include "AutomationPattern.h"
#include "AutomationTrack.h"
#include "TrackContainer.h"

#include "Engine.h"
#include "Song.h"

class AutomationTrackTest : QTestSuite
{
Q_OBJECT
private slots:
void initTestCase()
{
}

void testPatternLinear()
{
AutomationPattern p(nullptr);
p.setProgressionType(AutomationPattern::LinearProgression);
p.putValue(0, 0.0, false);
p.putValue(100, 1.0, false);

QCOMPARE(p.valueAt(0), 0.0f);
QCOMPARE(p.valueAt(25), 0.25f);
QCOMPARE(p.valueAt(50), 0.5f);
QCOMPARE(p.valueAt(75), 0.75f);
QCOMPARE(p.valueAt(100), 1.0f);
QCOMPARE(p.valueAt(150), 1.0f);
}

void testPatternDiscrete()
{
AutomationPattern p(nullptr);
p.setProgressionType(AutomationPattern::DiscreteProgression);
p.putValue(0, 0.0, false);
p.putValue(100, 1.0, false);

QCOMPARE(p.valueAt(0), 0.0f);
QCOMPARE(p.valueAt(50), 0.0f);
QCOMPARE(p.valueAt(100), 1.0f);
QCOMPARE(p.valueAt(150), 1.0f);
}

void testTrack()
{
Song* song = Engine::getSong();

FloatModel model;

AutomationPattern p1(nullptr);
p1.setProgressionType(AutomationPattern::LinearProgression);
p1.putValue(0, 0.0, false);
p1.putValue(10, 1.0, false);
p1.movePosition(0);
p1.addObject(&model);

AutomationPattern p2(nullptr);
p2.setProgressionType(AutomationPattern::LinearProgression);
p2.putValue(0, 0.0, false);
p2.putValue(100, 1.0, false);
p2.movePosition(100);
p2.addObject(&model);

QCOMPARE(Song::automatedValuesAt({&p1, &p2}, 0)[&model], 0.0f);
QCOMPARE(Song::automatedValuesAt({&p1, &p2}, 5)[&model], 0.5f);
QCOMPARE(Song::automatedValuesAt({&p1, &p2}, 10)[&model], 1.0f);
QCOMPARE(Song::automatedValuesAt({&p1, &p2}, 50)[&model], 1.0f);
QCOMPARE(Song::automatedValuesAt({&p1, &p2}, 100)[&model], 0.0f);
QCOMPARE(Song::automatedValuesAt({&p1, &p2}, 150)[&model], 0.5f);
}
} AutomationTrackTest;

#include "AutomationTrackTest.moc"

0 comments on commit 4bce488

Please sign in to comment.