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