//int num = 3; boolean showRecPlay = false; BImage bg; ArrayList squares = new ArrayList(0); //SoundSquare[] squares = new SoundSquare[0]; SoundMenu menu; int mainWidth = 500; int mainHeight = 355; int menuHeight = 45; void setup() { size(mainWidth, mainHeight+menuHeight); Sonia.start(this); // Start Sonia engine. LiveInput.start(256); int cx, cy; // centre point cx = mainWidth/2; cy = mainHeight/2; /* // create colors for squares color c1 = color(0,0,150,200); color c2 = color(150,150,150,200); color c3 = color(0,0,150,200); color c4 = color(255,255,255,200); squares[0] = new SoundSquare(cx+5, cy-5,"guir.aif",c1); squares[1] = new SoundSquare(cx-5, cy+5,"dwave.wav",c4); squares[2] = new SoundSquare(cx+2, cy-2,"breath.aif",c2); // set docking positions squares[0].dockX = 140; squares[1].dockX = 170; squares[2].dockX = 200; for(int i=0;i bx-bs && mouseX < bx+bs && mouseY > by-bs && mouseY < by+bs) { bover = true; if(!locked) { stroke(255); fill(col); } } else { stroke(153); fill(col); bover = false; } //line(100,0,100,200); // Draw the box //rect(bx, by, bs, bs); image(myImg, bx-bs, by-bs); float rate = (mainHeight - by)*20000/(mainHeight); mySample.setRate(rate); //line(0,100,200,100); // Draw the box //rect(bx, 100, bs, bs); float pan = -1f + bx/(mainWidth/2f); mySample.setPan(pan); } void mousePressed() { if(bover) { locked = true; fill(255, 255, 255); } else { locked = false; } bdifx = mouseX-bx; bdify = mouseY-by; } void mouseDragged() { if(locked) { bx = mouseX-bdifx; by = mouseY-bdify; // check if in "Trash" hot zone (width-30px and height-1/2 image height) if(menu.isInTrashZone(bx,by,bs)) { menu.highlightTrash(true); if(menu.isOnTrash(bx,by)) { deleteMe(); } } else { menu.highlightTrash(false); if(bx+bs>mainWidth) bx=mainWidth-bs; if(by+bs>mainHeight) by=mainHeight-bs; if(bx-bs<0) bx=bs; if(by-bs<0) by=bs; } } } void deleteMe() { // dock this on menubar by=dockY; bx=dockX; deleteMe=true; } void mouseReleased() { locked = false; } } /* void drawMenu() { fill(40, 40, 40); noStroke(); rect(0,mainHeight,mainWidth-30,menuHeight); fill(0,0,0); rect(mainWidth-30,mainHeight,30,menuHeight); } */ class SoundMenu { int topX,topY,mHeight,mWidth; SaveButton btnRec; ImageButton btnPlay; ImageButton btnTrash; int nSnd = 3; SoundFactoryButton[] btnSounds = new SoundFactoryButton[nSnd]; boolean bRecording = false; boolean bPlaying = false; int progress; int soundImgSize=40; SoundMenu(int x,int y,int w,int h) { // set size topX=x; topY=y; mHeight=h; mWidth=w; // load images if (showRecPlay) { //record button BImage imgRec_b = loadImage("rec_base.gif"); BImage imgRec_r = loadImage("rec_roll.gif"); BImage imgRec_d = loadImage("rec_down.gif"); btnRec = new SaveButton(topX+10,topY+10,20,20,imgRec_b,imgRec_r); // play button BImage imgPlay_b = loadImage("play_base.gif"); BImage imgPlay_r = loadImage("play_roll.gif"); BImage imgPlay_d = loadImage("play_down.gif"); btnPlay = new ImageButton(topX+34,topY+10,20,20,imgPlay_b,imgPlay_r,imgPlay_d); } // trash button BImage imgTr_b = loadImage("trash.gif"); BImage imgTr_r = loadImage("trash_over.gif"); BImage imgTr_d = loadImage("trash.gif"); btnTrash = new ImageButton(topX+mainWidth-35,topY+8,24,24,imgTr_b,imgTr_r,imgTr_d); // sound buttons BImage img1 = loadImage("s1.gif"); btnSounds[0] = new SoundFactoryButton(topX+134,topY+2,soundImgSize,soundImgSize,img1,img1,"dump.wav"); BImage img2 = loadImage("s2.gif"); btnSounds[1] = new SoundFactoryButton(topX+194,topY+2,soundImgSize,soundImgSize,img2,img2,"pulse.wav"); BImage img3 = loadImage("s3.gif"); btnSounds[2] = new SoundFactoryButton(topX+254,topY+2,soundImgSize,soundImgSize,img3,img3,"enote.wav"); } boolean isInTrashZone(float x, float y, int r) { // return true if point in trash zone if((x+r+10>mainWidth) && (y+r>mainHeight)) { return true; } return false; } boolean isOnTrash(float x, float y) { // return true if point on trash if((x>=topX+mainWidth-20) && (x<=topX+mainWidth+20) && (y>=topY+8) && (y<=topY+8+20)) { println("Shape on trash x:" + x + " y:" + y); return true; } return false; } void drawMenu() { //fill(220, 220, 220); noStroke(); rect(0,mainHeight,mainWidth-45,menuHeight); if (showRecPlay) { btnRec.update(); btnPlay.update(); btnRec.display(); btnPlay.display(); } btnTrash.update(); btnTrash.display(); for(int i=0; i= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } //////////////////////////// // main class to create/destroy sounds // button on menu for each type of sound // just need to override pressed to create a new sound class SoundFactoryButton extends ImageButton { String sound; boolean press_active; SoundFactoryButton(int _x, int _y, int _w, int _h, BImage b, BImage r, String _sound) { super(_x,_y,_w,_h,b,r,r); sound=_sound; } void update() { super.update(); if(pressed) { if(!over) { pressed=false; press_active=false; } else { if(!press_active) { println("pressed - create new sound " + sound); createSound(); } press_active = true; } } else { press_active=false; } } void createSound() { color c1 = color(0,0,150,200); squares.add(new SoundSquare(x+(h/2),y-35,sound,c1,base)); } } //////////////////////////// // main class to create/destroy sounds // button on menu for each type of sound // just need to override pressed to create a new sound class SaveButton extends ImageButton { FileDialog dlg; boolean press_active; SaveButton(int _x, int _y, int _w, int _h, BImage b, BImage r) { super(_x,_y,_w,_h,b,r,r); //dlg = new FileDialog(this); //dlg.setMode(FileDialog.SAVE); } void update() { super.update(); if(pressed) { if(!over) { pressed=false; press_active=false; } else { if(!press_active) { println("pressed - Save File "); showSave(); } press_active = true; } } else { press_active=false; } } } void showSave() { JSObject window = JSObject.getWindow(this); Object obj = window.call("getFormValue", null); Object[] args = {(String)obj}; window.call("alert", args); //dlg.show(); }