Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: Source/modules/webmidi/MIDIAccess.cpp

Issue 649683006: Web MIDI: add blink APIs to notify device connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comments at #7 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con st Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* execu tionContext) 50 MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, con st Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* execu tionContext)
51 : ActiveDOMObject(executionContext) 51 : ActiveDOMObject(executionContext)
52 , m_accessor(accessor) 52 , m_accessor(accessor)
53 , m_sysexEnabled(sysexEnabled) 53 , m_sysexEnabled(sysexEnabled)
54 { 54 {
55 m_accessor->setClient(this); 55 m_accessor->setClient(this);
56 for (size_t i = 0; i < ports.size(); ++i) { 56 for (size_t i = 0; i < ports.size(); ++i) {
57 const MIDIAccessInitializer::PortDescriptor& port = ports[i]; 57 const MIDIAccessInitializer::PortDescriptor& port = ports[i];
58 if (port.type == MIDIPort::MIDIPortTypeInput) { 58 if (port.type == MIDIPort::MIDIPortTypeInput) {
59 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, port.name, port.version)); 59 m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, port.name, port.version, port.active));
60 } else { 60 } else {
61 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id, port.manufacturer, port.name, port.version)); 61 m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id, port.manufacturer, port.name, port.version, port.active));
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 MIDIAccess::~MIDIAccess() 66 MIDIAccess::~MIDIAccess()
67 { 67 {
68 } 68 }
69 69
70 MIDIInputMap* MIDIAccess::inputs() const 70 MIDIInputMap* MIDIAccess::inputs() const
71 { 71 {
72 HeapHashMap<String, Member<MIDIInput> > inputs; 72 HeapHashMap<String, Member<MIDIInput> > inputs;
73 size_t inactive = 0;
tkent 2014/10/20 05:54:07 The name |inactive| looks weird. inactiveCount or
Takashi Toyoshima 2014/10/20 06:24:18 Done.
73 for (size_t i = 0; i < m_inputs.size(); ++i) { 74 for (size_t i = 0; i < m_inputs.size(); ++i) {
74 MIDIInput* input = m_inputs[i]; 75 MIDIInput* input = m_inputs[i];
75 inputs.add(input->id(), input); 76 if (input->isActive())
77 inputs.add(input->id(), input);
78 else
79 inactive++;
76 } 80 }
77 if (inputs.size() != m_inputs.size()) { 81 if ((inputs.size() + inactive) != m_inputs.size()) {
78 // There is id duplication that violates the spec. 82 // There is id duplication that violates the spec.
79 inputs.clear(); 83 inputs.clear();
80 } 84 }
81 return new MIDIInputMap(inputs); 85 return new MIDIInputMap(inputs);
82 } 86 }
83 87
84 MIDIOutputMap* MIDIAccess::outputs() const 88 MIDIOutputMap* MIDIAccess::outputs() const
85 { 89 {
86 HeapHashMap<String, Member<MIDIOutput> > outputs; 90 HeapHashMap<String, Member<MIDIOutput> > outputs;
91 size_t inactive = 0;
tkent 2014/10/20 05:54:07 ditto.
Takashi Toyoshima 2014/10/20 06:24:18 Done.
87 for (size_t i = 0; i < m_outputs.size(); ++i) { 92 for (size_t i = 0; i < m_outputs.size(); ++i) {
88 MIDIOutput* output = m_outputs[i]; 93 MIDIOutput* output = m_outputs[i];
89 outputs.add(output->id(), output); 94 if (output->isActive())
95 outputs.add(output->id(), output);
96 else
97 inactive++;
90 } 98 }
91 if (outputs.size() != m_outputs.size()) { 99 if ((outputs.size() + inactive) != m_outputs.size()) {
92 // There is id duplication that violates the spec. 100 // There is id duplication that violates the spec.
93 outputs.clear(); 101 outputs.clear();
94 } 102 }
95 return new MIDIOutputMap(outputs); 103 return new MIDIOutputMap(outputs);
96 } 104 }
97 105
98 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) 106 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version, bool active)
99 { 107 {
100 ASSERT(isMainThread()); 108 ASSERT(isMainThread());
101 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version)); 109 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version, act ive));
102 } 110 }
103 111
104 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) 112 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, bool active)
105 { 113 {
106 ASSERT(isMainThread()); 114 ASSERT(isMainThread());
107 unsigned portIndex = m_outputs.size(); 115 unsigned portIndex = m_outputs.size();
108 m_outputs.append(MIDIOutput::create(this, portIndex, id, manufacturer, name, version)); 116 m_outputs.append(MIDIOutput::create(this, portIndex, id, manufacturer, name, version, active));
117 }
118
119 void MIDIAccess::didSetInputPortState(unsigned portIndex, bool active)
120 {
121 ASSERT(isMainThread());
122 if (portIndex >= m_inputs.size())
tkent 2014/10/20 05:54:07 nit: if (portIndex < m_inputs.size()) m_input
Takashi Toyoshima 2014/10/20 06:24:18 Done.
123 return;
124 m_inputs[portIndex]->setActiveState(active);
125 }
126
127 void MIDIAccess::didSetOutputPortState(unsigned portIndex, bool active)
128 {
129 ASSERT(isMainThread());
130 if (portIndex >= m_outputs.size())
tkent 2014/10/20 05:54:07 Ditto.
Takashi Toyoshima 2014/10/20 06:24:18 Done.
131 return;
132 m_outputs[portIndex]->setActiveState(active);
109 } 133 }
110 134
111 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) 135 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp)
112 { 136 {
113 ASSERT(isMainThread()); 137 ASSERT(isMainThread());
114 if (portIndex >= m_inputs.size()) 138 if (portIndex >= m_inputs.size())
115 return; 139 return;
116 140
117 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime() 141 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime()
118 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now(). 142 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now().
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 177 }
154 178
155 void MIDIAccess::trace(Visitor* visitor) 179 void MIDIAccess::trace(Visitor* visitor)
156 { 180 {
157 visitor->trace(m_inputs); 181 visitor->trace(m_inputs);
158 visitor->trace(m_outputs); 182 visitor->trace(m_outputs);
159 EventTargetWithInlineData::trace(visitor); 183 EventTargetWithInlineData::trace(visitor);
160 } 184 }
161 185
162 } // namespace blink 186 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698