| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/webmidi/MIDIAccess.h" | 32 #include "modules/webmidi/MIDIAccess.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/loader/DocumentLoadTiming.h" | 35 #include "core/loader/DocumentLoadTiming.h" |
| 36 #include "core/loader/DocumentLoader.h" | 36 #include "core/loader/DocumentLoader.h" |
| 37 #include "modules/webmidi/MIDIAccessInitializer.h" | 37 #include "modules/webmidi/MIDIAccessInitializer.h" |
| 38 #include "modules/webmidi/MIDIConnectionEvent.h" | 38 #include "modules/webmidi/MIDIConnectionEvent.h" |
| 39 #include "modules/webmidi/MIDIController.h" | 39 #include "modules/webmidi/MIDIController.h" |
| 40 #include "modules/webmidi/MIDIInput.h" |
| 41 #include "modules/webmidi/MIDIInputMap.h" |
| 40 #include "modules/webmidi/MIDIOptions.h" | 42 #include "modules/webmidi/MIDIOptions.h" |
| 43 #include "modules/webmidi/MIDIOutput.h" |
| 44 #include "modules/webmidi/MIDIOutputMap.h" |
| 41 #include "modules/webmidi/MIDIPort.h" | 45 #include "modules/webmidi/MIDIPort.h" |
| 42 #include "platform/AsyncMethodRunner.h" | 46 #include "platform/AsyncMethodRunner.h" |
| 43 #include <v8.h> | 47 #include <v8.h> |
| 44 | 48 |
| 45 namespace blink { | 49 namespace blink { |
| 46 | 50 |
| 47 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) |
| 48 : ActiveDOMObject(executionContext) | 52 : ActiveDOMObject(executionContext) |
| 49 , m_accessor(accessor) | 53 , m_accessor(accessor) |
| 50 , m_sysexEnabled(sysexEnabled) | 54 , m_sysexEnabled(sysexEnabled) |
| 51 { | 55 { |
| 52 ScriptWrappable::init(this); | 56 ScriptWrappable::init(this); |
| 53 m_accessor->setClient(this); | 57 m_accessor->setClient(this); |
| 54 for (size_t i = 0; i < ports.size(); ++i) { | 58 for (size_t i = 0; i < ports.size(); ++i) { |
| 55 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; | 59 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; |
| 56 if (port.type == MIDIPort::MIDIPortTypeInput) { | 60 if (port.type == MIDIPort::MIDIPortTypeInput) { |
| 57 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer,
port.name, port.version)); | 61 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer,
port.name, port.version)); |
| 58 } else { | 62 } else { |
| 59 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id,
port.manufacturer, port.name, port.version)); | 63 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id,
port.manufacturer, port.name, port.version)); |
| 60 } | 64 } |
| 61 } | 65 } |
| 62 } | 66 } |
| 63 | 67 |
| 64 MIDIAccess::~MIDIAccess() | 68 MIDIAccess::~MIDIAccess() |
| 65 { | 69 { |
| 66 } | 70 } |
| 67 | 71 |
| 72 MIDIInputMap* MIDIAccess::inputs() const |
| 73 { |
| 74 HeapHashMap<String, Member<MIDIInput> > inputs; |
| 75 for (size_t i = 0; i < m_inputs.size(); ++i) { |
| 76 MIDIInput* input = m_inputs[i]; |
| 77 inputs.add(input->id(), input); |
| 78 } |
| 79 if (inputs.size() != m_inputs.size()) { |
| 80 // There is id duplication that violates the spec. |
| 81 inputs.clear(); |
| 82 } |
| 83 return new MIDIInputMap(inputs); |
| 84 } |
| 85 |
| 86 MIDIOutputMap* MIDIAccess::outputs() const |
| 87 { |
| 88 HeapHashMap<String, Member<MIDIOutput> > outputs; |
| 89 for (size_t i = 0; i < m_outputs.size(); ++i) { |
| 90 MIDIOutput* output = m_outputs[i]; |
| 91 outputs.add(output->id(), output); |
| 92 } |
| 93 if (outputs.size() != m_outputs.size()) { |
| 94 // There is id duplication that violates the spec. |
| 95 outputs.clear(); |
| 96 } |
| 97 return new MIDIOutputMap(outputs); |
| 98 } |
| 99 |
| 68 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) | 100 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c
onst String& name, const String& version) |
| 69 { | 101 { |
| 70 ASSERT(isMainThread()); | 102 ASSERT(isMainThread()); |
| 71 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); | 103 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); |
| 72 } | 104 } |
| 73 | 105 |
| 74 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) | 106 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer,
const String& name, const String& version) |
| 75 { | 107 { |
| 76 ASSERT(isMainThread()); | 108 ASSERT(isMainThread()); |
| 77 unsigned portIndex = m_outputs.size(); | 109 unsigned portIndex = m_outputs.size(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 155 } |
| 124 | 156 |
| 125 void MIDIAccess::trace(Visitor* visitor) | 157 void MIDIAccess::trace(Visitor* visitor) |
| 126 { | 158 { |
| 127 visitor->trace(m_inputs); | 159 visitor->trace(m_inputs); |
| 128 visitor->trace(m_outputs); | 160 visitor->trace(m_outputs); |
| 129 EventTargetWithInlineData::trace(visitor); | 161 EventTargetWithInlineData::trace(visitor); |
| 130 } | 162 } |
| 131 | 163 |
| 132 } // namespace blink | 164 } // namespace blink |
| OLD | NEW |