From 7246c3b85324bb595b4a2816db1426b5f9969470 Mon Sep 17 00:00:00 2001 From: yaw-man Date: Tue, 9 Aug 2022 12:54:02 -0300 Subject: [PATCH] Afficher l'axis x --- src/yaw-tab/DistrhoPluginInfo.h | 3 +++ src/yaw-tab/dsp.cpp | 21 +++++++++++++++++++++ src/yaw-tab/tab.cpp | 29 ++++++++++++++++++++++++++--- src/yaw-tab/ui.cpp | 14 +++++++++++++- src/yaw-tab/wtutil.h | 2 ++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/yaw-tab/DistrhoPluginInfo.h b/src/yaw-tab/DistrhoPluginInfo.h index 6344527..0ecaa0c 100644 --- a/src/yaw-tab/DistrhoPluginInfo.h +++ b/src/yaw-tab/DistrhoPluginInfo.h @@ -33,6 +33,9 @@ enum Parameters { kParameterTimeBeatType, kParameterTimeTicksPerBeat, kParameterTimeBeatsPerMinute, + kParameterTabletX, + kParameterTabletY, + kParameterTabletPressure, kParameterCount }; diff --git a/src/yaw-tab/dsp.cpp b/src/yaw-tab/dsp.cpp index 4331e9e..1a238e8 100644 --- a/src/yaw-tab/dsp.cpp +++ b/src/yaw-tab/dsp.cpp @@ -153,6 +153,24 @@ protected: parameter.name = "TimeBeatsPerMinute"; parameter.symbol = "time_beatsperminute"; break; + case kParameterTabletX: + parameter.name = "TabletX"; + parameter.symbol = "tablet_x"; + parameter.ranges.min = 0; + parameter.ranges.max = 1024; + break; + case kParameterTabletY: + parameter.name = "TabletY"; + parameter.symbol = "tablet_y"; + parameter.ranges.min = 0; + parameter.ranges.max = 1024; + break; + case kParameterTabletPressure: + parameter.name = "TabletPressure"; + parameter.symbol = "tablet_p"; + parameter.ranges.min = 0; + parameter.ranges.max = 1024; + break; } } @@ -231,6 +249,9 @@ protected: fParameters[kParameterTimeTicksPerBeat] = 0.0f; fParameters[kParameterTimeBeatsPerMinute] = 0.0f; } + + //il faut seulment changer un des parametres pour mettre à jour les donnés de la tablet + fParameters[kParameterTabletPressure] = 0; } /* -------------------------------------------------------------------------------------------------------- diff --git a/src/yaw-tab/tab.cpp b/src/yaw-tab/tab.cpp index ad0bc3c..a71953a 100644 --- a/src/yaw-tab/tab.cpp +++ b/src/yaw-tab/tab.cpp @@ -14,40 +14,60 @@ public: Tablet(HWND hwnd) { if (!hwnd) { return; } - if (!LoadWintab() || !gpWTInfoA(0, 0, nullptr)) { + if (!LoadWintab() || !gpWTInfoA(0, 0, NULL)) { return; } + wintabAvailable = true; NewContext(hwnd); } ~Tablet() { + gpWTClose(hctx); //Chui pas certain s'il faut fermer le context. UnloadWintab(); } + void NewPacket() { + //Serial number of newest packet. + UINT oldest, newest; + gpWTQueuePacketsEx(hctx, &oldest, &newest); + + //Store newest packet in pkt, flush older packets. + gpWTPacket(hctx, newest, &pkt); + } + + bool wintabAvailable = false; + PACKET pkt = { 0 }; + UINT maxPressure = 1; + private: - HCTX hctx = nullptr; + HCTX hctx = NULL; UINT wDevice = 0; AXIS TabletX = { 0 }; AXIS TabletY = { 0 }; + AXIS TabletPressure = { 0 }; LOGCONTEXT ctx = {}; void NewContext(HWND hwnd) { + if (hctx) { gpWTClose(hctx); } + ctx.lcOptions |= CXO_SYSTEM; gpWTInfoA(WTI_DEFSYSCTX, 0, &ctx); ctx.lcOptions |= CXO_MESSAGES; //TODO: checker çela ctx.lcPktData = PACKETDATA; ctx.lcPktMode = PACKETMODE; - + //Tablet extents. gpWTInfoA(WTI_DEVICES, DVC_X, &TabletX); gpWTInfoA(WTI_DEVICES, DVC_Y, &TabletY); + gpWTInfoA(WTI_DEVICES, DVC_NPRESSURE, &TabletPressure); ctx.lcInOrgX = 0; ctx.lcInOrgY = 0; ctx.lcInExtX = TabletX.axMax; ctx.lcInExtY = TabletY.axMax; + maxPressure = TabletPressure.axMax; ctx.lcOutOrgX = GetSystemMetrics(SM_XVIRTUALSCREEN); ctx.lcOutOrgY = GetSystemMetrics(SM_YVIRTUALSCREEN); @@ -55,6 +75,9 @@ private: ctx.lcOutExtY = -GetSystemMetrics(SM_CYVIRTUALSCREEN); hctx = gpWTOpenA(hwnd, &ctx, FALSE); + + gpWTEnable(hctx, TRUE); } + }; \ No newline at end of file diff --git a/src/yaw-tab/ui.cpp b/src/yaw-tab/ui.cpp index 51bd0b3..ba1079b 100644 --- a/src/yaw-tab/ui.cpp +++ b/src/yaw-tab/ui.cpp @@ -15,7 +15,7 @@ public: fResizable(isResizable()), fScale(1.0f), fScaleFactor(getScaleFactor()), - tab(getWindow().getNativeWindowHandle()) + tab(reinterpret_cast(getWindow().getNativeWindowHandle())) { std::memset(fParameters, 0, sizeof(float) * kParameterCount); std::memset(fStrBuf, 0, sizeof(char) * (0xff + 1)); @@ -45,6 +45,14 @@ protected: return; fParameters[index] = value; + + //Lire donnés de la tablet + tab.NewPacket(); + fParameters[kParameterTabletX] = tab.pkt.pkX; + fParameters[kParameterTabletY] = tab.pkt.pkY; + fParameters[kParameterTabletPressure] = tab.pkt.pkNormalPressure; + + repaint(); } @@ -163,6 +171,10 @@ protected: drawLeft(x, y, "BPM:"); drawRight(x, y, getTextBufFloat(fParameters[kParameterTimeBeatsPerMinute])); y += lineHeight; + + drawLeft(x, y, "x:"); + drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletX])); + y += lineHeight; } void onResize(const ResizeEvent& ev) override diff --git a/src/yaw-tab/wtutil.h b/src/yaw-tab/wtutil.h index 7e04f14..b8f9e3f 100644 --- a/src/yaw-tab/wtutil.h +++ b/src/yaw-tab/wtutil.h @@ -47,6 +47,7 @@ using WTMGRDEFCONTEXT = HCTX (API*)(HMGR, BOOL); using WTMGRDEFCONTEXTEX = HCTX (API*)(HMGR, UINT, BOOL); // TODO - add more wintab32 function defs as needed +using WTQPACKETSEX = BOOL(API*)(HCTX, UINT FAR*, UINT FAR*); ////////////////////////////////////////////////////////////////////////////// @@ -75,6 +76,7 @@ extern WTMGRDEFCONTEXT gpWTMgrDefContext; extern WTMGRDEFCONTEXTEX gpWTMgrDefContextEx; // TODO - add more wintab32 function pointers as needed +extern WTQPACKETSEX gpWTQueuePacketsEx; //////////////////////////////////////////////////////////////////////////////