This commit is contained in:
yaw-man 2022-08-10 10:54:24 -03:00
parent f2aae2a502
commit 64b045fa77
3 changed files with 114 additions and 76 deletions

View File

@ -7,7 +7,7 @@
#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_INPUTS 0
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_WANT_TIMEPOS 1
#define DISTRHO_UI_USE_NANOVG 1
@ -24,6 +24,7 @@ enum Parameters {
kParameterTabletY,
kParameterTabletZ,
kParameterTabletPressure,
kParameterTime,
kParameterCount
};

View File

@ -2,11 +2,12 @@
START_NAMESPACE_DISTRHO
class TabPlugin : public Plugin
class TabPlugin : public Plugin
{
public:
TabPlugin()
: Plugin(kParameterCount, 0, 0)
: Plugin(kParameterCount, 0, 0),
sampleRate(getSampleRate())
{
// clear all parameters
std::memset(fParameters, 0, sizeof(float) * kParameterCount);
@ -25,7 +26,7 @@ protected:
void initParameter(uint32_t index, Parameter& parameter) override
{
parameter.hints = kParameterIsAutomable | kParameterIsOutput;
parameter.hints = kParameterIsAutomable;
parameter.ranges.def = 0.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 16777216.0f;
@ -56,40 +57,69 @@ protected:
parameter.ranges.min = 0.0f;
parameter.ranges.max = 999.0f;
break;
case kParameterTime:
parameter.name = "t";
parameter.symbol = "t";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 999.0f;
parameter.hints |= kParameterIsOutput;
break;
}
}
void sampleRateChanged(double newRate) override
{
sampleRate = newRate;
}
float getParameterValue(uint32_t index) const override
{
return fParameters[index];
}
void setParameterValue(uint32_t, float) override
void setParameterValue(uint32_t idx, float val) override
{
// this is only called for input parameters, which we have none of.
fParameters[idx] = val;
switch (idx) {
case kParameterTabletX:
period = 0.02f * (0.001f * val) * sampleRate;
break;
case kParameterTabletY:
break;
case kParameterTabletZ:
break;
case kParameterTabletPressure:
volume = 0.001f * val;
break;
}
}
void run(const float** inputs, float** outputs, uint32_t frames) override
{
/**
This plugin does nothing, it just demonstrates information usage.
So here we directly copy inputs over outputs, leaving the audio untouched.
We need to be careful in case the host re-uses the same buffer for both inputs and outputs.
*/
if (outputs[0] != inputs[0])
std::memcpy(outputs[0], inputs[0], sizeof(float) * frames);
if (outputs[1] != inputs[1])
std::memcpy(outputs[1], inputs[1], sizeof(float) * frames);
for (uint32_t i = 0; i < frames; ++i) {
counter++;
if (counter > period) {
outputs[0][i] = outputs[1][i] = volume;
counter = 0;
}
else {
outputs[0][i] = outputs[1][i] = 0.0f;
}
}
// get time position
// Force UI to repaint via parameter change callback.
const TimePosition& timePos(getTimePosition());
fParameters[kParameterTabletPressure] = timePos.bbt.tick;
fParameters[kParameterTime] = timePos.bbt.tick;
}
private:
float fParameters[kParameterCount];
float period = 0.f;
float counter = 0.f;
float volume = 0.f;
float sampleRate;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabPlugin)
};

View File

@ -34,7 +34,10 @@ protected:
void parameterChanged(uint32_t index, float value) override
{
if (index != kParameterTime) {
fParameters[index] = value;
return;
}
//Lire donnés de la tablet
tab.NewPacket();
@ -49,6 +52,10 @@ protected:
fParameters[kParameterTabletZ] = z;
fParameters[kParameterTabletPressure] = p;
setParameterValue(kParameterTabletX, x);
setParameterValue(kParameterTabletY, y);
setParameterValue(kParameterTabletZ, z);
setParameterValue(kParameterTabletPressure, p);
repaint();
}