| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 , m_portIndex(portIndex) | 189 , m_portIndex(portIndex) |
| 190 { | 190 { |
| 191 } | 191 } |
| 192 | 192 |
| 193 MIDIOutput::~MIDIOutput() | 193 MIDIOutput::~MIDIOutput() |
| 194 { | 194 { |
| 195 } | 195 } |
| 196 | 196 |
| 197 void MIDIOutput::send(DOMUint8Array* array, double timestamp, ExceptionState& ex
ceptionState) | 197 void MIDIOutput::send(DOMUint8Array* array, double timestamp, ExceptionState& ex
ceptionState) |
| 198 { | 198 { |
| 199 ASSERT(array); |
| 200 |
| 199 if (timestamp == 0.0) | 201 if (timestamp == 0.0) |
| 200 timestamp = now(executionContext()); | 202 timestamp = now(executionContext()); |
| 201 | 203 |
| 202 // Implicit open. It does nothing if the port is already opened. | 204 // Implicit open. It does nothing if the port is already opened. |
| 203 // This should be performed even if |array| is invalid. | 205 // This should be performed even if |array| is invalid. |
| 204 open(); | 206 open(); |
| 205 | 207 |
| 206 if (!array) | |
| 207 return; | |
| 208 | |
| 209 if (MessageValidator::validate(array, exceptionState, midiAccess()->sysexEna
bled())) | 208 if (MessageValidator::validate(array, exceptionState, midiAccess()->sysexEna
bled())) |
| 210 midiAccess()->sendMIDIData(m_portIndex, array->data(), array->length(),
timestamp); | 209 midiAccess()->sendMIDIData(m_portIndex, array->data(), array->length(),
timestamp); |
| 211 } | 210 } |
| 212 | 211 |
| 213 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception
State& exceptionState) | 212 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception
State& exceptionState) |
| 214 { | 213 { |
| 215 if (timestamp == 0.0) | 214 if (timestamp == 0.0) |
| 216 timestamp = now(executionContext()); | 215 timestamp = now(executionContext()); |
| 217 | 216 |
| 218 RefPtr<DOMUint8Array> array = DOMUint8Array::create(unsignedData.size()); | 217 RefPtr<DOMUint8Array> array = DOMUint8Array::create(unsignedData.size()); |
| 219 DOMUint8Array::ValueType* const arrayData = array->data(); | 218 DOMUint8Array::ValueType* const arrayData = array->data(); |
| 220 const uint32_t arrayLength = array->length(); | 219 const uint32_t arrayLength = array->length(); |
| 221 | 220 |
| 222 for (size_t i = 0; i < unsignedData.size(); ++i) { | 221 for (size_t i = 0; i < unsignedData.size(); ++i) { |
| 223 if (unsignedData[i] > 0xff) { | 222 if (unsignedData[i] > 0xff) { |
| 224 exceptionState.throwTypeError("The value at index " + String::number
(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF."); | 223 exceptionState.throwTypeError("The value at index " + String::number
(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF."); |
| 225 return; | 224 return; |
| 226 } | 225 } |
| 227 if (i < arrayLength) | 226 if (i < arrayLength) |
| 228 arrayData[i] = unsignedData[i] & 0xff; | 227 arrayData[i] = unsignedData[i] & 0xff; |
| 229 } | 228 } |
| 230 | 229 |
| 231 send(array.get(), timestamp, exceptionState); | 230 send(array.get(), timestamp, exceptionState); |
| 232 } | 231 } |
| 233 | 232 |
| 234 void MIDIOutput::send(DOMUint8Array* data, ExceptionState& exceptionState) | 233 void MIDIOutput::send(DOMUint8Array* data, ExceptionState& exceptionState) |
| 235 { | 234 { |
| 235 ASSERT(data); |
| 236 send(data, 0.0, exceptionState); | 236 send(data, 0.0, exceptionState); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionState& exceptionSt
ate) | 239 void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionState& exceptionSt
ate) |
| 240 { | 240 { |
| 241 send(unsignedData, 0.0, exceptionState); | 241 send(unsignedData, 0.0, exceptionState); |
| 242 } | 242 } |
| 243 | 243 |
| 244 DEFINE_TRACE(MIDIOutput) | 244 DEFINE_TRACE(MIDIOutput) |
| 245 { | 245 { |
| 246 MIDIPort::trace(visitor); | 246 MIDIPort::trace(visitor); |
| 247 } | 247 } |
| 248 | 248 |
| 249 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |