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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 MIDIInput::MIDIInput(ScriptExecutionContext* context, const String& id, const St ring& manufacturer, const String& name, const String& version) 42 MIDIInput::MIDIInput(ScriptExecutionContext* context, const String& id, const St ring& manufacturer, const String& name, const String& version)
43 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version) 43 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version)
44 { 44 {
45 ScriptWrappable::init(this); 45 ScriptWrappable::init(this);
46 } 46 }
47 47
48 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data , size_t length, double timeStamp) 48 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data , size_t length, double timeStamp)
49 { 49 {
50 ASSERT(isMainThread()); 50 ASSERT(isMainThread());
51 51
52 RefPtr<Uint8Array> array = Uint8Array::create(length); 52 // The received MIDI data may contain one or more messages.
53 array->setRange(data, length, 0); 53 // The Web MIDI API requires that a separate event be dispatched for each me ssage,
54 // so we walk through the data and dispatch one at a time.
55 size_t i = 0;
56 while (i < length) {
57 unsigned char status = data[i];
58 unsigned char strippedStatus = status & 0xf0;
54 59
55 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); 60 // FIXME: support System Exclusive.
61 if (strippedStatus >= 0xf0)
62 break;
63
64 // All non System Exclusive messages have a total size of 3 except for P rogram Change and Channel Pressure.
65 size_t totalMessageSize = (strippedStatus == 0xc0 || strippedStatus == 0 xd0) ? 2 : 3;
66
67 if (i + totalMessageSize <= length) {
68 RefPtr<Uint8Array> array = Uint8Array::create(totalMessageSize);
69 array->setRange(data + i, totalMessageSize, 0);
70
71 dispatchEvent(MIDIMessageEvent::create(timeStamp, array));
72 }
73
74 i += totalMessageSize;
75 }
56 } 76 }
57 77
58 } // namespace WebCore 78 } // namespace WebCore
OLDNEW
« 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