Chapter 8. Subscription of ports

Table of Contents
Concept of subscription
More inside the subscription
Examples of subscription
Event processing

Concept of subscription

One of the new features in ALSA sequencer system is subscription of ports. In general, subscription is a connection between two sequencer ports. Even though an event can be delivered to a port without subscription using an explicit destination address, the subscription mechanism provides us more abstraction.

Suppose a MIDI input device which sends events from a keyboard. The port associated with this device has READ capability - which means this port is readable from other ports. If a user program wants to capture events from keyboard and store them as MIDI stream, this program must subscribe itself to the MIDI port for read. Then, a connection from MIDI input port to this program is established. From this time, events from keyboard are automatically sent to this program. Timestamps will be updated according to the subscribed queue.

	MIDI input port (keyboard)
	    |
	    V
	ALSA sequencer - update timestamp
	    |
	    V
	application port

There is another subscription type for opposite direction: Suppose a MIDI sequencer program which sends events to a MIDI output device. In ALSA system, MIDI device is not opened until the associated MIDI port is accessed. Thus, in order to activate MIDI device, we have to subscribe to MIDI port for write. After this connection is established, events will be properly sent to MIDI output device.

	application port
	    |
	    V
	ALSA sequencer - events are scheduled
	    |
	    V
	MIDI output port (WaveTable etc.)

From the viewpoint of subscription, the examples above are special cases. Basically, subscription means the connection between two arbitrary ports. For example, imagine a filter application which modifies the MIDI events like program, velocity or chorus effects. This application can accept arbitrary MIDI input and send to arbitrary port, just like a Unix pipe application using stdin and stdout files. We can even connect several filter applictions which work individually in order to process the MIDI events. Subscription can be used for this purpose. The connection between ports can be done also by the "third" client. Thus, filter applications have to manage only input and output events regardless of receiver/sender addresses. This idea is similar to MidiShare connection mechanism.

	sequencer port #1
	    |
	    V
	ALSA sequencer (scheduled or real-time)
	    |
	    V
	sequencer port #2