| 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 27 matching lines...) Expand all Loading... |
| 38 #include "modules/webmidi/MIDIInput.h" | 38 #include "modules/webmidi/MIDIInput.h" |
| 39 #include "modules/webmidi/MIDIInputMap.h" | 39 #include "modules/webmidi/MIDIInputMap.h" |
| 40 #include "modules/webmidi/MIDIOutput.h" | 40 #include "modules/webmidi/MIDIOutput.h" |
| 41 #include "modules/webmidi/MIDIOutputMap.h" | 41 #include "modules/webmidi/MIDIOutputMap.h" |
| 42 #include "modules/webmidi/MIDIPort.h" | 42 #include "modules/webmidi/MIDIPort.h" |
| 43 #include "platform/AsyncMethodRunner.h" | 43 #include "platform/AsyncMethodRunner.h" |
| 44 #include <memory> | 44 #include <memory> |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 namespace { |
| 49 |
| 48 using midi::mojom::PortState; | 50 using midi::mojom::PortState; |
| 49 | 51 |
| 52 // Since "open" status is separately managed per MIDIAccess instance, we do not |
| 53 // expose service level PortState directly. |
| 54 PortState ToDeviceState(PortState state) { |
| 55 if (state == PortState::OPENED) |
| 56 return PortState::CONNECTED; |
| 57 return state; |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
| 50 MIDIAccess::MIDIAccess( | 62 MIDIAccess::MIDIAccess( |
| 51 std::unique_ptr<MIDIAccessor> accessor, | 63 std::unique_ptr<MIDIAccessor> accessor, |
| 52 bool sysexEnabled, | 64 bool sysexEnabled, |
| 53 const Vector<MIDIAccessInitializer::PortDescriptor>& ports, | 65 const Vector<MIDIAccessInitializer::PortDescriptor>& ports, |
| 54 ExecutionContext* executionContext) | 66 ExecutionContext* executionContext) |
| 55 : ActiveScriptWrappable(this), | 67 : ActiveScriptWrappable(this), |
| 56 ActiveDOMObject(executionContext), | 68 ActiveDOMObject(executionContext), |
| 57 m_accessor(std::move(accessor)), | 69 m_accessor(std::move(accessor)), |
| 58 m_sysexEnabled(sysexEnabled), | 70 m_sysexEnabled(sysexEnabled), |
| 59 m_hasPendingActivity(false) { | 71 m_hasPendingActivity(false) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 137 } |
| 126 return new MIDIOutputMap(outputs); | 138 return new MIDIOutputMap(outputs); |
| 127 } | 139 } |
| 128 | 140 |
| 129 void MIDIAccess::didAddInputPort(const String& id, | 141 void MIDIAccess::didAddInputPort(const String& id, |
| 130 const String& manufacturer, | 142 const String& manufacturer, |
| 131 const String& name, | 143 const String& name, |
| 132 const String& version, | 144 const String& version, |
| 133 PortState state) { | 145 PortState state) { |
| 134 DCHECK(isMainThread()); | 146 DCHECK(isMainThread()); |
| 135 MIDIInput* port = | 147 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, |
| 136 MIDIInput::create(this, id, manufacturer, name, version, state); | 148 ToDeviceState(state)); |
| 137 m_inputs.append(port); | 149 m_inputs.append(port); |
| 138 dispatchEvent(MIDIConnectionEvent::create(port)); | 150 dispatchEvent(MIDIConnectionEvent::create(port)); |
| 139 } | 151 } |
| 140 | 152 |
| 141 void MIDIAccess::didAddOutputPort(const String& id, | 153 void MIDIAccess::didAddOutputPort(const String& id, |
| 142 const String& manufacturer, | 154 const String& manufacturer, |
| 143 const String& name, | 155 const String& name, |
| 144 const String& version, | 156 const String& version, |
| 145 PortState state) { | 157 PortState state) { |
| 146 DCHECK(isMainThread()); | 158 DCHECK(isMainThread()); |
| 147 unsigned portIndex = m_outputs.size(); | 159 unsigned portIndex = m_outputs.size(); |
| 148 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, name, | 160 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, name, |
| 149 version, state); | 161 version, ToDeviceState(state)); |
| 150 m_outputs.append(port); | 162 m_outputs.append(port); |
| 151 dispatchEvent(MIDIConnectionEvent::create(port)); | 163 dispatchEvent(MIDIConnectionEvent::create(port)); |
| 152 } | 164 } |
| 153 | 165 |
| 154 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) { | 166 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) { |
| 155 DCHECK(isMainThread()); | 167 DCHECK(isMainThread()); |
| 156 if (portIndex >= m_inputs.size()) | 168 if (portIndex >= m_inputs.size()) |
| 157 return; | 169 return; |
| 158 | 170 |
| 159 m_inputs[portIndex]->setState(state); | 171 PortState deviceState = ToDeviceState(state); |
| 172 if (m_inputs[portIndex]->getState() != deviceState) |
| 173 m_inputs[portIndex]->setState(deviceState); |
| 160 } | 174 } |
| 161 | 175 |
| 162 void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state) { | 176 void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state) { |
| 163 DCHECK(isMainThread()); | 177 DCHECK(isMainThread()); |
| 164 if (portIndex >= m_outputs.size()) | 178 if (portIndex >= m_outputs.size()) |
| 165 return; | 179 return; |
| 166 | 180 |
| 167 m_outputs[portIndex]->setState(state); | 181 PortState deviceState = ToDeviceState(state); |
| 182 if (m_outputs[portIndex]->getState() != deviceState) |
| 183 m_outputs[portIndex]->setState(deviceState); |
| 168 } | 184 } |
| 169 | 185 |
| 170 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, | 186 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, |
| 171 const unsigned char* data, | 187 const unsigned char* data, |
| 172 size_t length, | 188 size_t length, |
| 173 double timeStamp) { | 189 double timeStamp) { |
| 174 DCHECK(isMainThread()); | 190 DCHECK(isMainThread()); |
| 175 if (portIndex >= m_inputs.size()) | 191 if (portIndex >= m_inputs.size()) |
| 176 return; | 192 return; |
| 177 | 193 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 240 } |
| 225 | 241 |
| 226 DEFINE_TRACE(MIDIAccess) { | 242 DEFINE_TRACE(MIDIAccess) { |
| 227 visitor->trace(m_inputs); | 243 visitor->trace(m_inputs); |
| 228 visitor->trace(m_outputs); | 244 visitor->trace(m_outputs); |
| 229 EventTargetWithInlineData::trace(visitor); | 245 EventTargetWithInlineData::trace(visitor); |
| 230 ActiveDOMObject::trace(visitor); | 246 ActiveDOMObject::trace(visitor); |
| 231 } | 247 } |
| 232 | 248 |
| 233 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |