-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpuplotApp.cpp
More file actions
150 lines (122 loc) · 2.84 KB
/
Copy pathgpuplotApp.cpp
File metadata and controls
150 lines (122 loc) · 2.84 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "gpuplotApp.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
Graph::Graph() : index(-1)
{
init();
}
Graph::Graph(int indx) : index(indx)
{
init();
}
void Graph::init()
{
glsl = gl::GlslProg::create( loadResource( "shader.vert" ), loadResource( "shader.frag" ) );
//glsl->bind();
//batch = gl::Batch::create( geom::Rect().rect(Area(0,0,500,500)), glsl );
//mGlsl->bind();
for(int i =0; i < PLOT_NUM_POINTS; i++) { fifo.push_back(i); buf.push_back(i); }
}
void Graph::setValue(float v)
{
fifo.push_back(v);
fifo.pop_front();
buf.clear();
for(auto i : fifo) { buf.push_back(i * 0.5 + 0.5); }
}
void Graph::setIndex(int i)
{
index = i;
}
int Graph::getIndex()
{
return index;
}
Graph Graph::setPos(vec2 p)
{
pos = p;
return *this;
}
Graph Graph::setSize(vec2 s)
{
size = s;
return *this;
}
void Graph::draw()
{
//gl::ScopedGlslProg s(glsl);
glsl->bind();
glsl->uniform("utime", (float)getElapsedSeconds());
glsl->uniform("uVal", buf.data(), PLOT_NUM_POINTS);
//batch->draw();
gl::drawSolidRect(Rectf(pos, pos + size));
}
gpuplotApp::gpuplotApp() : receiver(localPort)
{
}
void gpuplotApp::setGraphAddress(int graphIndex, std::string address)
{
addresses[graphIndex] = address;
}
void gpuplotApp::oscParse(const osc::Message &msg)
{
int i = 0;
for(auto a : addresses)
{
if(a == msg.getAddress())
{
graphs[i].setValue(msg[0].flt());
break;
}
i++;
}
}
void gpuplotApp::setup()
{
for(int i =0; i < 4; i++)
{
graphs.push_back(Graph(i));
addresses.push_back("/graph" + std::to_string(i));
//setGraphAddress(i, addresses.back());
}
try {
// Bind the receiver to the endpoint. This function may throw.
receiver.bind();
}
catch( const osc::Exception &ex ) {
console() << ex.what();
quit();
}
receiver.listen(
[]( asio::error_code error, protocol::endpoint endpoint ) -> bool {
if( error ) {
return false;
}
else
return true;
});
receiver.setListener( "*", std::bind(&gpuplotApp::oscParse, this, std::placeholders::_1));
}
void gpuplotApp::update()
{
vec2 colRow(1,4);
vec2 graphSize = (vec2)getWindowSize()/colRow;
int j =0;
for(auto g : graphs)
{
vec2 pos(fmod(j, 1) * graphSize.x, j/1 * graphSize.y);
//int x = ;
graphs[j].setPos(pos + graphSize*0.025f);
graphs[j].setSize(graphSize * 0.95f);
j++;
}
}
void gpuplotApp::draw()
{
gl::clear( Color( 1, 1, 1 ) );
for(auto g : graphs)
{
g.draw();
}
}