import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; AudioSample beep0; AudioSample beep1; AudioSample beep2; AudioOutput out; SineWave sine; float circleX = 125; float tempo = 60; float circleChange; int pitch = 440; int rhythmKey = 0; int [] subdivision = {0,2,3,4,5,6}; boolean circleMotion; boolean beepBoolean = true; boolean funcBoolean = true; boolean subdivisionBoolean = false; PFont font; Minim minim = new Minim(this); void setup() { // Minim.start(this); beep0 = minim.loadSample("beep0.wav"); beep1 = minim.loadSample("beep1.wav"); beep2 = minim.loadSample("beep2.mp3"); out = minim.getLineOut(Minim.STEREO); sine = new SineWave(pitch, 0.0, out.sampleRate()); out.addSignal(sine); font = loadFont("TimesNewRomanPSMT-48.vlw"); size(700,500); frameRate(150); smooth(); } void draw() { //rectangle background(255); strokeWeight(20); stroke(23, 40); fill(125, 16, 240, 40); rect(100, 50, 200, 400); //rect use noStroke(); fill(16, 125, 240, 40); rect(350, 50, 300, 400); textFont (font, 20); fill(23, 100); text("Tempo/Pitch = F", 400, 90); text("Inc/Dec = UP/DOWN", 400, 130); text("Beep 1/2 = S", 400, 170); text("Beat = 2~6", 400, 210); text("No Beat = 0", 400, 250); //deco line strokeWeight(5); stroke(23, 40); for (int a = 300; a <= 420; a += 10) line ( 150, a, 250, a); //text String s = "Tempo:"+tempo; String p = "Pitch:"+pitch; String r = "Beat:"+rhythmKey; fill(0, 100); textFont (font, 30); text(s, 125, 170); text(p, 125, 220); text(r, 125, 270); circleChange = tempo/60; //line stroke(30, 100, 240, 110); strokeWeight(25); line(125, 100, 275, 100); //circle noStroke(); fill(255); ellipse(circleX, 100, 20, 20); //circle movement if (funcBoolean) { if (ceil(circleX) == 125 || floor(circleX) == 125 || int(circleX) < 125) { if (beepBoolean) beep0.trigger(); else beep1.trigger(); circleMotion = true; // if (subdivisionBoolean == true) // { // if (rhythmKey == 2) // sub } if (ceil(circleX) == 275 || floor(circleX) == 275 || int(circleX) > 275) { if (beepBoolean) beep0.trigger(); else beep1.trigger(); circleMotion = false; } if (circleMotion == true) circleX = circleX + circleChange; if (circleMotion == false) circleX = circleX - circleChange; } } void keyPressed() { if (key == 'f' || key == 'F') { funcBoolean = !funcBoolean; if (!funcBoolean) sine.setAmp(0.5); else sine.setAmp(0.0); } if (funcBoolean && key == CODED) { if (keyCode == UP) tempo++; if (keyCode == DOWN) tempo--; } else { if (keyCode == UP) pitch++; if (keyCode == DOWN) pitch--; sine.setFreq(pitch); } if (key == '0') { rhythmKey = 0; //subdivision[0]; subdivisionBoolean = false; } if (key == '2') { rhythmKey = 2; //subdivision[1]; subdivisionBoolean = true; } if (key == '3') { rhythmKey = 3; //subdivision[2]; subdivisionBoolean = true; } if (key == '4') { rhythmKey = 4; //subdivision[3]; subdivisionBoolean = true; } if (key == '5') { rhythmKey = 5; //subdivision[4]; subdivisionBoolean = true; } if (key == '6') { rhythmKey = 6; //subdivision[5]; subdivisionBoolean = true; } if (key == 's' || key == 'S') beepBoolean = !beepBoolean; } void stop() { beep0.close(); beep1.close(); beep2.close(); out.close(); minim.stop(); super.stop(); }