name
plug ( )
import promidi.*;

MidiIO midiIO;

void setup(){
  size(128*5,128*5);
  smooth();
  background(0);

  // get an instance of midiIO
  midiIO = MidiIO.getInstance(this);
  
  // print a list of all devices
  midiIO.printDevices();

  // plug all methods to handle midievents
  midiIO.plug(this,"noteOn",0,0);
  midiIO.plug(this,"noteOff",0,0);
  midiIO.plug(this,"controllerIn",0,0);
  midiIO.plug(this,"programChange",0,0);
}

void draw(){

}

void noteOn(Note note){
  int vel = note.getVelocity();
  int pit = note.getPitch();

  fill(255,vel*2,pit*2,vel*2);
  stroke(255,vel);
  ellipse(vel*5,pit*5,30,30);
}

void noteOff(Note note){
  int pit = note.getPitch();

  fill(255,pit*2,pit*2,pit*2);
  stroke(255,pit);
  ellipse(pit*5,pit*5,30,30);
}

void controllerIn(Controller controller){
  int num = controller.getNumber();
  int val = controller.getValue();

  fill(255,num*2,val*2,num*2);
  stroke(255,num);
  ellipse(num*5,val*5,30,30);
}

void programChange(ProgramChange programChange){
  int num = programChange.getNumber();

  fill(255,num*2,num*2,num*2);
  stroke(255,num);
  ellipse(num*5,num*5,30,30);
}
description
Plug is a handy method to handle incoming midiEvents. To create a plug you have to implement a method that gets a Note, a Controller or a ProgramChange as input parameter. Now you can plug these methods using this method and the correspoding midievents are send to the plugged method.
syntax
plug(i_object, i_methodName, i_intputDeviceNumber, i_midiChannel);
parameters
i_object
Object: the object thats method has to plugged
i_methodName
String: the name of the method that has to be plugged
i_intputDeviceNumber
int: the number of the device thats events areto the plug
i_midiChannel
int: the midichannel thats events areto the plug
returns
None
usage
Web & Application
related