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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
|
#include "testApp.h"
/*
maybe draw pixel lines to a range of buffers and then play them in various 3D directions
pixel lines can have nice, missing corners and be nicely smoothed
is it insane not to do this in vvvv
can there be an editing interface
have a play with vvvv/ max and try to replicate this idea QUICKLY?
*/
//--------------------------------------------------------------
void testApp::setup(){
midiIn.listPorts();
midiIn.openPort(1); //this was 1 on linux, 0 on OSX
midiIn.addListener(this);
midiOut.listPorts();
midiOut.openPort(1); //this was 1 on linux, 0 on OSX
// 0 output channeLs,
// 2 input channels
// 44100 samples per second
// BUFFER_SIZE samples per buffer
// 4 num buffers (latency)
soundStream.listDevices();
left = new float[BUFFER_SIZE];
right = new float[BUFFER_SIZE];
//soundStream.setDeviceID(7); //ignore to use default?
soundStream.setup(this, 0, 2, 44100, BUFFER_SIZE, 4);
//soundStream.setup(this, 0, 4, 44100, BUFFER_SIZE, 4);
ofSetHexColor(0x666666);
lFFTanalyzer.setup(44100, BUFFER_SIZE/2,32);
lFFTanalyzer.peakHoldTime = 15; // hold longer
lFFTanalyzer.peakDecayRate = 0.95f; // decay slower
lFFTanalyzer.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
lFFTanalyzer.linearEQSlope = 0.01f; // increasing gain at higher frequencies
rFFTanalyzer.setup(44100, BUFFER_SIZE/2,32);
rFFTanalyzer.peakHoldTime = 15; // hold longer
rFFTanalyzer.peakDecayRate = 0.95f; // decay slower
rFFTanalyzer.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
rFFTanalyzer.linearEQSlope = 0.01f; // increasing gain at higher frequencies
/*
=======
if (4chan)
{
lFFTanalyzer2.setup(44100, BUFFER_SIZE/2,32);
lFFTanalyzer2.peakHoldTime = 15; // hold longer
lFFTanalyzer2.peakDecayRate = 0.95f; // decay slower
lFFTanalyzer2.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
lFFTanalyzer2.linearEQSlope = 0.01f; // increasing gain at higher frequencies
rFFTanalyzer2.setup(44100, BUFFER_SIZE/2,32);
rFFTanalyzer2.peakHoldTime = 15; // hold longer
rFFTanalyzer2.peakDecayRate = 0.95f; // decay slower
rFFTanalyzer2.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
rFFTanalyzer2.linearEQSlope = 0.01f; // increasing gain at higher frequencies
}
<<<<<<< HEAD
*/
ofSetFrameRate(60);
ofBackground(0,0,0);
F_movieSpeed=0.0;
//blendImage.loadImage("blend01.png");
blendImage.loadMovie("blend.mp4");
blendImage.play();
blendImage.setLoopState(OF_LOOP_NORMAL);
blendImage.setSpeed(F_movieSpeed);
I_movieSource=0;
I_moviePlaying=0;
//renderImage.allocate(ofGetWidth(),ofGetHeight(),GL_RGB);
renderImage.allocate(4080,768,GL_RGB);
maskShader.load("composite");
//testImage.loadImage("mask.png");
maskShader.begin();
maskShader.setUniformTexture("Tex0", blendImage.getTextureReference(), 0);
maskShader.setUniformTexture("Tex1", renderImage.getTextureReference(), 1);
maskShader.end();
showFPS=false;
//defaults
F_scale=0;
F_drawFrames=10;
F_drawStep=0;
F_drawDecay=0.95;
F_lineWidth=1.0; //1.0;
F_drawAxis=90; //Y
F_xRotate=0;
F_yRotate=0;
F_zRotate=0;
F_xRotation=180;
F_yRotation=180; //was 180
F_zRotation=0;
F_particleAmount=2000; //100
F_particleLife=1.5; //0.5
F_particleSize=10.0; //1.0;
I_fade1=0;
I_fade2=0;
thisFFTbuffer=0;
lastFrameTime=ofGetElapsedTimef();
draworder=true; //forwards;
visMode=WAVEFORM;
B_vSync=true;
B_fill=true;
inputMode=PICTURE;
gammamap=new unsigned char[256];
whitePt=0.9;
blackPt=0.3;
gamma=1.0;
//calc gamma map
for (int i=0;i<256;i++){
float ewp=max(whitePt,blackPt+0.1f); //limit range to 0.1
gammamap[i]=(unsigned char)(pow(min(1.0f,max(0.0f,(((float(i)/255.0f)-blackPt)/(ewp-blackPt)))),gamma)*255.0);
}
B_glitch=false;
//blanker.allocate(64,64,OF_IMAGE_COLOR);
blanker.loadImage("black.png");
fullScreen=false;
setMidiState();
receiver.setup(OSCPORT);
target.setPosition(0,0,0);
camera.setPosition(0,0,-700);
camera.lookAt(target,ofVec3f(0,1,0));
narrator.init("TRSS_nesbitt_recordings.xml");
if( !XML.loadFile("videos.xml") ){
printf("unable to load videos, check data/ folder\n");
}else{
if(XML.pushTag("TRSS")) {
int num=XML.getNumTags("video");
if(num) {
int i;
for (i=0;i<num;i++) {
videoclips.push_back(ofVideoPlayer());
videoclips[i].loadMovie(XML.getAttribute("video","file","",i));
videoclips[i].setLoopState(OF_LOOP_NONE);
videoclips[i].stop();
videoclips[i].setPosition(0.0f);
//videoclips[i].play();
//videoclips[i].setSpeed(0.0f);
}
cerr<<"loaded "<<i<<" video clips"<<endl;
}
else printf("no video clips found!\n");
}
}
int videoplaying=-1;
xOffs=startX=yOffs=startY=0;
xModel=0;
yModel=-25;
zModel=-1050;
sModel=3.5f;
};
//--------------------------------------------------------------
void testApp::update(){
// check for waiting messages
while(receiver.hasWaitingMessages()){
// get the next message
ofxOscMessage m;
receiver.getNextMessage(&m);
///mrmr/pushbutton/6/Pauls-iPad 1000
vector<string> path;
explode(m.getAddress(),'/', back_inserter(path));
cerr<<"OSC: "<<m.getAddress()<<endl;
if (path.size()>1) {
if (path[1]=="mrmr"){
if (path.size()>3){
if (path[2]=="pushbutton"){
int channel=ofToInt(path[3]);
if (channel>12) channel--; //12 is missing
if (m.getArgAsInt32(0)==1000) {
if (videoplaying>-1&&videoclips.size()>channel) {
videoclips[videoplaying].stop();
videoclips[videoplaying].setPosition(0.0f);
}
//videoclips[channel].setPosition(0.0f);
//videoclips[channel].setSpeed(1.0f);
videoplaying=channel;
videoclips[channel].play();
}
}
}
}
else {
string type=path[1];
if (type=="narrator"||type=="video") {
int channel=ofToInt(path[2])-1;
int data=m.getArgAsInt32(0);
cerr<<"type: "<<type<<" channel: "<<channel<<" data: "<<data<<endl;
if (type=="video"){
if ((channel > -1)&&videoclips.size()>channel) {
if (data>0) {
cerr<<"playing video "<<channel<<endl;
if (videoplaying>-1&&videoclips.size()>channel) {
videoclips[videoplaying].stop();
videoclips[videoplaying].setPosition(0.0f);
}
//videoclips[channel].setPosition(0.0f);
//videoclips[channel].setSpeed(1.0f);
videoplaying=channel;
videoclips[channel].play();
}
}
}
if (type=="narrator"){
if ((channel > -1)&&narrator.getNumClips()>channel) {
if (data>0) { //???doesn't seem to work
cerr<<"playing narrator "<<channel<<endl;
narrator.startPlayer(channel);
}
}
}
}
}
}
}
if (I_movieSource!=I_moviePlaying) {
blendImage.stop();
switch(I_movieSource){
case 0:
blendImage.loadMovie("gradblend.mov");
break;
case 1:
blendImage.loadMovie("gradblend01.mov");
break;
case 2:
blendImage.loadMovie("ll_waltz1.mov");
break;
case 3:
blendImage.loadMovie("ll_longtrains.avi");
break;
}
blendImage.play();
blendImage.setLoopState(OF_LOOP_NORMAL);
I_moviePlaying=I_movieSource;
}
blendImage.setSpeed(F_movieSpeed);
//blendImage.idleMovie();
if (videoplaying>-1&&videoclips.size()>videoplaying) videoclips[videoplaying].update();
//if (videoclips[i].getSpeed()>0.01f) videoclips[i].update();
//if (videoclips[i].getPosition()>0.99f) videoclips[i].setSpeed(0.0f);
//if (videoclips[i].isPlaying()) videoclips[i].stop();
//}
narrator.update();
xOffs*=.95;
yOffs*=.95;
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetVerticalSync(B_vSync);
static int index=0;
float lavg_power = 0.0f;
float ravg_power = 0.0f;
if (visMode==FFT_RAW||visMode==FFT_AVG) {
myfft.powerSpectrum(0,(int)BUFFER_SIZE/2, left,BUFFER_SIZE,&lmagnitude[0],&lphase[0],&lpower[0],&lavg_power);
myfft.powerSpectrum(0,(int)BUFFER_SIZE/2, right,BUFFER_SIZE,&rmagnitude[0],&rphase[0],&rpower[0],&ravg_power);
}
if (visMode==FFT_AVG) {
lFFTanalyzer.calculate(lmagnitude);
rFFTanalyzer.calculate(rmagnitude);
}
thisFFTbuffer=(thisFFTbuffer-1);
thisFFTbuffer=thisFFTbuffer<0?BUFFER_FRAMES-1:thisFFTbuffer;
switch(visMode) {
case FFT_AVG:
for (int i=0;i<rFFTanalyzer.nAverages;i++) {
FFTbuffer[0][i][thisFFTbuffer]=lFFTanalyzer.averages[i];
FFTbuffer[1][i][thisFFTbuffer]=rFFTanalyzer.averages[i];
}
break;
case FFT_RAW:
for (int i=0;i<BUFFER_SIZE;i++) {
FFTbuffer[0][i][thisFFTbuffer]=lmagnitude[i]*3;
FFTbuffer[1][i][thisFFTbuffer]=rmagnitude[i]*3;
}
break;
case WAVEFORM:
for (int i=0;i<BUFFER_SIZE/2;i++) {
FFTbuffer[0][i][thisFFTbuffer]=left[i]*100;
FFTbuffer[1][i][thisFFTbuffer]=right[i]*100;
}
break;
}
//ofDisableAlphaBlending();
renderImage.begin(); //render to FOB
glDisable(GL_BLEND);
float hw=ofGetWidth()/2;
float hh=ofGetHeight()/2;
float xStep = ((float)ofGetWidth())/(lFFTanalyzer.nAverages*2);
float zStep = ((float)ofGetWidth())/F_drawFrames;
float newTime=ofGetElapsedTimef();
float interval=newTime-lastFrameTime;
lastFrameTime=newTime;
if (B_glitch) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
//glBlendColor(1.0f,1.0f,1.0f,((float)I_fade2)/255.0f);
ofSetColor(255,255,255,I_fade2);
blanker.draw(0,0,renderImage.getWidth(),renderImage.getHeight());
glDisable(GL_BLEND);
}
else {
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
}
F_xRotation+=(F_xRotate*interval);
F_yRotation+=((F_yRotate+xOffs)*interval);
F_zRotation+=((F_zRotate+yOffs)*interval);
F_drawFrames=max(1.99f,min(F_drawFrames+(F_drawStep*interval),(float)BUFFER_FRAMES));
ofPushMatrix();
//ofTranslate(hw,hh);
camera.begin();
ofRotateX(F_xRotation);
ofRotateY(F_yRotation);
ofRotateZ(F_zRotation);
/*
if (inputMode==GRABBER) {
ofSetColor(I_fade2,I_fade2,I_fade2);
ofPushMatrix();
ofRotateX(90);
ofRotateZ(-90);
outTexture.draw(hw,-hh,-ofGetWidth(),ofGetHeight());
ofPopMatrix();
}
*/
GLfloat fogColor[4] = {0,0,0, 1.0};
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY,1.0 );
glHint(GL_FOG_HINT, GL_DONT_CARE);
glFogf(GL_FOG_START, ofGetHeight()*(0.1+(F_drawDecay*5)));
glFogf(GL_FOG_END, ofGetHeight()*(0.5+(F_drawDecay*5)));
glEnable(GL_FOG);
//reverse draw order when looking from back
int jStart=0;
int jEnd=F_drawFrames-1;
int jStep=1;
float F_yseg=F_yRotation;
while (F_yseg<-90) F_yseg+=360;
while (F_yseg>270) F_yseg-=360;
if (F_yseg>90) {
jStart=jEnd;
jEnd=0;
jStep=-1;
if (draworder) {
draworder=false;
//printf("switched to reverse order\n");
}
}
else if (!draworder) {
draworder=true;
//printf("switched to normal order\n");
}
for (int j=jStart;j!=jEnd;j+=jStep) {
int fB=(thisFFTbuffer+j)%BUFFER_FRAMES;
ofPushMatrix(); //coordinate transform for FFT draw direction
ofTranslate(0,0,(j*zStep)-hw);
ofRotateX(F_drawAxis);
ofFill();
ofSetColor(0,0,0);
if (B_fill) {
glBegin(GL_QUAD_STRIP);
for (int i = 0; i < lFFTanalyzer.nAverages-1; i++){
glVertex3f((i*xStep)-hw,(FFTbuffer[0][i][fB] * F_scale),0);
glVertex3f((i*xStep)-hw,0,0);
}
for (int i =lFFTanalyzer.nAverages, k=lFFTanalyzer.nAverages-1; i < lFFTanalyzer.nAverages+rFFTanalyzer.nAverages; i++, k--){
glVertex3f((i*xStep)-hw,(FFTbuffer[1][(lFFTanalyzer.nAverages+rFFTanalyzer.nAverages)-(i+1)][fB] * F_scale),0);
glVertex3f((i*xStep)-hw,0,0);
}
glEnd();
}
ofNoFill();
ofSetLineWidth(F_lineWidth);
ofSetColor(I_fade1,I_fade1,I_fade1);
glBegin(GL_LINE_STRIP);
for (int i = 0; i < lFFTanalyzer.nAverages; i++){
glVertex3f((i*xStep)-hw,(FFTbuffer[0][i][fB] * F_scale),0);
}
for (int i =lFFTanalyzer.nAverages, k=lFFTanalyzer.nAverages-1; i < lFFTanalyzer.nAverages+rFFTanalyzer.nAverages; i++, k--){
glVertex3f((i*xStep)-hw,(FFTbuffer[1][(lFFTanalyzer.nAverages+rFFTanalyzer.nAverages)-(i+1)][fB] * F_scale),0);
}
glEnd();
ofPopMatrix();
}
camera.end();
ofPopMatrix();
if (videoplaying>-1&&videoclips.size()>videoplaying) {
if (videoclips[videoplaying].getPosition()<0.1f) {
glEnable(GL_BLEND);
uint8_t b=uint8_t((videoclips[videoplaying].getPosition()/0.1f)*255);
ofSetColor(255,255,255,b);
}
else if (videoclips[videoplaying].getPosition()>0.8f) {
glEnable(GL_BLEND);
uint8_t b=uint8_t((1.0f-((videoclips[videoplaying].getPosition()-0.8f)/0.2f))*255);
ofSetColor(255,255,255,b);
}
else ofSetColor(255,255,255);
videoclips[videoplaying].draw(0,0,renderImage.getWidth()/3,renderImage.getHeight());
videoclips[videoplaying].draw(renderImage.getWidth()*0.666666667,0,renderImage.getWidth()/3,renderImage.getHeight());
glDisable(GL_BLEND);
}
ofPushMatrix();
//ofTranslate(hw,hh);
camera.begin();
ofRotateX(F_xRotation);
ofRotateY(F_yRotation);
ofRotateZ(F_zRotation);
ofPushMatrix();
//ofTranslate(0,-100,-1050);
ofScale(sModel,sModel,sModel);
//ofTranslate(xModel*sModel,yModel*sModel,zModel*sModel);
ofTranslate(xModel,yModel,zModel);
//narrator.drawCloud(2);
narrator.drawPoints(F_particleSize,F_particleAmount,F_particleLife,F_particleX,F_particleY,F_particleZ);
ofPopMatrix();
ofSetColor(255,255,255);
camera.end();
ofPopMatrix();
renderImage.end();
//ofEndShape(false);
//fbImage.grabScreen(0,0,ofGetWidth(),ofGetHeight());
/*
ofSetHexColor(0xaaaaaa);
int width=2048/FFTanalyzer.nAverages;
for (int i = 0; i < FFTanalyzer.nAverages; i++){
ofRect(i*width,768,width,-FFTanalyzer.averages[i] * 20);
}
ofSetHexColor(0xffffff);
for (int i = 0; i < (int)(BUFFER_SIZE/2 - 1); i++){
ofRect(i,768-freq[i]*10.0f,1,1);
}
ofSetHexColor(0xff0000);
for (int i = 0; i < FFTanalyzer.nAverages; i++){
ofRect(i*width,768-FFTanalyzer.peaks[i] * 20,width,-1);
}
float avgStep = 1024/FFTanalyzer.nAverages;
ofNoFill();
ofSetLineWidth(1);
ofSetColor(223, 218, 218);
ofDrawBitmapString("FFT average", 4, 18);
ofBeginShape();
for (int i = 0; i < FFTanalyzer.nAverages; i++){
ofVertex(i*avgStep, 284 -FFTanalyzer.averages[i] * 20);
}
ofEndShape(false);
ofSetColor(97,181,243);
ofDrawBitmapString("FFT magnitude", 4, 38);
ofBeginShape();
for (int i = 0; i < BUFFER_SIZE; i++){
ofVertex(i*avgStep, 384 -magnitude[i] * 20);
}
ofEndShape(false);
ofSetColor(97,243,174);
ofDrawBitmapString("FFT phase", 4, 58);
ofBeginShape();
for (int i = 0; i < BUFFER_SIZE; i++){
ofVertex(i*avgStep, 484 -phase[i] * 20);
}
ofEndShape(false);
ofSetColor(243,174,94);
ofDrawBitmapString("FFT power", 4, 78);
ofBeginShape();
for (int i = 0; i < BUFFER_SIZE; i++){
ofVertex(i*avgStep, 584 -power[i] * 20);
}
ofEndShape(false);
//float * averages; // the actual averages
//float * peaks; // peaks of the averages, aka "maxAverages" in other implementations
*/
ofEnableAlphaBlending();
maskShader.begin();
glActiveTexture(GL_TEXTURE0_ARB);
blendImage.getTextureReference().bind();
glActiveTexture(GL_TEXTURE1_ARB);
renderImage.getTextureReference().bind();
glBegin(GL_QUADS);
glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);
glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, 0);
glVertex2f( 0, 0);
glMultiTexCoord2d(GL_TEXTURE0_ARB, blendImage.getWidth(), 0);
glMultiTexCoord2d(GL_TEXTURE1_ARB, renderImage.getWidth(), 0);
glVertex2f( ofGetWidth(), 0);
glMultiTexCoord2d(GL_TEXTURE0_ARB, blendImage.getWidth(), blendImage.getHeight());
glMultiTexCoord2d(GL_TEXTURE1_ARB, renderImage.getWidth(), renderImage.getHeight() );
glVertex2f( ofGetWidth(), ofGetHeight());
glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, blendImage.getHeight());
glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, renderImage.getHeight() );
glVertex2f( 0, ofGetHeight() );
glEnd();
glActiveTexture(GL_TEXTURE1_ARB);
renderImage.getTextureReference().unbind();
glActiveTexture(GL_TEXTURE0_ARB);
blendImage.getTextureReference().unbind();
maskShader.end();
/*
glPushMatrix();
glTranslatef(ofGetWidth()*0.5,ofGetHeight()*0.5,0);
glRotatef((float)ofGetFrameNum(),0,1.0,0);
renderImage.draw(ofGetWidth()*-0.5,ofGetHeight()*-0.5);
glPopMatrix();
*/
if (showFPS) {
string msg=ofToString(ofGetFrameRate(), 2);
msg+="\n"+ofToString(F_xRotation, 4)+" "+ofToString(F_yRotation, 4)+" "+ofToString(F_zRotation, 4);
msg+="\n"+ofToString(F_yseg, 4);
msg+="\n"+ofToString(narrator.getNumParticles())+" size "+ofToString(F_lineWidth);
msg+="\n"+ofToString(xModel)+","+ofToString(yModel)+","+ofToString(zModel)+" * "+ofToString(sModel);
syncOniPlayer *player=narrator.getCurrentPlayer();
if (player) {
msg+="\n"+ofToString(player->getCurrentFrame())+","+ofToString(player->getPosition(),2);
msg+="\n"+player->getCurrentFile();
}
ofDrawBitmapString(msg,20,20);
}
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
if(key == 'f'){
showFPS=!showFPS;
}
if(key == ' '){
fullScreen=!fullScreen;
ofSetFullscreen(fullScreen);
}
if(key == '/'){
narrator.startPlayer(23);
}
if(key == ','){
narrator.previous();
}
if(key == '.'){
narrator.next();
}
if(key>='1'&key<='9'){
int clip=key-'1';
cerr<<"playing video clip "<<clip<<endl;
if (videoclips.size()>clip) {
videoclips[videoplaying].stop();
videoclips[videoplaying].setPosition(0.0f);
videoclips[clip].play();
videoplaying=clip;
}
}
if(key == 't'){
for (int i=0;i<videoclips.size();i++) {
if (videoclips[i].isPlaying()) {
cerr<<"videoclip "<<i<<" is playing"<<endl;
}
}
}
if(key == 'r'){
yModel+=25;
}
if(key == 'v'){
yModel-=25;
}
if(key == 'd'){
xModel+=25;
}
if(key == 'g'){
xModel-=25;
}
if(key == 't'){
zModel+=25;
}
if(key == 'c'){
zModel-=25;
}
if(key == 'w'){
sModel*=1.02;
}
if(key == 's'){
sModel/=1.02;
}
if(key == 'q'){
I_fade1=min(I_fade1+1,255);
}
if(key == 'a'){
I_fade1=max(I_fade1-1,0);
}
if(key == 'h'){
F_particleX-=1;
}
if(key == 'k'){
F_particleX+=1;
}
if(key == 'm'){
F_particleY-=1;
}
if(key == 'u'){
F_particleY+=1;
}
if(key == 'i'){
F_particleZ+=1;
}
if(key == 'n'){
F_particleZ-=1;
}
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
xOffs=x-startX;
yOffs=y-startY;
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
startX=x;
startY=y;
}
//--------------------------------------------------------------
void testApp::mouseReleased(){
}
//--------------------------------------------------------------
void testApp::audioIn(float * input, int bufferSize, int nChannels){
/*if (sampnum<10) {
printf("size %i, channels %i\n",bufferSize,nChannels);
sampnum++;
}
*/
// samples are "interleaved"
//if (nChannels==2) {
for (int i = 0; i < bufferSize; i++){
left[i] = input[i*2];
right[i] = input[i*2+1];
}
//}
}
void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){
//newMessage(eventArgs.port, eventArgs.channel, eventArgs.byteTwo, eventArgs.timestamp);
//byteOne : message type
/*
int port;
int channel;
int status;
int byteOne;
int byteTwo;
double timestamp;
*/
//printf("%d %d %d %d %d\n",eventArgs.port,eventArgs.channel,eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo);
bool noteOn; //this old thing!
switch(eventArgs.status) {
case 144: //noteon-off
break;
case 176: //control change 1-8 x 4 banks
switch(eventArgs.byteOne) {
case 1:
F_scale = ((float)eventArgs.byteTwo)*.25;
break;
case 2:
F_particleSize=(float)eventArgs.byteTwo*0.25;
break;
case 3:
F_drawAxis=((float) eventArgs.byteTwo-64)*(360.0/127);
break;
case 4:
F_particleAmount=((float) eventArgs.byteTwo)*(10000.0f/127.0f);
break;
case 5:
F_particleLife=((float) eventArgs.byteTwo)*(3.0f/127.0f);
break;
case 6:
F_particleX=(((float) eventArgs.byteTwo)-64)*10.0f;
break;
case 7:
F_particleY=(((float) eventArgs.byteTwo)-64)*10.0f;
break;
case 8:
F_particleZ=(((float) eventArgs.byteTwo)-64)*10.0f;
break;
//65-80 buttons
//radio button set
case 65:
if (eventArgs.byteTwo==127) {
visMode=FFT_AVG;
midiOut.sendControlChange(1, 66, 0);
midiOut.sendControlChange(1, 67, 0);
}
else midiOut.sendControlChange(1, 65, 127);
break;
case 66:
if (eventArgs.byteTwo==127) {
visMode=FFT_RAW;
midiOut.sendControlChange(1, 65, 0);
midiOut.sendControlChange(1, 67, 0);
}
else midiOut.sendControlChange(1, 66, 127);
break;
case 67:
if (eventArgs.byteTwo==127) {
visMode=WAVEFORM;
midiOut.sendControlChange(1, 65, 0);
midiOut.sendControlChange(1, 66, 0);
}
else midiOut.sendControlChange(1, 67, 127);
break;
//radio button set
case 68:
if (eventArgs.byteTwo==127) {
inputMode=PICTURE;
midiOut.sendControlChange(1, 69, 0);
}
else midiOut.sendControlChange(1, 68, 127);
break;
case 69:
if (eventArgs.byteTwo==127) {
inputMode=GRABBER;
midiOut.sendControlChange(1, 68, 0);
}
else midiOut.sendControlChange(1, 69, 127);
break;
case 70:
B_glitch=(eventArgs.byteTwo==127);
break;
case 71:
B_fill=(eventArgs.byteTwo==127);
break;
case 72:
B_vSync=(eventArgs.byteTwo==127);
break;
//buttons to zero rotations
case 73:
F_xRotate=0;
midiOut.sendControlChange(1, 73, 0);
midiOut.sendControlChange(1, 81, 64);
break;
case 74:
F_yRotate=0;
midiOut.sendControlChange(1, 74, 0);
midiOut.sendControlChange(1, 82, 64);
break;
case 75:
F_zRotate=0;
midiOut.sendControlChange(1, 75, 0);
midiOut.sendControlChange(1, 83, 64);
break;
case 76:
F_drawStep=0;
midiOut.sendControlChange(1, 76, 0);
midiOut.sendControlChange(1, 84, 64);
break;
case 77:
if (eventArgs.byteTwo==127) {
I_movieSource=0;
midiOut.sendControlChange(1, 78, 0);
midiOut.sendControlChange(1, 79, 0);
midiOut.sendControlChange(1, 80, 0);
}
else midiOut.sendControlChange(1, 77, 127);
break;
case 78:
if (eventArgs.byteTwo==127) {
I_movieSource=1;
midiOut.sendControlChange(1, 77, 0);
midiOut.sendControlChange(1, 79, 0);
midiOut.sendControlChange(1, 80, 0);
}
else midiOut.sendControlChange(1, 78, 127);
break;
case 79:
if (eventArgs.byteTwo==127) {
I_movieSource=2;
midiOut.sendControlChange(1, 77, 0);
midiOut.sendControlChange(1, 78, 0);
midiOut.sendControlChange(1, 80, 0);
}
else midiOut.sendControlChange(1, 79, 127);
break;
case 80:
if (eventArgs.byteTwo==127) {
I_movieSource=3;
midiOut.sendControlChange(1, 77, 0);
midiOut.sendControlChange(1, 78, 0);
midiOut.sendControlChange(1, 79, 0);
}
else midiOut.sendControlChange(1, 80, 127);
break;
// probably make controls logarithmic
case 81:
F_xRotate=(((float) eventArgs.byteTwo)-64)*.1;
break;
case 82:
F_yRotate=(((float) eventArgs.byteTwo)-64)*.1;
break;
case 83:
F_zRotate=(((float) eventArgs.byteTwo)-64)*.1;
break;
case 84:
F_drawStep=(((float) eventArgs.byteTwo)-64)*.1;
break;
case 85:
//F_movieSpeed=((float)eventArgs.byteTwo)/64.0;
F_lineWidth=((float)eventArgs.byteTwo)/8.0;
break;
case 86:
F_drawDecay=((float)eventArgs.byteTwo)/127.0;
break;
case 87:
I_fade2=((float)eventArgs.byteTwo)*2;
break;
case 88:
I_fade1=((float)eventArgs.byteTwo)*2;
//printf("fog- %f\n", F_drawDecay);
break;
case 91: //top
F_xRotation=90;
F_yRotation=90;
F_zRotation=0;
midiOut.sendControlChange(1, 91, 0);
break;
case 92: //front
F_xRotation=180;
F_yRotation=180; //was 180
F_zRotation=0;
midiOut.sendControlChange(1, 92, 0);
break;
//89-92 bottom 4
}
//printf("rotation- %f %f %f\n",F_xRotate,F_yRotate,F_zRotate);
//printf(inputMode==PICTURE?"PICTURE mode\n":"GRABBER mode\n");
}
}
void testApp::setMidiState(){
int knobs[32];
int buttons[16];
int faders[8];
for (int i=0;i<32;i++) knobs[i]=0;
for (int i=0;i<16;i++) buttons[i]=0;
for (int i=0;i<8;i++) faders[i]=0;
knobs[0] = (F_scale * 5);
knobs[1]=(F_particleSize*4);
knobs[2]=(F_drawAxis/(360.0/127))+64;
knobs[3]=F_particleAmount/(10000.0f/127);
knobs[4]=F_particleLife/(3.0f/127);
knobs[5]=(F_particleX*.1)+64;
knobs[6]=(F_particleY*.1)+64;
knobs[7]=(F_particleZ*.1)+64;
//radio button set
buttons[0]=(visMode==FFT_AVG?127:0);
buttons[1]=(visMode==FFT_RAW?127:0);
buttons[2]=(visMode==WAVEFORM?127:0);
//radio button set
buttons[3]=(inputMode==PICTURE?127:0);
buttons[4]=(inputMode==GRABBER?127:0);
buttons[5]=B_glitch?127:0;
buttons[6]=B_fill?127:0;
buttons[7]=B_vSync?127:0;
buttons[12]=I_movieSource==0?127:0;
buttons[13]=I_movieSource==1?127:0;
buttons[14]=I_movieSource==2?127:0;
buttons[15]=I_movieSource==3?127:0;
faders[0]=(F_xRotate*10)+64;
faders[1]=(F_yRotate*10)+64;
faders[2]=(F_zRotate*10)+64;
faders[3]=(F_drawStep*10)+64;
faders[4]=F_lineWidth*8;
faders[5]=(F_drawDecay*127);
faders[6]=I_fade1/2;
faders[7]=I_fade1/2;
for (int i=0;i<32;i++) midiOut.sendControlChange(1, i+1, knobs[i]);
for (int i=0;i<16;i++) midiOut.sendControlChange(1, i+65, buttons[i]);
for (int i=0;i<8;i++) midiOut.sendControlChange(1, i+81, faders[i]);
}
/*
void sendNoteOn(int channel, int id, int value);
void sendNoteOff(int channel, int id, int value);
void sendControlChange(int channel, int id, int value);
*/
|