Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/webmidi/MIDIAccess.h" | 32 #include "modules/webmidi/MIDIAccess.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/loader/DocumentLoadTiming.h" | 35 #include "core/loader/DocumentLoadTiming.h" |
| 36 #include "core/loader/DocumentLoader.h" | 36 #include "core/loader/DocumentLoader.h" |
| 37 #include "modules/webmidi/MIDIAccessInitializer.h" | 37 #include "modules/webmidi/MIDIAccessInitializer.h" |
| 38 #include "modules/webmidi/MIDIConnectionEvent.h" | 38 #include "modules/webmidi/MIDIConnectionEvent.h" |
| 39 #include "modules/webmidi/MIDIController.h" | 39 #include "modules/webmidi/MIDIController.h" |
| 40 #include "modules/webmidi/MIDIInput.h" | |
| 41 #include "modules/webmidi/MIDIInputMap.h" | |
| 40 #include "modules/webmidi/MIDIOptions.h" | 42 #include "modules/webmidi/MIDIOptions.h" |
| 43 #include "modules/webmidi/MIDIOutput.h" | |
| 44 #include "modules/webmidi/MIDIOutputMap.h" | |
| 41 #include "modules/webmidi/MIDIPort.h" | 45 #include "modules/webmidi/MIDIPort.h" |
| 42 #include "platform/AsyncMethodRunner.h" | 46 #include "platform/AsyncMethodRunner.h" |
| 43 #include <v8.h> | 47 #include <v8.h> |
| 44 | 48 |
| 45 namespace blink { | 49 namespace blink { |
| 46 | 50 |
| 47 MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con st Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* execu tionContext) | 51 MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con st Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* execu tionContext) |
| 48 : ActiveDOMObject(executionContext) | 52 : ActiveDOMObject(executionContext) |
| 49 , m_accessor(accessor) | 53 , m_accessor(accessor) |
| 50 , m_sysexEnabled(sysexEnabled) | 54 , m_sysexEnabled(sysexEnabled) |
| 51 { | 55 { |
| 52 ScriptWrappable::init(this); | 56 ScriptWrappable::init(this); |
| 53 m_accessor->setClient(this); | 57 m_accessor->setClient(this); |
| 58 HeapHashMap<String, Member<MIDIInput> > inputs; | |
| 59 HeapHashMap<String, Member<MIDIOutput> > outputs; | |
| 54 for (size_t i = 0; i < ports.size(); ++i) { | 60 for (size_t i = 0; i < ports.size(); ++i) { |
| 55 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; | 61 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
| 56 if (port.type == MIDIPort::MIDIPortTypeInput) { | 62 if (port.type == MIDIPort::MIDIPortTypeInput) { |
| 57 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, port.name, port.version)); | 63 inputs.add(port.id, MIDIInput::create(this, port.id, port.manufactur er, port.name, port.version)); |
| 64 m_inputKeys.append(port.id); | |
| 58 } else { | 65 } else { |
| 59 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id, port.manufacturer, port.name, port.version)); | 66 outputs.add(port.id, MIDIOutput::create(this, outputs.size(), port.i d, port.manufacturer, port.name, port.version)); |
| 60 } | 67 } |
| 61 } | 68 } |
| 69 if (inputs.size() + outputs.size() != ports.size()) { | |
| 70 // There are id-duplicate ports that violate the spec. | |
| 71 return; | |
| 72 } | |
| 73 m_inputs = new MIDIInputMap(inputs); | |
| 74 m_outputs = new MIDIOutputMap(outputs); | |
| 62 } | 75 } |
| 63 | 76 |
| 64 MIDIAccess::~MIDIAccess() | 77 MIDIAccess::~MIDIAccess() |
| 65 { | 78 { |
| 66 } | 79 } |
| 67 | 80 |
| 68 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) | 81 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) |
| 69 { | 82 { |
| 70 ASSERT(isMainThread()); | 83 ASSERT(isMainThread()); |
| 71 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); | 84 // We currently assume no ports are added after an MIDIAccess object is |
|
Takashi Toyoshima
2014/09/01 13:48:39
Is there any real problem on adding a new port?
Le
yhirano
2014/09/02 05:17:13
Discussed offline: We decided to delete this asser
| |
| 85 // created. | |
| 86 ASSERT_NOT_REACHED(); | |
| 72 } | 87 } |
| 73 | 88 |
| 74 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) | 89 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) |
| 75 { | 90 { |
| 76 ASSERT(isMainThread()); | 91 ASSERT(isMainThread()); |
| 77 unsigned portIndex = m_outputs.size(); | 92 // We currently assume no ports are added after an MIDIAccess object is |
| 78 m_outputs.append(MIDIOutput::create(this, portIndex, id, manufacturer, name, version)); | 93 // created. |
| 94 ASSERT_NOT_REACHED(); | |
| 79 } | 95 } |
| 80 | 96 |
| 81 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) | 97 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) |
| 82 { | 98 { |
| 83 ASSERT(isMainThread()); | 99 ASSERT(isMainThread()); |
| 84 if (portIndex >= m_inputs.size()) | 100 if (portIndex >= m_inputs->size()) |
| 85 return; | 101 return; |
| 86 | 102 |
| 87 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime() | 103 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime() |
| 88 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now(). | 104 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now(). |
| 89 // This is how timestamps are defined in the Web MIDI spec. | 105 // This is how timestamps are defined in the Web MIDI spec. |
| 90 Document* document = toDocument(executionContext()); | 106 Document* document = toDocument(executionContext()); |
| 91 ASSERT(document); | 107 ASSERT(document); |
| 92 | 108 |
| 93 double timeStampInMilliseconds = 1000 * document->loader()->timing()->monoto nicTimeToZeroBasedDocumentTime(timeStamp); | 109 double timeStampInMilliseconds = 1000 * document->loader()->timing()->monoto nicTimeToZeroBasedDocumentTime(timeStamp); |
| 94 | 110 |
| 95 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStampIn Milliseconds); | 111 ASSERT(m_inputs->has(m_inputKeys[portIndex])); |
| 112 m_inputs->get(m_inputKeys[portIndex])->didReceiveMIDIData(portIndex, data, l ength, timeStampInMilliseconds); | |
| 96 } | 113 } |
| 97 | 114 |
| 98 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz e_t length, double timeStampInMilliseconds) | 115 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz e_t length, double timeStampInMilliseconds) |
| 99 { | 116 { |
| 100 if (!data || !length || portIndex >= m_outputs.size()) | 117 if (!data || !length || portIndex >= m_outputs->size()) |
| 101 return; | 118 return; |
| 102 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now() | 119 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now() |
| 103 // into a time in seconds which is based on the time coordinate system of mo notonicallyIncreasingTime(). | 120 // into a time in seconds which is based on the time coordinate system of mo notonicallyIncreasingTime(). |
| 104 double timeStamp; | 121 double timeStamp; |
| 105 | 122 |
| 106 if (!timeStampInMilliseconds) { | 123 if (!timeStampInMilliseconds) { |
| 107 // We treat a value of 0 (which is the default value) as special, meanin g "now". | 124 // We treat a value of 0 (which is the default value) as special, meanin g "now". |
| 108 // We need to translate it exactly to 0 seconds. | 125 // We need to translate it exactly to 0 seconds. |
| 109 timeStamp = 0; | 126 timeStamp = 0; |
| 110 } else { | 127 } else { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 123 } | 140 } |
| 124 | 141 |
| 125 void MIDIAccess::trace(Visitor* visitor) | 142 void MIDIAccess::trace(Visitor* visitor) |
| 126 { | 143 { |
| 127 visitor->trace(m_inputs); | 144 visitor->trace(m_inputs); |
| 128 visitor->trace(m_outputs); | 145 visitor->trace(m_outputs); |
| 129 EventTargetWithInlineData::trace(visitor); | 146 EventTargetWithInlineData::trace(visitor); |
| 130 } | 147 } |
| 131 | 148 |
| 132 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |