need help with chains?

Topics: Midi Message Classes
Dec 31, 2013 at 7:12 PM
I am trying to expand the MidiNoteMapper sample app to handle complex routing / mapping needs that I have.

I need to have two (or more) instances of the MidiNoteMapper class that point to the same input port (but listening on different channels). I am able to add the first instance of the MidiNoteMapper to the ChainManager just fine, and everything works. But, I try to add a second instance of the MidiNoteMapper to the ChainManager, I get a message of "End of Chain! Last Receiver did not implement IMidiReceiverChain". I've searched through the source for the libraries, and can find this message (in the resource file), but can't actually find an interface called "IMidiReceiverChain". I can see where, in MidiReceiverChainManager, the message is thrown, but I am unclear what interface, exactly, my modified version of the MidiNoteMapper class must implement. Can you help?

(any discussion about how the chains work and how to implement them would be appreciated!)
Coordinator
Dec 31, 2013 at 7:58 PM
The "IMidiReceiverChain" is an old name for what is now IChainOf<IMidiDataReceiver>. The IChainOf<T> interface is a generic interface to create a chain of components (chain of responsibility pattern) that all implement a specific interface T. The IChainOf<T> introduces a Successor property that points to the next component in the chain. The idea is that at the start of the chain some action is propagated through the chain of components. Each component can alter and/or filter data or change the action completely.

A MidiInPort is always at the start of the chain and a MidiOutPort is always at the end of a chain. The ChainManagers are there to manage building and initializing the input/output chains, allow iterating its component as well as component cleanup.

The "end of the chain" is the first component that does not implement IChainOf<T>. Because each component references the next component it requires the Successor property of the IChainOf<T>.

So in your case: you could build a component that examines the short data and dispatches these calls to several different other components (branching the chain based on channel number) - each branch doing further processing for that channel - each having their own MidiNoteMapper instance.

There is a reason this whole mechanism is in a separate assembly. I do not mean to pin people down on this mechanism - it is optional. So you can also choose something else to do/manage your processing.

Hope it helps.
Marc