Skip to content

Commit

Permalink
added handling of incoming SysEx messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kybr committed Feb 4, 2013
1 parent ba5fd11 commit 57dd866
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
24 changes: 24 additions & 0 deletions iOS/Control/Classes/MIDI.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ static void notifyProc(const MIDINotification *message, void *refCon) {// if MID
static void readProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MIDIPacket *packet = (MIDIPacket *)pktlist->packet;

// most (all?) normal MIDI messages are less than 4 bytes long and i can't
// find any way to ask if this is a SysEx packet, so this is a hack. we assume
// that if the packet length is > 3, then this is a SysEx message. also, this
// does not handle the case where a SysEx message has been broken into many
// packets. a SysEx message is basically just a list of bytes. here we build
// up a js array of ints (e.g. [1,2,3]) and pass it to processSysExMessage().
// -- karl yerkes
if (packet->length > 3) {
NSMutableString* mutableString = [NSMutableString
stringWithFormat:@"midiManager.processSysExMessage([%d",
packet->data[0]];
for (int i = 1; i < packet->length; ++i)
[mutableString appendFormat:@",%d", (int)packet->data[i]];
[mutableString appendFormat:@"]);"];

[me.webView
performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:)
withObject:mutableString
waitUntilDone:NO];

[pool drain];
return; // exit this function
}

int packetStart = packet->data[0];
int channel = (packetStart &= 15) + 1;
Expand Down
25 changes: 24 additions & 1 deletion www/js/MIDIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ function MIDIManager() {
return this;
}

MIDIManager.prototype.processSysExMessage = function(value) {
this.delegate.processSysEx(value);
}

MIDIManager.prototype.processSysEx = function(value) {
if (typeof control.constants != "undefined") {
for (var i = 0; i < control.constants.length; i++) {
var w = control.constants[i];
if (w.midiType == "sysex") {
w.setValue(value, false); // "value" is an array of ints
break;
}
}
}
for (var i = 0; i < control.widgets.length; i++) {
var w = control.widgets[i];
if (w.midiType == "sysex") {
w.setValue(value, false); // "value" is an array of ints
break;
}
}
}

MIDIManager.prototype.processMIDIMessage = function(msgType, channel, number, value) {
this.delegate.processMIDI(msgType, channel, number, value);
}
Expand Down Expand Up @@ -55,4 +78,4 @@ MIDIManager.prototype.sendMIDI = function(msgType, channel, number, value) {
PhoneGap.exec('MIDI.send', msgType, JSON.stringify(channel), number);
}
}
}
}

0 comments on commit 57dd866

Please sign in to comment.