misc/misc/processing/bvh_and_sound: PerfumeDance.pde

File PerfumeDance.pde, 2.1 KB (added by noboru.yamamoto, 10 years ago)

for Processing ver.3

Line 
1//import ddf.minim.*;
2
3//Minim minim;
4//AudioPlayer player;
5// ddf seems obsoleted in processig 2
6import processing.sound.*;
7
8SoundFile player;
9
10
11BvhParser parserA = new BvhParser();
12PBvh bvh1, bvh2, bvh3;
13int playing=0;
14 
15 
16public void setup()
17{
18  size( 1280, 720, P3D );
19  background( color(128,128,64) );
20  noStroke();
21  frameRate(60);//not 30 but 40
22 
23  bvh1 = new PBvh( loadStrings( "bvhfiles/aachan.bvh" ) ,color(255,0,0));
24  bvh2 = new PBvh( loadStrings( "bvhfiles/kashiyuka.bvh" ), color(255,150,150));
25  bvh3 = new PBvh( loadStrings( "bvhfiles/nocchi.bvh" ) ,color(0,0,255));
26
27  //minim = new Minim(this);
28  //player = minim.loadFile("Perfume_globalsite_sound.wav");
29  player =new SoundFile(this,"Perfume_globalsite_sound.wav");
30  playing = 1;
31  player.play();
32  //player.loop();
33}
34
35public void draw()
36{
37  int ms=millis()%70500;
38 
39  background( color(240,240,128) );
40 
41  //camera
42  float _cos = cos(ms / 5000.f);
43  float _sin = sin(ms / 5000.f);
44  camera(width/4.f + width/4.f * _cos +200, height/2.0f-100, 550 + 150 * _sin,width/2.0f, height/2.0f, -400, 0, 1, 0);
45 
46  //ground
47  fill( color( 255 ));
48  stroke(127);
49  line(width/2.0f, height/2.0f, -30, width/2.0f, height/2.0f, 30);
50  stroke(127);
51  line(width/2.0f-30, height/2.0f, 0, width/2.0f + 30, height/2.0f, 0);
52  stroke(255);
53  pushMatrix();
54  translate( width/2, height/2-10, 0);
55  scale(-1, -1, -1);
56 
57  //synchronize sound and animation
58  //model
59  bvh1.update( ms );
60  bvh2.update( ms );
61  bvh3.update( ms );
62  bvh1.draw();
63  bvh2.draw();
64  bvh3.draw();
65  popMatrix();
66
67
68  if (playing == 1) {
69      if (ms <= 64247){
70        player.cue(ms); 
71      }
72      else{
73        player.stop();
74        playing=0;
75             println("stop  music", ms, player.duration(), player.sampleRate(),player.frames());
76      }
77  }
78  else if (ms < 64247){
79    player =new SoundFile(this,"Perfume_globalsite_sound.wav");
80    player.play();
81    playing=1;
82    println("start music",ms,
83             player.duration(), player.sampleRate(),player.frames());
84    player.cue(ms);   
85   }
86}
87
88
89void stop()
90{
91  player.stop();
92  //minim.stop();
93
94  super.stop();
95}