Removed TIMEPOS requirement;
Removed rendundant parameter changes; Rescaled parameters (now 0.0 to 1.0); Removed double float conversion warnings; Refactored tablet data copy;
This commit is contained in:
parent
e3c74ff15d
commit
e16fda511d
|
@ -9,7 +9,6 @@
|
|||
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
|
||||
#define DISTRHO_PLUGIN_NUM_INPUTS 0
|
||||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
|
||||
#define DISTRHO_PLUGIN_WANT_TIMEPOS 1
|
||||
#define DISTRHO_UI_USE_NANOVG 1
|
||||
|
||||
// only checking if supported, not actually used
|
||||
|
|
|
@ -29,40 +29,32 @@ protected:
|
|||
parameter.hints = kParameterIsAutomable;
|
||||
parameter.ranges.def = 0.0f;
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 16777216.0f;
|
||||
parameter.ranges.max = 1.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;
|
||||
case kParameterTime:
|
||||
parameter.name = "t";
|
||||
parameter.symbol = "t";
|
||||
parameter.ranges.min = 0.0f;
|
||||
parameter.ranges.max = 999.0f;
|
||||
parameter.hints |= kParameterIsOutput;
|
||||
parameter.ranges.max = 30.0f;
|
||||
parameter.hints = kParameterIsOutput;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -83,14 +75,14 @@ protected:
|
|||
fParameters[idx] = val;
|
||||
switch (idx) {
|
||||
case kParameterTabletX:
|
||||
period = 0.02f * (0.001f * val) * sampleRate;
|
||||
period = 0.02f * val * static_cast<float>(sampleRate);
|
||||
break;
|
||||
case kParameterTabletY:
|
||||
break;
|
||||
case kParameterTabletZ:
|
||||
break;
|
||||
case kParameterTabletPressure:
|
||||
volume = 0.001f * val;
|
||||
volume = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +101,8 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
// Force UI to repaint via parameter change callback.
|
||||
const TimePosition& timePos(getTimePosition());
|
||||
fParameters[kParameterTime] = timePos.bbt.tick;
|
||||
parity = !parity;
|
||||
fParameters[kParameterTime] += parity ? 1 : -1;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -119,7 +110,8 @@ private:
|
|||
float period = 0.f;
|
||||
float counter = 0.f;
|
||||
float volume = 0.f;
|
||||
float sampleRate;
|
||||
double sampleRate;
|
||||
bool parity = false;
|
||||
|
||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabPlugin)
|
||||
};
|
||||
|
|
|
@ -26,17 +26,19 @@ public:
|
|||
UnloadWintab();
|
||||
}
|
||||
|
||||
void NewPacket() {
|
||||
bool NewPacket() {
|
||||
//Serial number of newest packet.
|
||||
UINT oldest, newest;
|
||||
//This function returns false when it fails.
|
||||
//This function returns false when it fails
|
||||
//which may happen with a full or empty queue.
|
||||
if (!gpWTQueuePacketsEx(hctx, &oldest, &newest)) {
|
||||
//Queue full, flush it all.
|
||||
//Queue may be full, flush it all just in case.
|
||||
gpWTPacketsGet(hctx, gpWTQueueSizeGet(hctx), nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Store newest packet in pkt, flush older packets.
|
||||
gpWTPacket(hctx, newest, &pkt);
|
||||
return gpWTPacket(hctx, newest, &pkt);
|
||||
}
|
||||
|
||||
bool wintabAvailable = false;
|
||||
|
@ -74,21 +76,21 @@ private:
|
|||
ctx.lcInExtX = TabletX.axMax;
|
||||
ctx.lcOutOrgX = TabletX.axMin;
|
||||
ctx.lcOutExtX = TabletX.axMax;
|
||||
extX = TabletX.axMax;
|
||||
extX = static_cast<float>(TabletX.axMax);
|
||||
|
||||
ctx.lcInOrgY = TabletY.axMin;
|
||||
ctx.lcInExtY = TabletY.axMax;
|
||||
ctx.lcOutOrgY = TabletY.axMin;
|
||||
ctx.lcOutExtY = TabletY.axMax;
|
||||
extY = TabletY.axMax;
|
||||
extY = static_cast<float>(TabletY.axMax);
|
||||
|
||||
ctx.lcInOrgZ = TabletZ.axMin;
|
||||
ctx.lcInExtZ = TabletZ.axMax;
|
||||
ctx.lcOutOrgZ = TabletZ.axMin;
|
||||
ctx.lcOutExtZ = TabletZ.axMax;
|
||||
extZ = TabletZ.axMax;
|
||||
extZ = static_cast<float>(TabletZ.axMax);
|
||||
|
||||
extP = TabletPressure.axMax;
|
||||
extP = static_cast<float>(TabletPressure.axMax);
|
||||
|
||||
hctx = gpWTOpenA(hwnd, &ctx, FALSE);
|
||||
|
||||
|
|
|
@ -31,6 +31,34 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
void getTabletData()
|
||||
{
|
||||
//Lire donnés de la tablet
|
||||
tab.NewPacket();
|
||||
|
||||
float x = static_cast<float>(tab.pkt.pkX) / tab.extX;
|
||||
float y = static_cast<float>(tab.pkt.pkY) / tab.extY;
|
||||
float z = static_cast<float>(tab.pkt.pkZ) / tab.extZ;
|
||||
float p = static_cast<float>(tab.pkt.pkNormalPressure) / tab.extP;
|
||||
|
||||
if (x != fParameters[kParameterTabletX]) {
|
||||
setParameterValue(kParameterTabletX, x);
|
||||
fParameters[kParameterTabletX] = x;
|
||||
}
|
||||
if (y != fParameters[kParameterTabletY]) {
|
||||
setParameterValue(kParameterTabletY, y);
|
||||
fParameters[kParameterTabletY] = y;
|
||||
}
|
||||
if (z != fParameters[kParameterTabletZ]) {
|
||||
setParameterValue(kParameterTabletZ, z);
|
||||
fParameters[kParameterTabletZ] = z;
|
||||
}
|
||||
if (p != fParameters[kParameterTabletPressure]) {
|
||||
setParameterValue(kParameterTabletPressure, p);
|
||||
fParameters[kParameterTabletPressure] = p;
|
||||
}
|
||||
}
|
||||
|
||||
void parameterChanged(uint32_t index, float value) override
|
||||
{
|
||||
|
||||
|
@ -39,23 +67,7 @@ protected:
|
|||
return;
|
||||
}
|
||||
|
||||
//Lire donnés de la tablet
|
||||
tab.NewPacket();
|
||||
|
||||
float x = 1000.0f * static_cast<float>(tab.pkt.pkX) / tab.extX;
|
||||
float y = 1000.0f * static_cast<float>(tab.pkt.pkY) / tab.extY;
|
||||
float z = 1000.0f * static_cast<float>(tab.pkt.pkZ) / tab.extZ;
|
||||
float p = 1000.0f * static_cast<float>(tab.pkt.pkNormalPressure) / tab.extP;
|
||||
|
||||
fParameters[kParameterTabletX] = x;
|
||||
fParameters[kParameterTabletY] = y;
|
||||
fParameters[kParameterTabletZ] = z;
|
||||
fParameters[kParameterTabletPressure] = p;
|
||||
|
||||
setParameterValue(kParameterTabletX, x);
|
||||
setParameterValue(kParameterTabletY, y);
|
||||
setParameterValue(kParameterTabletZ, z);
|
||||
setParameterValue(kParameterTabletPressure, p);
|
||||
getTabletData();
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
@ -113,10 +125,9 @@ protected:
|
|||
void drawCircle(float x, float y, float z, float p) {
|
||||
|
||||
static constexpr float circleRadius = 25.f;
|
||||
x *= getWidth() * 0.001f;
|
||||
y = (1000.f - y) * getHeight() * 0.001f;
|
||||
z = 1.f - z * 0.001f;
|
||||
p *= 0.001f;
|
||||
x *= getWidth();
|
||||
y = (1.f - y) * getHeight();
|
||||
z = 1.f - z;
|
||||
|
||||
beginPath();
|
||||
strokeColor(1.f, 1.f, 1.f, 0.5f);
|
||||
|
|
Loading…
Reference in New Issue