Hey guys,
I am a beginner and try to read out a mouse to translate it into MIDI signals, but I have a few problems. First of all I dont know why the mouse output to the left and right is not the same. It should be equal and I tried to fix it, but it only gets better when i write it in the draw(). But thats not my main issue I need to translate the mouse signal into a MIDI signal and I have no glue how to manage this. I guess I have to use the MIDIbus library, but HOW???
Would be great if anyone could help me out.
Thx in advance
tootha
This is the MouseRead:
import themidibus.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Robot robot;
int mouseSumX = 0;
int mouseSumY = 0;
final int mouseXMax = 2000;
final int mouseYMax = 400;
void setup() {
size(900, 400);
try {
robot = new Robot();
}
catch (Exception e) {
println("Can't Initialize the Robot");
}
resetMouse();
println(mouseX + " " + mouseY);
//noCursor();
}
void draw() {
checkMouse();
}
void mousePressed() {
if (mouseButton == LEFT) {
mouseSumX = 0;
mouseSumY = 0;
} else {
mouseSumX = mouseXMax;
mouseSumY = mouseYMax;
}
}
void checkMouse() {
int mouseMoveX = mouseX - width/2;
int mouseMoveY = mouseY - (height/2 - 22); // -22 to set mouse in middle
resetMouse();
//println(mouseMoveX);
if (frameCount > 1 && (abs(mouseMoveX) > 0 || abs(mouseMoveY) > 0)) {
mouseSumX += mouseMoveX;
mouseSumY += mouseMoveY;
if (abs(mouseMoveX) > 0) {
println("Event: x: " + mouseSumX + " " + mouseSumY);
}
if (abs(mouseMoveY) > 0) {
println("Event: y: " + mouseSumX + " " + mouseSumY);
}
}
}
void resetMouse() {
javax.swing.JFrame f = getJFrame(getSurface());
//println(f.getLocationOnScreen().x + " " + f.getLocationOnScreen().y);
robot.mouseMove(f.getLocationOnScreen().x + width/2, f.getLocationOnScreen().y + height/2);
}
static final javax.swing.JFrame getJFrame(final PSurface surf) {
return
(javax.swing.JFrame)
((processing.awt.PSurfaceAWT.SmoothCanvas)
surf.getNative()).getFrame();
}