Improving the functionality of interactive sketch for installation.
in
Contributed Library Questions
•
1 year ago
Hi there,
I have a few questions about how to improve this code. It's fairly makeshift at the moment and it doesn't function as it needs to. I've stripped out all of the code which isn't integral to the sketch's functionality to make it easier to investigate. Can anyone offer some help or advice?
I'd like the code to react to the space bar being pressed once to begin the recording, but subsequently to not react to it being pressed until the video has played through, the recording is finished and the image is displaying again.
Currently when the space bar is pressed again there is a fragment of audio which plays before resetting to the start of the track although i don't think this will be an issue if there's no way to press space during recording. However, ideally the only event that would cause the recording to stop and the image to display is if the n/N key is pressed during the recording but pressing any other keys, including the space bar, would do nothing. If this functionality can be assigned to n/N, there is still the issue of the audio fragment playing when the space bar is pressed again.
I also need to combine the mp3's audio with the video somehow, hopefully as the recordings are being made. From my research so far this seems unlikely. But perhaps the files can be muxed between recordings? Also will it be possible to record a mic input and add that as an extra audio channel to the video output?
Finally I'd like to know of a method for moving the recorded videos to a timestamped folder and deleting the .#res files when the sketch is closed so that if the sketch crashes for any reason, the videos will not be overwritten accidentally when the sketch is restarted.
I know that there's quite a few questions in here but some assistance with any aspects of them would be greatly appreciated.
Many Thanks
I have a few questions about how to improve this code. It's fairly makeshift at the moment and it doesn't function as it needs to. I've stripped out all of the code which isn't integral to the sketch's functionality to make it easier to investigate. Can anyone offer some help or advice?
I'd like the code to react to the space bar being pressed once to begin the recording, but subsequently to not react to it being pressed until the video has played through, the recording is finished and the image is displaying again.
Currently when the space bar is pressed again there is a fragment of audio which plays before resetting to the start of the track although i don't think this will be an issue if there's no way to press space during recording. However, ideally the only event that would cause the recording to stop and the image to display is if the n/N key is pressed during the recording but pressing any other keys, including the space bar, would do nothing. If this functionality can be assigned to n/N, there is still the issue of the audio fragment playing when the space bar is pressed again.
I also need to combine the mp3's audio with the video somehow, hopefully as the recordings are being made. From my research so far this seems unlikely. But perhaps the files can be muxed between recordings? Also will it be possible to record a mic input and add that as an extra audio channel to the video output?
Finally I'd like to know of a method for moving the recorded videos to a timestamped folder and deleting the .#res files when the sketch is closed so that if the sketch crashes for any reason, the videos will not be overwritten accidentally when the sketch is restarted.
I know that there's quite a few questions in here but some assistance with any aspects of them would be greatly appreciated.
Many Thanks
//--------------------------------------------------------------------------------------------------------------------------------
//------------------------------------/GLOBALS, IMPORT LIBRARIES/-------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------
import codeanticode.gsvideo.*;
GSCapture cam;
////////////////////////////////////////////////////////////////////////////////////////
import processing.video.*;
MovieMaker mm;
Movie vid;
int numPix;
int GridScale = 4;
color vidColours[];
////////////////////////////////////////////////////////////////////////////////////////
import ddf.minim.*;
Minim minim;
AudioPlayer player;
float leftVol = 0;
float rightVol = 0;
////////////////////////////////////////////////////////////////////////////////////////
int sn = 0;//savenumber
int fn = 0;//framenumber
////////////////////////////////////////////////////////////////////////////////////////
PImage img;- //--------------------------------------------------------------------------------------------------------------------------------
//------------------------------------/SETUP/-------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------
void setup() {
size(960, 540, P2D);
frameRate(15);
background(0);
////////////////////////////////////////////////////////////////////////////////////////
img = loadImage("img960x540.jpg");
////////////////////////////////////////////////////////////////////////////////////////
String[] cameras = GSCapture.list();
cam = new GSCapture(this, 1280, 720, cameras[0]);
////////////////////////////////////////////////////////////////////////////////////////
vid = new Movie(this, "video240x136.mov");
numPix = width / GridScale;
vidColours = new color[numPix * numPix];
vid.loop();
////////////////////////////////////////////////////////////////////////////////////////
minim = new Minim(this);
player = minim.loadFile("audio7sec.mp3", 2048);
}
////////////////////////////////////////////////////////////////////////////////////////
void movieEvent(Movie v) {
v.read();
v.loadPixels();
for (int i0 = 0; i0 < numPix; i0++) {
for (int i1 = 0; i1 < numPix; i1++) {
vidColours[i0*numPix + i1] = v.get(i1, i0);
}
}
} - //--------------------------------------------------------------------------------------------------------------------------------
//------------------------------------/DRAW/--------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------- - void draw() {
background(0);
////////////////////////////////////////////////////////////////////////////////////////
if (key != ' ') {
background(img);
if (keyPressed == true) {
if (fn >=125) {
fn = 0;
mm.finish();
player.pause();
player.rewind();
}
}
////////////////////////////////////////////////////////////////////////////////////////
else if (fn<=124) {//this stops audio if another button is pressed during the recording
player.pause();
player.rewind();
}
}
////////////////////////////////////////////////////////////////////////////////////////
//if(keyPressed){
// if (key == 'y'|| key == 'Y'){// yes tag for archive/yes save copy to usb
//if(keyPressed){
// if (key == 'n'|| key == 'N'){// no tag for delete/stops recording/returns to image screen
////////////////////////////////////////////////////////////////////////////////////////
else if (key == ' ') { //press the space bar to start recording the video
if (keyPressed == true) {
mm = new MovieMaker(this, width, height, "video-output_"+(sn)+".mov", 15, MovieMaker.VIDEO, MovieMaker.HIGH);
fn = 0;
player.rewind();//
sn++;
player.play();
cam.play();
}
filter(THRESHOLD);//comment out for colour webcam
leftVol = 0;
rightVol = 0;
for (int i0 = 0; i0 < numPix; i0++) {
for (int i1 = 0; i1 < numPix; i1++) {
fill(vidColours[i0*numPix + i1]);
rect(i1*GridScale, i0*GridScale, GridScale-1, GridScale-1);
}
}
for (int i1 = 0; i1 < player.left.size()-1; i1++) {
leftVol = abs(leftVol + player.left.get(i1)*50);
rightVol = abs(rightVol + player.right.get(i1)*50);
}
////////////////////////////////////////////////////////////////////////////////////////
if (leftVol > 400) {
if (cam.available() == true) {
cam.read();
image(cam, -320, -180); //for 1280x720 webcam
}
}
////////////////////////////////////////////////////////////////////////////////////////
else if (leftVol <0.1) {
background(0);
}
////////////////////////////////////////////////////////////////////////////////////////
if (rightVol > 500) {
for (int i0 = 0; i0 < numPix; i0++) {
for (int i1 = 0; i1 < numPix; i1++) {
fill(vidColours [i0*numPix + i1]);
rect(i1*GridScale, i0*GridScale, GridScale-1, GridScale-1);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
mm.addFrame();
fn++;
println (fn);
}
////////////////////////////////////////////////////////////////////////////////////////
if (fn ==110) {
mm.finish();
player.pause ();
player.rewind();
}
////////////////////////////////////////////////////////////////////////////////////////
if (fn >=125) {
cam.pause();
background(img);
}
}
////////////////////////////////////////////////////////////////////////////////////////
void stop() {
player.close();
minim.stop();//
super.stop();//
}
////////////////////////////////////////////////////////////////////////////////////////
1