Paint Music Application not working properly
in
Core Library Questions
•
27 days ago
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.
- import ddf.minim.*;
- import ddf.minim.signals.*;
- //----------------------------
- ArrayList<Dots> poop;
- Minim minim;
- AudioOutput out;
- SineWave sine;
- //----------------------------
- color c;
- int thickness=1;
- float Low = 261;
- float High = 523;
- //----------------------------
- void setup()
- {
- size(500, 300);
- smooth();
- poop = new ArrayList();
- frameRate(123);
- //-------------------------
- minim = new Minim(this);
- out = minim.getLineOut(Minim.STEREO);// get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
- //-------------------------
- 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
- sine.portamento(10);// set the portamento speed on the oscillator to 200 milliseconds
- out.addSignal(sine); // add the oscillator to the line out
- //-------------------------
- }
- void draw()
- {
- background(255);
- for (int k=0;k<poop.size();k++)
- {
- Dots dot = (Dots) poop.get(k);
- dot.display();
- }
- loadPixels();
- for (int i=0;i<width;i++)
- {
- for (int j=0;j<height;j++)
- {
- int index = i + j*width;
- color findColor = pixels[index];
- float r = red(findColor);
- float g = green(findColor);
- float b = blue(findColor);
- if (r<255) {
- color fc1 = get(i, j);
- float freq1 = map(hue(fc1), 0, 255, Low, High);
- sine.setFreq(freq1);
- sine.setAmp(thickness/100);
- }
- if ( g<255) {
- color fc2 = get(i, j);
- float freq2 = map(hue(fc2), 0, 255, Low, High);
- sine.setFreq(freq2);
- sine.setAmp(thickness/100);
- }
- if ( b<255) {
- color fc3 = get(i, j);
- float freq3 = map(hue(fc3), 0, 255, Low, High);
- sine.setFreq(freq3);
- sine.setAmp(thickness/100);
- }
- else {
- sine.setAmp(0.0);
- }
- }
- }
- // out.setVolume(0.5);
- }
- void keyPressed()
- {
- if (key=='r' || key == 'R') c = color(255, 0, 0);
- if (key=='g' || key == 'G') c = color(0, 255, 0);
- if (key=='b' || key == 'B') c = color(0, 0, 255);
- if (thickness<1) thickness=1;
- if (key=='x' || key == 'X') thickness++;
- if (key=='z' || key == 'Z') thickness--;
- }
- void mouseDragged()
- {
- Dots D = new Dots(mouseX, mouseY, pmouseX, pmouseY, c, thickness);
- poop.add(D);
- }
- class Dots {
- int x, y, px, py;
- private int thickness;
- color col;
- Dots(int _x, int _y, int _px, int _py, color _c, int _thickness)
- {
- x = _x;
- y = _y;
- px = _px;
- py = _py;
- col = _c;
- thickness = _thickness;
- }
- void display()
- {
- //noStroke();
- //fill(col);
- strokeWeight(thickness);
- stroke(col);
- line(x, y, px, py);
- }
- }
1