@@ -89,12 +89,14 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
8989 aPort->GetId (id);
9090 ErrorResult rv;
9191 if (aPort->State () == MIDIPortDeviceState::Disconnected) {
92- if (aPort->Type () == MIDIPortType::Input &&
93- MIDIInputMap_Binding::MaplikeHelpers::Has (mInputMap , id, rv)) {
94- MIDIInputMap_Binding::MaplikeHelpers::Delete (mInputMap , id, rv);
95- } else if (aPort->Type () == MIDIPortType::Output &&
96- MIDIOutputMap_Binding::MaplikeHelpers::Has (mOutputMap , id, rv)) {
97- MIDIOutputMap_Binding::MaplikeHelpers::Delete (mOutputMap , id, rv);
92+ if (aPort->Type () == MIDIPortType::Input && mInputMap ->Has (id)) {
93+ MIDIInputMap_Binding::MaplikeHelpers::Delete (mInputMap , aPort->StableId (),
94+ rv);
95+ mInputMap ->Remove (id);
96+ } else if (aPort->Type () == MIDIPortType::Output && mOutputMap ->Has (id)) {
97+ MIDIOutputMap_Binding::MaplikeHelpers::Delete (mOutputMap ,
98+ aPort->StableId (), rv);
99+ mOutputMap ->Remove (id);
98100 }
99101 // Check to make sure Has()/Delete() calls haven't failed.
100102 if (NS_WARN_IF(rv.Failed ())) {
@@ -106,31 +108,31 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
106108 // this means a port that was disconnected has been reconnected, with the
107109 // port owner holding the object during that time, and we should add that
108110 // port object to our maps again.
109- if (aPort->Type () == MIDIPortType::Input &&
110- !MIDIInputMap_Binding::MaplikeHelpers::Has (mInputMap , id, rv)) {
111+ if (aPort->Type () == MIDIPortType::Input && !mInputMap ->Has (id)) {
111112 if (NS_WARN_IF(rv.Failed ())) {
112113 LOG (" Input port not found" );
113114 return ;
114115 }
115116 MIDIInputMap_Binding::MaplikeHelpers::Set (
116- mInputMap , id , *(static_cast <MIDIInput*>(aPort)), rv);
117+ mInputMap , aPort-> StableId () , *(static_cast <MIDIInput*>(aPort)), rv);
117118 if (NS_WARN_IF(rv.Failed ())) {
118119 LOG (" Map Set failed for input port" );
119120 return ;
120121 }
121- } else if (aPort->Type () == MIDIPortType::Output &&
122- !MIDIOutputMap_Binding::MaplikeHelpers::Has (mOutputMap , id,
123- rv)) {
122+ mInputMap ->Insert (id, aPort);
123+ } else if (aPort->Type () == MIDIPortType::Output && mOutputMap ->Has (id)) {
124124 if (NS_WARN_IF(rv.Failed ())) {
125125 LOG (" Output port not found" );
126126 return ;
127127 }
128128 MIDIOutputMap_Binding::MaplikeHelpers::Set (
129- mOutputMap , id, *(static_cast <MIDIOutput*>(aPort)), rv);
129+ mOutputMap , aPort->StableId (), *(static_cast <MIDIOutput*>(aPort)),
130+ rv);
130131 if (NS_WARN_IF(rv.Failed ())) {
131132 LOG (" Map set failed for output port" );
132133 return ;
133134 }
135+ mOutputMap ->Insert (id, aPort);
134136 }
135137 }
136138 RefPtr<MIDIConnectionEvent> event =
@@ -144,9 +146,7 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
144146 MIDIPortType type = static_cast <MIDIPortType>(aInfo.type ());
145147 RefPtr<MIDIPort> port;
146148 if (type == MIDIPortType::Input) {
147- bool hasPort =
148- MIDIInputMap_Binding::MaplikeHelpers::Has (mInputMap , id, aRv);
149- if (hasPort || NS_WARN_IF(aRv.Failed ())) {
149+ if (mInputMap ->Has (id) || NS_WARN_IF(aRv.Failed ())) {
150150 // We already have the port in our map.
151151 return ;
152152 }
@@ -157,15 +157,15 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
157157 return ;
158158 }
159159 MIDIInputMap_Binding::MaplikeHelpers::Set (
160- mInputMap , id, *(static_cast <MIDIInput*>(port.get ())), aRv);
160+ mInputMap , port->StableId (), *(static_cast <MIDIInput*>(port.get ())),
161+ aRv);
161162 if (NS_WARN_IF(aRv.Failed ())) {
162163 LOG (" Coudld't set input port in map" );
163164 return ;
164165 }
166+ mInputMap ->Insert (id, port);
165167 } else if (type == MIDIPortType::Output) {
166- bool hasPort =
167- MIDIOutputMap_Binding::MaplikeHelpers::Has (mOutputMap , id, aRv);
168- if (hasPort || NS_WARN_IF(aRv.Failed ())) {
168+ if (mOutputMap ->Has (id) || NS_WARN_IF(aRv.Failed ())) {
169169 // We already have the port in our map.
170170 return ;
171171 }
@@ -176,11 +176,13 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
176176 return ;
177177 }
178178 MIDIOutputMap_Binding::MaplikeHelpers::Set (
179- mOutputMap , id, *(static_cast <MIDIOutput*>(port.get ())), aRv);
179+ mOutputMap , port->StableId (), *(static_cast <MIDIOutput*>(port.get ())),
180+ aRv);
180181 if (NS_WARN_IF(aRv.Failed ())) {
181182 LOG (" Coudld't set output port in map" );
182183 return ;
183184 }
185+ mOutputMap ->Insert (id, port);
184186 } else {
185187 // If we hit this, then we have some port that is neither input nor output.
186188 // That is bad.
0 commit comments