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 13 matching lines...) Expand all Loading... |
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/MIDIOutput.h" | 32 #include "modules/webmidi/MIDIOutput.h" |
33 | 33 |
| 34 #include "modules/webmidi/MIDIAccess.h" |
| 35 |
34 namespace WebCore { | 36 namespace WebCore { |
35 | 37 |
36 PassRefPtr<MIDIOutput> MIDIOutput::create(ScriptExecutionContext* context, const
String& id, const String& manufacturer, const String& name, const String& versi
on) | 38 PassRefPtr<MIDIOutput> MIDIOutput::create(MIDIAccess* access, unsigned portIndex
, ScriptExecutionContext* context, const String& id, const String& manufacturer,
const String& name, const String& version) |
37 { | 39 { |
38 return adoptRef(new MIDIOutput(context, id, manufacturer, name, version)); | 40 return adoptRef(new MIDIOutput(access, portIndex, context, id, manufacturer,
name, version)); |
39 } | 41 } |
40 | 42 |
41 MIDIOutput::MIDIOutput(ScriptExecutionContext* context, const String& id, const
String& manufacturer, const String& name, const String& version) | 43 MIDIOutput::MIDIOutput(MIDIAccess* access, unsigned portIndex, ScriptExecutionCo
ntext* context, const String& id, const String& manufacturer, const String& name
, const String& version) |
42 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version) | 44 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version) |
| 45 , m_access(access) |
| 46 , m_portIndex(portIndex) |
43 { | 47 { |
44 ScriptWrappable::init(this); | 48 ScriptWrappable::init(this); |
45 } | 49 } |
46 | 50 |
47 void MIDIOutput::send(Uint8Array* data, double timestamp) | 51 void MIDIOutput::send(Uint8Array* data, double timestamp) |
48 { | 52 { |
49 // FIXME: Implement MIDI protocol validation here. System exclusive | 53 if (!data) |
50 // messages must be checked at the same time. | 54 return; |
51 // Actual sending operation will be implemented in core/platform/midi. | 55 |
| 56 m_access->sendMIDIData(m_portIndex, data->data(), data->length(), timestamp)
; |
52 } | 57 } |
53 | 58 |
54 void MIDIOutput::send(Vector<unsigned>, double timestamp) | 59 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp) |
55 { | 60 { |
56 // FIXME: Ditto. Implementation will be shared between these two send | 61 RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size()); |
57 // functions. | 62 |
| 63 for (size_t i = 0; i < unsignedData.size(); ++i) { |
| 64 // FIXME: see if spec should throw an exception if unsigned value is out
of bounds. |
| 65 unsigned char value = unsignedData[i] & 0xff; |
| 66 array->set(i, value); |
| 67 } |
| 68 |
| 69 m_access->sendMIDIData(m_portIndex, array->data(), array->length(), timestam
p); |
58 } | 70 } |
59 | 71 |
60 } // namespace WebCore | 72 } // namespace WebCore |
OLD | NEW |