Hi, I'm working on a sound visualization and I'm trying add a button
that play the next song in the data folder.
I tried creating a separate array playlist but I found that the sound visualization stops
because the visualization is relying on "track.left.get(i)" of the sound waveform and
it's not included in the array playlist.
So I tried to make an array playlist using the original "track", but now I'm getting an error saying
"track.left cannot be resolved or is not a valid field".
Where am I doing wrong?
How should I write the codes so that both the button and the visualization works?
I'm really new to processing, so kind explanation would help a bunch.
Help me out please :(
The visualization looks roughly like this..
- import processing.serial.*;
- import cc.arduino.*;
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import ddf.minim.analysis.*;
- import ddf.minim.effects.*;
- Minim minim;
- AudioPlayer[] track; //audio file array
- //AudioPlayer track;
- WaveformRenderer waveform;
- float bpm = 50.2;
- float mspb = 60000/bpm;
- float x = 0;
- float y = 0;
- float x1 =0;
- float x2 =0;
- float y2 =0;
- float y1 =0;
- int a=1;
- float line_height = 1;
- int time = 0;
- PImage blackbutton;
- Arduino arduino;
- void setup() {
- size(1440, 700);
- arduino = new Arduino(this, Arduino.list()[0], 57600);
- for (int i = 0; i <= 13; i++)
- arduino.pinMode(i, Arduino.INPUT);
- colorMode(RGB);
- background(255);
- stroke(255);
- strokeWeight(0);
- frameRate(20);
- smooth();
- track = new AudioPlayer[3];
- minim = new Minim(this);
- track[0] = minim.loadFile("doublecherry.mp3", 2560);
- track[1] = minim.loadFile("springbreaks.mp3",2560);
- track[2] = minim.loadFile("robot.mp3",2560);
- //track.loop();
- //song = new AudioPlayer[3];
- blackbutton = loadImage("blackbutton.png");
- waveform = new WaveformRenderer();
- track.addListener(waveform);
- }
- void draw() {
- image(blackbutton,100,550,48,100);
- int lapse = millis();
- for (int i = 0; i <= 10; i++) {
- x1 = x;
- x2 = x;
- y1 = track.left.get(i);
- y2 = track.left.get(i+1);
- fill(1, map( abs(track.left.get(i)), 0, 1, 0, 255), 2,random(80));
- //fill(arduino.analogRead(i), map(abs(track.left.get(i)), 0,1,0,255),2, random(80));
- println(track.left.get(i));
- println(arduino.analogRead(i)/5);
- }{
- for (int i = 0; i < track.left.size()-1; i++) {
- x1 = x;
- x2 = x;
- y1 = track.left.get(i);
- y2 = track.left.get(i+1);
- noStroke();
- ellipseMode(CENTER);
- ellipse(x, y,abs(track.left.get(i))*13,abs(track.left.get(i))*13);
- x+=abs(track.left.get(i))*20;
- x+=5;
- }
- }
- if (lapse > mspb || x > width ) {
- time = millis();
- y += 6;
- x = 0;
- if (y > height){
- y = 0;
- background(255);
- }
- }
- waveform.draw();
- }
- void mousePressed() {
- if(mouseX>100 && mouseX<148)
- if(mouseY>550 && mouseY<650)
- if(track[0].isPlaying()){
- track[0].pause();
- }
- else{
- track[1].play();
- }
- if(mouseX>100 && mouseX<148)
- if(mouseY>550 && mouseY<650)
- if(track[1].isPlaying()){
- track[1].pause();
- }
- else{
- track[2].play();
- }
- if(mouseX>100 && mouseX<148)
- if(mouseY>550 && mouseY<650)
- if(track[2].isPlaying()){
- track[2].pause();
- }
- else{
- track[0].play();
- }
- }
- class WaveformRenderer implements AudioListener
- {
- private float[] left;
- private float[] right;
- WaveformRenderer(){
- left = null;
- right = null;
- }
- synchronized void samples(float[] samp){
- left = samp;
- }
- synchronized void samples(float[] sampL, float[] sampR){
- left = sampL;
- right = sampR;
- }
- synchronized void draw(){
- beginShape();
- for ( int i = 0; i < left.length; i++ ){
- ellipse(i, height/2 + left[i]*80, abs(track.left.get(i))*100, abs(track.left.get(i))*100);
- i+=80 ;
- }
- endShape();
- }
- }
- void stop(){
- track.close();
- minim.stop();
- super.stop();
- }
1