aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/LV2/include/lv2wrapper.h
blob: e92c6901d246b792fb19ed0fb23d1398b649bc37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "lv2/core/lv2.h"

LV2_Descriptor descriptor;

template<typename Plugin>
class LV2Wrapper
{
public:
    LV2Wrapper()
    {
        LV2_Descriptor d = {
            Plugin::URI,
            LV2Wrapper::instantiate,
            LV2Wrapper::connect_port,
            LV2Wrapper::activate,
            LV2Wrapper::run,
            LV2Wrapper::deactivate,
            LV2Wrapper::destroy,
            LV2Wrapper::extension_data
        };
        descriptor = d;
    }

private:
    static LV2_Handle instantiate(
            const LV2_Descriptor * d,
            double rate,
            const char * path,
            const LV2_Feature * const * features)
    {
        return new Plugin{rate};
    }

    static void connect_port(
            LV2_Handle instance,
            uint32_t port,
            void * data)
    {
        auto accel = static_cast<Plugin *>(instance);
        accel->connect_port(port, data);
    }

    static void activate(LV2_Handle instance)
    {
        auto accel = static_cast<Plugin *>(instance);
        accel->activate();
    }

    static void run(LV2_Handle instance, uint32_t num_samples)
    {
        auto accel = static_cast<Plugin *>(instance);
        accel->run(num_samples);
    }

    static void deactivate(LV2_Handle instance)
    {
        auto accel = static_cast<Plugin *>(instance);
        accel->deactivate();
    }

    static void destroy(LV2_Handle instance)
    {
        delete static_cast<Plugin *>(instance);
    }

    static const void * extension_data(const char * uri)
    {
        return nullptr;
    }
};

LV2_SYMBOL_EXPORT
const LV2_Descriptor * lv2_descriptor(uint32_t idx)
{
    if (idx == 0)
        return &descriptor;

    return nullptr;
}