LV2TestSuite.cpp 1.71 KB
Newer Older
1
#include "IFormatTestSuite.hpp"
2
#include "LV2Module.hpp"
3
#include "lilv.h"
4
#include "tools/LibLoading.hpp"
5
6
7
#include <algorithm>
#include <array>
#include <lv2/atom/forge.h>
8
9
#include <lv2/core/lv2.h>
#include <lv2/midi/midi.h>
10
#include <lv2/urid/urid.h>
11
#include <map>
12
#include <vector>
13
using namespace APAL;
14

15
16
17
18
/**
 * @brief Simple Testclass, derived from FormatTestSuiteBase to Test LV2 Format.
 * Using the LV2Module to make LV2 calls.
 */
19
20
class LV2TestSuite : public FormatTestSuiteBase
{
21

22
public:
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  LV2Module* module = nullptr;

  LV2TestSuite() {}
  ~LV2TestSuite()
  {
    if (this->module != nullptr)
      delete this->module;
  }
  inline virtual void initialize(TestSuiteData _data) override
  {
    this->data = _data;
    this->module = new LV2Module(this->data.pluginPath);
  }

  virtual std::string getFormatName() override { return "LV2"; }

  virtual SucceedState run() override
  {
    double sampleRate = 512;
    // size_t sampleCount = 512;
    for (auto plug : this->module->plugins) {
      plug.verify();
      plug.instantiate(sampleRate);
      plug.allocateAndConnectPorts(512);
      plug.activate();
      for (auto& p : plug.ports) {
        if (p.type == PortType::Midi && p.dir == Direction::Input) {
          p.addMidiMsg(0x1, 0x2, 0x3);
          p.addMidiMsg(0xFF, 0xFF, 0xFF);
52
        }
53
54
55
      }
      plug.run(sampleRate);
      plug.deactivate();
56
    }
57
58
59
60
61
62
63
64
65
66
67
68
69
    return TEST_SUCCEEDED;
  }

  virtual bool isSupported(std::string pluginPath) override
  {
    auto lib = LoadLib(pluginPath.c_str());
    if (lib == nullptr)
      return false;
    bool isSupp =
      LoadFunc<LV2_Descriptor_Function>(lib, "lv2_descriptor") != nullptr;
    UnloadLib(lib);
    return isSupp;
  }
70
71
};
REGISTER_TEST_SUITE(LV2TestSuite);