Hello,
I am trying to use the server/client class to receive data from a webpage. Basically, I send an AJAX call from the webpage, and I use processing to parse out the information I need (its a midi note that I am sending). It works great, except that it only lets me send about 6 notes, and then it crashes saying:
"Exception in thread "Animation Thread" java.lang.StringIndexOutOfBoundsException: String index out of range: -3"
Here is my code:
Code:
import processing.net.*;
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus
int port = 10002;
boolean myServerRunning = true;
int bgColor = 0;
int direction = 1;
int textLine = 60;
Server myServer;
void setup() {
size(800,800);
background(0);
textFont(createFont("SanSerif", 16));
myServer = new Server(this, port); // Starts a myServer on port 10002
MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, 2, 10); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
}
void draw() {
int channel = 0;
int pitch = 64;
int velocity = 127;
int number = 0;
int value = 90;
if (myServerRunning == true)
{
text("server", 15, 45);
Client thisClient = myServer.available();
if (thisClient != null) {
if (thisClient.available() > 0) {
String content = thisClient.readString();
int a = content.indexOf("/?");
int b = content.indexOf("HTTP");
String c = content.substring(a + 2, b - 1);
println(content.substring(a + 2, b));
int i = parseInt(c);
myBus.sendNoteOn(channel, i, velocity); // Send a Midi noteOn
delay(200);
myBus.sendNoteOff(channel, i, velocity); // Send a Midi nodeOff
text("mesage from: " + i, 15, textLine);
textLine = textLine + 35;
thisClient.stop();
}
}
}
}
Any help would be appreciated. Thanks.
-Thomas