We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi community!
I've writen some code but i don't know how to get it working properly. I want to make a sound play and scaling the shape to the sound when the mouse moves over a certain area (rectangle or other shape). The sound works, but only once. After the sound has played i'm not able to replay it. And i've on more question. How can i scale a triangle, is there a CENTER mode like for rects? Cause my code only works with Java i've attached a short video as well as the original code. Thank's! :)
import ddf.minim.*;
Minim minim;
AudioPlayer Snare, Bass, Cymbal_Crash;
void setup()
{
size(500, 250);
minim = new Minim(this);
Snare = minim.loadFile("Snare_Hit.wav");
Bass = minim.loadFile("Bass_Drum.wav");
Cymbal_Crash = minim.loadFile("Cymbal_Crash.wav");
}
void draw()
{
background(255);
ellipse(120.5, 125, 47, 47);
rect(250, 125, 47, 47);
//Snare_Hit = Circle
noFill();
float mix1 = Snare.mix.level();
println(mix1);
float grau1 = map(mix1, 0, 0.5, 0, 255);
stroke(grau1);
ellipse(120.5, 125, mix1*200, mix1*200);
//Bass_Drum = Rect
noFill();
float mix2 = Bass.mix.level();
println(mix2);
float grau2 = map(mix2, 0, 0.5, 0, 255);
stroke(grau2);
rectMode(CENTER);
rect(250, 125, mix2*200, mix2*200);
//Cymbal_Crash = Triangle
noFill();
float mix3 = Cymbal_Crash.mix.level();
println(mix3);
float grau3 = map(mix3, 0, 0.5, 0, 255);
stroke(grau3);
triangle(356.866, 148, 383.135, 102.5, 409.405, 148);
if (mouseX > 97+8 && mouseX < 144+8 && mouseY > 101.5+8 && mouseY < 148.5+8)
{
Snare.play();
}
if (mouseX > 225 && mouseX < 275 && mouseY > 100 && mouseY < 150)
{
Bass.play();
}
if (mouseX > 356 && mouseX < 411 && mouseY > 101.5 && mouseY < 149)
{
Cymbal_Crash.play();
}
}
Answers
call rewind() before play(). the playhead needs to be pushed back to the start after you played it. rewind does this.
and you can use
sound.trigger()
or you could when I last checked@mschi: The problem with rewind() ist that the sound keeps playing and overlays endless times so you only get to hear a mess. I would like to get the sound playing always one time when you move above the shape. Any ideas? :)
And trigger() does not seem to work anymore?
try pause(); rewind(); play();
maybe just calling play(0); also does the job.
Unfortounately this doesn't change anything. ^^
I really don't know what's wrong here, that's the actual code:
And that's a short demonstration of the repetitive sound:
youtu.be/QHWtoFx17jI
In setup just add player.loop();
take your play trigger code out of draw() and insert it into a mousePressed function:
@mschi: Wow, that's really cool and does the job for me, thank you very much! :)
Do you also know how to scale a triangle with it's ankerpoint centered? ^^
you basically have to do something like that:
background infos here http://processing.org/tutorials/transform2d/
yes .trigger works and it would be way easier. This is a processing example that I changed a little:
Hello, I think I know what the mousePressed is suppose to do but it is being used with width instead of height which does not seem to have the proper effect. I changed it to this and it seems to work better. Cool little mini drum pad BTW. DJ xSUBn ({-_-})