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

Side by Side Diff: Source/modules/webmidi/MIDIOutput.cpp

Issue 18858006: Implement MIDIOutput.send() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: forward declare MIDIAccess 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 | « Source/modules/webmidi/MIDIOutput.h ('k') | Source/modules/webmidi/MIDIOutput.idl » ('j') | 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 13 matching lines...) Expand all
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 "core/dom/ExceptionCode.h"
35 #include "modules/webmidi/MIDIAccess.h"
36
34 namespace WebCore { 37 namespace WebCore {
35 38
36 PassRefPtr<MIDIOutput> MIDIOutput::create(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& versi on) 39 PassRefPtr<MIDIOutput> MIDIOutput::create(MIDIAccess* access, unsigned portIndex , ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version)
37 { 40 {
38 return adoptRef(new MIDIOutput(context, id, manufacturer, name, version)); 41 return adoptRef(new MIDIOutput(access, portIndex, context, id, manufacturer, name, version));
39 } 42 }
40 43
41 MIDIOutput::MIDIOutput(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) 44 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) 45 : MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version)
46 , m_access(access)
47 , m_portIndex(portIndex)
43 { 48 {
44 ScriptWrappable::init(this); 49 ScriptWrappable::init(this);
45 } 50 }
46 51
47 void MIDIOutput::send(Uint8Array* data, double timestamp) 52 void MIDIOutput::send(Uint8Array* array, double timestamp, ExceptionCode& ec)
48 { 53 {
49 // FIXME: Implement MIDI protocol validation here. System exclusive 54 if (!array)
50 // messages must be checked at the same time. 55 return;
51 // Actual sending operation will be implemented in core/platform/midi. 56
57 const unsigned char* data = array->data();
58 size_t length = array->length();
59
60 // Filter out System Exclusive messages if we're not allowed.
61 // FIXME: implement more extensive filtering.
62 if (length > 0 && data[0] >= 0xf0 && !m_access->sysExEnabled()) {
63 ec = SecurityError;
64 return;
65 }
66
67 m_access->sendMIDIData(m_portIndex, data, length, timestamp);
52 } 68 }
53 69
54 void MIDIOutput::send(Vector<unsigned>, double timestamp) 70 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception Code& ec)
55 { 71 {
56 // FIXME: Ditto. Implementation will be shared between these two send 72 RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size());
57 // functions. 73
74 for (size_t i = 0; i < unsignedData.size(); ++i) {
75 if (unsignedData[i] > 0xff) {
76 ec = InvalidStateError;
77 return;
78 }
79 unsigned char value = unsignedData[i] & 0xff;
80 array->set(i, value);
81 }
82
83 send(array.get(), timestamp, ec);
84 }
85
86 void MIDIOutput::send(Uint8Array* data, ExceptionCode& ec)
87 {
88 send(data, 0, ec);
89 }
90
91 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionCode& ec)
92 {
93 send(unsignedData, 0, ec);
58 } 94 }
59 95
60 } // namespace WebCore 96 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/webmidi/MIDIOutput.h ('k') | Source/modules/webmidi/MIDIOutput.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698