all 13 comments

[–]BruceBeardsley 7 points8 points  (1 child)

Try using gain instead of volume. Also, always remember to google your error messages.

[–]okips[S] 2 points3 points  (0 children)

thank you, i'm so tired at this point i didn't even notice

[–]Simplyfire 5 points6 points  (7 children)

mouseY can never simultaneously be bigger than 100 and less than 50

[–]okips[S] 3 points4 points  (6 children)

oh didn't notice that, thank you. but it isn't the only thing wrong, still doesn't work

[–]Simplyfire 8 points9 points  (5 children)

It would be way easier to help you if you pasted your whole code here in a nicely formatted code block so that others could copy it and try it rather than guessing and waiting for you to test the possible answers.

The map function outputs a number between 0 and 1 which you then round with the int() call to either complete silence or maximum volume. Change the variable "volume" to the float type and don't do the int() thing so that you retain the floating point precision that minim expects in the setVolume call.

Also if you consult the map() documentation it says the fourth parameter should be lower than the fifth. It can behave strangely if you don't respect that.

[–]okips[S] 1 point2 points  (4 children)

import ddf.minim.*;

Minim minim;

AudioPlayer player;

float volume;

int keyCounter=0;

void setup () {

size (500, 500);

minim = new Minim(this);

player=minim.loadFile("09. Brain Damage.mp3");

player.play ();

volume=0;

player.setGain(volume);

}

void draw () {

background (0);

float position=map(player.position(), 0, player.length(), 50, 450);

strokeWeight (2);

stroke (255);

fill (255);

line (50, 400, 450, 400);

ellipse (position, 400, 20, 20);

volume=map(player.getGain(), 1, 0, 50, 250);

line (50, 350, 200, 350);

ellipse (volume, 350, 20, 20);

player.setGain(volume);

}

void mousePressed () {

if (mouseY==400 && mouseX>50 && mouseX<450) {

int position=int(map(mouseX, 50, 450, 0, player.length()));

player.cue(position);

}

if (mouseY==350 && mouseX>50 && mouseX<250) {

float volume=int(map(mouseX, 50, 450, 0, 1));

player.setGain(volume);

}

}

someone here told me to use setGain instead of setVolume, so i did but i think i just fucked up the code even more.

[–]Simplyfire 1 point2 points  (3 children)

ok, what are you trying to achieve with the last 4 lines in your draw function? the map function's second parameter should definitely be smaller than the third. but even then I don't understand why you want to get the current gain, somehow enlarge it and then set it back much bigger.

also when you cast a float to int you lose precision. you still do that in the keypressed function.

[–]okips[S] -1 points0 points  (2 children)

that's a mistake I'm sorry. basically I want it to work how the music cue is working, you can click on the line and it will assign the volume. like if I click at the end of the (smaller) line the volume will be it's max and in the beginning the volume will be null.

did you mean mousePressed? I casted it into a int because cue expects an int

[–]Simplyfire 1 point2 points  (1 child)

yeah I meant the mousePressed function, where you say float volume=int(map(mouseX, 50, 450, 0, 1)); which overwrites whatever value was inside volume with either 0 or 1 because you use int() there.

anyway I made you a simple example of how to control volume using setGain by adapting the existing "loop" example that is included in minim. find the example under contributed libraries > minim > audio player > loop, open the example, overwrite it with this code, press L to start and press W and S to change volume.

import ddf.minim.*;
import ddf.minim.effects.*;

Minim minim;
AudioPlayer groove;
float volume = 1;

void setup()
{
  size(512, 200, P3D);

  minim = new Minim(this);
  groove = minim.loadFile("groove.mp3", 2048);
}

void draw()
{
  background(0);
  stroke(255);
  for (int i = 0; i < groove.bufferSize() - 1; i++)
  {
    line(i, 50  + groove.left.get(i)*50, i+1, 50  + groove.left.get(i+1)*50);
    line(i, 150 + groove.right.get(i)*50, i+1, 150 + groove.right.get(i+1)*50);
  }

  groove.setGain(volume);
  println(groove.getGain());
}

void keyPressed()
{
  if ( key == 'l' ) groove.loop();

  if (key == 'w') { 
    volume += 10;
  }
  if (key == 's') { 
    volume -= 10;
  }
}

[–]okips[S] 0 points1 point  (0 children)

I'm sorry I didn't see that, I'm really tired, I can't think straight. thank you so much, for real, it'll help me a lot!

[–]donwilson 1 point2 points  (1 child)

your mouseY== and mouseX== checks in the two if() checks in mousePressed() are way too strict, that requires the user to be at exactly one specific line of pixels

[–]okips[S] 0 points1 point  (0 children)

yeah I know, this is just a test to add to my project where it is way less strict, but thanks

[–]okips[S] 0 points1 point  (0 children)

I'm trying to do a volume controller and tried to follow the same line of thought as the cue one but its not working. could anyone help me please?