Slider - adjust sound cp5

How do I adjust the value of a slider in controlP5 in Processing?
For example. I’ve made a slider using the cp5 library, and I would like to change the volume from low to high whenever I move the slider up and down. So if the slider is moved up the sound gets louder and louder and vice versa. I hope this makes sense. Thank you.

import controlP5.*;
ControlP5 controlP5;
import processing.sound.*;  
foundFile file;  
int from = color(255,0,0);
int to = color(0,120,200);



void setup() {
 size(500,700);
 //smooth();
 file = new SoundFile(this, "Sweetdreams.mp3");    //loading my sound file  
 file.play();                                                     

 controlP5 = new ControlP5(this);
 
 //change the default font to Verdana;
 PFont p = createFont("Verdana",20); //skrifttype og størrelse
 ControlFont font = new ControlFont(p);
 
 //change the original colors
 controlP5.setColorForeground(lerpColor(from, to, 0.5)); 
 controlP5.setColorBackground(color(150,158,159)); 
 controlP5.setFont(font);
 controlP5.setColorActive(lerpColor(from, to, 0.5)); 

 controlP5.addSlider("")
 .setRange(0,30)
 .setValue(20)
 .setPosition(180,80)
 .setSize(120,600)
 .setColorValue(200)
 .setColorLabel(200);
 }
void draw() { 
 background(0); // background black 
}

please post your code into the

</> code button in editor menu

is that a question about

  • sound lib volume

or

  • cp5 slider ( change event )

for both i see no code?


possibly start from each lib closely from a RUNNING example

import processing.sound.*;
SoundFile soundfile;

void setup() {
  size(640, 360);
  soundfile = new SoundFile(this, "vibraphon.aiff");
  soundfile.loop();
  println("use: mouseY for volume");
}      


void draw() {
  float amplitude = map(mouseY, 0, width, 0.2, 1.0);
  soundfile.amp(amplitude);
}
import controlP5.*;
ControlP5 cp5;

void setup() {
  size(700,400);
  noStroke();
  cp5 = new ControlP5(this);
  cp5.addSlider("slider")
     .setPosition(100,305)
     .setSize(200,20)
     .setRange(0,100)
     .setValue(50)
     ;
}

void draw() {
}

void slider(float val) {
  println("a slider event: "+val);
}


now try to combine them.

2 Likes

PLEASE,
i asked you to format your code,
not to delete it.

vandalizing your question AFTER you got answers
might make the whole thread worthless for following readers,


this is not a private helpline ( from a company selling software for 600 TALER )

in a public forum the questions and the answers should express the will of a community
to help each other and also to learn from each other to make a better codebase, free for all.


Hello,
I’m fairly new to programmation,
I tried to recreate this code for a class, I download the P5 library as well as the Sound library. When I want to run the program, the error box indicates the “foundFile” doesn’t exists. Am I missing something to download here, or is it directly in the code?

Thanks