Skip to content

Commit

Permalink
methods for Midi, closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowballThrower committed Apr 18, 2017
1 parent 99178ec commit 84cb7f7
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 73 deletions.
162 changes: 89 additions & 73 deletions Controller/DMXControl/Midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,86 +42,102 @@ void handlePitch(byte r1, byte r2) {
}
}

void serialEvent() {
while (Serial.available()) {
// get the new byte:
inByte = Serial.read();
if (inByte > 127) {
midicount = 0;
if (inByte >= ControlChange) {
if (inByte < 192) {
noteCC = 0;
receivemidi[0] = inByte - ControlChange;
}
}
if (inByte >= Note_On) {
if (inByte < 0xA0) {
noteCC = 1;
receivemidi[0] = inByte - 0x90;
}
}
if (inByte >= Note_Off) {
if (inByte < 0x90) {
noteCC = 2;
receivemidi[0] = inByte - 0x80;
}
void firstByte() {
midicount = 0;
if (inByte >= ControlChange) {
if (inByte < 192) {
noteCC = 0;
receivemidi[0] = inByte - ControlChange;
}
}
if (inByte >= Note_On) {
if (inByte < 0xA0) {
noteCC = 1;
receivemidi[0] = inByte - 0x90;
}
}
if (inByte >= Note_Off) {
if (inByte < 0x90) {
noteCC = 2;
receivemidi[0] = inByte - 0x80;
}
}
if (inByte >= PITCH_BEND) {
if (inByte < 0xF0) {
noteCC = 3;
receivemidi[0] = inByte - PITCH_BEND;
}
}
}

void bar() {
barLength = (barEnd - barStart);
if (receivemidi[1] >= lowNotes[3]) {
if (receivemidi[1] < lowNotes[3] + barLength) {
targetCh = barStart + 3 * receivemidi[1] + receivemidi[1] / segments - lowNotes[3];

if (noteCC == 2) {
values[targetCh] = 0;
}
if (inByte >= PITCH_BEND) {
if (inByte < 0xF0) {
noteCC = 3;
receivemidi[0] = inByte - PITCH_BEND;
}
if (noteCC == 1) {
values[targetCh] = 2 * receivemidi[2];
}
}
if (inByte < 128) {
midicount++;
if (midicount < 3) {
receivemidi[midicount] = inByte;
}
if (midicount == 2) {
if (midiActive) {
midiCh = receivemidi[0];
if (noteCC == 0) {
targetCh = receivemidi[1] + 128 * midiCh;
values[targetCh] = 2 * receivemidi[2];
} else {
if (noteCC == 3) {
handlePitch(receivemidi[1], receivemidi[2]);
} else {
if (receivemidi[0] < 3) {
if (receivemidi[1] >= lowNotes[midiCh]) {
barLength = (barEnd - barStart) / 3;
if (receivemidi[1] < lowNotes[midiCh] + barLength) {
targetCh = barStart + 3 * receivemidi[1] + midiCh - 3 * lowNotes[midiCh];

if (noteCC == 2) {
values[targetCh] = 0;
}
if (noteCC == 1) {
values[targetCh] = 2 * receivemidi[2];
}
}
}
}
if (midiCh == 3) {
barLength = (barEnd - barStart);
if (receivemidi[1] >= lowNotes[3]) {
if (receivemidi[1] < lowNotes[3] + barLength) {
targetCh = barStart + 3 * receivemidi[1] + receivemidi[1] / segments - lowNotes[3];

if (noteCC == 2) {
values[targetCh] = 0;
}
if (noteCC == 1) {
values[targetCh] = 2 * receivemidi[2];
}
}
}
}
}
}

void handleMidiData() {
midiCh = receivemidi[0];
if (noteCC == 0) {
targetCh = receivemidi[1] + 128 * midiCh;
values[targetCh] = 2 * receivemidi[2];
} else {
if (noteCC == 3) {
handlePitch(receivemidi[1], receivemidi[2]);
} else {
if (receivemidi[0] < 3) {
if (receivemidi[1] >= lowNotes[midiCh]) {
barLength = (barEnd - barStart) / 3;
if (receivemidi[1] < lowNotes[midiCh] + barLength) {
targetCh = barStart + 3 * receivemidi[1] + midiCh - 3 * lowNotes[midiCh];

if (noteCC == 2) {
values[targetCh] = 0;
}
if (noteCC == 1) {
values[targetCh] = 2 * receivemidi[2];
}
}
}
}
if (midiCh == 3) {
bar();
}
}
}
}

void nextBytes() {
midicount++;
if (midicount < 3) {
receivemidi[midicount] = inByte;
}
if (midicount == 2) {
if (midiActive) {
handleMidiData();
}
}
}

void serialEvent() {
while (Serial.available()) {
// get the new byte:
inByte = Serial.read();
if (inByte > 127) {
firstByte();
}
if (inByte < 128) {
nextBytes();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void close() {
}

private void handle(ShortMessage message) {
System.out.println(message.getCommand());
System.out.println(message.getChannel());
System.out.println(message.getData1());
System.out.println(message.getData2());
if (message.getCommand() == CONTROL_CHANGE) {
int fader = message.getChannel();
int value = message.getData2() + message.getData1() * 32;
Expand Down

0 comments on commit 84cb7f7

Please sign in to comment.