Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Paint Music Application not working properly

$
0
0
Hi,

I am trying to develop a Paint music application. This is how it should work, when you draw any stroke it should play the sound associated with the color and should play continuously. Every time when you make a different color stroke it should play some piece of sound. Currnelty I am only using primary colors but needed to be extend for more colors.  

Here, I am not using any external file (any wav or mp3 but this is the idea)   and using sine wave sound generator function.  I have tried to do the same but it is not working properly   

I also wanted to control the volume but it not happening too. 

  1. import ddf.minim.*;
  2. import ddf.minim.signals.*;
  3. //----------------------------
  4. ArrayList<Dots> poop;
  5. Minim minim;
  6. AudioOutput out;
  7. SineWave sine;
  8. //----------------------------
  9. color c;
  10. int thickness=1;
  11. float Low = 261;
  12. float High = 523; 
  13. //----------------------------
  14. void setup()
  15. {
  16.   size(500, 300);
  17.   smooth();
  18.   poop = new ArrayList();
  19.   frameRate(123);
  20.   //-------------------------
  21.   minim = new Minim(this);
  22.   out = minim.getLineOut(Minim.STEREO);// get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
  23.   //-------------------------
  24.   sine = new SineWave(440, 0.0, out.sampleRate());// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
  25.   sine.portamento(10);// set the portamento speed on the oscillator to 200 milliseconds
  26.   out.addSignal(sine); // add the oscillator to the line out
  27.   //-------------------------
  28. }

  29. void draw()
  30. {
  31.   background(255);
  32.   
  33.   for (int k=0;k<poop.size();k++)
  34.   {
  35.     Dots dot  = (Dots) poop.get(k);
  36.     dot.display();
  37.   }
  38.   loadPixels();
  39.   for (int i=0;i<width;i++)
  40.   {
  41.     for (int j=0;j<height;j++)
  42.     { 
  43.       int index = i + j*width;
  44.       color findColor = pixels[index];
  45.       float r = red(findColor);
  46.       float g = green(findColor);
  47.       float b = blue(findColor);
  48.       if (r<255) {
  49.         color fc1 = get(i, j);
  50.         float freq1 = map(hue(fc1), 0, 255, Low, High);
  51.         sine.setFreq(freq1);
  52.         sine.setAmp(thickness/100);
  53.       }
  54.       if ( g<255) {
  55.         color fc2 = get(i, j);
  56.         float freq2 = map(hue(fc2), 0, 255, Low, High);
  57.         sine.setFreq(freq2);
  58.         sine.setAmp(thickness/100);
  59.       }
  60.       if ( b<255) {
  61.         color fc3 = get(i, j);
  62.         float freq3 = map(hue(fc3), 0, 255, Low, High);
  63.         sine.setFreq(freq3);
  64.         sine.setAmp(thickness/100);
  65.       }
  66.       else {
  67.         sine.setAmp(0.0);
  68.       }
  69.     }
  70.   }
  71. //  out.setVolume(0.5);
  72. }


  73. void keyPressed()
  74. {
  75.   if (key=='r' || key == 'R') c = color(255, 0, 0);
  76.   if (key=='g' || key == 'G') c = color(0, 255, 0);
  77.   if (key=='b' || key == 'B') c = color(0, 0, 255);
  78.   if (thickness<1) thickness=1;
  79.   if (key=='x' || key == 'X') thickness++;
  80.   if (key=='z' || key == 'Z') thickness--;
  81. }


  82. void mouseDragged()
  83. {
  84.   Dots D = new Dots(mouseX, mouseY, pmouseX, pmouseY, c, thickness);
  85.   poop.add(D);
  86. }


  87. class Dots {
  88.   int x, y, px, py;
  89.   private int thickness;
  90.   color col;
  91.   Dots(int _x, int _y, int _px, int _py, color _c, int _thickness)
  92.   {
  93.     x = _x;
  94.     y = _y;
  95.     px = _px;
  96.     py = _py;
  97.     col = _c;
  98.     thickness = _thickness;
  99.   }
  100.   void display()
  101.   {
  102.     //noStroke();
  103.     //fill(col);
  104.     strokeWeight(thickness);
  105.     stroke(col);
  106.     line(x, y, px, py);
  107.   }
  108. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles