i have begun a project for my first electronics class and need help. my plan is to read audio input, calculate the frequencies inputted and have led's light up with certain frequencies. i have circuitry needed, but i am new to processing and am not familiar with it. i appreciate any help.
how do i use processing to control a string of LEDs to match sound frequencies?
How can I play the pixels of a live video with sound input?
Can I use the microphone or beats of a song as an input to change or paint a live video? I want to play with pixels by sound input. Is it possible?
Reading several files using multiple audioplayers, minim library
Hello,
I am trying to read several files using multiple audioplayers with minim library.
There are 4 .wav files corresponding to a zone, when one plays the others stop.
I am stuck with the index and would very much appreciate some help.
Thanks a lot in advance !
best, laurent
import ddf.minim.*;
Minim minim;
String [] fileNames = {"MOUSE", "WORDS", "FLOW", "VORTEX"};
int numSounds = fileNames.length-1;
int Border = 50;
/**AudioPlayer sounds1;
AudioPlayer sounds2;
AudioPlayer sounds3;
AudioPlayer sounds4;*/
AudioPlayer [] sounds = new AudioPlayer[numSounds];
int idx;
void setup () {
size(1080, 1080, P2D);
minim = new Minim (this);
/*sounds1 = minim.loadFile("MOUSE.wav");
sounds2 = minim.loadFile("WORDS.wav");
sounds3 = minim.loadFile("FLOW.wav");
sounds4 = minim.loadFile("VORTEX.wav");*/
for (byte idx = 0; idx != numSounds;
sounds[idx] = minim.loadFile (fileNames [idx++] +".wav"));
}
void draw() {
background (255);
fill(255, 0, 0);
rect(25, 25, 50, 50);
fill(0, 0, 255);
rect(125, 25, 50, 50);
}
void mouseMoved() {
if (mouseX > Border && mouseX < 350) {
sounds [(int)(idx)].play();
println("sound0:"+sounds);
} else if (mouseX < 750) {
} else {
}
if (mouseX < Border && mouseX > height-Border) {
}
}
void stop() {
for ( byte idx = 0; idx != numSounds; sounds[idx++].close() );
minim.stop();
super.stop();
}
touchOsc and Processing 3.2.3?
What do I need to do in order to get touchOsc working with processing 3.2.3? I see that my sketch is listening to port 31415, I have my touchOsc app sending out to port 31415, but I am getting nothing. Processing code below ... thank you.
*Edit - I'm not having any luck in 2.2.1 either.
import netP5.*;
import oscP5.*;
OscP5 oscP5;
float redFade;
void setup() {
size(480, 360);
oscP5 = new OscP5(this, 31415);
}
void draw() {
background(33);
//red rect
rectMode(CENTER);
pushStyle();
fill(0);
stroke(42, 42, 42);
rect(width/2, height/2, 255, 67);
fill(255, 15, 15);
rect(width/2, height/2, -redFade, 67);
popStyle();
}
void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if (addr.equals("/1/redFade")) { redFade = val;}
print("### received an osc message.");
}
Lockup with Game Control Plus by Quark
I am using the GC+ library to get Windows 7 joystick movements to processing. I then use the processing program to communicate with my Arduino microprocessor. Its a great library, awesome tutorials and documentation. My problem is it works for about 5 minutes flawlessly then my processing programs totally locks up. I cannot get the program to run again unless I reboot my computer. I am sorry I cannot follow the directions for posting code. Wow what I mess I am.
/**
Demonstration of using a joystick for Game Control Plus
When this sketch runs it will try and find
a game device that matches the configuration
file 'joystick' int the data file of the processing folder. if it can't match this device
then it will present you with a list of devices
you might try and use. Use the configurator in the Processing-->Files-->examples-->GC+ to write a data file that is included into the procesing
folder. You keymap and name various functions. These are then written down below in a code. (get matched
device and get slider).
The chosen device requires 2 sliders and 2 buttons.
*/
import org.gamecontrolplus.gui.*;
import org.gamecontrolplus.*;
import net.java.games.input.*;
import processing.serial.*;
ControlIO control;
ControlDevice stick;
float px, py, pz, pzz;
Serial myPort; // Create object from Serial class
public void setup() {
myPort = new Serial(this, "COM4", 9600);//this port can be different on even the same PC.
size(400, 400);
// Initialise the ControlIO
control = ControlIO.getInstance(this);
// Find a device that matches the configuration file
stick = control.getMatchedDevice("XBOX4"); // the device is named in the config file made by GC+ ap
if (stick == null) {
println("No suitable device configured");
System.exit(-1); // End the program NOW!
}
}
public void draw() {
px = stick.getSlider("STEERING").getValue(); //these values are named in the config file made by GC+ ap
py = stick.getSlider("THROTTLE").getValue();
pz = stick.getSlider("BRAKE").getValue();
px=map(px,-1,1,0,255);//data from game control is usually -1.0000 to + 1.0000///PWM of Arduino requires 0-255 for analogWrite output.
px = int(px);
py=map(py,-1,1,127,255);
py=int(py);
pz=map(pz,-1,1,127,0);
pz=int(pz);
pzz=py-(127-pz);
delay(100);
myPort.write("H" + int(px) + "," + int(pzz) + "\n"); //Arduino is looking for H255,255\n (can be any non numberical value to stop must be H to start)
background(255, 255, 240);
fill(255, 0, 0);
textSize(25);
text(int(px), 75, 100);//do not write to Processing monitor it takes too long, better to write to GUI.
text(int(pzz),75,200);
}
``
Opening A Webpage Inside Sketch
Is there anyone who can give me idea on how to open webpage inside sketch and not outside the sketch(browsers) with the help of controlP5 ?
Refreshing an image?
Okay, so I'm going to try and explain this the best I can and hopefully someone can help me. I have a program that basically takes a screen shot of the program window and saves it into the data folder. It then loads that image capture onto the screen where ever I tell it to. The problem that I'm having is that it doesn't load in a new image when I take a second screen shot. The new image is put into the data folder, but it doesn't replace the image that's up already.
import processing.video.*;
Capture cam;
PImage capture;
void setup() {
//window size
size(1280, 720, P3D);
background (0);
noCursor();
//webcam feed
capture = loadImage ("capture.jpg");
imageMode (CENTER);
String[] cameras = Capture.list();
//webcam feed
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw() {
if (cam.available() == true) {
cam.read();
}
//web cam feed position, size
image(cam, 640, 360, 320, 180);
}
void mousePressed() {
//image capture
saveFrame("data/capture.jpg");
cam.read();
//loads image capture in
image (capture, 200, 200, 480, 270);
image (capture, 1000, 500, 480, 270);
}
FFT Landscape generator
Hi there, I followed the Terrain Generator by Perlin Noise tutorial from youtube, and I tried to switch the perlin noise with an FFT of the mic audio input. X axis is fine, in the horizon I can clearly see my FFT effect, in the y axis I can't get the progressive generation, so to create a landscape from the sequences of FFT moments/frames. to get the Effect That the observer walks toward the horizon self-generated by FFT. Below is where I am:
//code
import processing.sound.*;
int cols, rows;
int scl = 20;
int w = 2000;
int h = 1600;
float [] [] terrain;
float flying = 0;
FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];
void setup () {
size (600, 600, P3D);
cols = w /scl;
rows = h /scl;
terrain = new float[cols][rows];
// Create an Input stream which is routed into the Amplitude analyzer
fft = new FFT(this, bands);
in = new AudioIn(this, 0);
// start the Audio Input
in.start();
// patch the AudioIn
fft.input(in);
}
void draw() {
fft.analyze(spectrum);
flying -= 0.1;
float yoff = flying;
for (int y = 0; y < rows; y++){
float xoff = 0;
for (int x = 0; x < cols; x++){
terrain[x] [y] = map(spectrum[x], 0, 1, 0, 10000);
xoff += 0.2;
}
yoff += 0.2;
}
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();
}
}
Could someone help me? Thanks a lot
Creating GUI for music visualizer
Cant seem to find any examples on how to create a GUI for music visualizer. The GUI I want to create is just a simple one that can browse music from my computer and play music through it. And also has standard buttons like play, pause and stop. Can anyone guide me or show me some examples ??
Program stops when window loses focus.
Hello.
I have a sketch that stops when I change it' windows focus to another window or minimize the sketch. Is there any thing I can do? I need to change the focus to play a game that the sketch is written for.
Webcam capture/ possible to crop a PImage
My code takes a screenshot of the window; the goal is to take a screenshot of the webcam feed, which is smaller than the program window, which is necessary for what my end goal. It then loads the screenshot into the program as a PImage. Is there a way to only capture the image from the dimensions of the webcam feed? Or is there a way to crop the .jpg in the data folder without leaving the program?
import processing.video.*;
Capture cam;
PImage capture;
void setup() {
//window size
size(1280, 720, P3D);
background (0);
noCursor();
//webcam feed
capture = loadImage ("capture.jpg");
imageMode (CENTER);
String[] cameras = Capture.list();
//webcam feed
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw() {
if (cam.available() == true) {
cam.read();
}
//web cam feed position, size
image(cam, 640, 360, 320, 180);
}
void mousePressed() {
//image capture
saveFrame("data/capture.jpg");
cam.read();
//loads image capture in
image (capture, 200, 200, 480, 270);
image (capture, 1000, 500, 480, 270);
}
Could anyone help me rearrange my code so that mousepressed presses all four ellipses?
The assignment is to create four ellipses that each have a different sound, and to make the code run so that each ellipse plays its sound when clicked (mousepressed). I have managed to get the top two ellipses to work; however, I cannot get the other two to work so I would really appreciate some help. (Down at the very end with my if/else if/else statements).
// import Minim
import ddf.minim.*;
Minim minim;
AudioSample d1;
AudioSample d2;
AudioSample d3;
AudioSample d4;
AudioOutput out;
// track when a drum has been struck
boolean drum1struck;
boolean drum2struck;
boolean drum3struck;
boolean drum4struck;
void setup() {
// initialize the screen
size(400, 400);
smooth();
// initialize sound
minim = new Minim(this);
out = minim.getLineOut();
d1 = minim.loadSample("bongo1.wav");
d2 = minim.loadSample("bongo7.wav");
d3 = minim.loadSample("tom1.wav");
d4 = minim.loadSample("tom2.wav");
// set boolean variables to initialize the graphics
drum1struck = false;
drum2struck = false;
drum3struck = false;
drum4struck = false;
}
void draw() {
background(255);
// draw the drums: if a drum has just been struck
// then fill its ellipse with color as visual feedback for the user
// drum 1
if (drum1struck == true) {
fill(255,0,0);
drum1struck = false;
}
else
{
fill(255);
}
ellipse(50, 55, 100, 100);
// drum 2
if (drum2struck == true) {
fill(255,0,0);
drum2struck = false;
} else {
fill(255);
}
ellipse(160, 55, 100, 100);
//drum 3
if (drum3struck == true) {
fill(255,0,0);
drum3struck = false;
}
else {
fill(255);
}
ellipse(50, 165, 100, 100);
//drum 4
if (drum4struck == true) {
fill(255,0,0);
drum4struck = false;
} else {
fill(255);
}
ellipse(160, 165, 100, 100);
}
void keyPressed() {
if (key == 'a' || key == 'A') { //note you may have to retype the
drum1struck = true; //single quote marks after copying
d1.trigger();
}
else if (key == 'b' || key == 'B') {
drum2struck = true;
d2.trigger();
}
else if (key == 'c' || key == 'C') {
drum3struck = true;
d3.trigger();
}
else if (key == 'd' || key == 'D') {
drum4struck = true;
d4.trigger();
}
}
void mousePressed() {
if (mouseX<105)
{
d1.trigger();
//set Boolean for drum1 to true
drum1struck = true;
}
else if (mouseX>105)
{d2.trigger();
//set Boolean for drum1 to true
drum2struck = true;
}
else if (mouseY<-200)
{
d3.trigger();
//set Boolean for drum1 to true
drum3struck = true;
}
else {
d4.trigger();
//set Boolean for drum1 to true
drum4struck = true;
}
}
Very low frame rate using Spout + Processing 3.2.3
Hi there,
I've just started to try using Spout to send sketches into Resolume, but when I add in the Spout code to an existing Sketch, the frame rate drops from 60fps to around 10fps. If I comment out the spout.sendTexture() call the frame rate goes back to 60fps. I am struggling to find any documentation explaining how to use spout correctly, the example spoutSender in the processing library also only achieves a frame rate of 20fps (with the textured spinning box), so thinking it might be something else I am missing. If anyone can provide any assisstance it would be most appreciated. Thanks, regards Andrew
Video Making
Can someone let me know the simplest way of create/making video through camera in processing ?
Sound
Does anyone know how to add sound in processing? I want to add sound when my ball moves, which only moves when I click around the ball by a specific range max. I downloaded the song, saved the file in my processing code file, but still can't get it added in my codes.
Libraries for text manipulation
Hello Processing members
I plan on doing an animation that pulls all the text from the screen to the middle and lets it pulse like a heart. For that I checked if I'm able to manipulate whole Strings and Chars the way I'm able to manipulate circles, for example. I found the libraries Nexttext and Fontastic, but those seem to be outdated, therefore I can't use them with Processing 3.0. Than there is the library Geomerative, which I manged to install through Processings library manager, but this one yields the error "duplicate libraries", which I can't find a , for me understandable, workaround for. I'm also using minim, since I combine the pulse with music input, minim works fine though.
Thus I'm asking if anyone here has an idea on how to fix this error, make the outdated libraries run or maybe someone has an alternative way/library to manipulate text.
Kindest regards.
The type JSONObject is ambiguous.
Already tried this https://forum.processing.org/two/discussion/16869/jsonobject-is-ambiguous-how-to-choose-processing-s-class
I`m using the dataset from this article http://blog.blprnt.com/blog/blprnt/processing-json-the-new-york-times
direct link http://www.blprnt.com/processing/NYTimes.zip
Trying to code a simple text box? Any help would be appreciated. Thanks!
Thanks!
Set border width GTextArea
Hello,
I have a question about the GTextArea from the G4P library: Is it possible to set the border/stroke width of a GTextArea? If I create a GTextArea, the border/stroke is 5px, but I want that to be 1px.
Thanks in advance Daantje
Syncing video to audio
Hello everyone,
I recently started working on a project that creates visuals for music using the minim library. All is well until I export the video file using GSvideo and use windows movie maker to create my music video. The audio seems to be quite a bit behind and the visuals don't really make sense (I've tried different frames/s values and still the same issue). I'm using processing 2.0, tried using the GSvideo pipeline but I'm not sure how to export both audio and video at the same time this way (any examples you have would be very much appreciated). Does anyone have any experience with this subject? Any pointers would be great.
Thanks in advance