Scrollable list to Bang


#1

I have scrollable list and i want to use the picked items in these to feed into 4 bangs which will then play different sets of sounds. I am struggling working out how to get this info to the bangs. Any help will be greatly appreciated !


#2

Please present a short code describing what you are doing and showing what parts you don’t understand. We are shooting in the dark here without this info.

Kf


#3
import controlP5.*;
import java.util.*;
import processing.sound.*;

SoundFile file1;
SoundFile file2;

ControlP5 cp5;

void setup() {
  file1 = new SoundFile(this, "sound1.wav");
  file2 = new SoundFile(this,"sound2.wav");
  cp5 = new ControlP5(this);
  
  background(0); 
  size(1450,900);

List l = Arrays.asList("Option1","Option2");
  
  
  cp5.addScrollableList("list1")
  .setPosition(250,500)
  .setSize(100,40)
  .setBarHeight(20)
  .setItemHeight(20)
  .addItems(l)
  //.setType(ScrollableList.DROPDOWN)
  .setLabel("List  1 ");
  
   cp5.addBang("a_bang1")
     .setPosition(1100, 500)
     .setSize(40, 40)
     .setLabel("1") 
     ;
     cp5.addBang("a_bang2")
     .setPosition(1150, 500)
     .setSize(40,40)
     .setLabel("2")
     ;
}

void draw(){
}

void a_bang1(){
if ( // this is where I want to ask if the list1 has picked option 1){
file1.play();
}
else if ( // has option 2 been selected){
file2.play();
}
}

void a_bang2(){
if ( // this is where I want to ask if the list1has picked option 1){
file2.play();
}
else if ( // has option 2 been selected){
file1.play();
}
}

Does this make any sense to you. I also would like to see the labels on the bangs but they do not show. Any ideas?
Thanks


#4

Please make sure you format your code. You can edit your post, select your code and click on the </> button aka. the button to format your code.

I changed the name of your variable for a list as a single letter name “l” is not very descriptive. You should called it something meaningful, based on the functionality of this object in your program.

Have a look at this example. It is one way to do things and hopefully it will provide you some ideas that you can exploit yourself. The trick is to detect when the list was clicked. You will have a variable that stores the selection. Notice I init this variable to NO_SELECTED in case the user runs the program and hits the bang button right way. Any other question or clarification, feel free to ask.

Kf

import controlP5.*;
import java.util.*;
import processing.sound.*;


final int NO_SELECTED = -1;
SoundFile file1;
SoundFile file2;

ControlP5 cp5;
int listOneSelection;
List list;

void setup() {
  file1 = new SoundFile(this, "sound1.wav");
  file2 = new SoundFile(this, "sound2.wav");
  cp5 = new ControlP5(this);

  background(0);
  size(1450, 900);

  list = Arrays.asList("Option1", "Option2");
  listOneSelection=NO_SELECTED;

  cp5.addScrollableList("list1")
    .setPosition(250, 500)
    .setSize(100, 40)
    .setBarHeight(20)
    .setItemHeight(20)
    .addItems(list)
    //.setType(ScrollableList.DROPDOWN)
    .setLabel("List 1 ");

  cp5.addBang("a_bang1")
    .setPosition(1100, 500)
    .setSize(40, 40)
    .setLabel("1")
    ;
  cp5.addBang("a_bang2")
    .setPosition(1150, 500)
    .setSize(40, 40)
    .setLabel("2")
    ;
}

void draw() {
}

void list1(int n) {
  listOneSelection=n;
}

void a_bang1() {

  manageSoundSelection();

  //if (1==1) // this is where I want to ask if the list1 has picked option 1){
  //  file1.play();
  //else if (1==1) // has option 2 been selected){
  //  file2.play();
}


void a_bang2() {

  manageSoundSelection();

  //if (1==1) // this is where I want to ask if the list1has picked option 1){
  //  file2.play();
  //else if (1==1) // has option 2 been selected){
  //  file1.play();
}


void manageSoundSelection() {
  switch(listOneSelection) {
  case NO_SELECTED:
    println("Nothing to do. Please make sure you choose an item in list 1");
    break;
  case 0:
  case 1:
    println("You have selected item " + listOneSelection + " fro list1");
    break;
  default:
    break;
  }
}


#5

Thank You :star:
That has done the trick
I can now see how it works