Advertisement
tameraslan

JukeRock - PathFlow

Dec 19th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.99 KB | None | 0 0
  1. /*
  2. JukeRock PathFlow processing sketch
  3. The sketch loads in the input file matrix from a text file and loads the sound accordingly. then it creates a matrix of buttons to simulate a climbing wall. Each button/grip is associated with a sound, horizontal levels the same, vertical levels changing in pitch/instrument. A sequencer periodically scans all the columns, playing activated button in the column at each step. This reflects the path followed by the climber in a melodic way.
  4. */
  5.  
  6.  
  7. //User definitions:
  8. int beat = 45;
  9. int unit = 60; // 60 pixels, 30 cm
  10. int VertItemCount = 12;
  11. int HorItemCount = 15;
  12. boolean SoundOn=true; // true: play mode; false: record mode
  13. boolean makeMovie = false;
  14. int fps=10;
  15.  
  16. import ddf.minim.*;
  17. import processing.video.*;
  18. MovieMaker mm;
  19. //AudioSample sound, S;
  20. Minim minim;
  21. int counter = 0;
  22. int gripC=0;
  23. int c = 0;
  24. Coord topLeft, topRight, bottomLeft, bottomRight;
  25.  
  26.  
  27.  
  28. int wWidth = unit*HorItemCount;
  29. int wHeight = unit*VertItemCount;
  30. float step = beat/HorItemCount;
  31. //Location arrays:
  32. Hold [][] HoldArray = new Hold [wWidth][wHeight];
  33. Coord [] Buffer = new Coord [16];
  34.  
  35. // audio input from text file
  36. String[] noteMatrix;
  37. String[] row;
  38. String note;
  39.  
  40. void setup () {
  41.  
  42. size(wWidth, wHeight);
  43. frameRate(10);
  44. background(255);
  45. if(makeMovie)
  46. mm = new MovieMaker(this, width, height, "path_flow.mov",10, MovieMaker.ANIMATION, MovieMaker.HIGH);
  47. noteMatrix = loadStrings("fm7.txt");
  48.  
  49. PImage r = loadImage("pressed_60.png");
  50. PImage y = loadImage("gray_60.png");
  51. PImage yr= loadImage("gray_roll_60.png");
  52. PImage p = loadImage("left_60.png");
  53.  
  54. int w = r.width;
  55. int h = r.height;
  56. minim = new Minim(this);
  57. for (int j=0; j<(wHeight/unit);j++)
  58. {
  59. row = split(noteMatrix[j], '\t');
  60. for (int i=0; i<(wWidth/unit);i++)
  61. {
  62.  
  63. note = row[i];
  64. HoldArray[i][j] = new Hold(i*unit,j*unit,i,j,w,h,y,yr,r,p,note);
  65. }
  66. }
  67.  
  68.  
  69.  
  70. }
  71.  
  72.  
  73. void draw (){
  74.  
  75. // procedure for updating and displaying grips:
  76. for (int i=0; i<wWidth/unit;i++)
  77. {
  78. for (int j=0;j<wHeight/unit;j++)
  79. {
  80. HoldArray[i][j].update();
  81. HoldArray[i][j].display();
  82.  
  83. }
  84. }
  85.  
  86.  
  87. if (counter==beat)
  88. {
  89. counter=0;
  90. }
  91. else
  92. {
  93. for(int a =0; a<HorItemCount;a++)
  94. {
  95. if(counter==int(step)*a)
  96. {
  97. for (int i = 0; i<VertItemCount;i++)
  98. if(HoldArray[a][i].activated)
  99. {
  100.  
  101. if(SoundOn)
  102. {
  103.  
  104. HoldArray[a][i].S.trigger();
  105. }
  106.  
  107. }
  108.  
  109. }
  110. }
  111. counter++;
  112. }
  113. //println(c);
  114. fill(108,56,8,150);
  115. if(c==3)
  116. {
  117. triangle(Buffer[0].x+unit/2,Buffer[0].y+unit/2,Buffer[1].x+unit/2,Buffer[1].y+unit/2,Buffer[2].x+unit/2,Buffer[2].y+unit/2);
  118. }
  119. else if (c==4)
  120. {
  121. int indBot1=0, indBot2=0, indTop1=0, indTop2=0;
  122. int maxY;
  123. maxY=0;
  124. for(int k=0;k<4;k++)
  125. {
  126. if(maxY<Buffer[k].y)
  127. {
  128. maxY=Buffer[k].y;
  129. indBot1=k;
  130. }
  131. }
  132. maxY=0;
  133. for(int k=0;k<4;k++)
  134. {
  135. if(maxY<Buffer[k].y && k !=indBot1)
  136. {
  137. maxY=Buffer[k].y;
  138. indBot2=k;
  139. }
  140. }
  141. for(int k=0;k<4;k++)
  142. {
  143. if(k!=indBot1 && k!=indBot2)
  144. indTop1=k;
  145. }
  146. for(int k=0;k<4;k++)
  147. {
  148. if(k!=indBot1 && k!=indBot2 && k!=indTop1)
  149. indTop2=k;
  150. }
  151. if (Buffer[indBot1].x < Buffer[indBot2].x)
  152. {
  153. bottomLeft = Buffer[indBot1];
  154. bottomRight= Buffer[indBot2];
  155. }
  156. else
  157. {
  158. bottomLeft = Buffer[indBot2];
  159. bottomRight= Buffer[indBot1];
  160. }
  161. if (Buffer[indTop1].x < Buffer[indTop2].x)
  162. {
  163. topLeft = Buffer[indTop1];
  164. topRight= Buffer[indTop2];
  165. }
  166. else
  167. {
  168. topLeft = Buffer[indTop2];
  169. topRight= Buffer[indTop1];
  170. }
  171.  
  172. quad(topLeft.x+unit/2,topLeft.y+unit/2,topRight.x+unit/2,topRight.y+unit/2,bottomRight.x+unit/2,bottomRight.y+unit/2,bottomLeft.x+unit/2,bottomLeft.y+unit/2);
  173. }
  174. if(makeMovie)
  175. {
  176. mm.addFrame();
  177.  
  178. }
  179.  
  180.  
  181.  
  182.  
  183. }
  184.  
  185.  
  186.  
  187. void stop() {
  188. // always close Minim audio classes when you are done with them
  189. if(makeMovie)
  190. mm.finish();
  191. minim.stop();
  192. super.stop();
  193. }
  194.  
  195. class Coord
  196. {
  197. int x;
  198. int y;
  199. Coord (int ii, int ij) {
  200. x = ii;
  201. y = ij;
  202. }
  203. }
  204.  
  205. // Hold Class File:
  206.  
  207. boolean mReleased = false;
  208. float radius;
  209. void mouseReleased()
  210. {
  211. mReleased = true;
  212. }
  213.  
  214. class Hold
  215. {
  216.  
  217. PImage base; // image on screen
  218. PImage roll; // image when mouse is on
  219. PImage down; // image when clicked
  220. PImage currentimage;
  221. PImage p;
  222. int x, y; // coordinates of the holds
  223. int i,j; // place in the array, like HoldArray [i][j]
  224. int w, h; // width and height of the image
  225. int age = 0; // "age" of the hold. when clicked, it's born, and after 4 seconds, its "born" again, creating a sound
  226. String note; //name of the tone of each hold
  227. float [] rgb = new float [3];
  228.  
  229. boolean over = false; // bool if mouse over
  230. boolean pressed = false; // bool if mouse clicked
  231. boolean activated = false; // bool if sound of the hold is activated
  232. boolean left = false;
  233. AudioSample S;
  234. Hold(int ix, int iy, int ii, int ij, int iw, int ih, PImage ibase, PImage iroll, PImage idown, PImage ip, String inote)
  235. {
  236. x = ix;
  237. y = iy;
  238. i=ii;
  239. j=ij;
  240. w = iw;
  241. h = ih;
  242. base = ibase;
  243. roll = iroll;
  244. down = idown;
  245. p = ip;
  246.  
  247. currentimage = base;
  248. note=inote;
  249. for (int j=0;j<2;j++)
  250. rgb[j] = int(random(0,255));
  251. S = minim.loadSample(note, 2048);
  252. }
  253.  
  254. void pressed()
  255. {
  256. if(over && mReleased && !activated)
  257. {
  258. pressed = !pressed;
  259. activated = !activated;
  260. if(SoundOn)
  261. {
  262.  
  263. S.trigger();
  264.  
  265. }
  266. // if (c==4)
  267. // {
  268. // for (int t=1;t<4;t++)
  269. // Buffer[t-1]=Buffer[t];
  270. // Buffer[3].x=x;
  271. // Buffer[3].y=y;
  272. //
  273. // }
  274. // else
  275. // {
  276. Buffer[c]= new Coord(x,y);
  277. c++;
  278. // }
  279.  
  280. mReleased = false;
  281. } else if (over && mReleased && activated)
  282. {
  283. pressed = !pressed;
  284. //activated = !activated;
  285. left=!left;
  286. mReleased = false;
  287. for(int t=0;t<c;t++)
  288. {
  289. if (Buffer[t].x==x && Buffer[t].y == y)
  290. {
  291. int v=t;
  292. while((v+1)!=c)
  293. {
  294. Buffer[v]=Buffer[v+1];
  295. v++;
  296.  
  297. }
  298. }
  299. }
  300. if(left)
  301. {
  302. c--;
  303. }
  304. else
  305. {
  306. Buffer[c]= new Coord(x,y);
  307. c++;
  308. }
  309.  
  310. }
  311. }
  312.  
  313. void over()
  314. {
  315. if (mouseX >= x && mouseX <= x+w &&
  316. mouseY >= y && mouseY <= y+h)
  317. {
  318. over = true;
  319. }
  320. else
  321. {
  322. over = false;
  323. }
  324. }
  325.  
  326. void update()
  327. {
  328. over();
  329. pressed();
  330. if(pressed)
  331. {
  332. currentimage = down;
  333. }
  334.  
  335. else if (left)
  336. {
  337. currentimage = p;
  338. }else
  339. {
  340. currentimage = base;
  341. }
  342. }
  343.  
  344.  
  345.  
  346. void display()
  347. {
  348. fill(255,255,255);
  349. noStroke();
  350. rect(x,y,unit,unit);
  351.  
  352. if (counter-i*step>=0)
  353. radius = counter -i*step;
  354. else
  355. radius = beat + counter -i*step;
  356. radius = radius/float(beat)*63;
  357.  
  358. //rect:
  359. fill(0,0,255,radius);
  360. noStroke();
  361. rect(x,y,unit,unit); // draw rect
  362.  
  363. // fill(255,255,255);
  364. // noStroke();
  365. // rect(x,y,unit,unit);
  366. image(currentimage, x, y);
  367.  
  368.  
  369. }
  370. }//end of class Hold
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement