| 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 28 matching lines...) Expand all Loading... |
| 39 #include "modules/webmidi/MIDIController.h" | 39 #include "modules/webmidi/MIDIController.h" |
| 40 #include "modules/webmidi/MIDIInput.h" | 40 #include "modules/webmidi/MIDIInput.h" |
| 41 #include "modules/webmidi/MIDIInputMap.h" | 41 #include "modules/webmidi/MIDIInputMap.h" |
| 42 #include "modules/webmidi/MIDIOutput.h" | 42 #include "modules/webmidi/MIDIOutput.h" |
| 43 #include "modules/webmidi/MIDIOutputMap.h" | 43 #include "modules/webmidi/MIDIOutputMap.h" |
| 44 #include "modules/webmidi/MIDIPort.h" | 44 #include "modules/webmidi/MIDIPort.h" |
| 45 #include "platform/AsyncMethodRunner.h" | 45 #include "platform/AsyncMethodRunner.h" |
| 46 | 46 |
| 47 namespace blink { | 47 namespace blink { |
| 48 | 48 |
| 49 using PortState = MIDIAccessor::MIDIPortState; |
| 50 |
| 49 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) |
| 50 : ActiveDOMObject(executionContext) | 52 : ActiveDOMObject(executionContext) |
| 51 , m_accessor(accessor) | 53 , m_accessor(accessor) |
| 52 , m_sysexEnabled(sysexEnabled) | 54 , m_sysexEnabled(sysexEnabled) |
| 53 { | 55 { |
| 54 m_accessor->setClient(this); | 56 m_accessor->setClient(this); |
| 55 for (size_t i = 0; i < ports.size(); ++i) { | 57 for (size_t i = 0; i < ports.size(); ++i) { |
| 56 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; | 58 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
| 57 if (port.type == MIDIPort::MIDIPortTypeInput) { | 59 if (port.type == MIDIPort::MIDIPortTypeInput) { |
| 58 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer,
port.name, port.version, port.isActive)); | 60 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer,
port.name, port.version, port.state)); |
| 59 } else { | 61 } else { |
| 60 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id,
port.manufacturer, port.name, port.version, port.isActive)); | 62 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id,
port.manufacturer, port.name, port.version, port.state)); |
| 61 } | 63 } |
| 62 } | 64 } |
| 63 } | 65 } |
| 64 | 66 |
| 65 MIDIAccess::~MIDIAccess() | 67 MIDIAccess::~MIDIAccess() |
| 66 { | 68 { |
| 67 } | 69 } |
| 68 | 70 |
| 69 MIDIInputMap* MIDIAccess::inputs() const | 71 MIDIInputMap* MIDIAccess::inputs() const |
| 70 { | 72 { |
| 71 HeapHashMap<String, Member<MIDIInput>> inputs; | 73 HeapHashMap<String, Member<MIDIInput>> inputs; |
| 72 size_t inactiveCount = 0; | 74 size_t inactiveCount = 0; |
| 73 for (size_t i = 0; i < m_inputs.size(); ++i) { | 75 for (size_t i = 0; i < m_inputs.size(); ++i) { |
| 74 MIDIInput* input = m_inputs[i]; | 76 MIDIInput* input = m_inputs[i]; |
| 75 if (input->isActive()) | 77 if (input->getState() != PortState::MIDIPortStateDisconnected) |
| 76 inputs.add(input->id(), input); | 78 inputs.add(input->id(), input); |
| 77 else | 79 else |
| 78 inactiveCount++; | 80 inactiveCount++; |
| 79 } | 81 } |
| 80 if ((inputs.size() + inactiveCount) != m_inputs.size()) { | 82 if ((inputs.size() + inactiveCount) != m_inputs.size()) { |
| 81 // There is id duplication that violates the spec. | 83 // There is id duplication that violates the spec. |
| 82 inputs.clear(); | 84 inputs.clear(); |
| 83 } | 85 } |
| 84 return new MIDIInputMap(inputs); | 86 return new MIDIInputMap(inputs); |
| 85 } | 87 } |
| 86 | 88 |
| 87 MIDIOutputMap* MIDIAccess::outputs() const | 89 MIDIOutputMap* MIDIAccess::outputs() const |
| 88 { | 90 { |
| 89 HeapHashMap<String, Member<MIDIOutput>> outputs; | 91 HeapHashMap<String, Member<MIDIOutput>> outputs; |
| 90 size_t inactiveCount = 0; | 92 size_t inactiveCount = 0; |
| 91 for (size_t i = 0; i < m_outputs.size(); ++i) { | 93 for (size_t i = 0; i < m_outputs.size(); ++i) { |
| 92 MIDIOutput* output = m_outputs[i]; | 94 MIDIOutput* output = m_outputs[i]; |
| 93 if (output->isActive()) | 95 if (output->getState() != PortState::MIDIPortStateDisconnected) |
| 94 outputs.add(output->id(), output); | 96 outputs.add(output->id(), output); |
| 95 else | 97 else |
| 96 inactiveCount++; | 98 inactiveCount++; |
| 97 } | 99 } |
| 98 if ((outputs.size() + inactiveCount) != m_outputs.size()) { | 100 if ((outputs.size() + inactiveCount) != m_outputs.size()) { |
| 99 // There is id duplication that violates the spec. | 101 // There is id duplication that violates the spec. |
| 100 outputs.clear(); | 102 outputs.clear(); |
| 101 } | 103 } |
| 102 return new MIDIOutputMap(outputs); | 104 return new MIDIOutputMap(outputs); |
| 103 } | 105 } |
| 104 | 106 |
| 105 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version, bool isActive) | 107 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version, PortState state) |
| 106 { | 108 { |
| 107 ASSERT(isMainThread()); | 109 ASSERT(isMainThread()); |
| 108 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, i
sActive); | 110 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, s
tate); |
| 109 m_inputs.append(port); | 111 m_inputs.append(port); |
| 110 dispatchEvent(MIDIConnectionEvent::create(port)); | 112 dispatchEvent(MIDIConnectionEvent::create(port)); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version, bool isActive) | 115 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version, PortState state) |
| 114 { | 116 { |
| 115 ASSERT(isMainThread()); | 117 ASSERT(isMainThread()); |
| 116 unsigned portIndex = m_outputs.size(); | 118 unsigned portIndex = m_outputs.size(); |
| 117 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, nam
e, version, isActive); | 119 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, nam
e, version, state); |
| 118 m_outputs.append(port); | 120 m_outputs.append(port); |
| 119 dispatchEvent(MIDIConnectionEvent::create(port)); | 121 dispatchEvent(MIDIConnectionEvent::create(port)); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void MIDIAccess::didSetInputPortState(unsigned portIndex, bool isActive) | 124 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) |
| 123 { | 125 { |
| 124 ASSERT(isMainThread()); | 126 ASSERT(isMainThread()); |
| 125 if (portIndex >= m_inputs.size()) | 127 if (portIndex >= m_inputs.size()) |
| 126 return; | 128 return; |
| 127 | 129 |
| 128 m_inputs[portIndex]->setActiveState(isActive); | 130 m_inputs[portIndex]->setState(state); |
| 129 dispatchEvent(MIDIConnectionEvent::create(m_inputs[portIndex])); | 131 dispatchEvent(MIDIConnectionEvent::create(m_inputs[portIndex])); |
| 130 } | 132 } |
| 131 | 133 |
| 132 void MIDIAccess::didSetOutputPortState(unsigned portIndex, bool isActive) | 134 void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state) |
| 133 { | 135 { |
| 134 ASSERT(isMainThread()); | 136 ASSERT(isMainThread()); |
| 135 if (portIndex >= m_outputs.size()) | 137 if (portIndex >= m_outputs.size()) |
| 136 return; | 138 return; |
| 137 | 139 |
| 138 m_outputs[portIndex]->setActiveState(isActive); | 140 m_outputs[portIndex]->setState(state); |
| 139 dispatchEvent(MIDIConnectionEvent::create(m_outputs[portIndex])); | 141 dispatchEvent(MIDIConnectionEvent::create(m_outputs[portIndex])); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) | 144 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat
a, size_t length, double timeStamp) |
| 143 { | 145 { |
| 144 ASSERT(isMainThread()); | 146 ASSERT(isMainThread()); |
| 145 if (portIndex >= m_inputs.size()) | 147 if (portIndex >= m_inputs.size()) |
| 146 return; | 148 return; |
| 147 | 149 |
| 148 // Convert from time in seconds which is based on the time coordinate system
of monotonicallyIncreasingTime() | 150 // Convert from time in seconds which is based on the time coordinate system
of monotonicallyIncreasingTime() |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 187 |
| 186 DEFINE_TRACE(MIDIAccess) | 188 DEFINE_TRACE(MIDIAccess) |
| 187 { | 189 { |
| 188 visitor->trace(m_inputs); | 190 visitor->trace(m_inputs); |
| 189 visitor->trace(m_outputs); | 191 visitor->trace(m_outputs); |
| 190 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIAccess>::trace(visit
or); | 192 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIAccess>::trace(visit
or); |
| 191 ActiveDOMObject::trace(visitor); | 193 ActiveDOMObject::trace(visitor); |
| 192 } | 194 } |
| 193 | 195 |
| 194 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |