Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: Source/modules/webmidi/MIDIInput.cpp

Issue 18163002: Dispatch separate MIDIMessageEvents for multiple messages in the received data buffer. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webmidi/MIDIInput.cpp
diff --git a/Source/modules/webmidi/MIDIInput.cpp b/Source/modules/webmidi/MIDIInput.cpp
index a5dee099588ff1cf228b26c9234b4e538f9e97da..1e9e62c80095d7bcfaa742d97850f4bb4e8f32a0 100644
--- a/Source/modules/webmidi/MIDIInput.cpp
+++ b/Source/modules/webmidi/MIDIInput.cpp
@@ -49,10 +49,30 @@ void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
{
ASSERT(isMainThread());
- RefPtr<Uint8Array> array = Uint8Array::create(length);
- array->setRange(data, length, 0);
+ // The received MIDI data may contain one or more messages.
+ // The Web MIDI API requires that a separate event be dispatched for each message,
+ // so we walk through the data and dispatch one at a time.
+ size_t i = 0;
+ while (i < length) {
+ unsigned char status = data[i];
+ unsigned char strippedStatus = status & 0xf0;
- dispatchEvent(MIDIMessageEvent::create(timeStamp, array));
+ // FIXME: support System Exclusive.
+ if (strippedStatus >= 0xf0)
+ break;
+
+ // All non System Exclusive messages have a total size of 3 except for Program Change and Channel Pressure.
+ size_t totalMessageSize = (strippedStatus == 0xc0 || strippedStatus == 0xd0) ? 2 : 3;
+
+ if (i + totalMessageSize <= length) {
+ RefPtr<Uint8Array> array = Uint8Array::create(totalMessageSize);
+ array->setRange(data + i, totalMessageSize, 0);
+
+ dispatchEvent(MIDIMessageEvent::create(timeStamp, array));
+ }
+
+ i += totalMessageSize;
+ }
}
} // namespace WebCore
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698