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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 const String& id, | 214 const String& id, |
215 const String& manufacturer, | 215 const String& manufacturer, |
216 const String& name, | 216 const String& name, |
217 const String& version, | 217 const String& version, |
218 PortState state) | 218 PortState state) |
219 : MIDIPort(access, id, manufacturer, name, TypeOutput, version, state), | 219 : MIDIPort(access, id, manufacturer, name, TypeOutput, version, state), |
220 m_portIndex(portIndex) {} | 220 m_portIndex(portIndex) {} |
221 | 221 |
222 MIDIOutput::~MIDIOutput() {} | 222 MIDIOutput::~MIDIOutput() {} |
223 | 223 |
224 void MIDIOutput::send(DOMUint8Array* array, | 224 void MIDIOutput::send(const NotShared<DOMUint8Array>& array, |
225 double timestamp, | 225 double timestamp, |
226 ExceptionState& exceptionState) { | 226 ExceptionState& exceptionState) { |
227 DCHECK(array); | 227 DCHECK(array.view()); |
228 | 228 |
229 if (timestamp == 0.0) | 229 if (timestamp == 0.0) |
230 timestamp = now(getExecutionContext()); | 230 timestamp = now(getExecutionContext()); |
231 | 231 |
232 // Implicit open. It does nothing if the port is already opened. | 232 // Implicit open. It does nothing if the port is already opened. |
233 // This should be performed even if |array| is invalid. | 233 // This should be performed even if |array| is invalid. |
234 open(); | 234 open(); |
235 | 235 |
236 if (MessageValidator::validate(array, exceptionState, | 236 if (MessageValidator::validate(array.view(), exceptionState, |
237 midiAccess()->sysexEnabled())) | 237 midiAccess()->sysexEnabled())) { |
238 midiAccess()->sendMIDIData(m_portIndex, array->data(), array->length(), | 238 midiAccess()->sendMIDIData(m_portIndex, array.view()->data(), |
239 timestamp); | 239 array.view()->length(), timestamp); |
| 240 } |
240 } | 241 } |
241 | 242 |
242 void MIDIOutput::send(Vector<unsigned> unsignedData, | 243 void MIDIOutput::send(Vector<unsigned> unsignedData, |
243 double timestamp, | 244 double timestamp, |
244 ExceptionState& exceptionState) { | 245 ExceptionState& exceptionState) { |
245 if (timestamp == 0.0) | 246 if (timestamp == 0.0) |
246 timestamp = now(getExecutionContext()); | 247 timestamp = now(getExecutionContext()); |
247 | 248 |
248 DOMUint8Array* array = DOMUint8Array::create(unsignedData.size()); | 249 DOMUint8Array* array = DOMUint8Array::create(unsignedData.size()); |
249 DOMUint8Array::ValueType* const arrayData = array->data(); | 250 DOMUint8Array::ValueType* const arrayData = array->data(); |
250 const uint32_t arrayLength = array->length(); | 251 const uint32_t arrayLength = array->length(); |
251 | 252 |
252 for (size_t i = 0; i < unsignedData.size(); ++i) { | 253 for (size_t i = 0; i < unsignedData.size(); ++i) { |
253 if (unsignedData[i] > 0xff) { | 254 if (unsignedData[i] > 0xff) { |
254 exceptionState.throwTypeError("The value at index " + String::number(i) + | 255 exceptionState.throwTypeError("The value at index " + String::number(i) + |
255 " (" + String::number(unsignedData[i]) + | 256 " (" + String::number(unsignedData[i]) + |
256 ") is greater than 0xFF."); | 257 ") is greater than 0xFF."); |
257 return; | 258 return; |
258 } | 259 } |
259 if (i < arrayLength) | 260 if (i < arrayLength) |
260 arrayData[i] = unsignedData[i] & 0xff; | 261 arrayData[i] = unsignedData[i] & 0xff; |
261 } | 262 } |
262 | 263 |
263 send(array, timestamp, exceptionState); | 264 send(NotShared<DOMUint8Array>(array), timestamp, exceptionState); |
264 } | 265 } |
265 | 266 |
266 void MIDIOutput::send(DOMUint8Array* data, ExceptionState& exceptionState) { | 267 void MIDIOutput::send(const NotShared<DOMUint8Array>& data, |
267 DCHECK(data); | 268 ExceptionState& exceptionState) { |
| 269 DCHECK(data.view()); |
268 send(data, 0.0, exceptionState); | 270 send(data, 0.0, exceptionState); |
269 } | 271 } |
270 | 272 |
271 void MIDIOutput::send(Vector<unsigned> unsignedData, | 273 void MIDIOutput::send(Vector<unsigned> unsignedData, |
272 ExceptionState& exceptionState) { | 274 ExceptionState& exceptionState) { |
273 send(unsignedData, 0.0, exceptionState); | 275 send(unsignedData, 0.0, exceptionState); |
274 } | 276 } |
275 | 277 |
276 DEFINE_TRACE(MIDIOutput) { | 278 DEFINE_TRACE(MIDIOutput) { |
277 MIDIPort::trace(visitor); | 279 MIDIPort::trace(visitor); |
278 } | 280 } |
279 | 281 |
280 } // namespace blink | 282 } // namespace blink |
OLD | NEW |