Chromium Code Reviews| Index: Source/modules/webmidi/MIDIAccess.cpp |
| diff --git a/Source/modules/webmidi/MIDIAccess.cpp b/Source/modules/webmidi/MIDIAccess.cpp |
| index a004a9571f8dbe97c997f2baf0e2158ecbe81deb..fc733b1a13efba74acec7f6d0688a9bd7781021a 100644 |
| --- a/Source/modules/webmidi/MIDIAccess.cpp |
| +++ b/Source/modules/webmidi/MIDIAccess.cpp |
| @@ -56,9 +56,9 @@ MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con |
| for (size_t i = 0; i < ports.size(); ++i) { |
| const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
| if (port.type == MIDIPort::MIDIPortTypeInput) { |
| - m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, port.name, port.version)); |
| + m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, port.name, port.version, port.active)); |
| } else { |
| - m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id, port.manufacturer, port.name, port.version)); |
| + m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id, port.manufacturer, port.name, port.version, port.active)); |
| } |
| } |
| } |
| @@ -70,11 +70,15 @@ MIDIAccess::~MIDIAccess() |
| MIDIInputMap* MIDIAccess::inputs() const |
| { |
| HeapHashMap<String, Member<MIDIInput> > inputs; |
| + size_t inactive = 0; |
|
tkent
2014/10/20 05:54:07
The name |inactive| looks weird. inactiveCount or
Takashi Toyoshima
2014/10/20 06:24:18
Done.
|
| for (size_t i = 0; i < m_inputs.size(); ++i) { |
| MIDIInput* input = m_inputs[i]; |
| - inputs.add(input->id(), input); |
| + if (input->isActive()) |
| + inputs.add(input->id(), input); |
| + else |
| + inactive++; |
| } |
| - if (inputs.size() != m_inputs.size()) { |
| + if ((inputs.size() + inactive) != m_inputs.size()) { |
| // There is id duplication that violates the spec. |
| inputs.clear(); |
| } |
| @@ -84,28 +88,48 @@ MIDIInputMap* MIDIAccess::inputs() const |
| MIDIOutputMap* MIDIAccess::outputs() const |
| { |
| HeapHashMap<String, Member<MIDIOutput> > outputs; |
| + size_t inactive = 0; |
|
tkent
2014/10/20 05:54:07
ditto.
Takashi Toyoshima
2014/10/20 06:24:18
Done.
|
| for (size_t i = 0; i < m_outputs.size(); ++i) { |
| MIDIOutput* output = m_outputs[i]; |
| - outputs.add(output->id(), output); |
| + if (output->isActive()) |
| + outputs.add(output->id(), output); |
| + else |
| + inactive++; |
| } |
| - if (outputs.size() != m_outputs.size()) { |
| + if ((outputs.size() + inactive) != m_outputs.size()) { |
| // There is id duplication that violates the spec. |
| outputs.clear(); |
| } |
| return new MIDIOutputMap(outputs); |
| } |
| -void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, const String& name, const String& version) |
| +void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, const String& name, const String& version, bool active) |
| { |
| ASSERT(isMainThread()); |
| - m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); |
| + m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version, active)); |
| } |
| -void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) |
| +void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, bool active) |
| { |
| ASSERT(isMainThread()); |
| unsigned portIndex = m_outputs.size(); |
| - m_outputs.append(MIDIOutput::create(this, portIndex, id, manufacturer, name, version)); |
| + m_outputs.append(MIDIOutput::create(this, portIndex, id, manufacturer, name, version, active)); |
| +} |
| + |
| +void MIDIAccess::didSetInputPortState(unsigned portIndex, bool active) |
| +{ |
| + ASSERT(isMainThread()); |
| + if (portIndex >= m_inputs.size()) |
|
tkent
2014/10/20 05:54:07
nit:
if (portIndex < m_inputs.size())
m_input
Takashi Toyoshima
2014/10/20 06:24:18
Done.
|
| + return; |
| + m_inputs[portIndex]->setActiveState(active); |
| +} |
| + |
| +void MIDIAccess::didSetOutputPortState(unsigned portIndex, bool active) |
| +{ |
| + ASSERT(isMainThread()); |
| + if (portIndex >= m_outputs.size()) |
|
tkent
2014/10/20 05:54:07
Ditto.
Takashi Toyoshima
2014/10/20 06:24:18
Done.
|
| + return; |
| + m_outputs[portIndex]->setActiveState(active); |
| } |
| void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStamp) |