We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys/girls,
Thanks for reading this, my place at university literally depends on getting this working in the next few days! I'm making a 'game' or more of a visual synthesizer I suppose. The background colour changes dependant on where the mouse is clicked, this part = simples.
The sounds are generated by a Sine wave oscillation - with the visual wave itself hidden (though it's an 'arty' project as i'm an 'arty' student - so if y'all can think of an 'arty' way of making the wave visible then go for it. This artyness also explains my lack of understanding/useful terminology so please excuse me)
I've done my best to compile the visual/audio elements and have worked through the errors encountered but am stuck after encountering a 'null pointer exception' - PLEASE HELP!!! I'm literally pulling my hair out....thanks in advance.
PImage bgImg;
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
Oscil wave;
void setup()
{
size(360, 640);
bgImg = loadImage("bgimg.png");
frameRate(30);
size(360, 640, P3D);
minim = new Minim(this);
// use the getLineOut method of the Minim object to get an AudioOutput object
out = minim.getLineOut();
// create a sine wave Oscil, set to 440 Hz, at 0.5 amplitude
wave = new Oscil( 440, 0.5f, Waves.SINE );
// patch the Oscil to the output
wave.patch( out );
}
void draw()
{
background(0);
stroke(255);
}
void mousePressed(){
wave.unpatch(out);
wave = new Oscil( mouseY, 0.5f, Waves.SINE );
wave.patch( out );
}
Answers
the bgimg is just a slightly textured background by the way, which could be removed but caused no issues before compilation, if that helps
Seems fine. Don't call size() twice. Don't call framerate() at all.
Thanks SO MUCH for the rapid response! Now the sound is playing, but only the sine wave is visible on a black background, not the colour changing dependant on mouse press stuff.......which i now realise in my panicked state i did not include fully (though for some reason i did remember to import the bgimg to the sketch and call a framerate.....that must have been confusing for you, sorry for that, ergh stress.)
anyway, here is the visual sketch which in full, that I would like to compile with the sound sketch you just fixed above. I've attempted to do so, but am having all kinds of issues....so here it is on it's own. Thanks again.
It's simple to merge the two. Just take what I've posted, add the global variable for the PImage of the background, load the image inside setup(), and draw and tint the background image in draw() after the background color is set.
Post the code of your attempt at it for more help.
Thanks, so here's my second attempt at merging the two following your instructions as best as i can.
(i know there are probably very obvious mistakes in it, but I am new to this so please excuse me - each time i solve one problem such as the current one being 'unexpected token - void' another one crops up).
You have two calls to size() again. You have a call to framerate() again. Your mousePressed function is inside your draw function. Press Ctrl + t to format your code.
Thanks, So I've deleted the second size() - was that the right one? And I have deleted the framerate(). I've also move the mousePressed function out of the draw and into the setup function - silly me. > <
I'm getting somewhere now - thanks again. it's running without errors! Though the screen is now split vertically in half (thinking i need to move the size perhaps??) a sine wave on one half and the background colour on the other, transitioning through the colours as planned. What I'm aiming for though is just to see the background taking up the whole screen, no sine wave, though the sine wave on top of the background would look kinda cool i guess. anything is better than this half and half business!
Also, the sound generated is cumulative/layering into one big very grating noise, with a constant background noise playing from the start without any clicking at all. Is there a way of firstly getting rid of that, so starting off silent then having a 1-2 second burst of sound played on each mouse press that ends automatically allowing a "fresh" sound to be played in isolation on next mousePress? Thanks! (I pressed ctrl + T after copy and pasting but can't tell if it did anything...)
Oh and just noticed that, say, 1 out of 3 times i run this i get the following error
"IndexOutOfBoundsException: Index: 26, Size:1"
Notice that there are three separate functions. In your lastest posted code, you've gotten the third one mixed in with the second one. Using ctrl + t to neaten up your code will format the spacing properly and allow you to see the problem.
Oh, kind internet stranger thank you again, the sound part of this is now working exactly as planned :)
Though the colour changing/ "tint" part was missing from the above code - so i went ahead and pasted it in where i reasoned it should go in the first chunk of the draw function (lines 29+30) - and it worked! Though the sine wave is now visible again, any ideas? A million thanks.
Could anyone please help me out here? I want the sine wave to not be visible.
"I want the sine wave to not be visible."
Well, then, just don't draw it?