Hello, Is it possible to control the sound level of a video in a processing program. I have two videos playing at the same time and I want the program to be able to turn on and off the sound level based on variable values. Thanks Vincent
Sound level controled by processing program
How to fix 3D mousebutton rotation angle?
Hi, this is very very urgent I hope someone can help me now!
I'm trying to make a galaxy and somewhat a music visualizer. The stars are rotating based on the cursor position. However, due to that, my object for the music visualizer (labelled sun) has problems now. It is supposed to appear in the middle and it's now all the way at the left (only appearing when my mouse is in the extreme bottom right).
How do I plant my sun object in the middle top such that no matter how the cursor moves it will always be seen? I would like to fix it there however keep the aspect of it rotating (fixing the point but keeping the rotation) I wonder if its possible also. Please help me thanks!!!!
import ddf.minim.*;
import ddf.minim.analysis.*;
import controlP5.*;
Minim minim;
AudioPlayer player;
AudioMetaData meta;
BeatDetect beat;
ControlP5 cp5;
int cols, rows;
int scl = 20;
int w = 3500;
int h = 1600;
int state = 1;
int r = 200;
float rad = 70;
float[][] terrain;
float flying = 0;
// Stars parameters
int depth = 8;
int nbStarsMax = 10000;
Stars[] tabStars = new Stars[nbStarsMax];
int maxStarsSpeed = 5;
// Drawing parameters
int sizeX = 1280;
int sizeY = 2000;
boolean clearScreen = true;
int taille = 1;
int transparency = 255;
// Rotation variable
int rotationMode = 3;
float angle = 0;
float delta = radians(0.25);
void setup() {
size(displayWidth, displayHeight, P3D);
cols = w/scl;
rows = h/scl;
terrain = new float[cols][rows];
String strX, strY;
float yoff = 0;
for (int y = 0; y < rows; y++) {
float xoff = 0;
for (int x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -150, 150);
xoff += 0.2;
}
yoff += 0.2;
noCursor();
}
for (int nb=0; nb<nbStarsMax; nb++) {
tabStars[nb] = new Stars(random(-2*width, 2*width), random(-2*height, 2*height),
-random(depth*255), random(1, maxStarsSpeed));
}
minim = new Minim(this);
player = minim.loadFile("new life... (original synth instrumental).mp3");
meta = player.getMetaData();
beat = new BeatDetect();
//player.play();
}
void draw() {
beat.detect(player.mix);
beat = new BeatDetect(player.bufferSize(), player.sampleRate());
beat.setSensitivity(350);
if (state==0) {
terrain();
starry();
sun();
} else if (state==1) {
startscreen();
}
}
void terrain() {
player.play();
flying -= 0.02;
float yoff = flying;
for (int y = 0; y < rows-1; y++) {
float xoff = 0;
for (int x = 0; x < cols; x++) {
terrain[x][y] = map(noise(yoff, xoff), 0, 1, -100, 100);
xoff += 0.2;
}
yoff += 0.15;
}
background(0);
stroke(255);
noFill();
translate(width/2, height/2+50);
rotateX(PI/3);
translate(-w/2, -h/2);
for (int y = 0; y < rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
vertex(x*scl, y*scl, terrain[x][y]);
vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
//rect(x*scl, y*scl, scl,scl);
}
endShape();
}
}
void starry() {
translate(width/2+((mouseX-(width/2))*10)/(width/2),
height/2+((mouseY-(height/2))*10)/(height/2), 0);
rotateY(-((mouseX-(width/2))*radians(30))/(width/2));
rotateX(((mouseY-(height/2))*radians(30))/(width/2));
if (rotationMode==1) {
angle += delta;
}
if (rotationMode==2) {
angle -= delta;
}
rotateZ(angle);
for (int nb=0; nb<nbStarsMax; nb++) {
tabStars[nb].aff();
tabStars[nb].anim();
}
}
void sun() {
float t = map(mouseX/4, mouseY/2, width/2, 0, 1);
beat.detect(player.mix);
fill(#1A1F18, 20);
colorMode(HSB, 360, 100, 100);
noStroke();
//rect(0, 0, width, height);
translate(width/2, height/2);
//translate(width/2+((mouseX-(width/2))*10)/(width/2),
// height/2+((mouseY-(height/2))*10)/(height/2), 0);
noFill();
//fill of speaker
fill(-1, 10);
if (beat.isOnset()) rad = rad*0.9;
else rad = 70;
//ellipse(0, 0, 2*rad, 2*rad);
sphere(rad);
lights();
stroke(-1, 50);
int bsize = player.bufferSize();
for (int i = 0; i < bsize - 1; i+=5)
{
float x1 = (r)*cos(i*2*PI/bsize);
float y1 = (r)*sin(i*2*PI/bsize);
float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
line(x1, y1, x2, y2);
}
beginShape();
noFill();
stroke(-1, 50);
for (int i = 0; i < bsize; i+=30)
{
float x2 = (r + player.left.get(i)*100)*cos(i*2*PI/bsize);
float y2 = (r + player.left.get(i)*100)*sin(i*2*PI/bsize);
vertex(x2, y2);
pushStyle();
stroke(-1);
strokeWeight(2);
point(x2, y2);
popStyle();
}
endShape();
// if (flag)
// showMeta();
}
void startscreen() {
background(0);
stroke(255);
noFill();
translate(width/2, height/2+50);
rotateX(PI/3);
translate(-w/2, -h/2);
for (int y = 0; y < rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
rect(x*scl, y*scl, scl, scl);
}
}
}
void keyPressed() {
if (keyCode ==' ') {
if (state==1) {
delay(1000);
state = 0;
}
}
}
// if(key=='s')saveFrame("###.jpeg");
// if(key=='a') {
// fill(0,3);
// rect(0,0, width, height);
// fill(255);
// ellipse(random(width), random(height), 3, 3);
// Hihat2.trigger();
// }
//if(key=='g') {
// Kick2.trigger();
// }
void mousePressed() {
if (mouseButton==LEFT)
rotationMode = 1;
if (mouseButton==RIGHT)
rotationMode = 2;
if (mouseButton==CENTER)
rotationMode = 3;
}
How do I dynamically control filter frequency in P3 sound library?
I have a global variable filterFrequency, which is supposed to control the filter frequency of the sound library.
I have this in my setup() method:
drums.loop();
bass.loop();
pad.loop();
pluck.loop();
lowPass = new LowPass(this);
lowPass.process(drums);
lowPass.process(bass);
lowPass.process(pad);
lowPass.process(pluck);
I have this in my draw() method:
lowPass.freq(filterFrequency);
I am changing the filterFrequency from outside P3. I can see that the variable is changing, but the filter is not responding. Anyone had this problem before?
Advice on how to convert sound into camera distortion?
I'm working on a program that distorts camera feed using audio input and I was just wondering if people had advice on libraries/concepts/necessary to do this? Or if they'd be willing to share their experience with past programming projects?
here's what I've gotten to so far:
/*
Be Careful with your speaker volume, you might produce a painful
feedback. We recommend to wear headphones for this example.
*/
import processing.sound.*;
import processing.video.*;
AudioIn input;
Amplitude rms;
Capture cam;
int scale=1;
void setup() {
size(1200,800);
background(255);
//Create an Audio input and grab the 1st channel
input = new AudioIn(this, 0);
// start the Audio Input
input.start();
// create a new Amplitude analyzer
rms = new Amplitude(this);
// Patch the input to an volume analyzer
rms.input(input);
String[] cameras = Capture.list();
if (cameras == null) {
println("Failed to retrieve the list of available cameras, will try the default...");
cam = new Capture(this, 640, 480);
} if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
printArray(cameras);
cam = new Capture(this, cameras[0]);
cam.start();
background(0,0,0);
noStroke();
}
}
void draw() {
input.amp(map(mouseY, 0, height, 0.0, 200.0));
scale=int(map(rms.analyze(), 0, 0.5, 1, 350));
noStroke();
if (cam.available() == true) {
cam.read();
}
image(cam, 0, 0, width, height);
}
Smooth Zoom on Mouse click. Easing? And Stop Zooming.
Hello,
I've got this project set up and it almost works! What I'm having trouble with is two things; the first is I would like when the mouse is clicked for the zoom to smoothly grow into it's final state instead of snapping like it does now. The second issue I'm having trouble with is I would like the image to move back to it's original scale when the left mouse is clicked for the second time. Currently it just keep zooming in and you have to right mouse click to reset. Any suggestions? Thanks, you all have been a great help over the past few months.
import hype.*;
import hype.extended.layout.HGridLayout;
import hype.extended.behavior.HAttractor;
HDrawablePool pool;
HAttractor ha;
HAttractor.HAttractionForce hf;
PImage img;
float zoom = 1;
float x,y;
void setup() {
size(1364,640);
H.init(this).background(#263746);
smooth();
img = loadImage("ring.png");
ha = new HAttractor()
.repelMode()
.addForce(320, 320, 200)
.debugMode(false);
hf = ha.getForce(0);
pool = new HDrawablePool(1248);
pool.autoAddToStage()
.add(new HEllipse(4))
.layout(new HGridLayout().startX(21).startY(21).spacing(26,26).cols(52))
.onCreate(
new HCallback() {
public void run(Object obj) {
HDrawable d = (HDrawable) obj;
d.stroke(#dddddc).fill(#263746).anchorAt(H.CENTER);
ha.addTarget(d, 8, 1f);
}
}
)
.requestAll()
;
}
void draw() {
hf.loc(mouseX, mouseY);
H.drawStage();
pushMatrix();
translate(682 + x*zoom, 320 + y*zoom);
scale(zoom);
imageMode(CENTER);
image(img, 10, 10, 400, 400);
popMatrix();
}
void mousePressed() {
if (mouseButton == LEFT) {
x += (width/2 - mouseX)/zoom;
y += (height/2 - mouseY)/zoom;
zoom *= 3;
} else {
zoom = 1;
x = 0;
y = 0;
}
}
Upload image to webserver
Hi, I need to upload images to a webserver. I use PHP on the server side. The images are shots from the webcam using Processing 3. I can't found code, tutorials or examples about it. Is it possible to do using Processing? Thanks.
Minim AudioPlayer .play()'s corruption of sample end
Here, every attempt to play a sample using code like this:
import ddf.minim.*;
Minim minim;
AudioPlayer player;
minim = new Minim(this);
player = minim.loadFile("C:\\temp\\4.wav");
player.play();
suffers from truncation e.g. this source:

gives this result (recorded with WMCapture):

Any idea why I am getting this and (presumably) other users are not?
I have no such playback problem with any of the many other audio programs I use on the same computer, inc. GoldWave.
Java is Version 8 update 31, OS is Windows.
Get Anchor Point of SVG
Hi!
I'm trying to get all the anchor points from a loaded svg. I tried to do it with geomerative, but i only figured out how to get the anchor points AND the handles. Thats what i got so far:
import geomerative.*;
RShape shp;
void setup() {
size(600, 600);
RG.init(this);
shp = RG.loadShape("b.svg");
}
void draw() {
background(255);
translate(width/2, height/2);
RPoint[] handles = shp.getHandles();
for (int i = 0; i< handles.length; i++) {
ellipse(handles[i].x, handles[i].y, 10, 10);
}
}
this is how the output looks:

this is what i want:

here's the svg i'm using: http://pastebin.com/UEBZPtZt
how can i filter out all the handles?
Sound Visualization
Hi, I am trying to use Processing to visualize the sound from a sound clip (seems like screen saver style), and the visualized effect could follow the rhythm of the sound that I want to use. If any one can how me to figure it out, or have any sample that I can look, it will be great. Thanks!
recording a video
Hello,
I wrote a programme for audio-reactive visuals … usually I perform live in clubs (like here), but this time I need to record a video (sound doesn’t matter). I tried to write out jpegs, and a screen capture with Quicktime, but both slows down the programme a bit. However it is pretty essential that the visuals react precisely to the audio.
Does anybody have some advice maybe?
Cheers!
Minim FilePlayer loop() has delay.
Hey!
I am using Minim's FilePlayer with a stereo mp3 file and I am getting a small delay at the end of the loop (it doesn't loop right away). I am reading that this might happen with mp3 files in general, but I couldnt make Minim play well with WAVs (can't load them into a sound player...).
Anyone has experience with this?
Cheers, H.
controlp5 behaving differently in setup and draw
Hi all, I have a difficulty with controlp5. I am trying to update the value in a textbox but it won't accept my new string. The code below is my test code to get this working.
In the setup I can pass a string into the .setValue(); and it works but when it comes to the draw I can no longer pass a string into it, it throws an error that says it expects a float.
So the question is why? I can't for the life of me work out why this works then doesn't.
Thanks.
import controlP5.*;
ControlP5 cp5;
String newInput = "boop";
void setup() {
size(700, 400);
PFont font = createFont("arial", 20);
cp5 = new ControlP5(this);
cp5.addTextfield("Word 1")
.setPosition(20, 170)
.setSize(200, 40)
.setFont(font)
.setAutoClear(true)
.setValue(newInput)
.setColor(255) //text color
.setColorBackground(0)
.setCaptionLabel(" ")
;
textFont(font);
}
void draw() {
background(210);
newInput = cp5.getController("Word 1").getStringValue();
cp5.getController("Word 1").setValue(newInput);
println("NI:" + newInput);
text(newInput, mouseX, mouseY);
}
Opening a new P3D window from a 2d main window
The main part of my sketch is a control window with 4 tabs all consisting of CP5 sliders and buttons, I also have a separate 3D view window using Proscene which the user interacts with. Each of these elements I have working on thier own, i.e. if I just have a sketch with the (2D) Control window all works fine, If I have a sketch with just the 3D view interactive view then that works fine.
The problem is combining the two, I can't seem to find the correct way to "start up" the second window which is the P3D window. Are there any simple examples anywhere that show this sort of multi window mixed 2d and 3d setup ? I have tried to follow the ControlP5Frame example, whilst that kind of works in that it draws my controls, none of the functions connected to those controls continue to work. Sure I'm missing something very basic here :)
New g4p V4.1 GCheckbox button.setSelected( true & false ) bug?
Is there a bug using setSelected in GCheckbox ? When I use it the checkbox disappear.
Edit: If I click the place where the GCheckbox was at - it reappears.
Edit2: adding
button.setSelected(true);
button.setSelected(false);
Before the real setSelected also fixes everything :-)
MidiBus send midi message
I try to send CC message or Note to an other application, but I fail :( I try with Vezer to send at Daslight4, that's work fine. So I want make a samething with my sketch not with Vezer
here my bad try to do :
import themidibus.*;
MidiBus bus ;
void setup() {
bus = new MidiBus(this, 0, "Stuff") ;
bus.addOutput("Stuff") ;
}
void draw() {
int channel = 0 ;
int number = 23 ;
int value = (int)random(127) ;
bus.sendControllerChange(channel, number, value) ;
}
Hype Framework HCanvas Bug
Hello,
I'm currently taking the Joshua Davis tutorials from GumRoad. So much fun recommend them to everyone. I'm currently running into issues with my HCanvas class. I can't seam to run any sketch (neither my code from scratch or examples from hype) with the HCanvas class in it. If I go through and comment out the elements with HCanvas it runs but once I try to add them it just gives me a spinning wheel that never finishes.
Has anyone run into issues like this? Is it possible they have update the Hype Framework and I'm juts using old classes?
Any help would be greatly appreciated.
Thanks
Weather Data Library - Missing Links
Hi all,
I'm looking for a library or piece of code that can link processing to weather data, either real time, or in the form of the standard typical meteorological year (TMY) of EnergyPlus.
Any ideas of existing implementations? I spotted a Yaoo weather library by onformative on processing.org but the link is broken.
Any help is greatly appreciated.
Changing the instrument with Minim
Hello guys,
How could I change the type of instrument using the Minim library?
For example, like to switch Piano Violin, etc ...
I managed to do this with the soundcipher library, but some things have to do with Minim, I would have a fft and sinusoidal signal ... below is the sample code.
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
ToneInstrument myNote;
int note = 150;
void setup(){
size(512, 200, P2D);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO, 1024);
//myNote = new ToneInstrument( 200.f, 0.3, 0.5f, 1.0f );
//out.playNote(0.f, 8.f, myNote );
}
void draw(){
background( 0 );
stroke( 255 );
for( int i = 0; i < out.bufferSize() - 1; i++ ){
float x1 = map( i, 0, out.bufferSize(), 0, width );
float x2 = map( i+1, 0, out.bufferSize(), 0, width );
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
//line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
}
}
void mousePressed(){
//out.instrument(0); //??
out.playNote(0.f, 1, note );
}
void keyPressed(){
if (key == 'M' || key == 'm') note++;
else if (key == 'N' || key == 'n') note--;
}
class ToneInstrument implements Instrument{
Oscil sineOsc, lFOOsc;
Balance balance;
ToneInstrument(float frequency, float amplitude, float lfoFrequency, float lfoAmplitude){
sineOsc = new Oscil(frequency, amplitude, Waves.SINE);
lFOOsc = new Oscil(lfoFrequency, lfoAmplitude, Waves.SINE);
balance = new Balance( 0.5 );
lFOOsc.patch( balance.balance );
sineOsc.patch( balance );
}
void noteOn(float dur){
balance.patch(out);
}
// every instrument must have a noteOff() method
void noteOff(){
balance.unpatch(out);
}
}
Thanks for listening
Tweening Library
Hi, I'm looking for a library to create tweens on objects composed by a background rectangle and a front image. I need move on x,y and rotate, with simple easing. I tried ANI benedikt-gross.de/libraries/Ani/ but not works with rotation. There is another library to recommend? Thanks!
Minim: preloading songs for FilePlayer
Cobbled together a Minim script, and a bit unsure if reusing minim.loadFileStream() for every song change is the correct move or not as I'm only rotating between 3-4 song files and I'm going to be importing this functionality in to a much more heavy script. Is there a way to preload all 3-4 songs and just switch between them with FilePlayer? Just started using minim ytd and still a bit overwhelmed by the whole UGens concept >_>
Also: the tickRate seems to be reacting strangely.. while switching around the songs, I noticed the range of speed was different for the same song at different times.. even though its supposed to be mapped between 0-3..
EDIT: found out that tickRate UGen dislikes being patched alongside other UGen (such as gain) which was causing the weird output
Thanks in advance for any help you can punt my way :)
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
TickRate rateControl;
Gain gain;
AudioOutput out;
FilePlayer filePlayer;
String[] fileName = {"again_loop.aif", "groove.mp3", "jingle.mp3"};
void setup(){
size(640, 200);
minim = new Minim(this);
out = minim.getLineOut();
rateControl = new TickRate(1.f);
gain = new Gain(dB);
rateControl.setInterpolation( true );
}
void draw(){
float rate = map(mouseX, 0, width, 0.0f, 3.f);
rateControl.value.setLastValue(rate);
}
void keyPressed() {
if ( key == '0' ) {
filePlayer = new FilePlayer(minim.loadFileStream(fileName[0]));
filePlayer.patch(rateControl).patch(gain).patch(out);
filePlayer.play();
}
if ( key == '1' ) {
filePlayer = new FilePlayer(minim.loadFileStream(fileName[1]));
filePlayer.patch(rateControl).patch(gain).patch(out);
filePlayer.loop();
}
if ( key == '2' ) {
filePlayer = new FilePlayer(minim.loadFileStream(fileName[2]));
filePlayer.patch(rateControl).patch(gain).patch(out);
filePlayer.loop();
}
}