MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TabletFrame.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Core {
4
5/**
6 * @brief Physical tool type.
7 *
8 * HID report descriptors distinguish pen from eraser and nothing further.
9 * Vendor-specific tools such as brush or airbrush are not representable
10 * without a device database and are reported as PEN.
11 */
12enum class TabletToolType : uint8_t {
13 PEN,
14 ERASER,
16};
17
18/**
19 * @brief Axes a tool actually reports.
20 *
21 * Slots whose bit is clear are always zero and must not be interpreted.
22 * Position and button slots are always present and have no bit.
23 */
24enum class TabletAxes : uint16_t {
25 NONE = 0,
26 PRESSURE = 1U << 0U,
27 DISTANCE = 1U << 1U,
28 TILT = 1U << 2U,
29 ROTATION = 1U << 3U,
30 SLIDER = 1U << 4U,
31 WHEEL = 1U << 5U
32};
33
34[[nodiscard]] constexpr TabletAxes operator|(TabletAxes a, TabletAxes b) noexcept
35{
36 return static_cast<TabletAxes>(
37 static_cast<uint16_t>(a) | static_cast<uint16_t>(b));
38}
39
41{
42 a = a | b;
43 return a;
44}
45
46[[nodiscard]] constexpr bool has_axis(TabletAxes set, TabletAxes axis) noexcept
47{
48 return (static_cast<uint16_t>(set) & static_cast<uint16_t>(axis)) != 0U;
49}
50
51/**
52 * @brief State bits packed into the STATE slot.
53 */
54enum class TabletState : uint32_t {
55 NONE = 0,
56 IN_PROXIMITY = 1U << 0U,
57 IN_CONTACT = 1U << 1U
58};
59
60/**
61 * @brief Slot indices into the double vector carried by a tablet InputValue.
62 *
63 * A tablet source emits one InputValue of Type::VECTOR per hardware sample,
64 * sized SLOT_COUNT. Every slot is always present. Absent axes read zero and
65 * the tool's TabletAxes mask says which those are.
66 *
67 * Position, pressure and distance are normalised 0..1. Tilt is -90..90
68 * degrees and rotation -180..180 degrees. Slider is -1..1. Buttons and
69 * state are integral values stored as doubles and recovered by casting.
70 *
71 * Slot layout is a public contract. Appending slots is permitted, reordering
72 * or reinterpreting existing slots is not.
73 */
74struct MAYAFLUX_API TabletFrame {
75 enum Slot : size_t {
76 X = 0, ///< 0.0 to 1.0 across the active area
77 Y = 1, ///< 0.0 to 1.0 across the active area
78 PRESSURE = 2, ///< 0.0 to 1.0
79 DISTANCE = 3, ///< 0.0 to 1.0, hover height
80 TILT_X = 4, ///< -90.0 to 90.0 degrees
81 TILT_Y = 5, ///< -90.0 to 90.0 degrees
82 ROTATION = 6, ///< -180.0 to 180.0 degrees
83 SLIDER = 7, ///< -1.0 to 1.0, barrel pressure or finger wheel
84 WHEEL = 8, ///< Degrees of wheel rotation this sample
85 WHEEL_CLICKS = 9, ///< Integral detents this sample
86 BUTTONS = 10, ///< Bit 0 barrel, bit 1 secondary barrel, bit 2 eraser
87 STATE = 11 ///< TabletState bitmask
88 };
89
90 static constexpr size_t SLOT_COUNT = 12;
91
92 /** @brief Decode the state slot of a frame. */
93 [[nodiscard]] static TabletState state_of(std::span<const double> frame) noexcept
94 {
95 if (frame.size() <= STATE)
96 return TabletState::NONE;
97 return static_cast<TabletState>(static_cast<uint32_t>(frame[STATE]));
98 }
99
100 /** @brief Test a state bit on a frame. */
101 [[nodiscard]] static bool in_state(std::span<const double> frame,
102 TabletState bit) noexcept
103 {
104 return (static_cast<uint32_t>(state_of(frame))
105 & static_cast<uint32_t>(bit))
106 != 0U;
107 }
108};
109
110} // namespace MayaFlux::Core
size_t a
size_t b
constexpr TabletAxes & operator|=(TabletAxes &a, TabletAxes b) noexcept
TabletToolType
Physical tool type.
TabletState
State bits packed into the STATE slot.
TabletAxes
Axes a tool actually reports.
constexpr TabletAxes operator|(TabletAxes a, TabletAxes b) noexcept
constexpr bool has_axis(TabletAxes set, TabletAxes axis) noexcept
static bool in_state(std::span< const double > frame, TabletState bit) noexcept
Test a state bit on a frame.
static TabletState state_of(std::span< const double > frame) noexcept
Decode the state slot of a frame.
Slot indices into the double vector carried by a tablet InputValue.