Improve audio and midi support.

This commit is contained in:
jmsgrogan 2021-05-23 21:02:38 +01:00
parent 9bcc0ae88e
commit 8b5f485d1e
47 changed files with 1446 additions and 634 deletions

View file

@ -1,6 +1,25 @@
add_executable(test_runner test_runner.cpp)
target_include_directories(test_runner PUBLIC
"${PROJECT_SOURCE_DIR}/test/"
add_library(test_utils SHARED
test_utils/TestCase.h
test_utils/TestCaseRunner.cpp
)
target_include_directories(test_utils PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/test_utils"
)
target_link_libraries(test_runner PUBLIC core
network database geometry audio graphics web)
list(APPEND TestFiles
audio/TestAudioWriter.cpp
audio/TestMidiReader.cpp)
list(APPEND TestNames
TestAudioWriter
TestMidiReader)
foreach(TestFile TestName IN ZIP_LISTS TestFiles TestNames)
add_executable(${TestName} ${TestFile})
target_link_libraries(${TestName} PUBLIC core network database geometry audio graphics web test_utils)
endforeach()
add_executable(test_runner test_runner.cpp)
target_link_libraries(test_runner PUBLIC core network database geometry audio graphics web)

View file

@ -0,0 +1,34 @@
#include "AudioSample.h"
#include "AudioSynth.h"
#include "AudioWriter.h"
#include "TestCase.h"
#include "TestCaseRunner.h"
#include <memory>
#include <string>
class TestWriteWav : public TestCase
{
public:
bool Run() override
{
AudioWriter writer;
writer.SetPath("test.wav");
AudioSynth synth;
auto sample = synth.GetSineWave(240, 5);
writer.Write(sample);
return true;
}
};
int main()
{
TestCaseRunner runner;
runner.AddTestCase("TestWriteNav", std::make_unique<TestWriteWav>());
const auto testsPassed = runner.Run();
return testsPassed ? 0 : -1;
}

View file

@ -0,0 +1,31 @@
#include "MidiReader.h"
#include "TestCase.h"
#include "TestCaseRunner.h"
#include <memory>
#include <string>
#include <iostream>
class TestReadMidi : public TestCase
{
public:
bool Run() override
{
MidiReader reader;
reader.Read("/home/jmsgrogan/Downloads/test.mid");
auto document = reader.GetDocument();
std::cout << document->Serialize() << std::endl;
return true;
}
};
int main()
{
TestCaseRunner runner;
runner.AddTestCase("TestReadMidi", std::make_unique<TestReadMidi>());
const auto testsPassed = runner.Run();
return testsPassed ? 0 : -1;
}

View file

@ -0,0 +1,13 @@
#pragma once
#include <memory>
class TestCase
{
public:
TestCase(){};
virtual ~TestCase() = default;
TestCase(const TestCase&) = delete;
virtual bool Run() {return false;};
};
using TestCasePtr = std::unique_ptr<TestCase>;

View file

@ -0,0 +1,26 @@
#include "TestCaseRunner.h"
#include <vector>
#include <iostream>
void TestCaseRunner::AddTestCase(const std::string& label, TestCasePtr testCase)
{
mCases.push_back({label, std::move(testCase)});
}
bool TestCaseRunner::Run()
{
bool testsPassed = true;
for(const auto& test : mCases)
{
std::cout << "Running " << test.first << std::endl;
const auto result = test.second->Run();
if (!result)
{
std::cout << test.first << " Failed" << std::endl;
testsPassed = false;
break;
}
}
return testsPassed;
}

View file

@ -0,0 +1,18 @@
#pragma once
#include "TestCase.h"
#include <vector>
class TestCaseRunner
{
public:
void AddTestCase(const std::string& label, TestCasePtr testCase);
bool Run();
private:
using TestInstance = std::pair<std::string, TestCasePtr>;
std::vector<TestInstance> mCases;
};