Processing + Xbox Controller + Sound

Hello, I'm new to processing and every time I try to play my program, I always get this message "NullPointExpectation" and my program doesn't want to work, can someone help me please.

Here is my program:

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

import processing.sound.*;

ControlIO control; ControlDevice stick; float X, Y;

ArrayList shadows = new ArrayList();

SoundFile soundfile;

public void setup() { size(400, 400);

soundfile = new SoundFile(this, "vibraphon.aiff");

println("SFSampleRate= " + soundfile.sampleRate() + " Hz"); println("SFSamples= " + soundfile.frames() + " samples"); println("SFDuration= " + soundfile.duration() + " seconds");

soundfile.loop();// Should play the file in a loop

control = ControlIO.getInstance(this);

stick = control.getMatchedDevice("joystick"); if (stick == null) { println("No suitable device configured"); System.exit(-1); }

stick.getButton("SHADOW").plug(this, "dropShadow", ControlIO.ON_PRESS);

soundfile = new SoundFile(this, "vibraphon.aiff");

println("SFSampleRate= " + soundfile.sampleRate() + " Hz"); println("SFSamples= " + soundfile.frames() + " samples"); println("SFDuration= " + soundfile.duration() + " seconds");

soundfile.loop();// Should play the file in a loop

}

// Poll for user input called from the draw() method. public void getUserInput() { X = map(stick.getSlider("X").getValue(), -1, 1, 0, width); Y = map(stick.getSlider("Y").getValue(), -1, 1, 0, height); }

// Event handler for the SHADOW button public void dropShadow() { // Make sure we have the latest position getUserInput(); shadows.add(new PVector(X, Y, 40)); }

public void draw() { getUserInput(); // Polling

fill(0, 0, 255, 32); noStroke(); for (PVector shadow : shadows) ellipse(shadow.x, shadow.y, shadow.z, shadow.z);

stroke(255, 70, 70, 70); fill(255, 70, 70, 70); ellipse(X, Y, 20, 20);

soundfile.rate(map(X, 0, width, 0.25, 4.0));

soundfile.amp(map(Y, 0, width, 0.2, 1.0));

soundfile.pan(map(Y, 0, width, -1.0, 1.0)); }

Answers

Sign In or Register to comment.