/
cabinet.pde
286 lines (241 loc) · 7 KB
/
cabinet.pde
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
import ddf.minim.*;
int PosXTexteVillageDe;
int PosYTexteVillageDe;
int PosYTexteNomDuVillage;
int PosXTexteNomDuVillage;
String bddName = "bdd.txt";
Minim minim;
AudioPlayer player;
bdd base;
record testrec = null;
int recordID =0;
display disp;
//test var
PImage[] img = new PImage[3];
public class record{
private int id;
AudioPlayer audio;
int marqueurTab[][];
String village;
PImage img;
int x,y,w,h;
public record(String villagestr, int idrec){
village = villagestr;
audio = minim.loadFile("data/"+village+"/audio.wav");
id = idrec;
img = new PImage();
//img = loadImage("data/"+village+"/visuel.png");
fillMarqueurTab();
fillDisplayData();
rect(x,y,w,h);
}
private void fillDisplayData(){
String[] stuff = loadStrings("data/"+village+"/display.txt");
int[] tampon = new int[4];
tampon = int(split(stuff[0],'@'));
x = tampon[0];
y = tampon[1];
w = tampon[2];
h = tampon[3];
}
private void fillMarqueurTab(){
String[] stuff = loadStrings("data/"+village+"/marqueur.txt");
int[] tampon = new int[2];
marqueurTab = new int[stuff.length][2];
//println(stuff[0]);
for(int i = 0; i<stuff.length;i++){
tampon = int(split(stuff[i],' '));
marqueurTab[i][0]= tampon[0];
marqueurTab[i][1]= tampon[1];
//println(marqueurTab[i][0] +" | " +marqueurTab[i][1]);
}
}
public int getLength(){
return audio.length();
}
public int getPosition(){
return audio.position();
}
public void lOop(){
audio.loop();
}
public int getIDCurrentWord(){
int position = audio.position();
println("position = "+position);
int wordID = searchForPosition(position);
println("wordID = "+wordID);
return wordID;
}
public int getMilliForWordID(int wordId){
for(int i = 0; i<marqueurTab.length-1;i++){
if (marqueurTab[i][0] == wordId) return marqueurTab[i][1];
}
return marqueurTab[0][1];
}
private int searchForPosition(int position){
for(int i = 0; i<marqueurTab.length-1;i++){
if(position < marqueurTab[0][1]) return marqueurTab[0][0];
if(position > marqueurTab[i][1] && position < marqueurTab[i+1][1]) return marqueurTab[i][0];
}
return 0;
}
public int getID() {return id;}
public String getVillage() {return village;}
public void recordPlay(int millisec){
audio.play(millisec);
}
public void recordPlay(){
audio.play();
}
public void recordPause(){
audio.pause();
}
}
public class bdd{
String bddData[][];
private String path;
record recordTab[];
int bddLength;
public bdd(String pth){
setPath(pth);
getBDD();
createRecord();
}
public void setPath(String pth){ path = pth;}
public String getPath(){ return path;}
public void setBddLength(int lgth){ bddLength = lgth;}
public int getBddLength(){ return bddLength;}
public String getVillageWithID(int id){
for(int i=0;i<bddLength;i++){
if(Integer.parseInt(bddData[i][0]) == id)
return bddData[id][1];
else return "error";
}
return "error";
}
public record getRecordByID(int idrec){
for(int i=0;i<bddLength;i++){
if(recordTab[i].getID() == idrec)
return recordTab[i];
}
return null;
}
private void createRecord(){
recordTab = new record[getBddLength()];
for(int i=0; i< getBddLength();i++){
recordTab[i] = new record(bddData[i][1],Integer.parseInt(bddData[i][0]));
}
}
private void getBDD(){
String tampon[];
String tampon1[];
//read bdd
tampon = loadStrings("bdd.txt");
setBddLength(tampon.length);
bddData = new String[tampon.length][2];
for(int i=0; i < tampon.length;i++){
tampon1 = split(tampon[i],'@');
bddData[i][0] = tampon1[0];
bddData[i][1] = tampon1[1];
}
}
}
public class display{
int windowWidth;
int windowHeigth;
int numberOfTrack;
public display(int w, int h, int nb){
windowWidth = w;
windowHeigth = h;
numberOfTrack = nb;
size(windowWidth,windowHeigth);
}
public void displayContent(record recordTab[]){
for (int i =0; i < numberOfTrack;i++){
image(recordTab[i].img,recordTab[i].x,recordTab[i].y,recordTab[i].w,recordTab[i].h);
//display marqueur
for(int k = 0; k < recordTab[i].marqueurTab.length ; k++){
rect(recordTab[i].x+whereToPutTheReader(recordTab[i].getLength(),recordTab[i].marqueurTab[k][1],recordTab[i].w),recordTab[i].y,1,10);
}
}
}
public void displaySelector(){
ellipse(testrec.x-60,testrec.y+(testrec.h/2),50,50);
}
}
void setup(){
//size(800,600);
disp = new display(1280,800,4);
minim = new Minim(this);
base = new bdd(bddName);
fillTextVillagePosition();
/*
img[1] = loadImage("data/faget/visuel.png");
img[0] = loadImage("data/plaisance/visuel.png");
img[2] = loadImage("data/romieu/visuel.png");
*/
//disp = new display(1280,800,4);
testrec = base.getRecordByID(0);
println(testrec.getVillage());
testrec.recordPlay();
//testrec.lOop();
}
void draw(){
background(0,0,0);
// disp.displayContent(base.recordTab); //display all sync points
fill(250);
noStroke();
rect(whereToPutTheReader(testrec.getLength(),testrec.getPosition(),testrec.w)+testrec.x,testrec.y,8,testrec.h);
//display village name
textSize(32);
text("Village de ", PosXTexteVillageDe, PosYTexteVillageDe);
text(testrec.getVillage(), PosXTexteNomDuVillage, PosYTexteNomDuVillage);
//disp.displaySelector();
}
public void fillTextVillagePosition(){
String[] stuff = loadStrings("textPosition.txt");
int[] tampon = new int[4];
tampon = int(split(stuff[0],'@'));
PosXTexteVillageDe = tampon[0];
PosYTexteVillageDe = tampon[1];
PosXTexteNomDuVillage = tampon[2];
PosYTexteNomDuVillage= tampon[3];
}
public int whereToPutTheReader(int soundLength, int soundPosition, int displaySize){
return ((displaySize*soundPosition)/soundLength);
}
void mousePressed(){
for(int i = 0; i<base.recordTab.length;i++){
//println(base.recordTab[i].x);
if(mouseX > base.recordTab[i].x && mouseX < base.recordTab[i].x+base.recordTab[i].w && mouseY > base.recordTab[i].y && mouseY < base.recordTab[i].y+base.recordTab[i].h){
recordID = base.recordTab[i].getID();
}
}
switchRecord();
}
void switchRecord(){
testrec.recordPause();
int wordid = testrec.getIDCurrentWord();
//int test = (int)(random(2));
//println(test);
testrec = base.getRecordByID(recordID);
int millisecForPlay = testrec.getMilliForWordID(wordid);
println(testrec.getVillage());
println("word number : "+millisecForPlay);
testrec.recordPlay(millisecForPlay);
//testrec.lOop();
}
void keyPressed(){
switch(key){
case 't' : recordID = 0; switchRecord(); break;
case 'j' : recordID = 1; switchRecord(); break;
case 'c' : recordID = 2; switchRecord(); break;
case 'a' : recordID = 3; switchRecord(); break;
}
}
void stop()
{
// always close Minim audio classes when you are done with them
minim.stop();
super.stop();
}