@@ -54,8 +54,7 @@ class observer_impl_base
5454#endif
5555
5656 // Set-up initial state
57- if (configuration.notify_in_constructor )
58- this ->check_devices ();
57+ this ->check_devices (configuration.notify_in_constructor );
5958
6059#if LIBREMIDI_HAS_UDEV
6160 // Start thread
@@ -139,7 +138,7 @@ class observer_impl_base
139138 this ->m_timer_fd .cancel ();
140139 m_fds[2 ].revents = 0 ;
141140
142- check_devices ();
141+ check_devices (true );
143142 }
144143 }
145144 }
@@ -185,7 +184,7 @@ class observer_impl_base
185184 .type = type}};
186185 }
187186
188- void check_devices ()
187+ void check_devices (bool notify )
189188 {
190189 Enumerator new_devs{*this };
191190
@@ -203,18 +202,6 @@ class observer_impl_base
203202 }
204203 }
205204
206- for (auto & in_next : new_devs.inputs )
207- {
208- if (auto it = std::find (m_current_inputs.begin (), m_current_inputs.end (), in_next);
209- it == m_current_inputs.end ())
210- {
211- if (auto & cb = this ->configuration .input_added )
212- {
213- cb (to_port_info<true >(in_next));
214- }
215- }
216- }
217-
218205 for (auto & out_prev : m_current_outputs)
219206 {
220207 if (auto it = std::find (new_devs.outputs .begin (), new_devs.outputs .end (), out_prev);
@@ -227,14 +214,29 @@ class observer_impl_base
227214 }
228215 }
229216
230- for ( auto & out_next : new_devs. outputs )
217+ if (notify )
231218 {
232- if (auto it = std::find (m_current_outputs.begin (), m_current_outputs.end (), out_next);
233- it == m_current_outputs.end ())
219+ if (auto & cb = this ->configuration .input_added )
220+ {
221+ for (auto & in_next : new_devs.inputs )
222+ {
223+ if (auto it = std::find (m_current_inputs.begin (), m_current_inputs.end (), in_next);
224+ it == m_current_inputs.end ())
225+ {
226+ cb (to_port_info<true >(in_next));
227+ }
228+ }
229+ }
230+
231+ if (auto & cb = this ->configuration .output_added )
234232 {
235- if (auto & cb = this -> configuration . output_added )
233+ for (auto & out_next : new_devs. outputs )
236234 {
237- cb (to_port_info<false >(out_next));
235+ if (auto it = std::find (m_current_outputs.begin (), m_current_outputs.end (), out_next);
236+ it == m_current_outputs.end ())
237+ {
238+ cb (to_port_info<false >(out_next));
239+ }
238240 }
239241 }
240242 }
0 commit comments