| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const Vector<MIDIAccessInitializer::PortDescriptor>& ports, | 65 const Vector<MIDIAccessInitializer::PortDescriptor>& ports, |
| 66 ExecutionContext* executionContext) | 66 ExecutionContext* executionContext) |
| 67 : ContextLifecycleObserver(executionContext), | 67 : ContextLifecycleObserver(executionContext), |
| 68 m_accessor(std::move(accessor)), | 68 m_accessor(std::move(accessor)), |
| 69 m_sysexEnabled(sysexEnabled), | 69 m_sysexEnabled(sysexEnabled), |
| 70 m_hasPendingActivity(false) { | 70 m_hasPendingActivity(false) { |
| 71 m_accessor->setClient(this); | 71 m_accessor->setClient(this); |
| 72 for (size_t i = 0; i < ports.size(); ++i) { | 72 for (size_t i = 0; i < ports.size(); ++i) { |
| 73 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; | 73 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
| 74 if (port.type == MIDIPort::TypeInput) { | 74 if (port.type == MIDIPort::TypeInput) { |
| 75 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, | 75 m_inputs.push_back(MIDIInput::create(this, port.id, port.manufacturer, |
| 76 port.name, port.version, | 76 port.name, port.version, |
| 77 ToDeviceState(port.state))); | 77 ToDeviceState(port.state))); |
| 78 } else { | 78 } else { |
| 79 m_outputs.append(MIDIOutput::create( | 79 m_outputs.push_back(MIDIOutput::create( |
| 80 this, m_outputs.size(), port.id, port.manufacturer, port.name, | 80 this, m_outputs.size(), port.id, port.manufacturer, port.name, |
| 81 port.version, ToDeviceState(port.state))); | 81 port.version, ToDeviceState(port.state))); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 MIDIAccess::~MIDIAccess() {} | 86 MIDIAccess::~MIDIAccess() {} |
| 87 | 87 |
| 88 void MIDIAccess::dispose() { | 88 void MIDIAccess::dispose() { |
| 89 m_accessor.reset(); | 89 m_accessor.reset(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 return m_hasPendingActivity && getExecutionContext() && | 102 return m_hasPendingActivity && getExecutionContext() && |
| 103 !getExecutionContext()->isContextDestroyed(); | 103 !getExecutionContext()->isContextDestroyed(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 MIDIInputMap* MIDIAccess::inputs() const { | 106 MIDIInputMap* MIDIAccess::inputs() const { |
| 107 HeapVector<Member<MIDIInput>> inputs; | 107 HeapVector<Member<MIDIInput>> inputs; |
| 108 HashSet<String> ids; | 108 HashSet<String> ids; |
| 109 for (size_t i = 0; i < m_inputs.size(); ++i) { | 109 for (size_t i = 0; i < m_inputs.size(); ++i) { |
| 110 MIDIInput* input = m_inputs[i]; | 110 MIDIInput* input = m_inputs[i]; |
| 111 if (input->getState() != PortState::DISCONNECTED) { | 111 if (input->getState() != PortState::DISCONNECTED) { |
| 112 inputs.append(input); | 112 inputs.push_back(input); |
| 113 ids.add(input->id()); | 113 ids.add(input->id()); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 if (inputs.size() != ids.size()) { | 116 if (inputs.size() != ids.size()) { |
| 117 // There is id duplication that violates the spec. | 117 // There is id duplication that violates the spec. |
| 118 inputs.clear(); | 118 inputs.clear(); |
| 119 } | 119 } |
| 120 return new MIDIInputMap(inputs); | 120 return new MIDIInputMap(inputs); |
| 121 } | 121 } |
| 122 | 122 |
| 123 MIDIOutputMap* MIDIAccess::outputs() const { | 123 MIDIOutputMap* MIDIAccess::outputs() const { |
| 124 HeapVector<Member<MIDIOutput>> outputs; | 124 HeapVector<Member<MIDIOutput>> outputs; |
| 125 HashSet<String> ids; | 125 HashSet<String> ids; |
| 126 for (size_t i = 0; i < m_outputs.size(); ++i) { | 126 for (size_t i = 0; i < m_outputs.size(); ++i) { |
| 127 MIDIOutput* output = m_outputs[i]; | 127 MIDIOutput* output = m_outputs[i]; |
| 128 if (output->getState() != PortState::DISCONNECTED) { | 128 if (output->getState() != PortState::DISCONNECTED) { |
| 129 outputs.append(output); | 129 outputs.push_back(output); |
| 130 ids.add(output->id()); | 130 ids.add(output->id()); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 if (outputs.size() != ids.size()) { | 133 if (outputs.size() != ids.size()) { |
| 134 // There is id duplication that violates the spec. | 134 // There is id duplication that violates the spec. |
| 135 outputs.clear(); | 135 outputs.clear(); |
| 136 } | 136 } |
| 137 return new MIDIOutputMap(outputs); | 137 return new MIDIOutputMap(outputs); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void MIDIAccess::didAddInputPort(const String& id, | 140 void MIDIAccess::didAddInputPort(const String& id, |
| 141 const String& manufacturer, | 141 const String& manufacturer, |
| 142 const String& name, | 142 const String& name, |
| 143 const String& version, | 143 const String& version, |
| 144 PortState state) { | 144 PortState state) { |
| 145 DCHECK(isMainThread()); | 145 DCHECK(isMainThread()); |
| 146 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, | 146 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, |
| 147 ToDeviceState(state)); | 147 ToDeviceState(state)); |
| 148 m_inputs.append(port); | 148 m_inputs.push_back(port); |
| 149 dispatchEvent(MIDIConnectionEvent::create(port)); | 149 dispatchEvent(MIDIConnectionEvent::create(port)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void MIDIAccess::didAddOutputPort(const String& id, | 152 void MIDIAccess::didAddOutputPort(const String& id, |
| 153 const String& manufacturer, | 153 const String& manufacturer, |
| 154 const String& name, | 154 const String& name, |
| 155 const String& version, | 155 const String& version, |
| 156 PortState state) { | 156 PortState state) { |
| 157 DCHECK(isMainThread()); | 157 DCHECK(isMainThread()); |
| 158 unsigned portIndex = m_outputs.size(); | 158 unsigned portIndex = m_outputs.size(); |
| 159 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, name, | 159 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, name, |
| 160 version, ToDeviceState(state)); | 160 version, ToDeviceState(state)); |
| 161 m_outputs.append(port); | 161 m_outputs.push_back(port); |
| 162 dispatchEvent(MIDIConnectionEvent::create(port)); | 162 dispatchEvent(MIDIConnectionEvent::create(port)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) { | 165 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) { |
| 166 DCHECK(isMainThread()); | 166 DCHECK(isMainThread()); |
| 167 if (portIndex >= m_inputs.size()) | 167 if (portIndex >= m_inputs.size()) |
| 168 return; | 168 return; |
| 169 | 169 |
| 170 PortState deviceState = ToDeviceState(state); | 170 PortState deviceState = ToDeviceState(state); |
| 171 if (m_inputs[portIndex]->getState() != deviceState) | 171 if (m_inputs[portIndex]->getState() != deviceState) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 230 } |
| 231 | 231 |
| 232 DEFINE_TRACE(MIDIAccess) { | 232 DEFINE_TRACE(MIDIAccess) { |
| 233 visitor->trace(m_inputs); | 233 visitor->trace(m_inputs); |
| 234 visitor->trace(m_outputs); | 234 visitor->trace(m_outputs); |
| 235 EventTargetWithInlineData::trace(visitor); | 235 EventTargetWithInlineData::trace(visitor); |
| 236 ContextLifecycleObserver::trace(visitor); | 236 ContextLifecycleObserver::trace(visitor); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |