Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.sound.*;
- SinOsc sine;
- Env env;
- float attackTime = 0.001;
- float sustainTime = 0.004;
- float sustainLevel = 0.3;
- float releaseTime = 0.5;
- String myText = "0";
- void setup() {
- size(600, 600);
- background(0);
- textAlign(CENTER, CENTER);
- textSize(30);
- // Create the sine oscillator.
- sine = new SinOsc(this);
- env = new Env(this);
- }
- void draw() {
- text(myText, 0, 0, width, height);
- }
- void mousePressed() {
- /* sine.play();
- sine.freq(Estring(Integer.parseInt(myText)));
- //sine.freq(200);
- env.play(sine, attackTime, sustainTime, sustainLevel, releaseTime);*/
- myText = "";
- background(0);
- }
- void keyPressed() {
- if (keyCode == ' ') {
- myText = "";
- background(0);
- } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
- //myText = "";
- myText += key;
- sine.play();
- sine.freq(Estring(Integer.parseInt(myText)));
- env.play(sine, attackTime, sustainTime, sustainLevel, releaseTime);
- background(0);
- }
- }
- float Estring(int fret) {
- // E2, 82.41 Hz
- float note;
- note = 82.41;
- for ( int i = 0; i < fret ; i++) {
- note *= 1.05;
- }
- if (fret == 0) {
- note = 82.41;
- }
- return note;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement