mirror of https://gitee.com/openkylin/linux.git
ALSA: firewire-digi00x: allow user space applications to read/write MIDI messages for all ports
At a commit c5fcee0373
("ALSA: firewire-digi00x: add MIDI operations for
MIDI control port"), I described that MIDI messages for control surface is
transferred by a different way from the messages for physical ports.
However, this is wrong. MIDI messages to/from all of MIDI ports are
transferred by isochronous packets.
This commit removes codes to transfer MIDI messages via asynchronous
transaction, from MIDI handling layer.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
8820a4cf0c
commit
0c3f15f39c
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include "digi00x.h"
|
#include "digi00x.h"
|
||||||
|
|
||||||
static int midi_phys_open(struct snd_rawmidi_substream *substream)
|
static int midi_open(struct snd_rawmidi_substream *substream)
|
||||||
{
|
{
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
||||||
int err;
|
int err;
|
||||||
|
@ -27,7 +27,7 @@ static int midi_phys_open(struct snd_rawmidi_substream *substream)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int midi_phys_close(struct snd_rawmidi_substream *substream)
|
static int midi_close(struct snd_rawmidi_substream *substream)
|
||||||
{
|
{
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
||||||
|
|
||||||
|
@ -40,180 +40,130 @@ static int midi_phys_close(struct snd_rawmidi_substream *substream)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void midi_phys_capture_trigger(struct snd_rawmidi_substream *substream,
|
static void midi_capture_trigger(struct snd_rawmidi_substream *substream,
|
||||||
int up)
|
int up)
|
||||||
{
|
{
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
||||||
|
unsigned int port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
spin_lock_irqsave(&dg00x->lock, flags);
|
if (substream->rmidi->device == 0)
|
||||||
|
port = substream->number;
|
||||||
if (up)
|
|
||||||
amdtp_dot_midi_trigger(&dg00x->tx_stream, substream->number,
|
|
||||||
substream);
|
|
||||||
else
|
else
|
||||||
amdtp_dot_midi_trigger(&dg00x->tx_stream, substream->number,
|
port = 2;
|
||||||
NULL);
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dg00x->lock, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void midi_phys_playback_trigger(struct snd_rawmidi_substream *substream,
|
|
||||||
int up)
|
|
||||||
{
|
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&dg00x->lock, flags);
|
spin_lock_irqsave(&dg00x->lock, flags);
|
||||||
|
|
||||||
if (up)
|
if (up)
|
||||||
amdtp_dot_midi_trigger(&dg00x->rx_stream, substream->number,
|
amdtp_dot_midi_trigger(&dg00x->tx_stream, port, substream);
|
||||||
substream);
|
|
||||||
else
|
else
|
||||||
amdtp_dot_midi_trigger(&dg00x->rx_stream, substream->number,
|
amdtp_dot_midi_trigger(&dg00x->tx_stream, port, NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dg00x->lock, flags);
|
spin_unlock_irqrestore(&dg00x->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int midi_ctl_open(struct snd_rawmidi_substream *substream)
|
static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
|
||||||
{
|
int up)
|
||||||
/* Do nothing. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int midi_ctl_capture_close(struct snd_rawmidi_substream *substream)
|
|
||||||
{
|
|
||||||
/* Do nothing. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int midi_ctl_playback_close(struct snd_rawmidi_substream *substream)
|
|
||||||
{
|
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
|
||||||
|
|
||||||
snd_fw_async_midi_port_finish(&dg00x->out_control);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void midi_ctl_capture_trigger(struct snd_rawmidi_substream *substream,
|
|
||||||
int up)
|
|
||||||
{
|
{
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
||||||
|
unsigned int port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
spin_lock_irqsave(&dg00x->lock, flags);
|
if (substream->rmidi->device == 0)
|
||||||
|
port = substream->number;
|
||||||
if (up)
|
|
||||||
dg00x->in_control = substream;
|
|
||||||
else
|
else
|
||||||
dg00x->in_control = NULL;
|
port = 2;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dg00x->lock, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void midi_ctl_playback_trigger(struct snd_rawmidi_substream *substream,
|
|
||||||
int up)
|
|
||||||
{
|
|
||||||
struct snd_dg00x *dg00x = substream->rmidi->private_data;
|
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&dg00x->lock, flags);
|
spin_lock_irqsave(&dg00x->lock, flags);
|
||||||
|
|
||||||
if (up)
|
if (up)
|
||||||
snd_fw_async_midi_port_run(&dg00x->out_control, substream);
|
amdtp_dot_midi_trigger(&dg00x->rx_stream, port, substream);
|
||||||
|
else
|
||||||
|
amdtp_dot_midi_trigger(&dg00x->rx_stream, port, NULL);
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dg00x->lock, flags);
|
spin_unlock_irqrestore(&dg00x->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_midi_substream_names(struct snd_dg00x *dg00x,
|
static void set_substream_names(struct snd_dg00x *dg00x,
|
||||||
struct snd_rawmidi_str *str,
|
struct snd_rawmidi *rmidi, bool is_console)
|
||||||
bool is_ctl)
|
|
||||||
{
|
{
|
||||||
struct snd_rawmidi_substream *subs;
|
struct snd_rawmidi_substream *subs;
|
||||||
|
struct snd_rawmidi_str *str;
|
||||||
|
int i;
|
||||||
|
|
||||||
list_for_each_entry(subs, &str->substreams, list) {
|
for (i = 0; i < 2; ++i) {
|
||||||
if (!is_ctl)
|
str = &rmidi->streams[i];
|
||||||
snprintf(subs->name, sizeof(subs->name),
|
|
||||||
"%s MIDI %d",
|
list_for_each_entry(subs, &str->substreams, list) {
|
||||||
dg00x->card->shortname, subs->number + 1);
|
if (!is_console) {
|
||||||
else
|
snprintf(subs->name, sizeof(subs->name),
|
||||||
/* This port is for asynchronous transaction. */
|
"%s MIDI %d",
|
||||||
snprintf(subs->name, sizeof(subs->name),
|
dg00x->card->shortname,
|
||||||
"%s control",
|
subs->number + 1);
|
||||||
dg00x->card->shortname);
|
} else {
|
||||||
|
snprintf(subs->name, sizeof(subs->name),
|
||||||
|
"%s control",
|
||||||
|
dg00x->card->shortname);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_substream_pair(struct snd_dg00x *dg00x, unsigned int out_ports,
|
||||||
|
unsigned int in_ports, bool is_console)
|
||||||
|
{
|
||||||
|
static const struct snd_rawmidi_ops capture_ops = {
|
||||||
|
.open = midi_open,
|
||||||
|
.close = midi_close,
|
||||||
|
.trigger = midi_capture_trigger,
|
||||||
|
};
|
||||||
|
static const struct snd_rawmidi_ops playback_ops = {
|
||||||
|
.open = midi_open,
|
||||||
|
.close = midi_close,
|
||||||
|
.trigger = midi_playback_trigger,
|
||||||
|
};
|
||||||
|
const char *label;
|
||||||
|
struct snd_rawmidi *rmidi;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* Add physical midi ports. */
|
||||||
|
err = snd_rawmidi_new(dg00x->card, dg00x->card->driver, is_console,
|
||||||
|
out_ports, in_ports, &rmidi);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
rmidi->private_data = dg00x;
|
||||||
|
|
||||||
|
if (!is_console)
|
||||||
|
label = "%s control";
|
||||||
|
else
|
||||||
|
label = "%s MIDI";
|
||||||
|
snprintf(rmidi->name, sizeof(rmidi->name), label,
|
||||||
|
dg00x->card->shortname);
|
||||||
|
|
||||||
|
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &playback_ops);
|
||||||
|
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &capture_ops);
|
||||||
|
|
||||||
|
rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT |
|
||||||
|
SNDRV_RAWMIDI_INFO_OUTPUT |
|
||||||
|
SNDRV_RAWMIDI_INFO_DUPLEX;
|
||||||
|
|
||||||
|
set_substream_names(dg00x, rmidi, is_console);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
|
int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
|
||||||
{
|
{
|
||||||
static const struct snd_rawmidi_ops phys_capture_ops = {
|
|
||||||
.open = midi_phys_open,
|
|
||||||
.close = midi_phys_close,
|
|
||||||
.trigger = midi_phys_capture_trigger,
|
|
||||||
};
|
|
||||||
static const struct snd_rawmidi_ops phys_playback_ops = {
|
|
||||||
.open = midi_phys_open,
|
|
||||||
.close = midi_phys_close,
|
|
||||||
.trigger = midi_phys_playback_trigger,
|
|
||||||
};
|
|
||||||
static const struct snd_rawmidi_ops ctl_capture_ops = {
|
|
||||||
.open = midi_ctl_open,
|
|
||||||
.close = midi_ctl_capture_close,
|
|
||||||
.trigger = midi_ctl_capture_trigger,
|
|
||||||
};
|
|
||||||
static const struct snd_rawmidi_ops ctl_playback_ops = {
|
|
||||||
.open = midi_ctl_open,
|
|
||||||
.close = midi_ctl_playback_close,
|
|
||||||
.trigger = midi_ctl_playback_trigger,
|
|
||||||
};
|
|
||||||
struct snd_rawmidi *rmidi[2];
|
|
||||||
struct snd_rawmidi_str *str;
|
|
||||||
unsigned int i;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* Add physical midi ports. */
|
/* Add physical midi ports. */
|
||||||
err = snd_rawmidi_new(dg00x->card, dg00x->card->driver, 0,
|
err = add_substream_pair(dg00x, DOT_MIDI_OUT_PORTS, DOT_MIDI_IN_PORTS,
|
||||||
DOT_MIDI_OUT_PORTS, DOT_MIDI_IN_PORTS, &rmidi[0]);
|
false);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
snprintf(rmidi[0]->name, sizeof(rmidi[0]->name),
|
if (dg00x->is_console)
|
||||||
"%s MIDI", dg00x->card->shortname);
|
err = add_substream_pair(dg00x, 1, 1, true);
|
||||||
|
|
||||||
snd_rawmidi_set_ops(rmidi[0], SNDRV_RAWMIDI_STREAM_INPUT,
|
return err;
|
||||||
&phys_capture_ops);
|
|
||||||
snd_rawmidi_set_ops(rmidi[0], SNDRV_RAWMIDI_STREAM_OUTPUT,
|
|
||||||
&phys_playback_ops);
|
|
||||||
|
|
||||||
/* Add a pair of control midi ports. */
|
|
||||||
err = snd_rawmidi_new(dg00x->card, dg00x->card->driver, 1,
|
|
||||||
1, 1, &rmidi[1]);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
snprintf(rmidi[1]->name, sizeof(rmidi[1]->name),
|
|
||||||
"%s control", dg00x->card->shortname);
|
|
||||||
|
|
||||||
snd_rawmidi_set_ops(rmidi[1], SNDRV_RAWMIDI_STREAM_INPUT,
|
|
||||||
&ctl_capture_ops);
|
|
||||||
snd_rawmidi_set_ops(rmidi[1], SNDRV_RAWMIDI_STREAM_OUTPUT,
|
|
||||||
&ctl_playback_ops);
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(rmidi); i++) {
|
|
||||||
rmidi[i]->private_data = dg00x;
|
|
||||||
|
|
||||||
rmidi[i]->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
|
|
||||||
str = &rmidi[i]->streams[SNDRV_RAWMIDI_STREAM_INPUT];
|
|
||||||
set_midi_substream_names(dg00x, str, i);
|
|
||||||
|
|
||||||
rmidi[i]->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
|
|
||||||
str = &rmidi[i]->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
|
|
||||||
set_midi_substream_names(dg00x, str, i);
|
|
||||||
|
|
||||||
rmidi[i]->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue