Advertisement
Guest User

Steemit Post

a guest
Aug 29th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import processing.sound.*;
  2. SinOsc sine;
  3. Env env;
  4.  
  5. float attackTime = 0.001;
  6. float sustainTime = 0.004;
  7. float sustainLevel = 0.3;
  8. float releaseTime = 0.5;
  9.  
  10. String myText = "0";
  11.  
  12. void setup() {
  13.   size(600, 600);
  14.   background(0);
  15.  
  16.   textAlign(CENTER, CENTER);
  17.   textSize(30);
  18.    
  19.   // Create the sine oscillator.
  20.   sine = new SinOsc(this);
  21.  
  22.   env = new Env(this);
  23.  
  24. }
  25.  
  26. void draw() {
  27.   text(myText, 0, 0, width, height);
  28. }
  29.  
  30. void mousePressed() {
  31.  /* sine.play();
  32.   sine.freq(Estring(Integer.parseInt(myText)));
  33.   //sine.freq(200);
  34.   env.play(sine, attackTime, sustainTime, sustainLevel, releaseTime);*/
  35.   myText = "";
  36.   background(0);
  37. }
  38.  
  39. void keyPressed() {
  40.  
  41.   if (keyCode == ' ') {
  42.     myText = "";
  43.     background(0);
  44.   } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
  45.     //myText = "";
  46.     myText += key;
  47.     sine.play();
  48.     sine.freq(Estring(Integer.parseInt(myText)));
  49.     env.play(sine, attackTime, sustainTime, sustainLevel, releaseTime);
  50.     background(0);
  51.   }
  52. }
  53.  
  54. float Estring(int fret) {
  55.   // E2, 82.41 Hz
  56.   float note;
  57.   note = 82.41;
  58.   for ( int i = 0; i < fret ; i++) {
  59.     note *= 1.05;
  60.   }
  61.   if (fret == 0) {
  62.     note = 82.41;
  63.   }
  64.   return note;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement