ICM Final: Musical Typewriter Screenshot

I got the audio visualization to work.  The waves represent the audio waveforms of the percussion alphabet.  The letters fade out gradually after you type them to in order to help pace the user and to represent the “life cycle” of each note through time.  Here is a screenshot:

Source code after the jump:

import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

Minim minim;
WaveformRenderer waveform;
//AudioSample objects for each letter of the alphabet
AudioSample play_a;
AudioSample play_b;
AudioSample play_c;
AudioSample play_d;
AudioSample play_e;
AudioSample play_f;
AudioSample play_g;
AudioSample play_h;
AudioSample play_i;
AudioSample play_j;
AudioSample play_k;
AudioSample play_l;
AudioSample play_m;
AudioSample play_n;
AudioSample play_o;
AudioSample play_p;
AudioSample play_q;
AudioSample play_r;
AudioSample play_s;
AudioSample play_t;
AudioSample play_u;
AudioSample play_v;
AudioSample play_w;
AudioSample play_x;
AudioSample play_y;
AudioSample play_z;

void setup()
{
minim = new Minim(this);
size(500,500);

background(0);
textFont(createFont(“Courier”, 50));
text(“Type letters”, 50, height/2-30);
text(“to play”, 50, height/2+45);

play_a = minim.loadSample(“A.mp3”, 512);
play_b = minim.loadSample(“B.mp3”, 512);
play_c = minim.loadSample(“C.mp3”, 512);
play_d = minim.loadSample(“D.mp3”, 512);
play_e = minim.loadSample(“E.mp3”, 512);
play_f = minim.loadSample(“F.mp3”, 512);
play_g = minim.loadSample(“G.mp3”, 512);
play_h = minim.loadSample(“H.mp3”, 512);
play_i = minim.loadSample(“I.mp3”, 512);
play_j = minim.loadSample(“J.mp3”, 512);
play_k = minim.loadSample(“K.mp3”, 512);
play_l = minim.loadSample(“L.mp3”, 512);
play_m = minim.loadSample(“M.mp3”, 512);
play_n = minim.loadSample(“N.mp3”, 512);
play_o = minim.loadSample(“O.mp3”, 512);
play_p = minim.loadSample(“P.mp3”, 512);
play_q = minim.loadSample(“Q.mp3”, 512);
play_r = minim.loadSample(“R.mp3”, 512);
play_s = minim.loadSample(“S.mp3”, 512);
play_t = minim.loadSample(“T.mp3”, 512);
play_u = minim.loadSample(“U.mp3”, 512);
play_v = minim.loadSample(“V.mp3”, 512);
play_w = minim.loadSample(“W.mp3”, 512);
play_x = minim.loadSample(“X.mp3”, 512);
play_y = minim.loadSample(“Y.mp3”, 512);
play_z = minim.loadSample(“Z.mp3”, 512);

waveform = new WaveformRenderer();
play_a.addListener(waveform);
play_b.addListener(waveform);
play_c.addListener(waveform);
play_d.addListener(waveform);
play_e.addListener(waveform);
play_f.addListener(waveform);
play_g.addListener(waveform);
play_h.addListener(waveform);
play_i.addListener(waveform);
play_j.addListener(waveform);
play_k.addListener(waveform);
play_l.addListener(waveform);
play_m.addListener(waveform);
play_n.addListener(waveform);
play_o.addListener(waveform);
play_p.addListener(waveform);
play_q.addListener(waveform);
play_r.addListener(waveform);
play_s.addListener(waveform);
play_t.addListener(waveform);
play_u.addListener(waveform);
play_v.addListener(waveform);
play_w.addListener(waveform);
play_x.addListener(waveform);
play_y.addListener(waveform);
play_z.addListener(waveform);

textFont(createFont(“Courier”, 200));
noStroke();
frameRate(30);
}

void draw()
{
noStroke();
fill(0,0,0,20);
rect(0,0,width,height);
waveform.draw();
}

void keyPressed()
{
fill(255);
if ( key == ‘a’)
{
play_a.trigger();
text(“A”, width/2-60, height/2+50);
}

if ( key == ‘b’)
{
play_b.trigger();
text(“B”, width/2-60, height/2+50);
}

if ( key == ‘c’)
{
play_c.trigger();
text(“C”, width/2-60, height/2+50);
}

if ( key == ‘d’)
{
play_d.trigger();
text(“D”, width/2-60, height/2+50);
}

if ( key == ‘e’)
{
play_e.trigger();
text(“E”, width/2-60, height/2+50);
}

if ( key == ‘f’)
{
play_f.trigger();
text(“F”, width/2-60, height/2+50);
}

if ( key == ‘g’)
{
play_g.trigger();
text(“G”, width/2-60, height/2+50);
}

if ( key == ‘h’)
{
play_h.trigger();
text(“H”, width/2-60, height/2+50);
}

if ( key == ‘i’)
{
play_i.trigger();
text(“I”, width/2-60, height/2+50);
}

if ( key == ‘j’)
{
play_j.trigger();
text(“J”, width/2-60, height/2+50);
}

if ( key == ‘k’)
{
text(“K”, width/2-60, height/2+50);
play_k.trigger();
}

if ( key == ‘l’)
{
play_l.trigger();
text(“L”, width/2-60, height/2+50);
}

if ( key == ‘m’)
{
text(“M”, width/2-60, height/2+50);
play_m.trigger();
}

if ( key == ‘n’)
{
play_n.trigger();
text(“N”, width/2-60, height/2+50);
}

if ( key == ‘o’)
{
play_o.trigger();
text(“O”, width/2-60, height/2+50);
}

if ( key == ‘p’)
{
play_p.trigger();
text(“P”, width/2-60, height/2+50);
}

if ( key == ‘q’)
{
play_q.trigger();
text(“Q”, width/2-60, height/2+50);
}

if ( key == ‘r’)
{
play_r.trigger();
text(“R”, width/2-60, height/2+50);
}

if ( key == ‘s’)
{
play_s.trigger();
text(“S”, width/2-60, height/2+50);
}

if ( key == ‘t’)
{
play_t.trigger();
text(“T”, width/2-60, height/2+50);
}

if ( key == ‘u’)
{
play_u.trigger();
text(“U”, width/2-60, height/2+50);
}

if ( key == ‘v’)
{
play_v.trigger();
text(“V”, width/2-60, height/2+50);
}

if ( key == ‘w’)
{
play_w.trigger();
text(“W”, width/2-60, height/2+50);
}

if ( key == ‘x’)
{
play_x.trigger();
text(“X”, width/2-60, height/2+50);
}

if ( key == ‘y’)
{
play_y.trigger();
text(“Y”, width/2-60, height/2+50);
}

if ( key == ‘z’)
{
play_z.trigger();
text(“Z”, width/2-60, height/2+50);
}

if (key == ‘ ‘)
{
fill(0,0,0,20);
noStroke();
rect(0,0,width,height);
}
}

void stop()
{
play_a.close();
minim.stop();
super.stop();
}

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()
{
// we’ve got a stereo signal if right or left are not null
if ( left != null && right != null )
{
noFill();
stroke(255);
beginShape();
for ( int i = 0; i < left.length; i++ )
{
vertex(i, height/4 + left[i]*120);
}
endShape();
beginShape();
for ( int i = 0; i < right.length; i++ )
{
vertex(i, 3*(height/4) + right[i]*120);
}
endShape();
}
else if ( left != null )
{
noFill();
stroke(255);
beginShape();
for ( int i = 0; i < left.length; i++ )
{
vertex(i, height/2 + left[i]*120);
}
endShape();
}
}
}

Published by

leesean

Foossa Facts