Ajouter Wintab (1).

This commit is contained in:
yaw-man 2022-08-07 20:43:35 -03:00
parent cee11b990c
commit 4b72442df0
7 changed files with 272 additions and 47 deletions

View File

@ -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"
)

View File

@ -1,19 +1,3 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
*
* 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

View File

@ -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');
}
/* --------------------------------------------------------------------------------------------------------

37
src/yaw-tab/tab.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <string>
#include <Windows.h>
#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;
}
};

View File

@ -1,25 +1,7 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
*
* 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;

137
src/yaw-tab/wtutil.cpp Normal file
View File

@ -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 <string>
#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);
}
//////////////////////////////////////////////////////////////////////////////

87
src/yaw-tab/wtutil.h Normal file
View File

@ -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 <windows.h>
#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
#include <wintab.h> // 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);
//////////////////////////////////////////////////////////////////////////////