Suppose you have 2 objects, for example an AudioProducer and an AudioConsumer,
AudioProducer with an output stream and AudioConsumer an input one.
Each time you want to connect them, you will use those 2 streams.
The first use of defaulting is to enable you to do the connection without
specifying the ports in that case.
Now suppose the 2 objects above can handle stereo, and each have a "left" and
"right" port. You'd still like to connect them as easily as before.
But how can the connecting system know which output port to connect to which
input port? It has no way to map correctly the streams.
Defaulting is then used to specify several streams, with an order. Thus, when
you connect an object with 2 default output streams to another one with 2
default input streams, you don't have to specify the ports, and the mapping
will be done correctly.
Of course, this is not limited to stereo. Any number of streams can be made default if needed, and the connect function will check that the number of defaults for 2 object match (in the required direction) if you don't specify the ports to use.
In the idl, you can use the default keyword in the stream declaration, or on a single line.
Example:
interface TwoToOneMixer { default in audio stream input1, input2; out audio stream output; };
In this example, the object will expect its 2 input ports to be connected by
default.
The order is the one specified on the default line, so an object like this one:
interface DualNoiseGenerator { out audio stream bzzt, couic; default couic, bzzt; };
Will allow connections from "couic" to "input1", and "bzzt" to "input2"
automatically.
Note that since there is only one output for the mixer, it will be made default
in this case (see below).
The syntax used in the noise generator is useful to declare a different order
than the declaration, or selecting only a few ports as default. The directions
of the ports on this line will be looked up by mcopidl, so don't specify them.
You can even mix input and output ports in such a line, only the order is
important.
Back to the index | brodu@kde.org |