//by Jia Tao //2009.11 // Import the Sonia library import pitaru.sonia_v2_9.*; //initial key's position int mx = 30; int my = 10; int r = 20; //size of each key int rNum = 25;// how many keys on each colomn int cNum = 47;//how many keys on each row //initiate the first character int a = 32; //array for the postion of all keys int[] positionX = new int[cNum]; int[] positionY = new int[rNum]; //starting number to store charArray int ch = 0; void setup() { size(980,660); Sonia.start(this); // Start Sonia engine. LiveInput.start(); // Start listening to the microphone smooth(); background(80); //set up font type String s = "Courier"; PFont font = createFont(s, 9); textFont(font); //draw round keys strokeWeight(0.5);//thin outline rectMode(CENTER); for(int i = 0; i< rNum; i++){ for(int j = 0; j< cNum; j++){ fill(255); //store every key's position positionX[j] = mx; positionY[i] = my; //draw the row of keys rect(mx, my,r,r); fill(0);//black text(char(a), positionX[j]-2, positionY[i]+2); //store everykey's char mx+=20; a++; } //go to the next row mx = 30; my+=20; } } void draw() { // Get the overall volume (between 0 and 1.0) float vol = LiveInput.getLevel(); //locate the row and the column of the picked chars int pickedC = int(random(cNum)); int pickedR = int(random(rNum)); //specify the position the picked char int x = positionX[pickedC]; int y = positionY[pickedR]; rectMode(CENTER); //array for char char[] charArray = new char[2000]; // If the volume is greater than 0.01 a rectangle is drawn at a random location in the window. // The louder the volume, the larger the rectangle. if (vol > 0.01) { noStroke(); fill(random(255),random(255),random(255),180); rect(x,y,r,r ); //calculate the char on certain row and column int whichChar = (31+pickedC+1+(pickedR*cNum)); //store the picked chars charArray[ch] = char(whichChar); ch++; } //initiate the place of "typed" chars int charX = 30; int charY = 515; //displays text in the textfield for (int i = 0; i< 2000; i++){ if (charX< 940){ text(charArray[i],charX,charY); charX+=9; }else { charX = 30; charY +=10; } } rectMode(CORNER); // Graph the overall volume // First draw a background strip fill(255); rect(0,0,20,height); rect(960,0,980,height); // Then draw a rectangle size according to volume fill(random(255),random(255),random(255)); rect(0,height-vol*height,20,vol*height); rect(960,height-vol*height,980,vol*height); } // Close the sound engine public void stop() { Sonia.stop(); super.stop(); }