Hello!!!
Sorry if I put a lot of code. I'm doing an application for a rhythm test, I connect the Arduino to sense when the person hit the sensor and send the data to Processing; in the other hand,I have an audio file with the rhythm that the person should follow. I use analyze() from Sound Library to obtain the Amplitud of the audio file. I send both of the data -the sensor and the amplitud to an excel file to obtain a graphic. Everything works independently but when I try to incorporate analyze() to the graphic interface, I try only with the "stop - btnStopSeq3" and "btnback3" buttons don´t works and appear a window: the program should be reopen, Report or Ignore. And the following:
I´m going to put all the tabs that I´m using, but I thing that only the problem is around PruebaDatosPantalla5-SongScreen-Analyze.
IN THE Tab PruebaDatosPantalla5:
import processing.serial.*; import g4p_controls.*; import processing.sound.*;
import java.util.*; import java.text.*;
Serial myPort; Table dataTable; Table table;
int numReadings = 500; int readingCounter = 0;
String val; String fileName; String val1; float New_rms_scaled;
Amplitude rms;
float scale = 5; float smooth_factor = 0.25; float sum;
Serial mipuerto;
GImageButton btnPlay, btnOptions1, btnOptions2, btnQuit_game, btnGame_info, btnPlay1, btnPlay2, btnPlaySeq3, btnPlaySeq5, btnPlaySeq7, btnPlayFile2, btnPlayFile3, btnStopSeq3, btnStopSeq5, btnStopSeq7, btnStopFile2, btnStopFile3, btnBackSeq3, btnBackSeq5, btnBackSeq7, btnBack2, btnBack3, btnHelp1, btnHelp2, btnHelp3, btnHelp4; GLabel lblOut, lblTempo, lblSong, lblCambiotiempo, lblCambiocancion; GCustomSlider sdrTempo, sdr; GDropList dplSong, dplCambiotiempo, dplCambiocancion, dplTempo; GPanel help_screen;
SoundFile seq3; SoundFile seq5; SoundFile seq7; SoundFile seq16; SoundFile seq19; SoundFile seq20; SoundFile seq21; SoundFile file2; SoundFile file3;
int red, green, blue;
long timer; String[] files;
PImage Seq16; PImage Seq19; PImage Seq20; PImage Seq21;
int j; int p; int i = 0; int mode = 1; int mute = 7; int audio = 1;
float k = 1;
void setup() { // this is run once.
//println(Serial.list());
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
table = new Table();
table.addColumn("Milisec"); table.addColumn("sensor"); table.addColumn("audio");
size(1024, 768);
cursor(CROSS);
make_inicio_screen();
make_settings_screen();
make_song_screen();
inicio_screen_visible(false);
settings_screen_visible(false);
song_screen_visible_Seq3(false);
song_screen_visible_Seq5(false);
song_screen_visible_Seq7(false);
song_screen_visible(false);
smooth();
space = loadImage("diseno.jpg");
prueba = loadImage("notasborder.jpg");
cursor(CROSS);
Seq3 = loadImage("Seq3.jpg");
Seq5 = loadImage("Seq5.jpg");
Seq7 = loadImage("Seq7.jpg");
Seq16 = loadImage("Seq16.jpg");
Seq19 = loadImage("Seq19.jpg");
Seq20 = loadImage("Seq20.jpg");
Seq21 = loadImage("Seq21.jpg");
}
void draw() { // this is run repeatedly.
if (myPort.available()>0)
{
val = myPort.readStringUntil('\n');
//println(val); //Shows received data
}
TableRow newRow = table.addRow(); //adds a row for new reading
newRow.setInt("Milisec", millis());
//println(millis());
readingCounter++; //writes file every numReadings reading cycles
newRow.setString("sensor", val);
newRow.setFloat("audio", New_rms_scaled);
table.trim("sensor");
saveTable(table, "data/prueba.csv"); //saves the data as a .csv
/////
switch(mode){
case 1:
inicio_screen_visible(true);
settings_screen_visible(false);
song_screen_visible_Seq3(false);
song_screen_visible_Seq5(false);
song_screen_visible_Seq7(false);
song_screen_visible(false);
inicio_screen();
break;
case 2:
settings_screen_visible(true);
inicio_screen_visible(false);
song_screen_visible_Seq3(false);
song_screen_visible_Seq5(false);
song_screen_visible_Seq7(false);
song_screen_visible(false);
settings_screen();
break;
case 3:
song_screen_visible_Seq3(true);
song_screen_visible_Seq5(true);
song_screen_visible_Seq7(true);
song_screen_visible(true);
inicio_screen_visible(false);
settings_screen_visible(false);
song_screen();
break;
case 4:
analyze();
}
}
public void handleButtonEvents(GImageButton button, GEvent event){
/////Botones InicioScreen
if(button == btnPlay1){
mode = 3;
}
if(button == btnOptions1){
mode = 2;
}
if(button == btnQuit_game){
exit();
}
//////BotonesSettingsScreen
if(button == btnBack2){ mode = 1; } if(button == btnHelp2){ mode = 5; }
////Botones SongScreen /// if(button == btnPlaySeq3){ loop(); seq3.play(); rms = new Amplitude(this); rms.input(seq3); mode = 4; }
if(button == btnStopSeq3){ loop(); seq3.stop(); //mode = 4; }
if(button == btnBackSeq3){ loop(); seq3.stop(); mode = 1; } /////// if(button == btnPlaySeq5){ loop(); //soundfile.play(); file3.play(k, 1.0); }
if(button == btnStopSeq5){ loop(); file3.stop(); }
if(button == btnBackSeq5){ loop(); file3.stop(); mode = 1; } /////// if(button == btnPlaySeq7){ loop(); //soundfile.play(); file2.play(k, 1.0); }
if(button == btnStopSeq7){ loop(); file2.stop(); }
if(button == btnBackSeq7){ loop(); file2.stop(); mode = 1; }
if(button == btnBack3){ loop(); file3.stop(); mode = 1; }
if(button == btnHelp1){ loop(); mode = 5; }
}
void handleSliderEvents(GValueControl slider, GEvent event){ /////Slider InicioScreen ////Slider SettingScreen if (slider == sdrTempo); println(sdrTempo.getValueF()+ " " + event); k = slider.getValueF(); }
public void handleDropListEvents(GDropList list, GEvent event){
if(list == dplSong);
println(sdrTempo.getValueF()+ " " + event);
dplSong.getSelectedIndex();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
IN THE TAB ANALYZE:
void analyze(){
sum += (rms.analyze() - sum) * smooth_factor; float rms_scaled = sum(height/2)scale;
ellipse(width/2, height/2, rms_scaled, rms_scaled);
//println(rms_scaled);
float New_rms_scaled = map(rms_scaled, 0, 97, 0, 410);
println(New_rms_scaled);
} /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// IN THE TAB SONGSCREEN:
int cancion;
void song_screen(){
song_screen_visible(true); //frameRate(1);
seq3 = new SoundFile(this, "Seq3.aiff"); seq5 = new SoundFile(this, "Seq5.aiff"); seq7 = new SoundFile(this, "Seq7.aiff"); seq16 = new SoundFile(this, "Seq16.aiff"); seq19 = new SoundFile(this, "Seq19.aiff"); seq20 = new SoundFile(this, "Seq20.aiff"); seq21 = new SoundFile(this, "Seq21.aiff"); file2 = new SoundFile(this, "2.aiff"); file3 = new SoundFile(this, "3.aiff");
switch(cancion){ case 0: Seq3partitura(); Seq3musica(); song_screen_visible(true); break;
case 1:
Seq5partitura();
Seq5musica();
song_screen_visible(true);
break;
case 2:
Seq7partitura();
Seq7musica();
song_screen_visible(true);
break;
}
int l = dplSong.getSelectedIndex(); cancion = l;
smooth();
}
void make_song_screen(){
int y = 10;
G4P.setCursor(ARROW); /////// files = new String[]{ "stopOff.jpg", "stopOn.jpg" }; btnStopSeq3 = new GImageButton(this, 350, 600, files);
files = new String[]{ "play1Off.jpg", "play1On.jpg" }; btnPlaySeq3 = new GImageButton(this, 600, 600, files);
files = new String[]{
"backOff.jpg", "backOn.jpg"
};
btnBackSeq3 = new GImageButton(this, 5, 5, files);
////////
files = new String[]{
"stopOff.jpg", "stopOn.jpg"
};
btnStopSeq5 = new GImageButton(this, 350, 600, files);
files = new String[]{ "play1Off.jpg", "play1On.jpg" }; btnPlaySeq5 = new GImageButton(this, 600, 600, files);
files = new String[]{
"backOff.jpg", "backOn.jpg"
};
btnBackSeq5 = new GImageButton(this, 5, 5, files);
////////
files = new String[]{
"stopOff.jpg", "stopOn.jpg"
};
btnStopSeq7 = new GImageButton(this, 350, 600, files);
files = new String[]{ "play1Off.jpg", "play1On.jpg" }; btnPlaySeq7 = new GImageButton(this, 600, 600, files);
files = new String[]{ "backOff.jpg", "backOn.jpg" }; btnBackSeq7 = new GImageButton(this, 5, 5, files);
lblSong = new GLabel(this, 300, y+50, 200, 20, "Choose Exercice"); lblSong.setTextBold(); String[] items = new String[]{ "Seq3", "Seq5", "Seq7", "Seq16", }; dplSong = new GDropList(this, 475, y+50, 250, 200, 10); dplSong.setItems(items, 0);
}
void song_screen_visible(boolean visible){ dplSong.setVisible(visible); lblSong.setVisible(visible); }
IN THE TAB SEQ3:
PImage Seq3;
void Seq3musica(){
stroke(0); song_screen_visible_Seq7(false); song_screen_visible_Seq5(false);
}
void Seq3partitura(){ background(255); image(Seq3, 360, 240);
}
void song_screen_visible_Seq3(boolean visible){ btnPlaySeq3.setVisible(visible); btnStopSeq3.setVisible(visible);
} /////////////////////////////////////////////////////////////////////////////////////////////////////////////// IN THE TAB SONGSETTINGS:
int cancion;
void song_screen(){
song_screen_visible(true);
seq3 = new SoundFile(this, "Seq3.aiff");
switch(cancion){ case 0: Seq3partitura(); Seq3musica(); song_screen_visible(true); break;
case 1:
Seq5partitura();
Seq5musica();
song_screen_visible(true);
break;
case 2:
Seq7partitura();
Seq7musica();
song_screen_visible(true);
break;
}
int l = dplSong.getSelectedIndex(); cancion = l;
smooth();
}
void make_song_screen(){
int y = 10;
G4P.setCursor(ARROW); /////// files = new String[]{ "stopOff.jpg", "stopOn.jpg" }; btnStopSeq3 = new GImageButton(this, 350, 600, files);
files = new String[]{ "play1Off.jpg", "play1On.jpg" }; btnPlaySeq3 = new GImageButton(this, 600, 600, files);
files = new String[]{
"backOff.jpg", "backOn.jpg"
};
btnBackSeq3 = new GImageButton(this, 5, 5, files);
////////
files = new String[]{
"stopOff.jpg", "stopOn.jpg"
};
btnStopSeq5 = new GImageButton(this, 350, 600, files);
files = new String[]{ "play1Off.jpg", "play1On.jpg" }; btnPlaySeq5 = new GImageButton(this, 600, 600, files);
files = new String[]{
"backOff.jpg", "backOn.jpg"
};
btnBackSeq5 = new GImageButton(this, 5, 5, files);
////////
files = new String[]{
"stopOff.jpg", "stopOn.jpg"
};
btnStopSeq7 = new GImageButton(this, 350, 600, files);
files = new String[]{ "play1Off.jpg", "play1On.jpg" }; btnPlaySeq7 = new GImageButton(this, 600, 600, files);
files = new String[]{ "backOff.jpg", "backOn.jpg" }; btnBackSeq7 = new GImageButton(this, 5, 5, files);
lblSong = new GLabel(this, 300, y+50, 200, 20, "Choose Exercice"); lblSong.setTextBold(); String[] items = new String[]{ "Seq3", "Seq5", "Seq7", "Seq16", }; dplSong = new GDropList(this, 475, y+50, 250, 200, 10); dplSong.setItems(items, 0);
}
void song_screen_visible(boolean visible){ dplSong.setVisible(visible); lblSong.setVisible(visible); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// IN THE TAB INICIOSCREEN:
PImage space = null; PImage space2 = null;
void inicio_screen(){ inicio_screen_visible(true); image(space, 0, 0); }
void make_inicio_screen(){ files = new String[]{ "playOff.jpg", "playOn.jpg" }; btnPlay1 = new GImageButton(this, 50, 700, files);
files = new String[]{ "optionsOff.jpg", "optionsOn.jpg" }; btnOptions1 = new GImageButton(this, 470, 700, files);
files = new String[]{ "quit_gameOff.jpg", "quit_gameOn.jpg" }; btnQuit_game = new GImageButton(this, 880, 700, files);
}
void inicio_screen_visible(boolean visible){ btnPlay1.setVisible(visible); btnOptions1.setVisible(visible); btnQuit_game.setVisible(visible); }