Skip to content

Commit

Permalink
packaged MIDI example as Processing example
Browse files Browse the repository at this point in the history
added midibus library
fixed MIDI example variables
  • Loading branch information
matsfunk committed Dec 4, 2016
1 parent 9b59518 commit bf52a00
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import javax.sound.midi.MidiChannel;
import nl.tue.id.oocsi.EventRecorder;
import nl.tue.id.oocsi.OOCSI;
import nl.tue.id.oocsi.OOCSIEvent;
import processing.core.PApplet;
import processing.core.PVector;
import themidibus.MidiBus;

// reference to local OOCSI
OOCSI oocsiPlayer;
EventRecorder oocsiLooper;
PVector pos = new PVector();
MidiChannel channel;
private MidiBus mb;
private int lastPitch = 0;

public void setup() {
size(200, 200);
noStroke();

// connect to OOCSI server running on the same machine (localhost)
// with the ID "sequencer" for the looper
OOCSI oocsiSequencer = new OOCSI(this, "sequencer", "localhost");
oocsiLooper = new EventRecorder(oocsiSequencer, "sequelChannel");
oocsiLooper.play();
oocsiLooper.startRecording();

// register a second OOCSI client on the same server that can send events and receive recorded events back
oocsiPlayer = new OOCSI(this, "player", "localhost");
oocsiPlayer.subscribe("sequelChannel");

// MIDI sub system
MidiBus.list();
mb = new MidiBus(this, -1, "Bus 1");
}

public void sequelChannel(OOCSIEvent event) {
// event received from looper
pos.x = event.getInt("x", 0);
pos.y = event.getInt("y", 0);

// plot it out
drawEvent(pos.x, pos.y);
}

public void draw() {

// fade previous screen
fill(0, 10);
rectMode(CORNER);
rect(0, 0, width, height);

// restart looper (trigger start and record at the same time)
if (frameCount % 360 == 0) {
oocsiLooper.startRecording();
oocsiLooper.play();
}
}

public void mousePressed() {
// draw new event
drawEvent(mouseX, mouseY);

// save new event to loop
oocsiPlayer.channel("sequelChannel").data("x", mouseX).data("y", mouseY).send();
}

private void drawEvent(float x, float y) {

int channel = 1;
int pitch = (int) map(x, 0, width, 40, 90);
int velocity = 80;
mb.sendNoteOff(channel, lastPitch, velocity);
mb.sendNoteOn(channel, pitch, velocity);
lastPitch = pitch;

// yellow fill for rectangle to plot out
fill(255, 255, 0, 120);
rectMode(CENTER);
rect(x, y, 10, 10);
}
Binary file not shown.
12 changes: 6 additions & 6 deletions test/tools/TestMIDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class TestMIDI extends PApplet {

// reference to local OOCSI
OOCSI oocsi2;
OOCSI oocsiPlayer;
EventRecorder oocsiLooper;
PVector pos = new PVector();
MidiChannel channel;
Expand All @@ -25,14 +25,14 @@ public void setup() {

// connect to OOCSI server running on the same machine (localhost)
// with the ID "sequencer" for the looper
OOCSI oocsi = new OOCSI(this, "sequencer", "localhost");
oocsiLooper = new EventRecorder(oocsi, "sequelChannel");
OOCSI oocsiSequencer = new OOCSI(this, "sequencer", "localhost");
oocsiLooper = new EventRecorder(oocsiSequencer, "sequelChannel");
oocsiLooper.play();
oocsiLooper.startRecording();

// register a second OOCSI client on the same server that can send events and receive recorded events back
oocsi2 = new OOCSI(this, "player", "localhost");
oocsi2.subscribe("sequelChannel");
oocsiPlayer = new OOCSI(this, "player", "localhost");
oocsiPlayer.subscribe("sequelChannel");

// MIDI sub system
MidiBus.list();
Expand Down Expand Up @@ -68,7 +68,7 @@ public void mousePressed() {
drawEvent(mouseX, mouseY);

// save new event to loop
oocsi2.channel("sequelChannel").data("x", mouseX).data("y", mouseY).send();
oocsiPlayer.channel("sequelChannel").data("x", mouseX).data("y", mouseY).send();
}

private void drawEvent(float x, float y) {
Expand Down

0 comments on commit bf52a00

Please sign in to comment.