We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have this code, I used for an sports event. It keeps track of the score, and plays the corresponding song of the winning team.
I thought it might be useful for someone.
import ddf.minim.*;
import de.bezier.data.*;
Minim minim;
final int teams = 10; //must be equal to teams in the excel-page.
AudioPlayer[] team = new AudioPlayer[teams];
WaveformRenderer waveform;
XlsReader reader;
int[] team_player = new int[teams];
int[] team_point = new int[teams];
int[] team_isPlaying = new int[teams];
int pos = -1;
int max = -1;
int last_song;
int current_song;
int m_last;
int check_interval = 1000; //determines how often the program should test whether there is a new team leading
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
team[0] = minim.loadFile("team1.mp3", 1024); //load the songs for each team.
team[1] = minim.loadFile("team2.mp3", 1024);
team[2] = minim.loadFile("team3.mp3", 1024);
team[3] = minim.loadFile("team4.mp3", 1024);
team[4] = minim.loadFile("team5.mp3", 1024);
team[5] = minim.loadFile("team6.mp3", 1024);
team[6] = minim.loadFile("team7.mp3", 1024);
team[7] = minim.loadFile("team8.mp3", 1024);
team[8] = minim.loadFile("team9.mp3", 1024);
team[9] = minim.loadFile("team10.mp3", 1024);
waveform = new WaveformRenderer();
// see the example Recordable >> addListener for more about this
for (int i = 0; i < teams; i++)
{
team[i].addListener(waveform);
}
check_excel(); //calls the check_excel first time, so you don't have to wait: check_interval
}
void draw()
{
background(0);
// see waveform.pde for an explanation of how this works
waveform.draw();
if (millis() - m_last > check_interval)
{
m_last = millis();
check_excel();
}
}
void check_excel() {
{
reader = new XlsReader( this, "workbook.xls" );
for (int i = 0; i < teams; i++)
{
team_point[i] = reader.getInt(10, 1+i);
}
for (int i = 0; i < team_player.length; i++)
{
if (team_point[i] > max)
{
pos = i;
max = team_point[i];
}
}
println("Biggest: " + max + " at position " + pos);
last_song = current_song;
current_song = pos;
if (last_song != current_song){
println("this is not the same team");
team[last_song].pause();
team[last_song].rewind();
team[current_song].loop();
} else {
println("the same team is winning");
}
}
}
void stop()
{
// always close Minim audio classes when you are done with them
for (int i = 0; i < teams; i++)
{
team[i].close();
}
// always stop Minim before exiting.
minim.stop();
super.stop();
}