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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 ASSERT(isMainThread()); | 135 ASSERT(isMainThread()); |
136 if (portIndex >= m_inputs.size()) | 136 if (portIndex >= m_inputs.size()) |
137 return; | 137 return; |
138 | 138 |
139 // Convert from time in seconds which is based on the time coordinate system
of monotonicallyIncreasingTime() | 139 // Convert from time in seconds which is based on the time coordinate system
of monotonicallyIncreasingTime() |
140 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t
ime coordinate system as performance.now(). | 140 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t
ime coordinate system as performance.now(). |
141 // This is how timestamps are defined in the Web MIDI spec. | 141 // This is how timestamps are defined in the Web MIDI spec. |
142 Document* document = toDocument(executionContext()); | 142 Document* document = toDocument(executionContext()); |
143 ASSERT(document); | 143 ASSERT(document); |
144 | 144 |
145 double timeStampInMilliseconds = 1000 * document->loader()->timing()->monoto
nicTimeToZeroBasedDocumentTime(timeStamp); | 145 double timeStampInMilliseconds = 1000 * document->loader()->timing().monoton
icTimeToZeroBasedDocumentTime(timeStamp); |
146 | 146 |
147 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStampIn
Milliseconds); | 147 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStampIn
Milliseconds); |
148 } | 148 } |
149 | 149 |
150 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz
e_t length, double timeStampInMilliseconds) | 150 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz
e_t length, double timeStampInMilliseconds) |
151 { | 151 { |
152 if (!data || !length || portIndex >= m_outputs.size()) | 152 if (!data || !length || portIndex >= m_outputs.size()) |
153 return; | 153 return; |
154 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to
the same time coordinate system as performance.now() | 154 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to
the same time coordinate system as performance.now() |
155 // into a time in seconds which is based on the time coordinate system of mo
notonicallyIncreasingTime(). | 155 // into a time in seconds which is based on the time coordinate system of mo
notonicallyIncreasingTime(). |
156 double timeStamp; | 156 double timeStamp; |
157 | 157 |
158 if (!timeStampInMilliseconds) { | 158 if (!timeStampInMilliseconds) { |
159 // We treat a value of 0 (which is the default value) as special, meanin
g "now". | 159 // We treat a value of 0 (which is the default value) as special, meanin
g "now". |
160 // We need to translate it exactly to 0 seconds. | 160 // We need to translate it exactly to 0 seconds. |
161 timeStamp = 0; | 161 timeStamp = 0; |
162 } else { | 162 } else { |
163 Document* document = toDocument(executionContext()); | 163 Document* document = toDocument(executionContext()); |
164 ASSERT(document); | 164 ASSERT(document); |
165 double documentStartTime = document->loader()->timing()->referenceMonoto
nicTime(); | 165 double documentStartTime = document->loader()->timing().referenceMonoton
icTime(); |
166 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; | 166 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; |
167 } | 167 } |
168 | 168 |
169 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); | 169 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); |
170 } | 170 } |
171 | 171 |
172 void MIDIAccess::stop() | 172 void MIDIAccess::stop() |
173 { | 173 { |
174 m_accessor.clear(); | 174 m_accessor.clear(); |
175 } | 175 } |
176 | 176 |
177 DEFINE_TRACE(MIDIAccess) | 177 DEFINE_TRACE(MIDIAccess) |
178 { | 178 { |
179 visitor->trace(m_inputs); | 179 visitor->trace(m_inputs); |
180 visitor->trace(m_outputs); | 180 visitor->trace(m_outputs); |
181 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIAccess>::trace(visit
or); | 181 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIAccess>::trace(visit
or); |
182 ActiveDOMObject::trace(visitor); | 182 ActiveDOMObject::trace(visitor); |
183 } | 183 } |
184 | 184 |
185 } // namespace blink | 185 } // namespace blink |
OLD | NEW |