import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; static final boolean DRAW_COLUMNS = true; static final boolean DRAW_TICKER = true; // For sound synthesis Minim minim; AudioOutput out; float[] freqs; // The frequencies we want int quantise = 16; int tick = 0; // Particles Particle[] particles; int particleCount = 12; OrbitParticle[] orbitParticles; int orbitParticleCount = 4; float maxEnergy = 500; // Pulse Particles BParticle[] bParticles; // Beat Particles BeatParticle[] beatParticles; int totalParticles = particleCount + orbitParticleCount; void setup() { size(640, 480); smooth(); background(20); // For sound synthesis minim = new Minim(this); out = minim.getLineOut(Minim.STEREO, 6000); setFreqs(); // Particles particles = new Particle[particleCount]; for (int i = 0; i < particleCount; i++) { particles[i] = new Particle(); } orbitParticles = new OrbitParticle[orbitParticleCount]; for (int i = 0; i < orbitParticleCount; i++) { orbitParticles[i] = new OrbitParticle(); } totalParticles += freqs.length; bParticles = new BParticle[freqs.length]; beatParticles = new BeatParticle[freqs.length]; } void draw() { if (tick++ > quantise) tick = 0; /*float colWidth = (width + 0.0) / freqs.length; for (int i = 0; i < freqs.length;) { stroke(80); line(colWidth * i, 0, colWidth * i++, height); }*/ fill(20, 20); noStroke(); rect(0, 0, width, height); if (DRAW_TICKER) { if (tick % quantise == 0) { fill(0, 204, 255); ellipse(4, 4, 4, 4); } } // Update the particles for (int i = 0; i < particleCount; i++) { particles[i].move(); } for (int i = 0; i < orbitParticleCount; i++) { orbitParticles[i].move(); } for (int i = 0; i < bParticles.length; i++) { if (bParticles[i] != null) bParticles[i].update(); } for (int i = 0; i < beatParticles.length; i++) { if (beatParticles[i] != null) beatParticles[i].update(); } } void mousePressed() { int freqIndex = int(map(mouseX, 0, width, 0, freqs.length)); int nullIndex = -1; if (mouseButton == RIGHT) { for (int i = 0; i < bParticles.length; i++) { if (bParticles[i] == null) { nullIndex = i; } else { if (bParticles[i].freqIndex == freqIndex) { out.removeSignal(bParticles[i].wave); bParticles[i].wave = null; bParticles[i] = null; return; } } } bParticles[nullIndex] = new BParticle(freqIndex, quantise * int(random(1, 4) * 4)); } else { for (int i = 0; i < beatParticles.length; i++) { if (beatParticles[i] == null) { nullIndex = i; } else { if (beatParticles[i].freqIndex == freqIndex) { out.removeSignal(beatParticles[i].wave); beatParticles[i].wave = null; beatParticles[i] = null; return; } } } beatParticles[nullIndex] = new BeatParticle(freqIndex); } } void stop() { out.close(); minim.stop(); super.stop(); } float[] shuffleArray(float[] array) { for (int i = 0; i < array.length; i++) { int j = int(random(0, array.length - 1)); float tmp = array[j]; array[j] = array[i]; array[i] = tmp; } return array; } void setFreqs() { // Full set of scales in 12TET /*int scaleCount = 2; freqs = new float[scaleCount * 12]; float fundamental = 220.0; for (int i = 0; i < freqs.length; i++) { freqs[i] = fundamental * pow(2, i/12.0); }*/ // Full set of scales in 17tet /*int scaleCount = 3; freqs = new float[scaleCount * 17]; float fundamental = 220.0; for (int i = 0; i < freqs.length; i++) { freqs[i] = fundamental * pow(2, i/17.0); }*/ // Wholly random. /*int numSteps = int(random(2, 40)); freqs = new float[numSteps]; for (int i = 0; i < numSteps; i++) { freqs[i] = random(40, 1200); }*/ // E natural minor freqs = new float[15]; freqs[0] = 329.63; freqs[1] = 369.99; freqs[2] = 392.00; freqs[3] = 440.00; freqs[4] = 493.88; freqs[5] = 523.25; freqs[6] = 587.33; freqs[7] = 659.26; freqs[8] = 164.81; freqs[9] = 185.00; freqs[10] = 196.00; freqs[11] = 220.00; freqs[12] = 246.94; freqs[13] = 261.63; freqs[14] = 293.66; // E minor triad /*freqs = new float[4]; freqs[0] = 329.63; freqs[1] = 392.00; freqs[2] = 493.88; freqs[3] = 659.26;*/ // E minor pentatonic /*freqs = new float[6]; freqs[0] = 329.63; freqs[1] = 369.99; freqs[2] = 392.00; freqs[3] = 493.88; freqs[4] = 523.25; freqs[5] = 659.26;*/ freqs = shuffleArray(freqs); }