Skip to content

Commit d85b220

Browse files
committed
add gestural descriptor template
1 parent fead234 commit d85b220

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
//********************************************************************************//
2+
// Puara Gestures - Template (.h) //
3+
// https://github.com/Puara/puara-gestures //
4+
// Société des Arts Technologiques (SAT) - https://sat.qc.ca //
5+
// Input Devices and Music Interaction Laboratory (IDMIL) - https://www.idmil.org //
6+
// Edu Meneses (2025) - https://www.edumeneses.com //
7+
//********************************************************************************//
8+
#pragma once
9+
10+
#include <puara/structs.h>
11+
#include <puara/utils.h>
12+
13+
namespace puara_gestures
14+
{
15+
16+
/**
17+
* @brief This is a template of a gestural descriptor.
18+
*
19+
* It shows different instantiation practices to tie (connect) the class to a variable
20+
* or puara structure. This connection is usefull to facilitate the call for updating
21+
* the descriptor.
22+
*
23+
*/
24+
class Template
25+
{
26+
public:
27+
/**
28+
* @brief We declare the internal parameters and variables here. The variable
29+
* value (private, at the end of this class) is used to store the last calculated
30+
* descriptor value for future access.
31+
*/
32+
int config_parameter{};
33+
34+
/**
35+
* @brief Basic construct with no parameters.
36+
*
37+
*/
38+
Template() noexcept
39+
: config_parameter(1)
40+
, tied_data(nullptr)
41+
{
42+
}
43+
44+
Template(const Template&) noexcept = default;
45+
Template(Template&&) noexcept = default;
46+
Template& operator=(const Template&) noexcept = default;
47+
Template& operator=(Template&&) noexcept = default;
48+
49+
/**
50+
* @brief Constructor that ties the class to the external variable with type double.
51+
*
52+
* @param tied
53+
*/
54+
explicit Template(double* tied)
55+
: config_parameter(1)
56+
, tied_data(tied)
57+
{
58+
}
59+
60+
/**
61+
* @brief Constructor that ties the class to the external variable with the puara
62+
* type Coord1D. The struct member x is used as the tied variable.
63+
*
64+
* @param tied
65+
*/
66+
explicit Template(Coord1D* tied)
67+
: config_parameter(1)
68+
, tied_data(&(tied->x))
69+
{
70+
}
71+
72+
/**
73+
* @brief The update function usually calculates the descriptor (gesture), stores it
74+
* on the internal variable (e.g., stored_value), and returns it.
75+
*
76+
* In some cases, it is preferable to return 1 to indicate success, and use another
77+
* function, e.g., current_value(), to access the value.
78+
*
79+
*/
80+
double update(double data)
81+
{
82+
/**
83+
* Add your code to extract/calculate the descriptor here.
84+
*/
85+
value = data + data;
86+
87+
return value;
88+
}
89+
90+
/**
91+
* @brief This is a wrapper to allow the user to use a puara-specific structure
92+
* to calculate the descriptor.
93+
*
94+
* @param reading (Coord1D) The puara-specific structure to be used.
95+
*/
96+
double update(Coord1D reading)
97+
{
98+
return Template::update(reading.x);
99+
}
100+
101+
/**
102+
* @brief This is another wrapper to allow the user to use the tied variable to
103+
* calculate the descriptor.
104+
*
105+
*/
106+
double update()
107+
{
108+
if (tied_data != nullptr)
109+
{
110+
return Template::update(*tied_data);
111+
}
112+
else
113+
{
114+
return 0;
115+
}
116+
}
117+
118+
/**
119+
* @brief Get the current value of the descriptor.
120+
*
121+
* @return double
122+
*/
123+
double current_value() const { return value; }
124+
125+
/**
126+
* @brief This function allows the user to set a new tied variable for the class.
127+
*
128+
* @param new_tie The new tied variable to be set.
129+
*/
130+
int tie(Coord1D* new_tie)
131+
{
132+
tied_data = &(new_tie->x);
133+
return 1;
134+
}
135+
136+
/**
137+
* @brief This function also allows the user to set a new tied variable for the class.
138+
*
139+
* @param new_tie The new tied variable to be set.
140+
*/
141+
int tie(double* new_tie)
142+
{
143+
tied_data = new_tie;
144+
return 1;
145+
}
146+
147+
/**
148+
* @brief private variables: the tied_data pointer and the internal value variable.
149+
*
150+
*/
151+
private:
152+
const double* tied_data{};
153+
double value = 0;
154+
};
155+
} // namespace puara_gestures
156+
157+
/**
158+
* Please check other descriptors such as Jab for examples on internal wrappers to
159+
* allow multidimensional gestures based on their 1DoF counterparts.
160+
*/
161+

0 commit comments

Comments
 (0)