################################################################################
# gravitas - Chase Bliss Audio Gravitas MK II model for MOD Devices
################################################################################

GRAV_VERSION = main
GRAV_SITE = https://github.com/DISTRHO/DPF.git
GRAV_SITE_METHOD = git
GRAV_BUNDLES = gravitas.lv2

define GRAV_PLUGIN_INFO_H
#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
#define DISTRHO_PLUGIN_INFO_H_INCLUDED

#define DISTRHO_PLUGIN_BRAND   "Chase Bliss Audio"
#define DISTRHO_PLUGIN_NAME    "Gravitas MK II"
#define DISTRHO_PLUGIN_URI     "https://github.com/austin-dsp/lv2-plugins/gravitas"
#define DISTRHO_PLUGIN_CLAP_ID "com.chasebliss.gravitas"

#define DISTRHO_PLUGIN_NUM_INPUTS   2
#define DISTRHO_PLUGIN_NUM_OUTPUTS  2
#define DISTRHO_PLUGIN_IS_RT_SAFE   1
#define DISTRHO_PLUGIN_IS_SYNTH     0
#define DISTRHO_PLUGIN_HAS_UI       0
#define DISTRHO_PLUGIN_WANT_STATE   0
#define DISTRHO_PLUGIN_WANT_LATENCY 0
#define DISTRHO_PLUGIN_WANT_TIMEPOS 0
#define DISTRHO_PLUGIN_WANT_MIDI_INPUT  0
#define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 0

enum Parameters {
    pVolume = 0,
    pRate,
    pDepth,
    pWaveform,
    pDrive,
    pTone,
    pHarmonic,
    pMix,
    pRamp,

    kParameterCount
};

#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
endef

define GRAV_PLUGIN_CPP
#include "DistrhoPlugin.hpp"
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdlib>

START_NAMESPACE_DISTRHO

class GravitasPlugin : public Plugin {
public:
    GravitasPlugin() : Plugin(kParameterCount, 0, 0), fSampleRate(48000.0f), fPhase(0.0f), fRampPhase(0.0f), fSmoothLfo(0.0f), fRandomTarget(0.5f), fRandomCurrent(0.5f) {
        fParams[pVolume] = 0.5f;
        fParams[pRate] = 0.5f;
        fParams[pDepth] = 0.7f;
        fParams[pWaveform] = 0.0f;
        fParams[pDrive] = 0.0f;
        fParams[pTone] = 0.5f;
        fParams[pHarmonic] = 0.0f;
        fParams[pMix] = 1.0f;
        fParams[pRamp] = 0.0f;

        clearBuffers();
    }

protected:
    const char* getLabel() const override { return "Gravitas"; }
    const char* getDescription() const override {
        return "True analog-style harmonic and standard tremolo with mix control and expanded presets based on Chase Bliss Audio Gravitas.";
    }
    const char* getMaker() const override { return "Chase Bliss Audio / AustinDSP"; }
    const char* getLicense() const override { return "MIT"; }
    uint32_t getVersion() const override { return d_version(1, 2, 0); }
    int64_t getUniqueId() const override { return d_cconst('C', 'B', 'G', 'R'); }

    void sampleRateChanged(double newSampleRate) override {
        fSampleRate = (float)newSampleRate;
        clearBuffers();
    }

    void clearBuffers() {
        fRampPhase = 0.0f;
        fSmoothLfo = 0.0f;
        fRandomTarget = 0.5f;
        fRandomCurrent = 0.5f;
        for (int i = 0; i < 2; ++i) {
            fLowpassL[i] = 0.0f;
            fLowpassR[i] = 0.0f;
        }
    }

    void initParameter(uint32_t index, Parameter& parameter) override {
        parameter.hints = kParameterIsAutomatable;
        switch(index) {
            case pVolume:
                parameter.name = "Volume";
                parameter.symbol = "volume";
                parameter.ranges.def = 0.5f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
            case pRate:
                parameter.name = "Rate";
                parameter.symbol = "rate";
                parameter.unit = "Hz";
                parameter.ranges.def = 0.5f;
                parameter.ranges.min = 0.05f;
                parameter.ranges.max = 15.0f;
                break;
            case pDepth:
                parameter.name = "Depth";
                parameter.symbol = "depth";
                parameter.ranges.def = 0.7f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
            case pWaveform:
                parameter.name = "Waveform";
                parameter.symbol = "waveform";
                parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
                parameter.ranges.def = 0.0f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 5.0f;
                break;
            case pDrive:
                parameter.name = "Drive";
                parameter.symbol = "drive";
                parameter.ranges.def = 0.0f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
            case pTone:
                parameter.name = "Tone";
                parameter.symbol = "tone";
                parameter.ranges.def = 0.5f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
            case pHarmonic:
                parameter.name = "Harmonic Mode";
                parameter.symbol = "harmonic";
                parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
                parameter.ranges.def = 0.0f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
            case pMix:
                parameter.name = "Mix";
                parameter.symbol = "mix";
                parameter.ranges.def = 1.0f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
            case pRamp:
                parameter.name = "Ramp";
                parameter.symbol = "ramp";
                parameter.ranges.def = 0.0f;
                parameter.ranges.min = 0.0f;
                parameter.ranges.max = 1.0f;
                break;
        }
    }

    float getParameterValue(uint32_t index) const override { return fParams[index]; }
    void setParameterValue(uint32_t index, float value) override { fParams[index] = value; }

    void run(const float** inputs, float** outputs, uint32_t frames) override {
        const float* inL = inputs[0];
        const float* inR = inputs[1];
        float* outL = outputs[0];
        float* outR = outputs[1];

        float volume = fParams[pVolume] * 2.0f;
        float rate = fParams[pRate];
        float depth = fParams[pDepth];
        int waveform = (int)(fParams[pWaveform] + 0.5f);
        float drive = fParams[pDrive];
        float tone = fParams[pTone];
        int harmonic = (int)(fParams[pHarmonic] + 0.5f);
        float mix = fParams[pMix];
        float ramp = fParams[pRamp];

        float rampModVal = 1.0f;
        if (ramp > 0.001f) {
            float rampFreq = 0.05f + ramp * 1.95f;
            fRampPhase += (rampFreq * frames) / fSampleRate;
            if (fRampPhase >= 1.0f) fRampPhase -= 1.0f;
            rampModVal = (fRampPhase < 0.5f) ? (fRampPhase * 2.0f) : ((1.0f - fRampPhase) * 2.0f);
        } else {
            fRampPhase = 0.0f;
        }

        float effectiveDepth = depth * (0.1f + 0.9f * rampModVal);
        float lfoInc = rate / fSampleRate;

        float cutoff = 800.0f;
        float cCoeff = 1.0f - std::exp(-2.0f * 3.14159265f * cutoff / fSampleRate);

        for (uint32_t i = 0; i < frames; ++i) {
            fPhase += lfoInc;
            if (fPhase >= 1.0f) {
                fPhase -= 1.0f;
                if (waveform == 5) {
                    fRandomCurrent = fRandomTarget;
                    fRandomTarget = (float)std::rand() / (float)RAND_MAX;
                }
            }

            float rawLfo = 0.0f;
            switch (waveform) {
                case 0: // Sine
                    rawLfo = 0.5f - 0.5f * std::cos(fPhase * 6.2831853f);
                    break;
                case 1: // Triangle
                    rawLfo = (fPhase < 0.5f) ? (fPhase * 2.0f) : ((1.0f - fPhase) * 2.0f);
                    break;
                case 2: // Square
                    rawLfo = (fPhase < 0.5f) ? 0.0f : 1.0f;
                    break;
                case 3: // Ramp Up
                    rawLfo = fPhase;
                    break;
                case 4: // Ramp Down
                    rawLfo = 1.0f - fPhase;
                    break;
                case 5: // Random
                    rawLfo = fRandomCurrent + (fRandomTarget - fRandomCurrent) * fPhase;
                    break;
            }

            float smoothingFactor = (waveform == 2 || waveform == 5) ? 0.03f : 0.4f;
            fSmoothLfo += (rawLfo - fSmoothLfo) * smoothingFactor;

            float dryL = inL[i];
            float dryR = inR[i];

            float processedL = dryL;
            float processedR = dryR;
            if (drive > 0.001f) {
                float pregain = 1.0f + drive * 8.0f;
                processedL = std::tanh(processedL * pregain) / std::tanh(pregain);
                processedR = std::tanh(processedR * pregain) / std::tanh(pregain);
            }

            if (harmonic == 1) {
                fLowpassL[0] += cCoeff * (processedL - fLowpassL[0]);
                float lowL = fLowpassL[0];
                float highL = processedL - lowL;

                fLowpassR[0] += cCoeff * (processedR - fLowpassR[0]);
                float lowR = fLowpassR[0];
                float highR = processedR - lowR;

                float lowGain = 1.0f - effectiveDepth * fSmoothLfo;
                float highGain = 1.0f - effectiveDepth * (1.0f - fSmoothLfo);

                processedL = lowL * lowGain + highL * highGain;
                processedR = lowR * lowGain + highR * highGain;
            } else {
                float tremGain = 1.0f - effectiveDepth * (1.0f - fSmoothLfo);
                processedL *= tremGain;
                processedR *= tremGain;
            }

            if (tone < 0.49f || tone > 0.51f) {
                float tFactor = tone * 2.0f;
                if (tFactor < 1.0f) {
                    fLowpassL[1] += 0.2f * (processedL - fLowpassL[1]);
                    processedL = processedL * tFactor + fLowpassL[1] * (1.0f - tFactor);
                    fLowpassR[1] += 0.2f * (processedR - fLowpassR[1]);
                    processedR = processedR * tFactor + fLowpassR[1] * (1.0f - tFactor);
                }
            }

            processedL = dryL * (1.0f - mix) + processedL * mix;
            processedR = dryR * (1.0f - mix) + processedR * mix;

            outL[i] = processedL * volume;
            outR[i] = processedR * volume;
        }
    }

private:
    float fParams[kParameterCount];
    float fSampleRate;
    float fPhase;
    float fRampPhase;
    float fSmoothLfo;
    float fRandomTarget;
    float fRandomCurrent;
    float fLowpassL[2];
    float fLowpassR[2];

    DISTRHO_DECLARE_NON_COPYABLE(GravitasPlugin)
};

Plugin* createPlugin() { return new GravitasPlugin(); }

END_NAMESPACE_DISTRHO
endef

define GRAV_PLUGIN_MAKEFILE
#!/usr/bin/make -f
NAME      = gravitas
FILES_DSP = Plugin.cpp
include ../../Makefile.plugins.mk
TARGETS = lv2_dsp
all: $(TARGETS)
endef

define GRAV_MANIFEST_TTL
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas>
    a lv2:Plugin ;
    lv2:binary <gravitas_dsp.so> ;
    rdfs:seeAlso <gravitas.ttl> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-classic-bias>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:seeAlso <classic-bias.ttl> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-harmonic-pulsar>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:seeAlso <harmonic-pulsar.ttl> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-choppy-square>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:seeAlso <choppy-square.ttl> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-overdriven-ramp>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:seeAlso <overdriven-ramp.ttl> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-random-flutter>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:seeAlso <random-flutter.ttl> .
endef

define GRAV_PLUGIN_TTL
@prefix lv2:   <http://lv2plug.in/ns/lv2core#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix doap:  <http://usefulinc.com/ns/doap#> .
@prefix units: <http://lv2plug.in/ns/extensions/units#> .
@prefix pset:  <http://lv2plug.in/ns/ext/presets#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas>
    a lv2:Plugin ;
    doap:name "Chase Bliss Audio Gravitas MK II" ;
    doap:license <https://opensource.org/licenses/MIT> ;
    lv2:project <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    lv2:optionalFeature lv2:hardRTCapable ;
    lv2:port
    [
        a lv2:InputPort, lv2:AudioPort ;
        lv2:index 0 ;
        lv2:symbol "audio_in_l" ;
        lv2:name "Audio Input L" ;
    ] ,
    [
        a lv2:InputPort, lv2:AudioPort ;
        lv2:index 1 ;
        lv2:symbol "audio_in_r" ;
        lv2:name "Audio Input R" ;
    ] ,
    [
        a lv2:OutputPort, lv2:AudioPort ;
        lv2:index 2 ;
        lv2:symbol "audio_out_l" ;
        lv2:name "Audio Output L" ;
    ] ,
    [
        a lv2:OutputPort, lv2:AudioPort ;
        lv2:index 3 ;
        lv2:symbol "audio_out_r" ;
        lv2:name "Audio Output R" ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 4 ;
        lv2:symbol "volume" ;
        lv2:name "Volume" ;
        lv2:default 0.5 ;
        lv2:minimum 0.0 ;
        lv2:maximum 1.0 ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 5 ;
        lv2:symbol "rate" ;
        lv2:name "Rate" ;
        lv2:default 0.5 ;
        lv2:minimum 0.05 ;
        lv2:maximum 15.0 ;
        units:unit units:hz ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 6 ;
        lv2:symbol "depth" ;
        lv2:name "Depth" ;
        lv2:default 0.7 ;
        lv2:minimum 0.0 ;
        lv2:maximum 1.0 ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 7 ;
        lv2:symbol "waveform" ;
        lv2:name "Waveform" ;
        lv2:default 0 ;
        lv2:minimum 0 ;
        lv2:maximum 5 ;
        lv2:portProperty lv2:enumeration ;
        lv2:scalePoint [ rdfs:label "Sine" ; rdf:value 0 ] ;
        lv2:scalePoint [ rdfs:label "Triangle" ; rdf:value 1 ] ;
        lv2:scalePoint [ rdfs:label "Square" ; rdf:value 2 ] ;
        lv2:scalePoint [ rdfs:label "Ramp Up" ; rdf:value 3 ] ;
        lv2:scalePoint [ rdfs:label "Ramp Down" ; rdf:value 4 ] ;
        lv2:scalePoint [ rdfs:label "Random" ; rdf:value 5 ] ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 8 ;
        lv2:symbol "drive" ;
        lv2:name "Drive" ;
        lv2:default 0.0 ;
        lv2:minimum 0.0 ;
        lv2:maximum 1.0 ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 9 ;
        lv2:symbol "tone" ;
        lv2:name "Tone" ;
        lv2:default 0.5 ;
        lv2:minimum 0.0 ;
        lv2:maximum 1.0 ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 10 ;
        lv2:symbol "harmonic" ;
        lv2:name "Harmonic Mode" ;
        lv2:default 0 ;
        lv2:minimum 0 ;
        lv2:maximum 1 ;
        lv2:portProperty lv2:enumeration ;
        lv2:scalePoint [ rdfs:label "Standard" ; rdf:value 0 ] ;
        lv2:scalePoint [ rdfs:label "Harmonic" ; rdf:value 1 ] ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 11 ;
        lv2:symbol "mix" ;
        lv2:name "Mix" ;
        lv2:default 1.0 ;
        lv2:minimum 0.0 ;
        lv2:maximum 1.0 ;
    ] ,
    [
        a lv2:InputPort, lv2:ControlPort ;
        lv2:index 12 ;
        lv2:symbol "ramp" ;
        lv2:name "Ramp" ;
        lv2:default 0.0 ;
        lv2:minimum 0.0 ;
        lv2:maximum 1.0 ;
    ] .
endef

define GRAV_PRESET_1
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-classic-bias>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:label "Classic Bias" ;
    lv2:port
    [ lv2:symbol "volume" ; pset:value 0.5 ] ,
    [ lv2:symbol "rate" ; pset:value 0.4 ] ,
    [ lv2:symbol "depth" ; pset:value 0.7 ] ,
    [ lv2:symbol "waveform" ; pset:value 0 ] ,
    [ lv2:symbol "drive" ; pset:value 0.0 ] ,
    [ lv2:symbol "tone" ; pset:value 0.5 ] ,
    [ lv2:symbol "harmonic" ; pset:value 0 ] ,
    [ lv2:symbol "mix" ; pset:value 1.0 ] ,
    [ lv2:symbol "ramp" ; pset:value 0.0 ] .
endef

define GRAV_PRESET_2
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-harmonic-pulsar>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:label "Harmonic Pulsar" ;
    lv2:port
    [ lv2:symbol "volume" ; pset:value 0.6 ] ,
    [ lv2:symbol "rate" ; pset:value 1.5 ] ,
    [ lv2:symbol "depth" ; pset:value 0.9 ] ,
    [ lv2:symbol "waveform" ; pset:value 1 ] ,
    [ lv2:symbol "drive" ; pset:value 0.2 ] ,
    [ lv2:symbol "tone" ; pset:value 0.7 ] ,
    [ lv2:symbol "harmonic" ; pset:value 1 ] ,
    [ lv2:symbol "mix" ; pset:value 1.0 ] ,
    [ lv2:symbol "ramp" ; pset:value 0.3 ] .
endef

define GRAV_PRESET_3
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-choppy-square>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:label "Choppy Square" ;
    lv2:port
    [ lv2:symbol "volume" ; pset:value 0.5 ] ,
    [ lv2:symbol "rate" ; pset:value 3.0 ] ,
    [ lv2:symbol "depth" ; pset:value 1.0 ] ,
    [ lv2:symbol "waveform" ; pset:value 2 ] ,
    [ lv2:symbol "drive" ; pset:value 0.1 ] ,
    [ lv2:symbol "tone" ; pset:value 0.5 ] ,
    [ lv2:symbol "harmonic" ; pset:value 0 ] ,
    [ lv2:symbol "mix" ; pset:value 1.0 ] ,
    [ lv2:symbol "ramp" ; pset:value 0.0 ] .
endef

define GRAV_PRESET_4
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-overdriven-ramp>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:label "Overdriven Ramp" ;
    lv2:port
    [ lv2:symbol "volume" ; pset:value 0.5 ] ,
    [ lv2:symbol "rate" ; pset:value 2.0 ] ,
    [ lv2:symbol "depth" ; pset:value 0.8 ] ,
    [ lv2:symbol "waveform" ; pset:value 3 ] ,
    [ lv2:symbol "drive" ; pset:value 0.6 ] ,
    [ lv2:symbol "tone" ; pset:value 0.6 ] ,
    [ lv2:symbol "harmonic" ; pset:value 0 ] ,
    [ lv2:symbol "mix" ; pset:value 1.0 ] ,
    [ lv2:symbol "ramp" ; pset:value 0.5 ] .
endef

define GRAV_PRESET_5
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix pset: <http://lv2plug.in/ns/ext/presets#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://github.com/austin-dsp/lv2-plugins/gravitas#preset-random-flutter>
    a pset:Preset ;
    lv2:appliesTo <https://github.com/austin-dsp/lv2-plugins/gravitas> ;
    rdfs:label "Random Flutter" ;
    lv2:port
    [ lv2:symbol "volume" ; pset:value 0.5 ] ,
    [ lv2:symbol "rate" ; pset:value 4.5 ] ,
    [ lv2:symbol "depth" ; pset:value 0.5 ] ,
    [ lv2:symbol "waveform" ; pset:value 5 ] ,
    [ lv2:symbol "drive" ; pset:value 0.0 ] ,
    [ lv2:symbol "tone" ; pset:value 0.5 ] ,
    [ lv2:symbol "harmonic" ; pset:value 1 ] ,
    [ lv2:symbol "mix" ; pset:value 1.0 ] ,
    [ lv2:symbol "ramp" ; pset:value 0.2 ] .
endef

export GRAV_PLUGIN_INFO_H
export GRAV_PLUGIN_CPP
export GRAV_PLUGIN_MAKEFILE
export GRAV_MANIFEST_TTL
export GRAV_PLUGIN_TTL
export GRAV_PRESET_1
export GRAV_PRESET_2
export GRAV_PRESET_3
export GRAV_PRESET_4
export GRAV_PRESET_5

define GRAV_CONFIGURE_CMDS
	mkdir -p $(@D)/examples/gravitas
	printf '%s' "$$GRAV_PLUGIN_INFO_H" > $(@D)/examples/gravitas/DistrhoPluginInfo.h
	printf '%s' "$$GRAV_PLUGIN_CPP" > $(@D)/examples/gravitas/Plugin.cpp
	printf '%s' "$$GRAV_PLUGIN_MAKEFILE" > $(@D)/examples/gravitas/Makefile
endef

define GRAV_BUILD_CMDS
	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) NOOPT=true -C $(@D)/examples/gravitas lv2_dsp
endef

define GRAV_INSTALL_TARGET_CMDS
	mkdir -p $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2
	cp $(@D)/bin/gravitas.lv2/gravitas_dsp.so $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/
	printf '%s' "$$GRAV_MANIFEST_TTL" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/manifest.ttl
	printf '%s' "$$GRAV_PLUGIN_TTL" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/gravitas.ttl
	printf '%s' "$$GRAV_PRESET_1" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/classic-bias.ttl
	printf '%s' "$$GRAV_PRESET_2" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/harmonic-pulsar.ttl
	printf '%s' "$$GRAV_PRESET_3" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/choppy-square.ttl
	printf '%s' "$$GRAV_PRESET_4" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/overdriven-ramp.ttl
	printf '%s' "$$GRAV_PRESET_5" > $(TARGET_DIR)/usr/lib/lv2/gravitas.lv2/random-flutter.ttl
endef

$(eval $(generic-package))