Using A Game Controller to Play Sound Files

edited October 2015 in Library Questions
import ddf.minim.*;
import ddf.minim.analysis.*; 
import ddf.minim.effects.*; 
import ddf.minim.signals.*; 
import ddf.minim.spi.*; 
import ddf.minim.ugens.*; 

import net.java.games.input.*; 
import org.gamecontrolplus.*; 
import org.gamecontrolplus.gui.*; 

ControlIO control; 
ControlDevice stick; 

Minim minim; 
AudioPlayer player; 

public void setup() { 
size (400, 400); 
control = ControlIO.getInstance(this); 
stick = control.getMatchedDevice("DrumController"); 
minim = new Minim(this); 
player = minim.loadFile("Kick.wav", 500); 
if (stick == null) { println("No Device Configured"); System.exit(-1);
 }}

void draw(){ 
if (stick.getButton("Circle").pressed() == true){ 
player.rewind(); 
player.play(); 
 }} 

I am using this code to use a PS3 controller to play a sound when one of the buttons is pressed. I have the sound file in and controller configuration in my project folder. Any help on reasons that it still won't play the sound when the button is pressed???

Answers

  • edited October 2015 Answer ✓

    Make sure that the configuration file does not match another device attached to the system e.g. mouse

    Can you copy the display the contents of the "DrumController" file in this discussion.

    DO NOT POST DUPLICATE DISCUSSIONS. I have deleted the other one.

    Also look at how to format text and code for this forum. Then EDIT your post above until the code is correctly displayed.

  • Here's the content of the "DrumController" file:

    Play Drum

    R2 Kick 1 BUTTON 9 0 0.0 0.0

    L2 Snare 1 BUTTON 8 0 0.0 0.0

    L1 Crash Cymbol 1 BUTTON 10 0 0.0 0.0

    R1 Ride Cymbol 1 BUTTON 11 0 0.0 0.0

    Circle HiMidTom 1 BUTTON 13 0 0.0 0.0

    X LowMidTom 1 BUTTON 14 0 0.0 0.0

    Left ClosedHiHat 1 BUTTON 7 0 0.0 0.0

    Down FloorTom 1 BUTTON 6 0 0.0 0.0

  • edited October 2015

    OK it will look for a device that has 8 buttons called 9 8 10 11 13 14 7 6

    All these buttons are available on the PS3 controller, I just tried it. So it is likely that you have actually connected with the PS3 controlled. Try changing draw to

    void draw() { 
      if (stick.getButton("Circle").pressed() == true) { 
        println("Circle button pressed");
        player.rewind(); 
        player.play();
      }
    } 
    

    Do you see Circle button pressed in the console window when you press the button?

  • No, nothing appears in the window...

  • Ok, so for some reason it all of a sudden wanted to work. Not sure what changed, but it's doing what it should now. Thanks for the help.

Sign In or Register to comment.