[PD-cvs] pd/src s_midi_alsa.c,1.1.2.2.2.3,1.1.2.2.2.4
Tim Blechmann
timblech at users.sourceforge.net
Thu Oct 6 20:41:44 CEST 2005
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9653/src
Modified Files:
Tag: devel_0_39
s_midi_alsa.c
Log Message:
iohannes's autoconnect patch
Index: s_midi_alsa.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_midi_alsa.c,v
retrieving revision 1.1.2.2.2.3
retrieving revision 1.1.2.2.2.4
diff -C2 -d -r1.1.2.2.2.3 -r1.1.2.2.2.4
*** s_midi_alsa.c 21 Aug 2005 11:28:24 -0000 1.1.2.2.2.3
--- s_midi_alsa.c 6 Oct 2005 18:41:42 -0000 1.1.2.2.2.4
***************
*** 48,53 ****
--- 48,61 ----
int i;
snd_seq_client_info_t *alsainfo;
+ /* do we want to connect pd automatically with other devices ?; see below! */
+ /* LATER: think about a flag to enable/disable automatic connection
+ * (sometimes it could be a pain)
+ */
+ int autoconnect = 1;
alsa_nmidiin = 0;
alsa_nmidiout = 0;
+
+ if (nmidiout == 0 && nmidiin == 0) return;
+
if(nmidiin>MAXMIDIINDEV )
{
***************
*** 74,96 ****
return;
}
! for (i=0;i<nmidiout;i++)
{
int port;
sprintf(portname,"Pure Data Midi-In %d",i+1);
! port = snd_seq_create_simple_port(midi_handle,portname,SND_SEQ_PORT_CAP_WRITE |SND_SEQ_PORT_CAP_SUBS_WRITE , SND_SEQ_PORT_TYPE_APPLICATION);
! alsa_midiinfd[i] = port;
if (port < 0) goto error;
}
! for (i=0;i<nmidiin;i++)
{
int port;
sprintf(portname,"Pure Data Midi-Out %d",i+1);
! port = snd_seq_create_simple_port(midi_handle,portname, SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_APPLICATION);
! alsa_midioutfd[i] = port;
if (port < 0) goto error;
}
- if (nmidiout == 0 && nmidiin == 0) return;
snd_seq_client_info_malloc(&alsainfo);
snd_seq_get_client_info(midi_handle,alsainfo);
--- 82,107 ----
return;
}
! for (i=0;i<nmidiin;i++)
{
int port;
sprintf(portname,"Pure Data Midi-In %d",i+1);
! port = snd_seq_create_simple_port(midi_handle,portname,
! SND_SEQ_PORT_CAP_WRITE |SND_SEQ_PORT_CAP_SUBS_WRITE,
! SND_SEQ_PORT_TYPE_APPLICATION);
! alsa_midiinfd[i] = port;
if (port < 0) goto error;
}
! for (i=0;i<nmidiout;i++)
{
int port;
sprintf(portname,"Pure Data Midi-Out %d",i+1);
! port = snd_seq_create_simple_port(midi_handle,portname,
! SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ,
! SND_SEQ_PORT_TYPE_APPLICATION);
! alsa_midioutfd[i] = port;
if (port < 0) goto error;
}
snd_seq_client_info_malloc(&alsainfo);
snd_seq_get_client_info(midi_handle,alsainfo);
***************
*** 104,109 ****
alsa_nmidiout = nmidiout;
alsa_nmidiin = nmidiin;
return;
! error:
sys_setalarm(1000000);
post("couldn't open alsa MIDI output device");
--- 115,179 ----
alsa_nmidiout = nmidiout;
alsa_nmidiin = nmidiin;
+
+ /* JMZ: connect all available devices to pd */
+ if (autoconnect)
+ {
+
+ snd_seq_client_info_t *cinfo;
+ snd_seq_port_info_t *pinfo;
+
+ snd_seq_port_subscribe_t *subs;
+ snd_seq_addr_t other, topd, frompd;
+ /* since i don't know how to connect multiple ports
+ * (connect everything to each port, modulo,...),
+ * i only fully connect where we have only one single port
+ */
+ if(alsa_nmidiin)
+ {
+ topd.client =client;
+ topd.port =alsa_midiinfd[0];
+ }
+ if(alsa_nmidiout)
+ {
+ frompd.client =client;
+ frompd.port =alsa_midioutfd[0];
+ }
+
+ snd_seq_port_subscribe_alloca(&subs);
+
+ snd_seq_client_info_alloca(&cinfo);
+ snd_seq_port_info_alloca(&pinfo);
+ snd_seq_client_info_set_client(cinfo, -1);
+ while (snd_seq_query_next_client(midi_handle, cinfo) >= 0)
+ {
+ /* reset query info */
+ int client_id=snd_seq_client_info_get_client(cinfo);
+
+ if((SND_SEQ_CLIENT_SYSTEM != client_id)&&(client != client_id))
+ { /* skipping port 0 and ourself */
+ snd_seq_port_info_set_client(pinfo, client_id);
+ snd_seq_port_info_set_port(pinfo, -1);
+ while (snd_seq_query_next_port(midi_handle, pinfo) >= 0)
+ {
+ other.client=client_id;
+ other.port =snd_seq_port_info_get_port(pinfo);
+ if(1==alsa_nmidiin) /* only autoconnect 1st port */
+ {
+ snd_seq_port_subscribe_set_sender(subs, &other);
+ snd_seq_port_subscribe_set_dest(subs, &topd);
+ snd_seq_subscribe_port(midi_handle, subs);
+ }
+ if(1==alsa_nmidiout) /* only autoconnect 1st port */
+ {
+ snd_seq_port_subscribe_set_sender(subs, &frompd);
+ snd_seq_port_subscribe_set_dest(subs, &other);
+ snd_seq_subscribe_port(midi_handle, subs);
+ }
+ }
+ }
+ }
+ }
return;
! error:
sys_setalarm(1000000);
post("couldn't open alsa MIDI output device");
More information about the Pd-cvs
mailing list