-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTOPtoPSN.hpp
86 lines (66 loc) · 3.15 KB
/
TOPtoPSN.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Shared Use License: This file is owned by Derivative Inc. (Derivative) and
* can only be used, and/or modified for use, in conjunction with
* Derivative's TouchDesigner software, and only if you are a licensee who has
* accepted Derivative's TouchDesigner license or assignment agreement (which
* also govern the use of this file). You may share a modified version of this
* file with another authorized licensee of Derivative's TouchDesigner software.
* Otherwise, no redistribution or sharing of this file, with or without
* modification, is permitted.
*/
#include "CHOP_CPlusPlusBase.h"
#include <psn_lib.hpp>
#include <boost/asio.hpp>
/*
This example file implements a class that does 2 different things depending on
if a CHOP is connected to the CPlusPlus CHOPs input or not.
The example is timesliced, which is the more complex way of working.
If an input is connected the node will output the same number of channels as the
input and divide the first 'N' samples in the input channel by 2. 'N' being the current
timeslice size. This is noteworthy because if the input isn't changing then the output
will look wierd since depending on the timeslice size some number of the first samples
of the input will get used.
If no input is connected then the node will output a smooth sine wave at 120hz.
*/
// To get more help about these functions, look at CHOP_CPlusPlusBase.h
class TOPtoPSN : public CHOP_CPlusPlusBase
{
public:
TOPtoPSN(const OP_NodeInfo* info);
virtual ~TOPtoPSN();
virtual void getGeneralInfo(CHOP_GeneralInfo* ) override;
virtual bool getOutputInfo(CHOP_OutputInfo*) override;
virtual const char* getChannelName(int32_t index, void* reserved) override;
virtual void execute(const CHOP_Output*,
OP_Inputs*,
void* reserved) override;
virtual int32_t getNumInfoCHOPChans() override;
virtual void getInfoCHOPChan(int index,
OP_InfoCHOPChan* chan) override;
virtual bool getInfoDATSize(OP_InfoDATSize* infoSize) override;
virtual void getInfoDATEntries(int32_t index,
int32_t nEntries,
OP_InfoDATEntries* entries) override;
virtual void setupParameters(OP_ParameterManager* manager) override;
virtual void pulsePressed(const char* name) override;
private:
// We don't need to store this pointer, but we do for the example.
// The OP_NodeInfo class store information about the node that's using
// this instance of the class (like its name).
const OP_NodeInfo *myNodeInfo;
// In this example this value will be incremented each time the execute()
// function is called, then passes back to the CHOP
int32_t myExecuteCount;
boost::asio::io_context io_context_;
boost::asio::ip::udp::endpoint endpoint_;
boost::asio::ip::udp::socket socket_;
int messages_;
int sentPackets_;
int trackersSize_;
std::string lastError_;
::psn::psn_tracker_array trackers_;
::psn::psn_encoder psn_encoder_;
std::string prevInterfaceAddr_;
void updateTrackers(OP_Inputs *inputs, const OP_TOPInput *top, const float *pixels);
void sendTrackers(OP_Inputs *inputs, const boost::asio::ip::udp::endpoint &endpoint);
void sendInfo(OP_Inputs *inputs, const boost::asio::ip::udp::endpoint &endpoint);
};