Multiplexer

Multiplexer Filter

 

Position Velocity

The Multiplexer Physlet combines data from multiple data sources in order to produce new data.  Incoming data is attached to a data listener that has been created using the

document.multiplexer.addDataListener( int index ) 

method.  The index is used to identify the incoming data.  For example, if index=2 then then the Multiplexer Physlet will name the incoming data x2  and y2.   Another data source may use index=3 thereby producing data named x3 and y3.

After all the data listeners have been created, the script author writes two analytic functions of the new xi and yi variables and passes these functions to the

document.multiplexer.setFunctions( String xFunction, String yFunction ) 

method.  The Multiplexer will use these functions to generate outgoing data source whenever an active data listener changes state.

Active Data Listeners

Incoming data will not cause the Multiplex filter to generate output data unless the incoming data source has been set to be active.  This is done using the

document.multiplexer.setActiveListener( int index, boolean active ) 

method.  The default value of this attribute is false.

Limiting the number of active data listeners keeps unnecessary output from being generated and insures that all incoming data is up-to-date before the outgoing data is calculated.  Data sources inside Animator (and most other Physlets) are updated in the order that they are created.  In the above example, the blue ball is created last so we set the data listener associated with the blue ball to be active.  The Multiplexer will have already received data from the red ball, thereby insuring the output is calculated only once and that this calculation uses current values of both balls.

It is, of course, possible to collect data from multiple Physlets.  The script author may choose to make more than one incoming data source active if these data sources respond to user actions such as dragging.  However, if multiple Physlets are animated, it would be better to synchronize the animation in the Physlets and to connect the synchronizing clock to the Multiplexer as the only active data listener.  (See example 2.)