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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
#include "oni.h"
void syncOniPlayer::addPlayer(string name){
//ofxOpenNI *o=new ofxOpenNI;
//o->setupFromONI(name,true);
//o->setPaused(true);
//players.push_back(o);
players.push_back(NULL);
filenames.push_back(name);
soundplayer.setLoop(false);
//players[players.size()-1]->setSpeed(0.0f);
//players[players.size()-1]->setup(true);
//players[players.size()-1]->start();
//players[players.size()-1]->startPlayer(name);
}
void syncOniPlayer::play(){
for (int i=0;i<players.size();i++) {
players[i]=new ofxOpenNI();
//players[i]->setSafeThreading(true);
players[i]->setupFromONI(filenames[i],true);
//players[i]->setSafeThreading(true);
//players[i]->addDepthGenerator();
//players[i]->addImageGenerator();
//players[i]->setRegister(true);
players[i]->setLooped(false);
//players[i]->setBaseUserClass(user);
players[i]->start();
//players[players.size()-1]->setSpeed(1.0f);
if (audio!="") {
soundplayer.loadSound(audio);
soundplayer.play();
};
//sleep(2);
drawable=true;
startTime=ofGetElapsedTimef();
playerActive=true;
}
}
void syncOniPlayer::update(){
for (int i=0;i<players.size();i++) {
if (playerActive) players[i]->update();
}
}
void syncOniPlayer::pause(){
for (int i=0;i<players.size();i++) {
//players[players.size()-1]->setSpeed(0.0f);
players[i]->setPaused(true);
}
}
bool syncOniPlayer::isPlaying(){
if (players.size()) return players[0]->isPlaying();
else return false;
}
int syncOniPlayer::getCurrentFrame(){
if (players.size()) return players[0]->getCurrentFrame();
else return -1;
}
float syncOniPlayer::getPosition(){
if (players.size()) return players[0]->getPosition();
else return -1.0f;
}
void syncOniPlayer::drawWindows(){
if (!drawable) return;
for (int i=0;i<players.size();i++) {
if (players[i]==NULL) break;
ofTranslate(0, i * 400);
players[i]->drawDepth(50, 0,520,390);
players[i]->drawImage(600, 0,520,390);
}
}
void syncOniPlayer::drawCloud(int step){
int count;
for (int n=0;n<players.size();n++) {
const XnDepthPixel* depthmap=players[n]->getDepthGenerator().GetDepthMap();
//uint16_t* depthpixels=depthmap.getPixels();
int range=1700;
int depthW=players[n]->getWidth();
int depthH=players[n]->getHeight();
for (int i=0;i<depthW;i+=step) {
glBegin(GL_LINES);
for (int j=0;j<depthH;j+=step) {
ofPoint p= players[n]->projectiveToWorld(ofPoint(i,j,(float)(depthmap[j*depthW+i])));
//ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
if (p.z == 0 || p.z>range) continue; // gets rid of background
glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255);
glVertex3f(p.x, p.y, p.z);
//if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl;
}
glEnd();
}
}
return;
}
void syncOniPlayer::drawPoints(float _birth,float life,float dx,float dy, float dz,float size){
if (!drawable) return;
//glEnable(GL_PROGRAM_POINT_SIZE);
//glEnable(GL_POINT_SMOOTH);
//glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
//glPointSize( size);
//glBegin(GL_POINTS);
if (playerActive){
//apply envelope
float attackSeconds=0.5f;
float playOutFraction=0.9f;
float birth;
float clipTime=ofGetElapsedTimef()-startTime;
if (clipTime<attackSeconds) {
//ramp in
birth=_birth*(clipTime/attackSeconds);
}
else if (players[0]->getPosition()>playOutFraction) {
//cerr<<"playing out!"<<endl;
birth=_birth*(1.0f-((players[0]->getPosition()-playOutFraction)/(1.0f-playOutFraction)));
//if it reaches the end stop creating points but allow old points to play out
if (players[0]->getPosition()>0.99) playerActive=false;
}
else birth=_birth;
//cerr<<birth<<" "<<clipTime<<" "<<players[0]->getPosition()<<endl;
const XnDepthPixel* depthmap=players[0]->getDepthGenerator().GetDepthMap();
const ofPixels& pixels=players[0]->getImagePixels();
int range=1700;
int dmw=players[0]->getWidth();
int dmh=players[0]->getHeight();
if (dmw&&dmh){
int step=pixels.getWidth()/dmw;
for (int o=0;o<birth;o++) {
int i=ofRandom(dmw);
int j=ofRandom(dmh);
ofPoint p= players[0]->projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
if (p.z <100 || p.z>range) continue;
//points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2));
//fpoint f=fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2);
//f.draw(life,dx,dy,dz);
if (pointPool.size()) {//take 1st dead particle
points[(*pointPool.begin())].setup(p.x, p.y, p.z,
LUT[pixels[((j*step*dmw)+(i*step))*3]],
LUT[pixels[((j*step*dmw)+(i*step))*3]+1],
LUT[pixels[((j*step*dmw)+(i*step))*3]+2]
);
pointPool.erase(pointPool.begin());
}
else {//make a new one
points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2));
}
}
}
}
for (int i=0;i<points.size();i++){
if (!points[i].draw(life,dx,dy,dz,size)) {
pointPool.insert(i);
}
}
//glEnd();
glDisable( GL_BLEND );
//glDisable(GL_PROGRAM_POINT_SIZE);
}
int syncOniPlayer::getNumParticles(){
return points.size()-pointPool.size();
}
string syncOniPlayer::getCurrentFile(){
return filenames[0]+" "+audio;
}
void syncOniPlayer::stop(){
soundplayer.stop();
for (int i=0;i<players.size();i++) {
if (players[i]!=NULL) {
players[i]->stop();
delete players[i];
players[i]=NULL;
}
}
drawable=false;
playerActive=false;
}
//=================
void oniManager::init(const char* filename){
playing=-1;
int numDevices=1;
string f=string(filename);
if( !XML.loadFile(f) ){
printf("unable to load recordings, check data/ folder\n");
}else{
if(XML.pushTag("TRSS")) {
int num=XML.getNumTags("rec");
if(num) {
for (int i=0;i<num;i++) {
players.push_back(syncOniPlayer());
players[i].addPlayer(XML.getAttribute("rec","left","",i));
if (numDevices==2) {
players[i].addPlayer(XML.getAttribute("rec","right","",i));
}
players[i].audio=XML.getAttribute("rec","audio","",i);
}
}
else printf("no recordings found!\n");
}
}
}
void oniManager::startPlayer(int newplayer){
if (players.size()>newplayer){
if (playing>-1) players[playing].stop();
usleep(5000);
playing=newplayer;
players[playing].play();
}
}
string oniManager::getCurrentFile(){
if (players.size()>playing&&playing>-1) return players[playing].getCurrentFile();
else return "";
}
int oniManager::getNumClips(){
return players.size();
}
void oniManager::update(){
//if (playing>-1&&!players[playing].isPlaying()) players[playing].play();
if (players.size()>playing&&playing>-1) players[playing].update();
}
void oniManager::drawWindows(){
if (players.size()>playing&&playing>-1) players[playing].drawWindows();
}
void oniManager::drawCloud(int step){
if (players.size()>playing&&playing>-1) players[playing].drawCloud(step);
}
void oniManager::next(){
int newp=(playing+1)%players.size();
startPlayer(newp);
}
void oniManager::previous(){
int newp=playing-1<0?players.size()-1:playing-1;
startPlayer(newp);
}
int oniManager::getNumParticles(){
if (players.size()>playing&&playing>-1) return players[playing].getNumParticles();
else return 0;
}
void oniManager::drawPoints(float size,float birth,float life,float dx,float dy, float dz){
if (players.size()>playing&&playing>-1) {
players[playing].drawPoints(birth,life,dx,dy,dz,size);
}
}
syncOniPlayer* oniManager::getCurrentPlayer(){
if (players.size()>playing&&playing>-1) return &players[playing];
else return NULL;
}
|