Edit: TLDR:
How do I bind the plug method to a method of an object? Something like:
Code:
Foo f = new Foo();
midiIO.plug(foo, "noteOn", 0, 0);
class Foo {
void noteOn(Note note){
println("note received");
}
}
-----
Hi guys - long time listener, first time caller:
I'm having some trouble with the plug method of the proMidi 2.0 library. I am trying to plug a method of a class "Ship" to receive noteOn messages, but I keep getting the
"Error on plug: >noteOn< You can only plug methods that have a MidiEvent, a Note, a Controller or a ProgramChange as Parameter"-exception. I understand the exception, but I don't understand why - the callback-method does have a Note as a parameter...
Some code:
stjernetur.pde-snippet:
Code:
import promidi.*;
Engine engine;
void setup(){
randomSeed(1337);
frameRate(30);
colorMode(HSB);
engine = new Engine();
engine.setupRenderer();
engine.addHunter(300, 1200, 400, 800, 1, 1);
engine.bindMidiToShip(0, 1);
}
Engine.pde-snippet:
Code:
class Engine {
MidiIO midiIO;
ArrayList ships;
Engine(){
midiIO = MidiIO.getInstance();
ships = new ArrayList();
}
void addHunter(int xPos, int yPos, int xGoal, int yGoal, int direction, int midiChannel){
Hunter h = new Hunter(xPos, yPos, xGoal, yGoal, direction, midiChannel);
ships.add(h);
}
void bindMidiToShip(int shipId, int midiChannel){
midiIO.plug((Ship) ships.get(shipId), "noteOn", 0, midiChannel);
}
}
The "Hunter" is a subclass of the "Ship"-class, which I want instances of to be the callback objects for the proMidi-plug method. The callback function looks like this:
Ship.pde-snippet:
Code:
class Ship {
//Code removed
public void noteOn(Note note){
println("note on " + note.getPitch());
int notePitch = constrain(note.getPitch(), 0, 255);
shoot(color(notePitch, 200, 200));
}
}
So, to clarify, I have a "Ship"-class with the subclass "Hunter". I also have an "Engine"-class which produces and stores "Hunter"-instances in a ArrayList.
With a call of the "bindMidiToShip"-method I want to make a "Hunter"-instance the callback object of the plug-method, but I keep getting the "You can only plug methods that have a MidiEvent, a Note, a Controller or a ProgramChange as Parameter"-exception, even though the method specified has a Note type as a parameter.
I am probably just confused on the subjects of callback-objects and method, but I can't seem to wrap my head where the error is.
Please let me know if I should post more code.
Cheers, krqluld