OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "modules/webmidi/MIDIAccess.h" | |
33 | |
34 #include "core/dom/ExceptionCode.h" | |
35 #include "modules/webmidi/MIDIConnectionEvent.h" | |
36 #include "modules/webmidi/MIDIInput.h" | |
37 #include "modules/webmidi/MIDIOutput.h" | |
38 #include "modules/webmidi/MIDIPort.h" | |
39 | |
40 namespace WebCore { | |
41 | |
42 PassRefPtr<MIDIAccess> MIDIAccess::create(ScriptExecutionContext* context) | |
43 { | |
44 RefPtr<MIDIAccess> midiAccess(adoptRef(new MIDIAccess(context))); | |
45 midiAccess->suspendIfNeeded(); | |
46 return midiAccess.release(); | |
47 } | |
48 | |
49 MIDIAccess::~MIDIAccess() | |
50 { | |
51 stop(); | |
52 } | |
53 | |
54 MIDIAccess::MIDIAccess(ScriptExecutionContext* context) | |
55 : ActiveDOMObject(context) | |
56 { | |
57 } | |
58 | |
59 const MIDIPortVector& MIDIAccess::getInputs() | |
60 { | |
61 return m_inputs; | |
62 } | |
63 | |
64 const MIDIPortVector& MIDIAccess::getOutputs() | |
65 { | |
66 return m_outputs; | |
67 } | |
68 | |
69 RefPtr<MIDIInput> MIDIAccess::getInput(PassRefPtr<MIDIPort> target, ExceptionCod e& ec) | |
70 { | |
71 return getInput(target->id(), ec); | |
72 } | |
73 | |
74 RefPtr<MIDIInput> MIDIAccess::getInput(const String& id, ExceptionCode& ec) | |
75 { | |
76 for (MIDIPortVector::const_iterator i = m_inputs.begin(); i != m_inputs.end( ); ++i) { | |
77 if ((*i)->id() != id) | |
Chris Rogers
2013/04/29 19:22:09
Instead of checking for inequality and using "cont
| |
78 continue; | |
79 return MIDIInput::create(*i); | |
80 } | |
Chris Rogers
2013/04/29 19:22:09
It would be good to add a comment here to describe
| |
81 for (MIDIPortVector::const_iterator i = m_outputs.begin(); i != m_outputs.en d(); ++i) { | |
82 if ((*i)->id() != id) | |
83 continue; | |
84 ec = INVALID_ACCESS_ERR; | |
85 return 0; | |
86 } | |
87 ec = NOT_FOUND_ERR; | |
88 return 0; | |
89 } | |
90 | |
91 RefPtr<MIDIInput> MIDIAccess::getInput(short index, ExceptionCode& ec) | |
92 { | |
93 if (static_cast<size_t>(index) < m_inputs.size()) | |
94 return getInput(m_inputs[index]->id(), ec); | |
95 | |
96 ec = NOT_FOUND_ERR; | |
97 return 0; | |
98 } | |
99 | |
100 RefPtr<MIDIOutput> MIDIAccess::getOutput(PassRefPtr<MIDIPort> target, ExceptionC ode& ec) | |
101 { | |
102 return getOutput(target->id(), ec); | |
103 } | |
104 | |
105 RefPtr<MIDIOutput> MIDIAccess::getOutput(const String& id, ExceptionCode& ec) | |
106 { | |
107 for (MIDIPortVector::const_iterator i = m_outputs.begin(); i != m_outputs.en d(); ++i) { | |
108 if ((*i)->id() != id) | |
109 continue; | |
110 return MIDIOutput::create(*i); | |
111 } | |
112 for (MIDIPortVector::const_iterator i = m_inputs.begin(); i != m_inputs.end( ); ++i) { | |
113 if ((*i)->id() != id) | |
114 continue; | |
115 ec = INVALID_ACCESS_ERR; | |
116 return 0; | |
117 } | |
118 ec = NOT_FOUND_ERR; | |
119 return 0; | |
120 } | |
121 | |
122 RefPtr<MIDIOutput> MIDIAccess::getOutput(short index, ExceptionCode& ec) | |
123 { | |
124 if (static_cast<size_t>(index) < m_outputs.size()) | |
125 return getOutput(m_outputs[index]->id(), ec); | |
126 | |
127 ec = NOT_FOUND_ERR; | |
128 return 0; | |
129 } | |
130 | |
131 } // namespace WebCore | |
OLD | NEW |