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(ScriptExecutionContext* context, const S
tring& id, const String& manufacturer, const String& name, const 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 return adoptRef(new MIDIInput(context, id, manufacturer, name, version)); | 41 return adoptRef(new MIDIInput(access, context, id, manufacturer, name, versi
on)); |
40 } | 42 } |
41 | 43 |
42 MIDIInput::MIDIInput(ScriptExecutionContext* context, const String& id, const St
ring& manufacturer, const String& name, const String& version) | 44 MIDIInput::MIDIInput(MIDIAccess* access, ScriptExecutionContext* context, const
String& id, const String& manufacturer, const String& name, const String& versio
n) |
43 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version) | 45 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeInput, version) |
| 46 , m_access(access) |
44 { | 47 { |
45 ScriptWrappable::init(this); | 48 ScriptWrappable::init(this); |
46 } | 49 } |
47 | 50 |
| 51 MIDIInput::~MIDIInput() |
| 52 { |
| 53 } |
| 54 |
48 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
, size_t length, double timeStamp) | 55 void MIDIInput::didReceiveMIDIData(unsigned portIndex, const unsigned char* data
, size_t length, double timeStamp) |
49 { | 56 { |
50 ASSERT(isMainThread()); | 57 ASSERT(isMainThread()); |
51 | 58 |
52 // The received MIDI data may contain one or more messages. | 59 // The received MIDI data may contain one or more messages. |
53 // The Web MIDI API requires that a separate event be dispatched for each me
ssage, | 60 // 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. | 61 // so we walk through the data and dispatch one at a time. |
55 size_t i = 0; | 62 size_t i = 0; |
56 while (i < length) { | 63 while (i < length) { |
57 unsigned char status = data[i]; | 64 unsigned char status = data[i]; |
58 unsigned char strippedStatus = status & 0xf0; | 65 unsigned char strippedStatus = status & 0xf0; |
59 | 66 |
60 // FIXME: support System Exclusive. | 67 // FIXME: integrate sending side filtering and implement more extensive
filtering. |
61 if (strippedStatus >= 0xf0) | 68 if (strippedStatus >= 0xf0 && !m_access->sysExEnabled()) |
62 break; | 69 break; |
63 | 70 |
64 // All non System Exclusive messages have a total size of 3 except for P
rogram Change and Channel Pressure. | 71 // 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; | 72 size_t totalMessageSize = (strippedStatus == 0xc0 || strippedStatus == 0
xd0) ? 2 : 3; |
66 | 73 |
67 if (i + totalMessageSize <= length) { | 74 if (i + totalMessageSize <= length) { |
68 RefPtr<Uint8Array> array = Uint8Array::create(totalMessageSize); | 75 RefPtr<Uint8Array> array = Uint8Array::create(totalMessageSize); |
69 array->setRange(data + i, totalMessageSize, 0); | 76 array->setRange(data + i, totalMessageSize, 0); |
70 | 77 |
71 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); | 78 dispatchEvent(MIDIMessageEvent::create(timeStamp, array)); |
72 } | 79 } |
73 | 80 |
74 i += totalMessageSize; | 81 i += totalMessageSize; |
75 } | 82 } |
76 } | 83 } |
77 | 84 |
78 } // namespace WebCore | 85 } // namespace WebCore |
OLD | NEW |