OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/webmidi/MIDIInput.h" | 32 #include "modules/webmidi/MIDIInput.h" |
| 33 |
| 34 #include "modules/webmidi/MIDIAccess.h" |
33 #include "modules/webmidi/MIDIMessageEvent.h" | 35 #include "modules/webmidi/MIDIMessageEvent.h" |
34 | 36 |
35 namespace WebCore { | 37 namespace WebCore { |
36 | 38 |
37 PassRefPtr<MIDIInput> MIDIInput::create(MIDIAccess* access, ScriptExecutionConte
xt* context, const String& id, const String& manufacturer, const String& name, c
onst String& version) | 39 PassRefPtr<MIDIInput> MIDIInput::create(MIDIAccess* access, ScriptExecutionConte
xt* context, const String& id, const String& manufacturer, const String& name, c
onst String& version) |
38 { | 40 { |
39 ASSERT(access); | 41 ASSERT(access); |
40 return adoptRef(new MIDIInput(access, context, id, manufacturer, name, versi
on)); | 42 return adoptRef(new MIDIInput(access, context, id, manufacturer, name, versi
on)); |
41 } | 43 } |
42 | 44 |
43 MIDIInput::MIDIInput(MIDIAccess* access, ScriptExecutionContext* context, const
String& id, const String& manufacturer, const String& name, const String& versio
n) | 45 MIDIInput::MIDIInput(MIDIAccess* access, ScriptExecutionContext* context, const
String& id, const String& manufacturer, const String& name, const String& versio
n) |
44 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version) | 46 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version) |
45 , m_access(access) | 47 , m_access(access) |
46 { | 48 { |
47 ScriptWrappable::init(this); | 49 ScriptWrappable::init(this); |
48 } | 50 } |
49 | 51 |
50 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
, size_t length, double timeStamp) | 52 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
, size_t length, double timeStamp) |
51 { | 53 { |
52 ASSERT(isMainThread()); | 54 ASSERT(isMainThread()); |
53 | 55 |
54 // The received MIDI data may contain one or more messages. | 56 // The received MIDI data may contain one or more messages. |
55 // The Web MIDI API requires that a separate event be dispatched for each me
ssage, | 57 // The Web MIDI API requires that a separate event be dispatched for each me
ssage, |
56 // so we walk through the data and dispatch one at a time. | 58 // so we walk through the data and dispatch one at a time. |
57 size_t i = 0; | 59 size_t i = 0; |
58 while (i < length) { | 60 while (i < length) { |
59 unsigned char status = data[i]; | 61 unsigned char status = data[i]; |
60 unsigned char strippedStatus = status & 0xf0; | 62 unsigned char strippedStatus = status & 0xf0; |
61 | 63 |
62 // FIXME: support System Exclusive. | 64 // FIXME: integrate sending side filtering and implement more extensive
filtering. |
63 if (strippedStatus >= 0xf0) | 65 if (strippedStatus >= 0xf0 && !m_access->sysExEnabled()) |
64 break; | 66 break; |
65 | 67 |
66 // All non System Exclusive messages have a total size of 3 except for P
rogram Change and Channel Pressure. | 68 // All non System Exclusive messages have a total size of 3 except for P
rogram Change and Channel Pressure. |
67 size_t totalMessageSize = (strippedStatus == 0xc0 || strippedStatus == 0
xd0) ? 2 : 3; | 69 size_t totalMessageSize = (strippedStatus == 0xc0 || strippedStatus == 0
xd0) ? 2 : 3; |
68 | 70 |
69 if (i + totalMessageSize <= length) { | 71 if (i + totalMessageSize <= length) { |
70 RefPtr<Uint8Array> array = Uint8Array::create(totalMessageSize); | 72 RefPtr<Uint8Array> array = Uint8Array::create(totalMessageSize); |
71 array->setRange(data + i, totalMessageSize, 0); | 73 array->setRange(data + i, totalMessageSize, 0); |
72 | 74 |
73 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); | 75 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); |
74 } | 76 } |
75 | 77 |
76 i += totalMessageSize; | 78 i += totalMessageSize; |
77 } | 79 } |
78 } | 80 } |
79 | 81 |
80 } // namespace WebCore | 82 } // namespace WebCore |
OLD | NEW |