95 lines
4.7 KiB
C++
95 lines
4.7 KiB
C++
#include "../src/DrumMap.h"
|
|
#include "../src/PluginProcessor.h"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
namespace
|
|
{
|
|
void require(bool condition, const char* message)
|
|
{
|
|
if (!condition)
|
|
{
|
|
std::cerr << "FAIL: " << message << '\n';
|
|
std::exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
require(drum_map::mapping[36] == 36 && drum_map::mapping[38] == 38, "standard kick and snare");
|
|
require(drum_map::mapping[21] == 44 && drum_map::mapping[25] == 46, "hi-hat pedal and open");
|
|
require(drum_map::mapping[61] == 42 && drum_map::mapping[60] == 46, "hi-hat articulations");
|
|
require(drum_map::mapping[72] == 41 && drum_map::mapping[81] == 48, "tom rims");
|
|
require(drum_map::mapping[86] == 49 && drum_map::mapping[103] == 57, "crashes");
|
|
require(drum_map::mapping[110] == 59 && drum_map::mapping[117] == 53, "ride edge and bell");
|
|
require(drum_map::mapping[1] == 39 && drum_map::mapping[2] == 70 && drum_map::mapping[3] == 54, "percussion");
|
|
require(drum_map::mapping[0] == 0 && drum_map::mapping[4] == 4 && drum_map::mapping[5] == 5, "unassigned notes");
|
|
|
|
MapperProcessor processor;
|
|
processor.prepareToPlay(48000, 256);
|
|
juce::AudioBuffer<float> audio(0, 256);
|
|
juce::MidiBuffer midi;
|
|
midi.addEvent(juce::MidiMessage::noteOn(10, 25, static_cast<juce::uint8>(91)), 3);
|
|
midi.addEvent(juce::MidiMessage::aftertouchChange(10, 25, 62), 4);
|
|
midi.addEvent(juce::MidiMessage::noteOff(10, 25, static_cast<juce::uint8>(33)), 5);
|
|
midi.addEvent(juce::MidiMessage::noteOn(1, 50, static_cast<juce::uint8>(100)), 6);
|
|
midi.addEvent(juce::MidiMessage::noteOff(1, 50), 7);
|
|
midi.addEvent(juce::MidiMessage::controllerEvent(10, 4, 45), 8);
|
|
midi.addEvent(juce::MidiMessage::noteOn(2, 4, static_cast<juce::uint8>(80)), 9);
|
|
processor.processBlock(audio, midi);
|
|
|
|
require(midi.getNumEvents() == 5, "mute events omitted");
|
|
auto it = midi.begin();
|
|
auto e = *it++;
|
|
require(e.samplePosition == 3 && e.getMessage().isNoteOn() && e.getMessage().getNoteNumber() == 46
|
|
&& e.getMessage().getChannel() == 10 && e.getMessage().getVelocity() == 91, "note-on fields");
|
|
e = *it++;
|
|
require(e.samplePosition == 4 && e.getMessage().isAftertouch() && e.getMessage().getNoteNumber() == 46
|
|
&& e.getMessage().getAfterTouchValue() == 62, "polyphonic aftertouch");
|
|
e = *it++;
|
|
require(e.samplePosition == 5 && e.getMessage().isNoteOff() && e.getMessage().getNoteNumber() == 46
|
|
&& e.getMessage().getVelocity() == 33, "note-off fields");
|
|
e = *it++;
|
|
require(e.samplePosition == 8 && e.getMessage().isController()
|
|
&& e.getMessage().getControllerNumber() == 4 && e.getMessage().getControllerValue() == 45, "controller passthrough");
|
|
e = *it++;
|
|
require(e.samplePosition == 9 && e.getMessage().getNoteNumber() == 4, "unassigned note passthrough");
|
|
|
|
midi.clear();
|
|
midi.addEvent(juce::MidiMessage::noteOn(1, 61, static_cast<juce::uint8>(0)), 1);
|
|
processor.processBlock(audio, midi);
|
|
require(midi.getNumEvents() == 1 && (*midi.begin()).getMessage().isNoteOff()
|
|
&& (*midi.begin()).getMessage().getNoteNumber() == 42, "zero-velocity note-on");
|
|
|
|
require(argc == 2, "VST3 bundle path provided");
|
|
juce::ScopedJuceInitialiser_GUI initialiseJuce;
|
|
juce::AudioPluginFormatManager formats;
|
|
formats.addFormat(std::make_unique<juce::VST3PluginFormat>());
|
|
juce::OwnedArray<juce::PluginDescription> descriptions;
|
|
formats.getFormat(0)->findAllTypesForFile(descriptions, juce::String(argv[1]));
|
|
require(descriptions.size() == 1, "VST3 bundle discovered");
|
|
juce::String error;
|
|
auto plugin = formats.createPluginInstance(*descriptions[0], 48000, 256, error);
|
|
if (plugin == nullptr)
|
|
std::cerr << "VST3 load error: " << error << '\n';
|
|
require(plugin != nullptr, "VST3 instance created");
|
|
require(plugin->acceptsMidi() && plugin->producesMidi(), "VST3 MIDI input and output");
|
|
plugin->prepareToPlay(48000, 256);
|
|
midi.clear();
|
|
midi.addEvent(juce::MidiMessage::noteOn(10, 25, static_cast<juce::uint8>(91)), 3);
|
|
midi.addEvent(juce::MidiMessage::noteOff(10, 25), 5);
|
|
midi.addEvent(juce::MidiMessage::noteOn(10, 50, static_cast<juce::uint8>(91)), 6);
|
|
plugin->processBlock(audio, midi);
|
|
require(midi.getNumEvents() == 2, "VST3 processing omits mute");
|
|
it = midi.begin();
|
|
e = *it++;
|
|
require(e.samplePosition == 3 && e.getMessage().isNoteOn() && e.getMessage().getNoteNumber() == 46
|
|
&& e.getMessage().getChannel() == 10 && e.getMessage().getVelocity() == 91, "VST3 mapped note-on");
|
|
e = *it++;
|
|
require(e.samplePosition == 5 && e.getMessage().isNoteOff() && e.getMessage().getNoteNumber() == 46,
|
|
"VST3 mapped note-off");
|
|
plugin->releaseResources();
|
|
std::cout << "Mapper tests passed\n";
|
|
}
|