MVP
This commit is contained in:
parent
f2aae2a502
commit
64b045fa77
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -2,101 +2,131 @@
|
|||
|
||||
START_NAMESPACE_DISTRHO
|
||||
|
||||
class TabPlugin : public Plugin
|
||||
class TabPlugin : public Plugin
|
||||
{
|
||||
public:
|
||||
TabPlugin()
|
||||
: Plugin(kParameterCount, 0, 0)
|
||||
{
|
||||
// clear all parameters
|
||||
std::memset(fParameters, 0, sizeof(float) * kParameterCount);
|
||||
TabPlugin()
|
||||
: Plugin(kParameterCount, 0, 0),
|
||||
sampleRate(getSampleRate())
|
||||
{
|
||||
// clear all parameters
|
||||
std::memset(fParameters, 0, sizeof(float) * kParameterCount);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
const char* getLabel() const override { return "yaw-tab"; }
|
||||
const char* getDescription() const override { return "Drawing tablet synth UI"; }
|
||||
const char* getMaker() const override { return "yaw-audio"; }
|
||||
const char* getHomePage() const override { return "https://yaw.man/plugins/yaw-tab"; }
|
||||
const char* getLicense() const override { return "ISC"; }
|
||||
uint32_t getVersion() const override { return d_version(1, 0, 0); }
|
||||
int64_t getUniqueId() const override { return d_cconst('y', 'w', 't', 'b'); }
|
||||
const char* getLabel() const override { return "yaw-tab"; }
|
||||
const char* getDescription() const override { return "Drawing tablet synth UI"; }
|
||||
const char* getMaker() const override { return "yaw-audio"; }
|
||||
const char* getHomePage() const override { return "https://yaw.man/plugins/yaw-tab"; }
|
||||
const char* getLicense() const override { return "ISC"; }
|
||||
uint32_t getVersion() const override { return d_version(1, 0, 0); }
|
||||
int64_t getUniqueId() const override { return d_cconst('y', 'w', 't', 'b'); }
|
||||
|
||||
|
||||
void initParameter(uint32_t index, Parameter& parameter) override
|
||||
{
|
||||
parameter.hints = kParameterIsAutomable | kParameterIsOutput;
|
||||
parameter.ranges.def = 0.0f;
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 16777216.0f;
|
||||
void initParameter(uint32_t index, Parameter& parameter) override
|
||||
{
|
||||
parameter.hints = kParameterIsAutomable;
|
||||
parameter.ranges.def = 0.0f;
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 16777216.0f;
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case kParameterTabletX:
|
||||
parameter.name = "x";
|
||||
parameter.symbol = "x";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
case kParameterTabletY:
|
||||
parameter.name = "y";
|
||||
parameter.symbol = "y";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
case kParameterTabletZ:
|
||||
parameter.name = "z";
|
||||
parameter.symbol = "z";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
case kParameterTabletPressure:
|
||||
parameter.name = "p";
|
||||
parameter.symbol = "p";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (index)
|
||||
{
|
||||
case kParameterTabletX:
|
||||
parameter.name = "x";
|
||||
parameter.symbol = "x";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
case kParameterTabletY:
|
||||
parameter.name = "y";
|
||||
parameter.symbol = "y";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
case kParameterTabletZ:
|
||||
parameter.name = "z";
|
||||
parameter.symbol = "z";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
break;
|
||||
case kParameterTabletPressure:
|
||||
parameter.name = "p";
|
||||
parameter.symbol = "p";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
float getParameterValue(uint32_t index) const override
|
||||
{
|
||||
return fParameters[index];
|
||||
void sampleRateChanged(double newRate) override
|
||||
{
|
||||
sampleRate = newRate;
|
||||
}
|
||||
|
||||
}
|
||||
float getParameterValue(uint32_t index) const override
|
||||
{
|
||||
return fParameters[index];
|
||||
|
||||
void setParameterValue(uint32_t, float) override
|
||||
{
|
||||
// this is only called for input parameters, which we have none of.
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
void setParameterValue(uint32_t idx, float val) override
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputs[1] != inputs[1])
|
||||
std::memcpy(outputs[1], inputs[1], sizeof(float) * frames);
|
||||
void run(const float** inputs, float** outputs, uint32_t frames) override
|
||||
{
|
||||
|
||||
// get time position
|
||||
const TimePosition& timePos(getTimePosition());
|
||||
fParameters[kParameterTabletPressure] = timePos.bbt.tick;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Force UI to repaint via parameter change callback.
|
||||
const TimePosition& timePos(getTimePosition());
|
||||
fParameters[kParameterTime] = timePos.bbt.tick;
|
||||
}
|
||||
|
||||
private:
|
||||
float fParameters[kParameterCount];
|
||||
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)
|
||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabPlugin)
|
||||
};
|
||||
|
||||
Plugin* createPlugin()
|
||||
{
|
||||
return new TabPlugin();
|
||||
return new TabPlugin();
|
||||
}
|
||||
|
||||
END_NAMESPACE_DISTRHO
|
||||
|
|
|
@ -34,7 +34,10 @@ protected:
|
|||
void parameterChanged(uint32_t index, float value) override
|
||||
{
|
||||
|
||||
fParameters[index] = value;
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue