import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import ddf.minim.*; 
import ddf.minim.ugens.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class ImageMusic_pde extends PApplet {




Minim minim;
AudioOutput out;
PImage imgJPG;
public void setup()
{
  minim = new Minim(this);

 
  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();
  imgJPG = loadImage("image.png");
  
  setNewSize(imgJPG.width, imgJPG.height);
  imgJPG.loadPixels();

  out.setTempo(180);

  out.pauseNotes();

  for (int i = 0; i < imgJPG.pixels.length; i++) {
    float sound = red(imgJPG.pixels[i]) + blue(imgJPG.pixels[i]) + green(imgJPG.pixels[i]);
    out.playNote(i, 1, sound);
  }

  updatePixels();

  out.resumeNotes();
}

public void draw()
{
  background(0);
  stroke(255);
  image(imgJPG, 0, 0);
}

public void setNewSize(int w, int h)
{
  surface.setSize(w,h);
  size(w,h);
}
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "ImageMusic_pde" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
