MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TabletNode.cpp
Go to the documentation of this file.
1#include "TabletNode.hpp"
2
4
6 : InputNode(config)
7 , m_config(config)
8 , m_tablet_context(config.default_value, config.default_value,
9 Core::InputType::TABLET, 0)
10{
11}
12
14{
16 return m_last_output;
17 }
18
19 const auto& vec = value.as_vector();
20 if (vec.size() < Core::TabletFrame::SLOT_COUNT) {
21 return m_last_output;
22 }
23
24 std::copy_n(vec.begin(), Core::TabletFrame::SLOT_COUNT, m_frame.begin());
25 m_frame_pending.store(true, std::memory_order_release);
26
27 if (m_config.state_bit) {
28 const auto state = static_cast<uint32_t>(m_frame[Core::TabletFrame::STATE]);
29 const auto bit = static_cast<uint32_t>(*m_config.state_bit);
30 return (state & bit) != 0U ? 1.0 : 0.0;
31 }
32
33 if (m_config.button_bit) {
34 const auto mask = static_cast<uint32_t>(m_frame[Core::TabletFrame::BUTTONS]);
35 return (mask & (1U << *m_config.button_bit)) != 0U ? 1.0 : 0.0;
36 }
37
40 }
41
42 return m_frame[m_config.slot];
43}
44
55
57{
59
60 if (!m_frame_pending.exchange(false, std::memory_order_acq_rel)) {
61 return;
62 }
63
65
67 fire_edges();
68
69 m_previous_state = static_cast<uint32_t>(m_frame[Core::TabletFrame::STATE]);
70}
71
73{
74 const auto current = static_cast<uint32_t>(m_frame[Core::TabletFrame::STATE]);
75 const uint32_t changed = current ^ m_previous_state;
76
77 const auto proximity = static_cast<uint32_t>(Core::TabletState::IN_PROXIMITY);
78 const auto contact = static_cast<uint32_t>(Core::TabletState::IN_CONTACT);
79
80 if ((changed & proximity) != 0U) {
81 fire((current & proximity) != 0U
84 }
85
86 if ((changed & contact) != 0U) {
87 fire((current & contact) != 0U
90 }
91}
92
93void TabletNode::fire(const std::vector<FrameCallback>& callbacks)
94{
95 for (const auto& callback : callbacks) {
96 callback(m_tablet_context);
97 }
98}
99
100} // namespace MayaFlux::Nodes::Input
glm::vec2 current
float value
uint32_t device_id
Source device ID.
Definition InputNode.hpp:51
double raw_value
Unsmoothed input value.
Definition InputNode.hpp:49
Core::InputType source_type
Backend that produced this input.
Definition InputNode.hpp:50
void update_context(double value) override
Update context after processing.
void notify_tick(double value) override
Notify callbacks (minimal for InputNode)
Abstract base class for nodes that receive external input.
std::array< double, Core::TabletFrame::SLOT_COUNT > frame
std::vector< FrameCallback > m_proximity_enter_callbacks
std::vector< FrameCallback > m_contact_begin_callbacks
std::vector< FrameCallback > m_proximity_exit_callbacks
std::vector< FrameCallback > m_frame_callbacks
std::array< double, Core::TabletFrame::SLOT_COUNT > m_frame
void notify_tick(double value) override
Notify callbacks (minimal for InputNode)
TabletNode(TabletConfig config={})
Definition TabletNode.cpp:5
std::atomic< bool > m_frame_pending
double extract_value(const Core::InputValue &value) override
Extract a scalar value from an InputValue.
std::vector< FrameCallback > m_contact_end_callbacks
void update_context(double value) override
Update context after processing.
void fire(const std::vector< FrameCallback > &callbacks)
double value
Current sample value.
Definition Node.hpp:63
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:425
@ VECTOR
Multiple float values (e.g., accelerometer xyz)
Generic input value container.
@ STATE
TabletState bitmask.
@ BUTTONS
Bit 0 barrel, bit 1 secondary barrel, bit 2 eraser.
static constexpr size_t SLOT_COUNT
double default_value
Initial output value.
Definition InputNode.hpp:71
std::optional< uint32_t > button_bit
When set, extract this BUTTONS bit.
std::optional< Core::TabletState > state_bit
When set, extract this STATE bit.
size_t slot
Frame slot driving the scalar.
Selects which part of a tablet frame becomes the node's scalar.