Exemple #1
0
/* open associated midi device for input */
static int midisynth_subscribe(void *private_data, snd_seq_port_subscribe_t *info)
{
	int err;
	seq_midisynth_t *msynth = (seq_midisynth_t *)private_data;
	snd_rawmidi_runtime_t *runtime;
	snd_rawmidi_params_t params;

	/* open midi port */
	if ((err = snd_rawmidi_kernel_open(msynth->card->number, msynth->device, msynth->subdevice, SNDRV_RAWMIDI_LFLG_INPUT, &msynth->input_rfile)) < 0) {
		snd_printd("midi input open failed!!!\n");
		return err;
	}
	runtime = msynth->input_rfile.input->runtime;
	memset(&params, 0, sizeof(params));
	params.avail_min = 1;
	params.buffer_size = input_buffer_size;
	if ((err = snd_rawmidi_input_params(msynth->input_rfile.input, &params)) < 0) {
		snd_rawmidi_kernel_release(&msynth->input_rfile);
		return err;
	}
	runtime->event = snd_midi_input_event;
	runtime->private_data = msynth;
	snd_rawmidi_kernel_read(msynth->input_rfile.input, NULL, 0);
	return 0;
}
Exemple #2
0
/* open associated midi device for input */
static int midisynth_subscribe(void *private_data, struct snd_seq_port_subscribe *info)
{
    int err;
    struct seq_midisynth *msynth = private_data;
    struct snd_rawmidi_runtime *runtime;
    struct snd_rawmidi_params params;

    /* open midi port */
    if ((err = snd_rawmidi_kernel_open(msynth->card, msynth->device,
                                       msynth->subdevice,
                                       SNDRV_RAWMIDI_LFLG_INPUT,
                                       &msynth->input_rfile)) < 0) {
        pr_debug("ALSA: seq_midi: midi input open failed!!!\n");
        return err;
    }
    runtime = msynth->input_rfile.input->runtime;
    memset(&params, 0, sizeof(params));
    params.avail_min = 1;
    params.buffer_size = input_buffer_size;
    if ((err = snd_rawmidi_input_params(msynth->input_rfile.input, &params)) < 0) {
        snd_rawmidi_kernel_release(&msynth->input_rfile);
        return err;
    }
    snd_midi_event_reset_encode(msynth->parser);
    runtime->event = snd_midi_input_event;
    runtime->private_data = msynth;
    snd_rawmidi_kernel_read(msynth->input_rfile.input, NULL, 0);
    return 0;
}
Exemple #3
0
/* handle rawmidi input event (MIDI v1.0 stream) */
static void snd_midi_input_event(snd_rawmidi_substream_t * substream)
{
	snd_rawmidi_runtime_t *runtime;
	seq_midisynth_t *msynth;
	snd_seq_event_t ev;
	char buf[16], *pbuf;
	long res, count;

	if (substream == NULL)
		return;
	runtime = substream->runtime;
	msynth = (seq_midisynth_t *) runtime->private_data;
	if (msynth == NULL)
		return;
	memset(&ev, 0, sizeof(ev));
	while (runtime->avail > 0) {
		res = snd_rawmidi_kernel_read(substream, buf, sizeof(buf));
		if (res <= 0)
			continue;
		if (msynth->parser == NULL)
			continue;
		pbuf = buf;
		while (res > 0) {
			count = snd_midi_event_encode(msynth->parser, pbuf, res, &ev);
			if (count < 0)
				break;
			pbuf += count;
			res -= count;
			if (ev.type != SNDRV_SEQ_EVENT_NONE) {
				ev.source.port = msynth->seq_port;
				ev.dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
				snd_seq_kernel_client_dispatch(msynth->seq_client, &ev, 1, 0);
				/* clear event and reset header */
				memset(&ev, 0, sizeof(ev));
			}
		}
	}
}