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

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

Issue 943173002: Web MIDI: dispatch MIDIConnectionEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review #3 Created 5 years, 10 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
« no previous file with comments | « Source/modules/webmidi/MIDIAccess.h ('k') | Source/modules/webmidi/MIDIAccess.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if ((outputs.size() + inactiveCount) != m_outputs.size()) { 99 if ((outputs.size() + inactiveCount) != m_outputs.size()) {
100 // There is id duplication that violates the spec. 100 // There is id duplication that violates the spec.
101 outputs.clear(); 101 outputs.clear();
102 } 102 }
103 return new MIDIOutputMap(outputs); 103 return new MIDIOutputMap(outputs);
104 } 104 }
105 105
106 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version, bool isActive) 106 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version, bool isActive)
107 { 107 {
108 ASSERT(isMainThread()); 108 ASSERT(isMainThread());
109 m_inputs.append(MIDIInput::create(this, id, manufacturer, name, version, isA ctive)); 109 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, i sActive);
110 m_inputs.append(port);
111 dispatchEvent(MIDIConnectionEvent::create(port));
110 } 112 }
111 113
112 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, bool isActive) 114 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, bool isActive)
113 { 115 {
114 ASSERT(isMainThread()); 116 ASSERT(isMainThread());
115 unsigned portIndex = m_outputs.size(); 117 unsigned portIndex = m_outputs.size();
116 m_outputs.append(MIDIOutput::create(this, portIndex, id, manufacturer, name, version, isActive)); 118 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, nam e, version, isActive);
119 m_outputs.append(port);
120 dispatchEvent(MIDIConnectionEvent::create(port));
117 } 121 }
118 122
119 void MIDIAccess::didSetInputPortState(unsigned portIndex, bool isActive) 123 void MIDIAccess::didSetInputPortState(unsigned portIndex, bool isActive)
120 { 124 {
121 ASSERT(isMainThread()); 125 ASSERT(isMainThread());
122 if (portIndex < m_inputs.size()) 126 if (portIndex >= m_inputs.size())
123 m_inputs[portIndex]->setActiveState(isActive); 127 return;
128
129 m_inputs[portIndex]->setActiveState(isActive);
130 dispatchEvent(MIDIConnectionEvent::create(m_inputs[portIndex]));
124 } 131 }
125 132
126 void MIDIAccess::didSetOutputPortState(unsigned portIndex, bool isActive) 133 void MIDIAccess::didSetOutputPortState(unsigned portIndex, bool isActive)
127 { 134 {
128 ASSERT(isMainThread()); 135 ASSERT(isMainThread());
129 if (portIndex < m_outputs.size()) 136 if (portIndex >= m_outputs.size())
130 m_outputs[portIndex]->setActiveState(isActive); 137 return;
138
139 m_outputs[portIndex]->setActiveState(isActive);
140 dispatchEvent(MIDIConnectionEvent::create(m_outputs[portIndex]));
131 } 141 }
132 142
133 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) 143 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp)
134 { 144 {
135 ASSERT(isMainThread()); 145 ASSERT(isMainThread());
136 if (portIndex >= m_inputs.size()) 146 if (portIndex >= m_inputs.size())
137 return; 147 return;
138 148
139 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime() 149 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime()
140 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now(). 150 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now().
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 186
177 DEFINE_TRACE(MIDIAccess) 187 DEFINE_TRACE(MIDIAccess)
178 { 188 {
179 visitor->trace(m_inputs); 189 visitor->trace(m_inputs);
180 visitor->trace(m_outputs); 190 visitor->trace(m_outputs);
181 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIAccess>::trace(visit or); 191 RefCountedGarbageCollectedEventTargetWithInlineData<MIDIAccess>::trace(visit or);
182 ActiveDOMObject::trace(visitor); 192 ActiveDOMObject::trace(visitor);
183 } 193 }
184 194
185 } // namespace blink 195 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webmidi/MIDIAccess.h ('k') | Source/modules/webmidi/MIDIAccess.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698