Processing and Variable Metronomes

This is the place for all suggestions, releases and feedback regarding Milovana Hardware efforts.
Post Reply
Xenophobe
Explorer
Explorer
Posts: 92
Joined: Sat Jul 07, 2007 1:42 pm

Processing and Variable Metronomes

Post by Xenophobe »

Hello,

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();
}
-Xen
Attachments
timealarm2.zip
Processing code to demonstrate automatically ramping metronomes
(51.34 KiB) Downloaded 273 times
Xenophobe
Explorer
Explorer
Posts: 92
Joined: Sat Jul 07, 2007 1:42 pm

Re: Processing and Variable Metronomes

Post by Xenophobe »

Comments? Has anyone tried it?
Xenophobe
Explorer
Explorer
Posts: 92
Joined: Sat Jul 07, 2007 1:42 pm

Re: Processing and Variable Metronomes

Post by Xenophobe »

miller wrote:One quick question... is there a way to package your creation more like an executable, so that end users wouldn't have to install Processing to run the metronome?
You betcha. I don't access to the IDE right now but I'm pretty sure you can export programs as either JAR or EXE.
MegganKelley
Curious Newbie
Curious Newbie
Posts: 3
Joined: Tue Oct 09, 2012 8:22 am
Location: http://www.alldvdsonline.co.uk/
Contact:

Re: Processing and Variable Metronomes

Post by MegganKelley »

Just wanted to let you know that I've downloaded Processing & your variable metronome and got everything up and running. I'm not familiar with Processing (had never heard of it before, in fact), but it sounds interesting and I'll have a look.
Creating so touching plots and decent character developement, Mickey's Twice Upon A Christmas DVD will be the next huge thing on your TV with Rules of Engagement Seasons 1-4 DVD!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests