From 4b72442df08626097417f67ca49ba355572cb29e Mon Sep 17 00:00:00 2001 From: yaw-man Date: Sun, 7 Aug 2022 20:43:35 -0300 Subject: [PATCH] Ajouter Wintab (1). --- src/yaw-tab/CMakeLists.txt | 8 +- src/yaw-tab/DistrhoPluginInfo.h | 17 ---- src/yaw-tab/dsp.cpp | 15 ++-- src/yaw-tab/tab.cpp | 37 +++++++++ src/yaw-tab/ui.cpp | 18 ----- src/yaw-tab/wtutil.cpp | 137 ++++++++++++++++++++++++++++++++ src/yaw-tab/wtutil.h | 87 ++++++++++++++++++++ 7 files changed, 272 insertions(+), 47 deletions(-) create mode 100644 src/yaw-tab/tab.cpp create mode 100644 src/yaw-tab/wtutil.cpp create mode 100644 src/yaw-tab/wtutil.h diff --git a/src/yaw-tab/CMakeLists.txt b/src/yaw-tab/CMakeLists.txt index cb6f58f..1dde9d2 100644 --- a/src/yaw-tab/CMakeLists.txt +++ b/src/yaw-tab/CMakeLists.txt @@ -3,7 +3,11 @@ dpf_add_plugin(yaw-tab FILES_DSP dsp.cpp FILES_UI + wtutil.cpp + tab.cpp ui.cpp) -target_include_directories( - yaw-tab PUBLIC ".") +target_include_directories(yaw-tab PUBLIC + "." + "../../lib/wintab" +) diff --git a/src/yaw-tab/DistrhoPluginInfo.h b/src/yaw-tab/DistrhoPluginInfo.h index 28dc136..6344527 100644 --- a/src/yaw-tab/DistrhoPluginInfo.h +++ b/src/yaw-tab/DistrhoPluginInfo.h @@ -1,19 +1,3 @@ -/* - * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho - * - * Permission to use, copy, modify, and/or distribute this software for any purpose with - * or without fee is hereby granted, provided that the above copyright notice and this - * permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN - * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - #ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED #define DISTRHO_PLUGIN_INFO_H_INCLUDED @@ -26,7 +10,6 @@ #define DISTRHO_PLUGIN_NUM_INPUTS 2 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2 #define DISTRHO_PLUGIN_WANT_TIMEPOS 1 -#define DISTRHO_UI_USER_RESIZABLE 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 2534d32..4331e9e 100644 --- a/src/yaw-tab/dsp.cpp +++ b/src/yaw-tab/dsp.cpp @@ -2,11 +2,6 @@ START_NAMESPACE_DISTRHO -// ----------------------------------------------------------------------------------------------------------- - -/** - Plugin to show how to get some basic information sent to the UI. - */ class InfoExamplePlugin : public Plugin { public: @@ -31,7 +26,7 @@ protected: */ const char* getLabel() const override { - return "Info"; + return "yaw-tab"; } /** @@ -39,7 +34,7 @@ protected: */ const char* getDescription() const override { - return "Plugin to show how to get some basic information sent to the UI."; + return "Drawing tablet synth UI"; } /** @@ -47,7 +42,7 @@ protected: */ const char* getMaker() const override { - return "DISTRHO"; + return "yaw-audio"; } /** @@ -55,7 +50,7 @@ protected: */ const char* getHomePage() const override { - return "https://github.com/DISTRHO/DPF"; + return "https://yaw.man/plugins/yaw-tab"; } /** @@ -81,7 +76,7 @@ protected: */ int64_t getUniqueId() const override { - return d_cconst('d', 'N', 'f', 'o'); + return d_cconst('y', 'w', 't', 'b'); } /* -------------------------------------------------------------------------------------------------------- diff --git a/src/yaw-tab/tab.cpp b/src/yaw-tab/tab.cpp new file mode 100644 index 0000000..779be6f --- /dev/null +++ b/src/yaw-tab/tab.cpp @@ -0,0 +1,37 @@ +#include +#include +#include "MSGPACK.H" +#include "wintab.h" + +#define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE) +#define PACKETMODE PK_BUTTONS +#include "pktdef.h" +#include "wtutil.h" + +class Tablet { +public: + + Tablet() { + if (!LoadWintab() || !gpWTInfoA(0, 0, nullptr)) { + return; + } + } + + ~Tablet() { + UnloadWintab(); + } + +private: + + HCTX hctx = NULL; + UINT wDevice = 0; + AXIS TabletX = { 0 }; + AXIS TabletY = { 0 }; + LOGCONTEXT ctx = {}; + + void NewContext() { + ctx.lcOptions |= CXO_SYSTEM; + + } + +}; \ No newline at end of file diff --git a/src/yaw-tab/ui.cpp b/src/yaw-tab/ui.cpp index 0834612..ec92507 100644 --- a/src/yaw-tab/ui.cpp +++ b/src/yaw-tab/ui.cpp @@ -1,25 +1,7 @@ -/* - * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho - * - * Permission to use, copy, modify, and/or distribute this software for any purpose with - * or without fee is hereby granted, provided that the above copyright notice and this - * permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN - * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - #include "DistrhoUI.hpp" START_NAMESPACE_DISTRHO -// ----------------------------------------------------------------------------------------------------------- - class InfoExampleUI : public UI { static const uint kInitialWidth = 405; diff --git a/src/yaw-tab/wtutil.cpp b/src/yaw-tab/wtutil.cpp new file mode 100644 index 0000000..2a135a8 --- /dev/null +++ b/src/yaw-tab/wtutil.cpp @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// DESCRIPTION +// Some general-purpose functions for the WinTab demos. +// +// COPYRIGHT +// Copyright (c) 2014-2020 Wacom Co., Ltd. +// All rights reserved. +// +/////////////////////////////////////////////////////////////////////////////// + +#include +#include "wtutil.h" + +////////////////////////////////////////////////////////////////////////////// + +HINSTANCE ghWintab = nullptr; + +WTINFOA gpWTInfoA = nullptr; +WTOPENA gpWTOpenA = nullptr; +WTGETA gpWTGetA = nullptr; +WTSETA gpWTSetA = nullptr; +WTCLOSE gpWTClose = nullptr; +WTPACKET gpWTPacket = nullptr; +WTENABLE gpWTEnable = nullptr; +WTOVERLAP gpWTOverlap = nullptr; +WTSAVE gpWTSave = nullptr; +WTCONFIG gpWTConfig = nullptr; +WTRESTORE gpWTRestore = nullptr; +WTEXTSET gpWTExtSet = nullptr; +WTEXTGET gpWTExtGet = nullptr; +WTQUEUESIZESET gpWTQueueSizeSet = nullptr; +WTDATAPEEK gpWTDataPeek = nullptr; +WTPACKETSGET gpWTPacketsGet = nullptr; +WTMGROPEN gpWTMgrOpen = nullptr; +WTMGRCLOSE gpWTMgrClose = nullptr; +WTMGRDEFCONTEXT gpWTMgrDefContext = nullptr; +WTMGRDEFCONTEXTEX gpWTMgrDefContextEx = nullptr; + +// TODO - add more wintab32 function pointers as needed + +////////////////////////////////////////////////////////////////////////////// +// Purpose +// Find wintab32.dll and load it. +// Find the exported functions we need from it. +// +// Returns +// TRUE on success. +// FALSE on failure. +// +BOOL LoadWintab(void) +{ + // load the wintab32 dll + ghWintab = LoadLibraryA("Wintab32.dll"); + + if (!ghWintab) + { + const DWORD err = GetLastError(); + ShowError("Could not load Wintab32.dll: " + std::to_string(err)); + return FALSE; + } + // Explicitly find the exported Wintab functions in which we are interested. + // We are using the ASCII, not unicode versions (where applicable). + gpWTOpenA = (WTOPENA)GetProcAddress(ghWintab, "WTOpenA"); + gpWTInfoA = (WTINFOA)GetProcAddress(ghWintab, "WTInfoA"); + gpWTGetA = (WTGETA)GetProcAddress(ghWintab, "WTGetA"); + gpWTSetA = (WTSETA)GetProcAddress(ghWintab, "WTSetA"); + gpWTPacket = (WTPACKET)GetProcAddress(ghWintab, "WTPacket"); + gpWTClose = (WTCLOSE)GetProcAddress(ghWintab, "WTClose"); + gpWTEnable = (WTENABLE)GetProcAddress(ghWintab, "WTEnable"); + gpWTOverlap = (WTOVERLAP)GetProcAddress(ghWintab, "WTOverlap"); + gpWTSave = (WTSAVE)GetProcAddress(ghWintab, "WTSave"); + gpWTConfig = (WTCONFIG)GetProcAddress(ghWintab, "WTConfig"); + gpWTRestore = (WTRESTORE)GetProcAddress(ghWintab, "WTRestore"); + gpWTExtSet = (WTEXTSET)GetProcAddress(ghWintab, "WTExtSet"); + gpWTExtGet = (WTEXTGET)GetProcAddress(ghWintab, "WTExtGet"); + gpWTQueueSizeSet = (WTQUEUESIZESET)GetProcAddress(ghWintab, "WTQueueSizeSet"); + gpWTDataPeek = (WTDATAPEEK)GetProcAddress(ghWintab, "WTDataPeek"); + gpWTPacketsGet = (WTPACKETSGET)GetProcAddress(ghWintab, "WTPacketsGet"); + gpWTMgrOpen = (WTMGROPEN)GetProcAddress(ghWintab, "WTMgrOpen"); + gpWTMgrClose = (WTMGRCLOSE)GetProcAddress(ghWintab, "WTMgrClose"); + gpWTMgrDefContext = (WTMGRDEFCONTEXT)GetProcAddress(ghWintab, "WTMgrDefContext"); + gpWTMgrDefContextEx = (WTMGRDEFCONTEXTEX)GetProcAddress(ghWintab, "WTMgrDefContextEx"); + + // TODO - don't forget to NULL out pointers in UnloadWintab(). + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////// +// Purpose +// Uninitializes use of wintab32.dll +// +// Returns +// Nothing. +// +void UnloadWintab(void) +{ + if (ghWintab) + { + FreeLibrary(ghWintab); + ghWintab = nullptr; + } + gpWTOpenA = nullptr; + gpWTClose = nullptr; + gpWTInfoA = nullptr; + gpWTPacket = nullptr; + gpWTEnable = nullptr; + gpWTOverlap = nullptr; + gpWTSave = nullptr; + gpWTConfig = nullptr; + gpWTGetA = nullptr; + gpWTSetA = nullptr; + gpWTRestore = nullptr; + gpWTExtSet = nullptr; + gpWTExtGet = nullptr; + gpWTQueueSizeSet = nullptr; + gpWTDataPeek = nullptr; + gpWTPacketsGet = nullptr; + gpWTMgrOpen = nullptr; + gpWTMgrClose = nullptr; + gpWTMgrDefContext = nullptr; + gpWTMgrDefContextEx = nullptr; +} + +////////////////////////////////////////////////////////////////////////////// +// Purpose +// Display error to user. +// +void ShowError(const std::string &pszErrorMessage_I) +{ + //TODO: post error message to buffer in Tablet class + //which in turn can post to TabUI + //MessageBoxA(NULL, pszErrorMessage_I.c_str(), "Error", MB_OK | MB_ICONERROR); +} + +////////////////////////////////////////////////////////////////////////////// + diff --git a/src/yaw-tab/wtutil.h b/src/yaw-tab/wtutil.h new file mode 100644 index 0000000..7e04f14 --- /dev/null +++ b/src/yaw-tab/wtutil.h @@ -0,0 +1,87 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// DESCRIPTION +// Defines for the general-purpose functions for the WinTab demos. +// +// COPYRIGHT +// Copyright (c) 2014-2020 Wacom Co., Ltd. +// All rights reserved. +// +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + + +#include +#include +#include +#include + +#include // NOTE: get from wactab header package + +////////////////////////////////////////////////////////////////////////////// +// Ignore warnings about using unsafe string functions. +#pragma warning( disable : 4996 ) + +////////////////////////////////////////////////////////////////////////////// +// Function pointers to Wintab functions exported from wintab32.dll. +using WTINFOA = UINT (API*)(UINT, UINT, LPVOID); +using WTOPENA = HCTX (API*)(HWND, LPLOGCONTEXTA, BOOL); +using WTGETA = BOOL (API*)(HCTX, LPLOGCONTEXT); +using WTSETA = BOOL (API*)(HCTX, LPLOGCONTEXT); +using WTCLOSE = BOOL (API*)(HCTX); +using WTENABLE = BOOL (API*)(HCTX, BOOL); +using WTPACKET = BOOL (API*)(HCTX, UINT, LPVOID); +using WTOVERLAP = BOOL (API*)(HCTX, BOOL); +using WTSAVE = BOOL (API*)(HCTX, LPVOID); +using WTCONFIG = BOOL (API*)(HCTX, HWND); +using WTRESTORE = HCTX (API*)(HWND, LPVOID, BOOL); +using WTEXTSET = BOOL (API*)(HCTX, UINT, LPVOID); +using WTEXTGET = BOOL (API*)(HCTX, UINT, LPVOID); +using WTQUEUESIZESET = BOOL (API*)(HCTX, int); +using WTDATAPEEK = int (API*)(HCTX, UINT, UINT, int, LPVOID, LPINT); +using WTPACKETSGET = int (API*)(HCTX, int, LPVOID); +using WTMGROPEN = HMGR (API*)(HWND, UINT); +using WTMGRCLOSE = BOOL (API*)(HMGR); +using WTMGRDEFCONTEXT = HCTX (API*)(HMGR, BOOL); +using WTMGRDEFCONTEXTEX = HCTX (API*)(HMGR, UINT, BOOL); + +// TODO - add more wintab32 function defs as needed + +////////////////////////////////////////////////////////////////////////////// + +// Loaded Wintab32 API functions. +extern HINSTANCE ghWintab; + +extern WTINFOA gpWTInfoA; +extern WTOPENA gpWTOpenA; +extern WTGETA gpWTGetA; +extern WTSETA gpWTSetA; +extern WTCLOSE gpWTClose; +extern WTPACKET gpWTPacket; +extern WTENABLE gpWTEnable; +extern WTOVERLAP gpWTOverlap; +extern WTSAVE gpWTSave; +extern WTCONFIG gpWTConfig; +extern WTRESTORE gpWTRestore; +extern WTEXTSET gpWTExtSet; +extern WTEXTGET gpWTExtGet; +extern WTQUEUESIZESET gpWTQueueSizeSet; +extern WTDATAPEEK gpWTDataPeek; +extern WTPACKETSGET gpWTPacketsGet; +extern WTMGROPEN gpWTMgrOpen; +extern WTMGRCLOSE gpWTMgrClose; +extern WTMGRDEFCONTEXT gpWTMgrDefContext; +extern WTMGRDEFCONTEXTEX gpWTMgrDefContextEx; + +// TODO - add more wintab32 function pointers as needed + +////////////////////////////////////////////////////////////////////////////// + +BOOL LoadWintab(void); +void UnloadWintab(void); + +void ShowError(const std::string &pszErrorMessage_I); + +////////////////////////////////////////////////////////////////////////////// +