Discussion:
SND_SEQ_EVENT_PORT_UNSUBSCRIBED v. listconnectedto()
(too old to reply)
Peter Billam
2014-04-11 05:32:36 UTC
Permalink
Greetings. Hope you're all well :-) Erm... If I'm running an
ALSA-MIDI client, let's say called midifoo, and then someone does:
aconnect midifoo:1 TiMidity
or:
aconnect -d midifoo:1 TiMidity
then it seems to me that my client midifoo does not receive any
SND_SEQ_EVENT_PORT_SUBSCRIBED or SND_SEQ_EVENT_PORT_UNSUBSCRIBED
alsaevent. Is that right ?

Apparently these event-types only get received if an INPUT-port
is connected or disconnected ...

Is there a way of asking System to inform midifoo also about
connections and disconnections on OUTPUT-ports ?
or does midifoo have to poll listconnectedto() and look for changes ?

~> aptitude show alsa-base | grep Version
Version: 1.0.25+3~deb7u1

Hope this makes sense... greetings anyway :-)

Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
Clemens Ladisch
2014-04-12 19:01:42 UTC
Permalink
... it seems to me that my client midifoo does not receive any
SND_SEQ_EVENT_PORT_SUBSCRIBED or SND_SEQ_EVENT_PORT_UNSUBSCRIBED
alsaevent.
Apparently these event-types only get received if an INPUT-port
is connected or disconnected ...
As you have observed, a port must be marked as INPUT to be able
to receive events.
Is there a way of asking System to inform midifoo also about
connections and disconnections on OUTPUT-ports ?
Mark that port also as INPUT. (You do not need to allow write
subscriptions to that port.)

Alternatively, listen for these notifications from the System
Announce port.


Regards,
Clemens
Peter Billam
2014-04-14 06:41:18 UTC
Permalink
Post by Clemens Ladisch
Post by Peter Billam
Is there a way of asking System to inform midifoo also about
connections and disconnections on OUTPUT-ports ?
Mark that port also as INPUT. (You do not need to allow write
subscriptions to that port.)
OK, it makes sense: those notifications are sent to the Port,
not to the Client.

For me, this arises in the context of midialsa.lua :
http://www.pjb.com.au/comp/lua/midialsa.html
I borrowed the C-code from Patricio Paez' python-module.
Is marking the OUTPUT-port also as INPUT just a matter of adding
SND_SEQ_PORT_CAP_WRITE| to the
snd_seq_create_simple_port(seq_handle, "Output port" ...
parameters ?

int portid, n;
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
fprintf(stderr, "Error creating ALSA client.\n");
lua_pushboolean(L, 0); return 1;
}
snd_seq_set_client_name(seq_handle, client_name );

if ( createqueue )
queue_id = snd_seq_alloc_queue(seq_handle);
else
queue_id = SND_SEQ_QUEUE_DIRECT;

for ( n=0; n < ninputports; n++ ) {
if (( portid = snd_seq_create_simple_port(seq_handle, "Input port",
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating input port %d.\n", n );
lua_pushboolean(L, 0); return 1;
}
if( createqueue ) {
/* set timestamp info of port */
snd_seq_port_info_t *pinfo;
snd_seq_port_info_alloca(&pinfo);
snd_seq_get_port_info(seq_handle, portid, pinfo);
snd_seq_port_info_set_timestamping(pinfo, 1);
snd_seq_port_info_set_timestamp_queue(pinfo, queue_id);
snd_seq_port_info_set_timestamp_real(pinfo, 1);
snd_seq_set_port_info(seq_handle, portid, pinfo);
}
}
for ( n=0; n < noutputports; n++ ) {
if (( portid = snd_seq_create_simple_port(seq_handle, "Output port",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating output port %d.\n", n );
lua_pushboolean(L, 0); return 1;
}
}
firstoutputport = ninputports;
lastoutputport = noutputports + ninputports - 1;
lua_pushboolean(L, 1); return 1;

I have another question there, too, only slightly off-topic:
If I want to create an Input/Output port, so that both input and
output go through midifoo:0 , do I have to use snd_seq_create_port()
or is that possible within snd_seq_create_simple_port() using
different "caps = capability bits" parameters ?
http://alsa-project.org/alsa-doc/alsa-lib/group___seq_port.html
That is: do I just add SND_SEQ_PORT_CAP_DUPLEX| to the
snd_seq_create_simple_port() call ? Does it make sense to specify
both SND_SEQ_PORT_CAP_WRITE and SND_SEQ_PORT_CAP_READ, without
also specifying SND_SEQ_PORT_CAP_DUPLEX ? or vice versa ?
I'm not sure how they interrelate ...
Post by Clemens Ladisch
Alternatively, listen for these notifications from the System
Announce port.
Good low-tech workaround :-)

Thanks, Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
Clemens Ladisch
2014-04-14 20:30:22 UTC
Permalink
Post by Peter Billam
Is marking the OUTPUT-port also as INPUT just a matter of adding
SND_SEQ_PORT_CAP_WRITE| to the
snd_seq_create_simple_port(seq_handle, "Output port" ...
parameters ?
Yes.
Post by Peter Billam
If I want to create an Input/Output port, so that both input and
output go through midifoo:0 , do I have to use snd_seq_create_port()
or is that possible within snd_seq_create_simple_port() using
different "caps = capability bits" parameters ?
Just specify both READ and WRITE.
Post by Peter Billam
That is: do I just add SND_SEQ_PORT_CAP_DUPLEX| to the
snd_seq_create_simple_port() call ? Does it make sense to specify
both SND_SEQ_PORT_CAP_WRITE and SND_SEQ_PORT_CAP_READ, without
also specifying SND_SEQ_PORT_CAP_DUPLEX ? or vice versa ?
If you want to allow other clients to send events to the port, set the
WRITE flag.

If you want to allow other clients to create a subscription to the port,
set the WRITE and SUBS_WRITE flags.

If you want to allow other clients to create a subscription from the
port, set the READ and SUBS_READ flags.

(Setting only the READ flag does not make sense because these flags
specify what *other* clients are allowed to do.)

The DUPLEX flag is purely informational, but you should set it if the
port supports both directions.


Regards,
Clemens
Peter Billam
2014-04-15 00:37:23 UTC
Permalink
Post by Clemens Ladisch
Post by Peter Billam
Is marking the OUTPUT-port also as INPUT just a matter of adding
SND_SEQ_PORT_CAP_WRITE| to the
snd_seq_create_simple_port(seq_handle, "Output port" ...
parameters ?
Yes.
Post by Peter Billam
If I want to create an Input/Output port, so that both input
and output go through midifoo:0
Just specify both READ and WRITE.
Post by Peter Billam
That is: do I just add SND_SEQ_PORT_CAP_DUPLEX| to the
snd_seq_create_simple_port() call ? Does it make sense to specify
both SND_SEQ_PORT_CAP_WRITE and SND_SEQ_PORT_CAP_READ, without
also specifying SND_SEQ_PORT_CAP_DUPLEX ? or vice versa ?
If you want to allow other clients to send events to the port,
set the WRITE flag.
If you want to allow other clients to create a subscription to
the port, set the WRITE and SUBS_WRITE flags.
If you want to allow other clients to create a subscription from
the port, set the READ and SUBS_READ flags.
(Setting only the READ flag does not make sense because these flags
specify what *other* clients are allowed to do.)
The DUPLEX flag is purely informational, but you should set it if
the port supports both directions.
That's excellent, Clemens, very helpful, many thanks :-)

Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
Loading...