# Slider - adjust sound cp5

**URL:** <https://discourse.processing.org/t/slider-adjust-sound-cp5/15606>\
**Category:** Libraries\
**Created:** [November 18, 2019, 8:40am UTC](https://discourse.processing.org/t/slider-adjust-sound-cp5/15606 "2019-11-18T08:40:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yty](https://avatars.discourse-cdn.com/v4/letter/y/b38774/32.png) [@yty](https://discourse.processing.org/u/yty)\
**Post date:** [November 18, 2019, 8:40am UTC](https://discourse.processing.org/t/slider-adjust-sound-cp5/15606/1 "2019-11-18T08:40:55Z")

</div>

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.

```auto
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 
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 18, 2019, 8:53am UTC](https://discourse.processing.org/t/slider-adjust-sound-cp5/15606/2 "2019-11-18T08:53:35Z")

</div>

please post your code into the

```auto
</> 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

```auto
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);
}

```

```auto
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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 18, 2019, 10:55am UTC](https://discourse.processing.org/t/slider-adjust-sound-cp5/15606/3 "2019-11-18T10:55:02Z")

</div>

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](http://duckiversum.de/andere/bilder/muenze_taler_1.jpg) )

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.

* * *

---

<div class="post-metadata">

**Author:** ![basu\_nosu](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@basu\_nosu](https://discourse.processing.org/u/basu_nosu)\
**Post date:** [February 19, 2022, 12:00am UTC](https://discourse.processing.org/t/slider-adjust-sound-cp5/15606/4 "2022-02-19T00:00:25Z")

</div>

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
