We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, So I'm modifying some code created by this guy here - http://www.controllerism.com/controllerism-how-to-interactive-visuals-with-processing It's some cool coding that allows visuals to react to a combo of MIDI controller inputs and audio input. No I'm trying to take the visualizer element and allow it to just react to Audio Input but can't get the code to produce the visualizer! Looking to fix this v.quickly as there is a live event where I'd like to demonstrate it!
My modified code is this (I am aware I haven't created an option for switching scenes yet):
// Tomash Ghz - tomashg.com
// Ableton synced visuals in Processing Tutorial
import ddf.minim.*; // Iport the Minim Library for sound input
Minim minim; // Create instances of Minim
AudioInput in;
int scene=1; // Keep track of the current scene
int shape=1; // and shape
color backgroundCol=0; // Store the background color
color strokeCol=255; // Store the shape outile color
float soundWeight; // Store the sound volume weight
void setup() { // Setup function runs only once when the sketch starts. Initialize everything here
size(1280, 768); // Set the window size
noFill(); // Will draw only outline of shapes
rectMode(CENTER); // Set the rectangle origin to its center
colorMode(HSB, 360, 100, 100); // Set the color values to Hue Saturation Brightness instead of Red Green Blue
smooth(8); // Draw smooth shapes
minim = new Minim(this); // Create a new Minim class for sound input
in = minim.getLineIn(Minim.STEREO, 2048, 192000.0); // Enable
}
void draw() { // Draw function runs every frame. Update everything and draw on the screen
soundWeight=in.mix.level()*20; // Read the audio input and scale the value
drawScene(); // Draw the visuals
}
void drawScene(){ // A function we use to draw different things according to the current scene
switch(scene){ // We only have 4 scenes here
case 0:
background(0); // set the background black
break;
case 1:
background(backgroundCol); // just draw the background with its color
break;
case 2:
drawShapes(0); //draw static shapes over the background
break;
case 3:
drawShapes(soundWeight); //draw shapes that scale to the incoming volume levels. We pass the sound weight as the size value
break;
}
}
void randomColors(){ // A function we use to change randomly the colors
backgroundCol=color(random(127,255),50,50); // Set a random color for the background with a hue from 127 to 255
strokeCol=color(random(0,126),100,100);; // Set a random color for the outlines with a hue from 0 to 126
}
void drawShapes(float size){ // A function we use to draw a shape according to the current shape
background(backgroundCol); // First draw the background
stroke(strokeCol); // Set the outline color
pushMatrix();
translate(width/2,height/2); // Start drawing from the center of the screen
switch(shape%3){ // We only have 3 shapes so lets sycle through them. We add the size value
case 0:
rect(0,0,width/4+size*width/8,width/4+size*width/8); // Draw a square
break;
case 1:
ellipse(0,0,width/4+size*width/8,width/4+size*width/8); // Draw a circle
break;
case 2:
triangle(-width/8-size*width/16,width/8+size*width/16,0,-width/8-size*width/16,width/8+size*width/16,width/8+size*width/16); // Draw a triangle
break;
}
popMatrix();
}
Answers
Print size on line 63, see if it's what you expect.
Also print width/4+size*width/8
I think there might be some integer division going on somewhere.