|
// License:CC0 1.0 |
|
|
|
int OSCSendPort = 19100; |
|
int OSCReceivePort = 28100; |
|
|
|
import oscP5.*; |
|
import netP5.*; |
|
import themidibus.*; |
|
import controlP5.*; |
|
|
|
MidiBus myBus; |
|
ControlP5 cp5; |
|
OscP5 oscP5; |
|
NetAddress remoteOscServer; |
|
|
|
String textMessage = "/"; |
|
String midiInputDeviceName; |
|
boolean IsRawMidiMode = false; |
|
|
|
CheckBox checkbox; |
|
|
|
void setup() { |
|
size(400, 200); |
|
|
|
myBus = new MidiBus(this, -1, -1); |
|
oscP5 = new OscP5(this, OSCReceivePort); |
|
remoteOscServer = new NetAddress("127.0.0.1", OSCSendPort); |
|
|
|
cp5 = new ControlP5(this); |
|
String[] midiInDeviceList = MidiBus.availableInputs(); |
|
cp5.addScrollableList("MIDI_INPUT_DEVICE") |
|
.setPosition(20, 20) |
|
.setSize(200, 180) |
|
.setBarHeight(24) |
|
.setItemHeight(24) |
|
.addItems(midiInDeviceList) |
|
; |
|
|
|
checkbox = cp5.addCheckBox("checkBox") |
|
.setPosition(280, 20) |
|
.setSize(15, 15) |
|
.addItem("RAW_MODE", 0) |
|
; |
|
} |
|
void MIDI_INPUT_DEVICE(int n) { |
|
String newDeviceName = cp5.get(ScrollableList.class, "MIDI_INPUT_DEVICE").getItem(n).get("name").toString(); |
|
myBus.removeInput(midiInputDeviceName); |
|
midiInputDeviceName = newDeviceName; |
|
myBus.addInput(midiInputDeviceName); |
|
} |
|
|
|
void controlEvent(ControlEvent theEvent) { |
|
if (theEvent.isFrom(checkbox)) { |
|
IsRawMidiMode = (checkbox.getArrayValue()[0] == 1.0f) ? true : false; |
|
println(IsRawMidiMode); |
|
} |
|
} |
|
|
|
void oscSend(String oscAddPtn,int data1,int data2,int data3){ |
|
if(!IsRawMidiMode){ |
|
OscMessage sendData = new OscMessage(oscAddPtn); |
|
sendData.add(data1); |
|
sendData.add(data2); |
|
sendData.add(data3); |
|
oscP5.send(sendData, remoteOscServer); |
|
textMessage = oscAddPtn + " " + data1 + " " + data2 + " " + data3; |
|
} |
|
} |
|
void draw() { |
|
background(0); |
|
textSize(10); |
|
text("MIDI INPUT:", 20, 15); |
|
text("OSC SEND PORT : " + OSCSendPort, 270, 180); |
|
text("OSC SEND ADDRESS:", 40, 80); |
|
textSize(24); |
|
text(textMessage, 40, 80 + 24); |
|
} |
|
void noteOn(int channel, int pitch, int velocity) { |
|
oscSend("/midi/noteon/",channel,pitch,velocity); |
|
} |
|
void noteOff(int channel, int pitch, int velocity) { |
|
oscSend("/midi/noteoff/",channel,pitch,velocity); |
|
} |
|
void controllerChange(int channel, int number, int value) { |
|
oscSend("/midi/controlchange",channel,number,value); |
|
} |
|
void pitchBend(int channel, int msb, int lsb) { |
|
oscSend("/midi/pitchbend",channel,msb,lsb); |
|
} |
|
|
|
void rawMidi(byte[] data) { |
|
if (IsRawMidiMode == true){ |
|
String oscAddPtn = "/rawmidi"; |
|
textMessage = oscAddPtn + " "; |
|
OscMessage sendData = new OscMessage(oscAddPtn); |
|
for (byte d: data){ |
|
sendData.add(Byte.toUnsignedInt(d)); |
|
textMessage = textMessage + " " + hex(d) + "h"; |
|
} |
|
oscP5.send(sendData, remoteOscServer); |
|
}else{ |
|
int event = Byte.toUnsignedInt(data[0]); |
|
//Pitch Bend |
|
if (event >= 0xE0 & event <= 0xEF){ |
|
int channel = event - 0xE0; |
|
int msb = Byte.toUnsignedInt(data[1]); |
|
int lsb = Byte.toUnsignedInt(data[2]); |
|
pitchBend(channel,msb,lsb); |
|
} |
|
} |
|
} |