I've been playing with Processing lately -- it's a java-based programming language (google it). One thing I made is a variable metronome. It starts out relatively slow (around one beat every two seconds) and then slowly ramps up to about three beats a second. From there, it returns to the slower beat and begins the climb again. It has some other characteristics but they're too complicated to mention here. I'm posting this because I thought it was *ahem* entertaining and relevant to the site.
The code refers to two sound files. In addition to the code inserted below, I've attached a zip of the folder containing the code and sound.
Code: Select all
import ddf.minim.*;
Minim minim;
AudioSample kick;
AudioSample chimes;
float last;
float nextkick;
float lastchime;
float tic_prob_max = 2100;
float tic_prob_min = 300;
float tic_triggers = 0;
float tic_prob_next_change = 2;
float delay_to_change_window_size;
float tic_prob_change_max_triggers = 10;
float tic_prob_increment_max = 300;
float tic_prob_increment_min = 50;
float tic_prob_increment_increment_min = 10;
float tic_prob_increment;
float tic_direction = 0;
float tic_direction_change_prob = .05;
float tic_prob;
PFont myFont;
void setup()
{
size(512, 200, P2D);
myFont = createFont("verdana", 12);
textFont(myFont);
// always start Minim before you do anything with it
minim = new Minim(this);
// load BD.mp3 from the data folder with a 1024 sample buffer
// kick = Minim.loadSample("BD.mp3");
// load BD.mp3 from the data folder, with a 512 sample buffer
kick = minim.loadSample("BD.mp3", 2048);
chimes = minim.loadSample("chimes.wav",512);
nextkick = millis() + tic_prob_max;
tic_prob = tic_prob_max;
tic_prob_increment = tic_prob_increment_min;
}
void draw()
{
background(0);
float m = millis();
if (m > nextkick) {
nextkick = m + tic_prob;
last = m;
kick.trigger();
tic_triggers++;
//chimes.trigger();
if (tic_prob >= tic_prob_max) {
tic_direction = 0;
tic_prob_increment = min(tic_prob_increment_max,tic_prob_increment+tic_prob_increment_min);
if (tic_prob_increment == tic_prob_increment_max) {
tic_prob_increment = tic_prob_increment_min;
}
} else if (tic_prob <= tic_prob_min) {
tic_direction = 1;
}
}
if (m >=tic_prob_next_change) {
tic_prob_next_change = m + random(1000,15000);
if (tic_direction == 1) {
tic_prob = min(tic_prob+tic_prob_increment,tic_prob_max);
tic_prob = tic_prob_max;
tic_direction = 0;
} else {
tic_prob = max(tic_prob-tic_prob_increment,tic_prob_min);
}
}
if (tic_triggers >= 100) {
tic_triggers = 0;
chimes.trigger();
}
fill(255);
text("tic_prob = " + tic_prob,10,20);
text("tic_prob_increment = " + tic_prob_increment,10,50);
text("tic_direction = " + tic_direction,10,70);
text("tic_prob_change_in = " + (tic_prob_next_change - m),10,90);
}
void keyPressed()
{
if ( key == 'k' ) kick.trigger();
}
void stop()
{
// always close Minim audio classes when you are done with them
kick.close();
minim.stop();
super.stop();
}