/** * \brief set client name * \param seq sequencer handle * \param name name string * \return 0 on success or negative error code * * \sa snd_seq_set_client_info() */ int snd_seq_set_client_name(snd_seq_t *seq, const char *name) { snd_seq_client_info_t info; int err; if ((err = snd_seq_get_client_info(seq, &info)) < 0) return err; strncpy(info.name, name, sizeof(info.name) - 1); return snd_seq_set_client_info(seq, &info); }
/** * \brief add client event filter * \param seq sequencer handle * \param event_type event type to be added * \return 0 on success or negative error code * * \sa snd_seq_set_client_info() */ int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type) { snd_seq_client_info_t info; int err; if ((err = snd_seq_get_client_info(seq, &info)) < 0) return err; snd_seq_client_info_event_filter_add(&info, event_type); return snd_seq_set_client_info(seq, &info); }
static int set_seq_name(snd_seq_t *handle) { int err; snd_seq_client_info_t info; memset(&info, 0, sizeof(info)); info.client = snd_seq_client_id(handle); info.type = USER_CLIENT; snprintf(info.name, sizeof(info.name), "SoundTracker(%i)", getpid()); err = snd_seq_set_client_info(handle, &info); if (err < 0) { fprintf(stderr, "Set client info error: %s\n", snd_strerror(err)); return -1; } return 0; } /* set_seq_name() */
void sys_alsa_do_open_midi(int nmidiin, int *midiinvec, int nmidiout, int *midioutvec) { char portname[50]; int err = 0; int client; int i; snd_seq_client_info_t *alsainfo; alsa_nmidiin = 0; alsa_nmidiout = 0; if (nmidiout == 0 && nmidiin == 0) return; if(nmidiin>MAXMIDIINDEV ) { post("midi input ports reduced to maximum %d", MAXMIDIINDEV); nmidiin=MAXMIDIINDEV; } if(nmidiout>MAXMIDIOUTDEV) { post("midi output ports reduced to maximum %d", MAXMIDIOUTDEV); nmidiout=MAXMIDIOUTDEV; } if (nmidiin>0 && nmidiout>0) err = snd_seq_open(&midi_handle,"default",SND_SEQ_OPEN_DUPLEX,0); else if (nmidiin > 0) err = snd_seq_open(&midi_handle,"default",SND_SEQ_OPEN_INPUT,0); else if (nmidiout > 0) err = snd_seq_open(&midi_handle,"default",SND_SEQ_OPEN_OUTPUT,0); if (err!=0) { sys_setalarm(1000000); post("couldn't open alsa sequencer"); 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); snd_seq_client_info_set_name(alsainfo,"Pure Data"); client = snd_seq_client_info_get_client(alsainfo); snd_seq_set_client_info(midi_handle,alsainfo); snd_seq_client_info_free(alsainfo); post("Opened Alsa Client %d in:%d out:%d",client,nmidiin,nmidiout); sys_setalarm(0); snd_midi_event_new(ALSA_MAX_EVENT_SIZE,&midiev); alsa_nmidiout = nmidiout; alsa_nmidiin = nmidiin; return; error: sys_setalarm(1000000); post("couldn't open alsa MIDI output device"); return; }