cross-platform / dspatch

The Refreshingly Simple Cross-Platform C++ Dataflow / Patching / Pipelining / Graph Processing / Stream Processing / Reactive Programming Framework
https://flowbasedprogramming.com/
BSD 2-Clause "Simplified" License
220 stars 44 forks source link

named and optional IO #20

Open trporn opened 4 years ago

trporn commented 4 years ago

It is quite simple and refreshing indeed. It would be nice to add named inputs/outputs so that components can be connected by name. It would be less bug prone, especially since the types are dynamic and there is no type safety on the bus.

Also, can a component know if a specific output is required by some future component or not? This is nice for performance reasons. If it is not needed, it can be skipped.

Thx.

MarcusTomlinson commented 4 years ago

Hi @trporn, thanks for your interest in DSPatch!

Connection by pin name string is certainly doable but arguably a cleaner, even less error prone way to do this would be to declare public enums for your IO in each of your components like so:

enum class Inputs
{
    Left = 0,
    Right = 1
};

Regarding determining if an output is being used, no, not at this point at least. Because circuits are implemented as pull systems, components know only about the components feeding into them, not the ones they feed to.

MarcusTomlinson commented 4 years ago

Oh wait, we do ref count component outputs. Your latter request may be doable. I will look into it :)

trporn commented 4 years ago

Yeap, enum is a nicer way to go. You can use something like magic_enum from https://github.com/Neargye/magic_enum to automatically infer the number of elements in the enum, turn enums to strings etc. This would make the enum declaration replace the definition of the number of inputs/outputs, so the hassle is kept to a minimum.

Oh wait, we do ref count component outputs. Your latter request may be doable. I will look into it :)

I think it is generally desirable to be able to treat the whole circuit as a graph. This way you can answer questions like "what output changes if I changed this input?" or "which of the inputs influence that output"