From e16fda511d7845a733bf8bfccfe0d174bb236f04 Mon Sep 17 00:00:00 2001 From: yaw-man Date: Sat, 13 Aug 2022 12:02:47 -0300 Subject: [PATCH] Removed TIMEPOS requirement; Removed rendundant parameter changes; Rescaled parameters (now 0.0 to 1.0); Removed double float conversion warnings; Refactored tablet data copy; --- src/yaw-tab/DistrhoPluginInfo.h | 1 - src/yaw-tab/dsp.cpp | 26 ++++++---------- src/yaw-tab/tab.cpp | 18 ++++++----- src/yaw-tab/ui.cpp | 53 ++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/yaw-tab/DistrhoPluginInfo.h b/src/yaw-tab/DistrhoPluginInfo.h index b63e1e4..02b0c46 100644 --- a/src/yaw-tab/DistrhoPluginInfo.h +++ b/src/yaw-tab/DistrhoPluginInfo.h @@ -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 diff --git a/src/yaw-tab/dsp.cpp b/src/yaw-tab/dsp.cpp index 7728ce9..38426bc 100644 --- a/src/yaw-tab/dsp.cpp +++ b/src/yaw-tab/dsp.cpp @@ -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(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) }; diff --git a/src/yaw-tab/tab.cpp b/src/yaw-tab/tab.cpp index 45e93c6..25d51c2 100644 --- a/src/yaw-tab/tab.cpp +++ b/src/yaw-tab/tab.cpp @@ -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(TabletX.axMax); ctx.lcInOrgY = TabletY.axMin; ctx.lcInExtY = TabletY.axMax; ctx.lcOutOrgY = TabletY.axMin; ctx.lcOutExtY = TabletY.axMax; - extY = TabletY.axMax; + extY = static_cast(TabletY.axMax); ctx.lcInOrgZ = TabletZ.axMin; ctx.lcInExtZ = TabletZ.axMax; ctx.lcOutOrgZ = TabletZ.axMin; ctx.lcOutExtZ = TabletZ.axMax; - extZ = TabletZ.axMax; + extZ = static_cast(TabletZ.axMax); - extP = TabletPressure.axMax; + extP = static_cast(TabletPressure.axMax); hctx = gpWTOpenA(hwnd, &ctx, FALSE); diff --git a/src/yaw-tab/ui.cpp b/src/yaw-tab/ui.cpp index d678491..7b1d5d6 100644 --- a/src/yaw-tab/ui.cpp +++ b/src/yaw-tab/ui.cpp @@ -31,6 +31,34 @@ public: protected: + void getTabletData() + { + //Lire donnés de la tablet + tab.NewPacket(); + + float x = static_cast(tab.pkt.pkX) / tab.extX; + float y = static_cast(tab.pkt.pkY) / tab.extY; + float z = static_cast(tab.pkt.pkZ) / tab.extZ; + float p = static_cast(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(tab.pkt.pkX) / tab.extX; - float y = 1000.0f * static_cast(tab.pkt.pkY) / tab.extY; - float z = 1000.0f * static_cast(tab.pkt.pkZ) / tab.extZ; - float p = 1000.0f * static_cast(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);