Foreach (Reactive) and Foreach (Primitive)

Assuming that I have several midi inputs (MidiIn) and objects that I want to set incoming messages accordingly (as property), maybe by doing a simple condition (like if byte[1] == xx then {} ).

Which practice is supposed to be more efficient / better?

Left. Encapsulate ForEach loop in a ForEach (reactive)
Right. Encapsulate ForEach (reactive) in a ForEach loop

or they are equally the same ?


1 Like

I would prefer the left one. It only does something if messages come in.

1 Like

Thanks @Elias
In both cases the result is the same right?
Is there any other way - design to deal with this?

The result is the same yes.

Hard to say, that really depends on what you are trying to build. Just from looking at your patch I could imagine one issue which could arise (and I’m not sure about) is whether the midi notifications arrive on a different thread than the main thread. If that is the case you might be running into troubles if those SetMidiMessage nodes operate on properties of objects living in the main thread. In that case nodes like ObserveOnMainThread or Sampler might come to your rescue.

1 Like