mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-28 05:40:23 -04:00
Splitted rawmidi streams. Removed stream constraint on config files
This commit is contained in:
parent
3e091c8822
commit
66f13f6115
21 changed files with 142 additions and 233 deletions
|
|
@ -19,13 +19,6 @@ typedef enum sndrv_rawmidi_stream snd_rawmidi_stream_t;
|
|||
#define SND_RAWMIDI_STREAM_INPUT ((snd_rawmidi_stream_t) SNDRV_RAWMIDI_STREAM_INPUT)
|
||||
#define SND_RAWMIDI_STREAM_LAST ((snd_rawmidi_stream_t) SNDRV_RAWMIDI_STREAM_LAST)
|
||||
|
||||
#define SND_RAWMIDI_INFO_OUTPUT SNDRV_RAWMIDI_INFO_OUTPUT
|
||||
#define SND_RAWMIDI_INFO_INPUT SNDRV_RAWMIDI_INFO_INPUT
|
||||
#define SND_RAWMIDI_INFO_DUPLEX SNDRV_RAWMIDI_INFO_DUPLEX
|
||||
#define SND_RAWMIDI_OPEN_OUTPUT (1<<SNDRV_RAWMIDI_STREAM_OUTPUT)
|
||||
#define SND_RAWMIDI_OPEN_INPUT (1<<SNDRV_RAWMIDI_STREAM_INPUT)
|
||||
#define SND_RAWMIDI_OPEN_DUPLEX (SND_RAWMIDI_OPEN_OUTPUT|SND_RAWMIDI_OPEN_INPUT)
|
||||
|
||||
#define SND_RAWMIDI_APPEND 1
|
||||
#define SND_RAWMIDI_NONBLOCK 2
|
||||
|
||||
|
|
@ -51,19 +44,20 @@ typedef enum _snd_rawmidi_type snd_rawmidi_type_t;
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int snd_rawmidi_open(snd_rawmidi_t **rmidi, char *name, int streams, int mode);
|
||||
int snd_rawmidi_open(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi,
|
||||
char *name, int mode);
|
||||
int snd_rawmidi_close(snd_rawmidi_t *rmidi);
|
||||
int snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream);
|
||||
int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, int nonblock);
|
||||
int snd_rawmidi_info(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, snd_rawmidi_info_t * info);
|
||||
int snd_rawmidi_params(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, snd_rawmidi_params_t * params);
|
||||
int snd_rawmidi_status(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, snd_rawmidi_status_t * status);
|
||||
int snd_rawmidi_drain(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream);
|
||||
int snd_rawmidi_drop(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream);
|
||||
int snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi);
|
||||
int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi, int nonblock);
|
||||
int snd_rawmidi_info(snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info);
|
||||
int snd_rawmidi_params(snd_rawmidi_t *rmidi, snd_rawmidi_params_t * params);
|
||||
int snd_rawmidi_status(snd_rawmidi_t *rmidi, snd_rawmidi_status_t * status);
|
||||
int snd_rawmidi_drain(snd_rawmidi_t *rmidi);
|
||||
int snd_rawmidi_drop(snd_rawmidi_t *rmidi);
|
||||
ssize_t snd_rawmidi_write(snd_rawmidi_t *rmidi, const void *buffer, size_t size);
|
||||
ssize_t snd_rawmidi_read(snd_rawmidi_t *rmidi, void *buffer, size_t size);
|
||||
|
||||
int snd_rawmidi_params_current(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, snd_rawmidi_params_t *params);
|
||||
int snd_rawmidi_params_current(snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -595,25 +595,6 @@ int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
|
|||
ERR("Invalid type for PCM %s definition", name);
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_config_search(pcm_conf, "stream", &conf);
|
||||
if (err >= 0) {
|
||||
const char *id = snd_config_get_id(conf);
|
||||
err = snd_config_get_string(conf, &str);
|
||||
if (err < 0) {
|
||||
ERR("Invalid type for %s", id);
|
||||
return err;
|
||||
}
|
||||
if (strcmp(str, "playback") == 0) {
|
||||
if (stream != SND_PCM_STREAM_PLAYBACK)
|
||||
return -EINVAL;
|
||||
} else if (strcmp(str, "capture") == 0) {
|
||||
if (stream != SND_PCM_STREAM_CAPTURE)
|
||||
return -EINVAL;
|
||||
} else {
|
||||
ERR("Invalid value for %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
err = snd_config_search(pcm_conf, "type", &conf);
|
||||
if (err < 0) {
|
||||
ERR("type is not defined");
|
||||
|
|
|
|||
|
|
@ -608,8 +608,6 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -481,8 +481,6 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -238,8 +238,6 @@ int _snd_pcm_copy_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -477,8 +477,6 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -687,8 +687,6 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "card") == 0) {
|
||||
err = snd_config_get_integer(n, &card);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -379,8 +379,6 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -496,8 +496,6 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -603,8 +603,6 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "slave") == 0) {
|
||||
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
ERR("Invalid type for %s", id);
|
||||
|
|
|
|||
|
|
@ -382,8 +382,6 @@ int _snd_pcm_null_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
ERR("Unknown field %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -718,8 +718,6 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -634,8 +634,6 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -899,8 +899,6 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, char *name,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -1380,8 +1380,6 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "sname") == 0) {
|
||||
err = snd_config_get_string(n, &sname);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -736,8 +736,6 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "stream") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "server") == 0) {
|
||||
err = snd_config_get_string(n, &server);
|
||||
if (err < 0) {
|
||||
|
|
|
|||
|
|
@ -28,14 +28,6 @@
|
|||
#include <asm/page.h>
|
||||
#include "rawmidi_local.h"
|
||||
|
||||
static inline int snd_rawmidi_stream_ok(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream)
|
||||
{
|
||||
assert(rmidi);
|
||||
assert(stream == SND_RAWMIDI_STREAM_INPUT ||
|
||||
stream == SND_RAWMIDI_STREAM_OUTPUT);
|
||||
return rmidi->streams & (1 << (snd_enum_to_int(stream)));
|
||||
}
|
||||
|
||||
int snd_rawmidi_close(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
int err;
|
||||
|
|
@ -48,19 +40,16 @@ int snd_rawmidi_close(snd_rawmidi_t *rmidi)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi,
|
||||
snd_rawmidi_stream_t stream ATTRIBUTE_UNUSED)
|
||||
int snd_rawmidi_poll_descriptor(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
assert(rmidi);
|
||||
return rmidi->poll_fd;
|
||||
}
|
||||
|
||||
int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi,
|
||||
snd_rawmidi_stream_t stream ATTRIBUTE_UNUSED,
|
||||
int nonblock)
|
||||
int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi, int nonblock)
|
||||
{
|
||||
int err;
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
assert(rmidi);
|
||||
assert(!(rmidi->mode & SND_RAWMIDI_APPEND));
|
||||
if ((err = rmidi->ops->nonblock(rmidi, nonblock)) < 0)
|
||||
return err;
|
||||
|
|
@ -71,86 +60,75 @@ int snd_rawmidi_nonblock(snd_rawmidi_t *rmidi,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int snd_rawmidi_info(snd_rawmidi_t *rmidi,
|
||||
snd_rawmidi_stream_t stream,
|
||||
snd_rawmidi_info_t * info)
|
||||
int snd_rawmidi_info(snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
assert(rmidi);
|
||||
assert(info);
|
||||
info->stream = snd_enum_to_int(stream);
|
||||
return rmidi->ops->info(rmidi, info);
|
||||
}
|
||||
|
||||
int snd_rawmidi_params(snd_rawmidi_t *rmidi,
|
||||
snd_rawmidi_stream_t stream,
|
||||
snd_rawmidi_params_t * params)
|
||||
int snd_rawmidi_params(snd_rawmidi_t *rmidi, snd_rawmidi_params_t * params)
|
||||
{
|
||||
int err;
|
||||
snd_rawmidi_str_t *pstr;
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
assert(rmidi);
|
||||
assert(params);
|
||||
params->stream = snd_enum_to_int(stream);
|
||||
err = rmidi->ops->params(rmidi, params);
|
||||
if (err < 0)
|
||||
return err;
|
||||
pstr = &rmidi->stream[snd_enum_to_int(stream)];
|
||||
pstr->buffer_size = params->buffer_size;
|
||||
pstr->avail_min = params->avail_min;
|
||||
pstr->no_active_sensing = params->no_active_sensing;
|
||||
rmidi->buffer_size = params->buffer_size;
|
||||
rmidi->avail_min = params->avail_min;
|
||||
rmidi->no_active_sensing = params->no_active_sensing;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_rawmidi_status(snd_rawmidi_t *rmidi,
|
||||
snd_rawmidi_stream_t stream,
|
||||
snd_rawmidi_status_t * status)
|
||||
int snd_rawmidi_status(snd_rawmidi_t *rmidi, snd_rawmidi_status_t * status)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
assert(rmidi);
|
||||
assert(status);
|
||||
status->stream = snd_enum_to_int(stream);
|
||||
return rmidi->ops->status(rmidi, status);
|
||||
}
|
||||
|
||||
int snd_rawmidi_drop(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream)
|
||||
int snd_rawmidi_drop(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
return rmidi->ops->drop(rmidi, stream);
|
||||
assert(rmidi);
|
||||
return rmidi->ops->drop(rmidi);
|
||||
}
|
||||
|
||||
int snd_rawmidi_drain(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream)
|
||||
int snd_rawmidi_drain(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
return rmidi->ops->drain(rmidi, stream);
|
||||
assert(rmidi);
|
||||
return rmidi->ops->drain(rmidi);
|
||||
}
|
||||
|
||||
ssize_t snd_rawmidi_write(snd_rawmidi_t *rmidi, const void *buffer, size_t size)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, SND_RAWMIDI_STREAM_OUTPUT));
|
||||
assert(rmidi);
|
||||
assert(rmidi->stream == SND_RAWMIDI_STREAM_OUTPUT);
|
||||
assert(buffer || size == 0);
|
||||
return rmidi->ops->write(rmidi, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t snd_rawmidi_read(snd_rawmidi_t *rmidi, void *buffer, size_t size)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, SND_RAWMIDI_STREAM_INPUT));
|
||||
assert(rmidi);
|
||||
assert(rmidi->stream == SND_RAWMIDI_STREAM_INPUT);
|
||||
assert(buffer || size == 0);
|
||||
return rmidi->ops->read(rmidi, buffer, size);
|
||||
}
|
||||
|
||||
int snd_rawmidi_params_current(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, snd_rawmidi_params_t *params)
|
||||
int snd_rawmidi_params_current(snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params)
|
||||
{
|
||||
snd_rawmidi_str_t *pstr;
|
||||
assert(snd_rawmidi_stream_ok(rmidi, SND_RAWMIDI_STREAM_OUTPUT));
|
||||
assert(rmidi);
|
||||
assert(params);
|
||||
pstr = &rmidi->stream[snd_enum_to_int(stream)];
|
||||
params->buffer_size = pstr->buffer_size;
|
||||
params->avail_min = pstr->avail_min;
|
||||
params->no_active_sensing = pstr->no_active_sensing;
|
||||
params->buffer_size = rmidi->buffer_size;
|
||||
params->avail_min = rmidi->avail_min;
|
||||
params->no_active_sensing = rmidi->no_active_sensing;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_rawmidi_params_default(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream, snd_rawmidi_params_t *params)
|
||||
int snd_rawmidi_params_default(snd_rawmidi_t *rmidi, snd_rawmidi_params_t *params)
|
||||
{
|
||||
assert(snd_rawmidi_stream_ok(rmidi, stream));
|
||||
assert(rmidi);
|
||||
assert(params);
|
||||
params->buffer_size = PAGE_SIZE;
|
||||
params->avail_min = 1;
|
||||
|
|
@ -158,8 +136,8 @@ int snd_rawmidi_params_default(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream
|
|||
return 0;
|
||||
}
|
||||
|
||||
int snd_rawmidi_open(snd_rawmidi_t **rawmidip, char *name,
|
||||
int streams, int mode)
|
||||
int snd_rawmidi_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||
char *name, int mode)
|
||||
{
|
||||
const char *str;
|
||||
int err;
|
||||
|
|
@ -168,10 +146,10 @@ int snd_rawmidi_open(snd_rawmidi_t **rawmidip, char *name,
|
|||
snd_rawmidi_params_t params;
|
||||
unsigned int stream;
|
||||
const char *lib = NULL, *open = NULL;
|
||||
int (*open_func)(snd_rawmidi_t **rawmidip, char *name, snd_config_t *conf,
|
||||
int streams, int mode);
|
||||
int (*open_func)(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||
char *name, snd_config_t *conf, int mode);
|
||||
void *h;
|
||||
assert(rawmidip && name);
|
||||
assert((inputp || outputp) && name);
|
||||
err = snd_config_update();
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -180,10 +158,10 @@ int snd_rawmidi_open(snd_rawmidi_t **rawmidip, char *name,
|
|||
int card, dev, subdev;
|
||||
err = sscanf(name, "hw:%d,%d,%d", &card, &dev, &subdev);
|
||||
if (err == 3)
|
||||
return snd_rawmidi_hw_open(rawmidip, name, card, dev, subdev, streams, mode);
|
||||
return snd_rawmidi_hw_open(inputp, outputp, name, card, dev, subdev, mode);
|
||||
err = sscanf(name, "hw:%d,%d", &card, &dev);
|
||||
if (err == 2)
|
||||
return snd_rawmidi_hw_open(rawmidip, name, card, dev, -1, streams, mode);
|
||||
return snd_rawmidi_hw_open(inputp, outputp, name, card, dev, -1, mode);
|
||||
ERR("Unknown RAWMIDI %s", name);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
@ -191,28 +169,6 @@ int snd_rawmidi_open(snd_rawmidi_t **rawmidip, char *name,
|
|||
ERR("Invalid type for RAWMIDI %s definition", name);
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_config_search(rawmidi_conf, "streams", &conf);
|
||||
if (err >= 0) {
|
||||
const char *id = snd_config_get_id(conf);
|
||||
err = snd_config_get_string(conf, &str);
|
||||
if (err < 0) {
|
||||
ERR("Invalid type for %s", id);
|
||||
return err;
|
||||
}
|
||||
if (strcmp(str, "output") == 0) {
|
||||
if (streams == SND_RAWMIDI_OPEN_INPUT)
|
||||
return -EINVAL;
|
||||
} else if (strcmp(str, "input") == 0) {
|
||||
if (streams == SND_RAWMIDI_OPEN_OUTPUT)
|
||||
return -EINVAL;
|
||||
} else if (strcmp(str, "duplex") == 0) {
|
||||
if (streams != SND_RAWMIDI_OPEN_DUPLEX)
|
||||
return -EINVAL;
|
||||
} else {
|
||||
ERR("Invalid value for %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
err = snd_config_search(rawmidi_conf, "type", &conf);
|
||||
if (err < 0) {
|
||||
ERR("type is not defined");
|
||||
|
|
@ -269,14 +225,17 @@ int snd_rawmidi_open(snd_rawmidi_t **rawmidip, char *name,
|
|||
ERR("symbol %s is not defined inside %s", open, lib);
|
||||
return -ENXIO;
|
||||
}
|
||||
err = open_func(rawmidip, name, rawmidi_conf, streams, mode);
|
||||
err = open_func(inputp, outputp, name, rawmidi_conf, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
for (stream = 0; stream < 2; stream++) {
|
||||
if (!(streams & (1 << stream)))
|
||||
continue;
|
||||
snd_rawmidi_params_default(*rawmidip, snd_int_to_enum(stream), ¶ms);
|
||||
err = snd_rawmidi_params(*rawmidip, snd_int_to_enum(stream), ¶ms);
|
||||
if (inputp) {
|
||||
snd_rawmidi_params_default(*inputp, ¶ms);
|
||||
err = snd_rawmidi_params(*inputp, ¶ms);
|
||||
assert(err >= 0);
|
||||
}
|
||||
if (outputp) {
|
||||
snd_rawmidi_params_default(*outputp, ¶ms);
|
||||
err = snd_rawmidi_params(*outputp, ¶ms);
|
||||
assert(err >= 0);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#define SNDRV_RAWMIDI_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 0)
|
||||
|
||||
typedef struct {
|
||||
int open;
|
||||
int fd;
|
||||
int card, device, subdevice;
|
||||
} snd_rawmidi_hw_t;
|
||||
|
|
@ -40,6 +41,9 @@ typedef struct {
|
|||
static int snd_rawmidi_hw_close(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
snd_rawmidi_hw_t *hw = rmidi->private;
|
||||
hw->open--;
|
||||
if (hw->open)
|
||||
return 0;
|
||||
if (close(hw->fd)) {
|
||||
SYSERR("close failed\n");
|
||||
return -errno;
|
||||
|
|
@ -71,6 +75,7 @@ static int snd_rawmidi_hw_nonblock(snd_rawmidi_t *rmidi, int nonblock)
|
|||
static int snd_rawmidi_hw_info(snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info)
|
||||
{
|
||||
snd_rawmidi_hw_t *hw = rmidi->private;
|
||||
info->stream = snd_enum_to_int(rmidi->stream);
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_INFO, info) < 0) {
|
||||
SYSERR("SNDRV_RAWMIDI_IOCTL_INFO failed");
|
||||
return -errno;
|
||||
|
|
@ -81,6 +86,7 @@ static int snd_rawmidi_hw_info(snd_rawmidi_t *rmidi, snd_rawmidi_info_t * info)
|
|||
static int snd_rawmidi_hw_params(snd_rawmidi_t *rmidi, snd_rawmidi_params_t * params)
|
||||
{
|
||||
snd_rawmidi_hw_t *hw = rmidi->private;
|
||||
params->stream = snd_enum_to_int(rmidi->stream);
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_PARAMS, params) < 0) {
|
||||
SYSERR("SNDRV_RAWMIDI_IOCTL_PARAMS failed");
|
||||
return -errno;
|
||||
|
|
@ -91,6 +97,7 @@ static int snd_rawmidi_hw_params(snd_rawmidi_t *rmidi, snd_rawmidi_params_t * pa
|
|||
static int snd_rawmidi_hw_status(snd_rawmidi_t *rmidi, snd_rawmidi_status_t * status)
|
||||
{
|
||||
snd_rawmidi_hw_t *hw = rmidi->private;
|
||||
status->stream = snd_enum_to_int(rmidi->stream);
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_STATUS, status) < 0) {
|
||||
SYSERR("SNDRV_RAWMIDI_IOCTL_STATUS failed");
|
||||
return -errno;
|
||||
|
|
@ -98,20 +105,22 @@ static int snd_rawmidi_hw_status(snd_rawmidi_t *rmidi, snd_rawmidi_status_t * st
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_rawmidi_hw_drop(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream)
|
||||
static int snd_rawmidi_hw_drop(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
snd_rawmidi_hw_t *hw = rmidi->private;
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_DROP, &stream) < 0) {
|
||||
int str = snd_enum_to_int(rmidi->stream);
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_DROP, &str) < 0) {
|
||||
SYSERR("SNDRV_RAWMIDI_IOCTL_DROP failed");
|
||||
return -errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_rawmidi_hw_drain(snd_rawmidi_t *rmidi, snd_rawmidi_stream_t stream)
|
||||
static int snd_rawmidi_hw_drain(snd_rawmidi_t *rmidi)
|
||||
{
|
||||
snd_rawmidi_hw_t *hw = rmidi->private;
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_DRAIN, &stream) < 0) {
|
||||
int str = snd_enum_to_int(rmidi->stream);
|
||||
if (ioctl(hw->fd, SNDRV_RAWMIDI_IOCTL_DRAIN, &str) < 0) {
|
||||
SYSERR("SNDRV_RAWMIDI_IOCTL_DRAIN failed");
|
||||
return -errno;
|
||||
}
|
||||
|
|
@ -151,21 +160,25 @@ snd_rawmidi_ops_t snd_rawmidi_hw_ops = {
|
|||
};
|
||||
|
||||
|
||||
int snd_rawmidi_hw_open(snd_rawmidi_t **handlep, char *name, int card, int device, int subdevice, int streams, int mode)
|
||||
int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||
char *name, int card, int device, int subdevice,
|
||||
int mode)
|
||||
{
|
||||
int fd, ver, ret;
|
||||
int attempt = 0;
|
||||
char filename[32];
|
||||
snd_ctl_t *ctl;
|
||||
snd_rawmidi_t *rmidi;
|
||||
snd_rawmidi_hw_t *hw;
|
||||
snd_rawmidi_hw_t *hw = NULL;
|
||||
snd_rawmidi_info_t info;
|
||||
int fmode;
|
||||
int fmode, str;
|
||||
int c;
|
||||
|
||||
*handlep = NULL;
|
||||
if (inputp)
|
||||
*inputp = NULL;
|
||||
if (outputp)
|
||||
*outputp = NULL;
|
||||
|
||||
assert(card >= 0 && card < 32);
|
||||
|
||||
if ((ret = snd_ctl_hw_open(&ctl, NULL, card)) < 0)
|
||||
return ret;
|
||||
sprintf(filename, SNDRV_FILE_RAWMIDI, card, device);
|
||||
|
|
@ -181,23 +194,15 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **handlep, char *name, int card, int devic
|
|||
return ret;
|
||||
}
|
||||
|
||||
switch (streams) {
|
||||
case SND_RAWMIDI_OPEN_OUTPUT:
|
||||
if (!inputp)
|
||||
fmode = O_WRONLY;
|
||||
break;
|
||||
case SND_RAWMIDI_OPEN_INPUT:
|
||||
else if (!outputp)
|
||||
fmode = O_RDONLY;
|
||||
break;
|
||||
case SND_RAWMIDI_OPEN_DUPLEX:
|
||||
else
|
||||
fmode = O_RDWR;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (mode & SND_RAWMIDI_APPEND) {
|
||||
assert(streams & SND_RAWMIDI_OPEN_OUTPUT);
|
||||
assert(outputp);
|
||||
fmode |= O_APPEND;
|
||||
}
|
||||
|
||||
|
|
@ -241,37 +246,61 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **handlep, char *name, int card, int devic
|
|||
goto __again;
|
||||
}
|
||||
}
|
||||
snd_ctl_close(ctl);
|
||||
|
||||
hw = calloc(1, sizeof(snd_rawmidi_hw_t));
|
||||
if (hw == NULL) {
|
||||
close(fd);
|
||||
snd_ctl_close(ctl);
|
||||
return -ENOMEM;
|
||||
}
|
||||
rmidi = calloc(1, sizeof(snd_rawmidi_t));
|
||||
if (rmidi == NULL) {
|
||||
free(hw);
|
||||
close(fd);
|
||||
snd_ctl_close(ctl);
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (hw == NULL)
|
||||
goto _nomem;
|
||||
hw->card = card;
|
||||
hw->device = device;
|
||||
hw->subdevice = subdevice;
|
||||
hw->fd = fd;
|
||||
if (name)
|
||||
rmidi->name = strdup(name);
|
||||
rmidi->type = SND_RAWMIDI_TYPE_HW;
|
||||
rmidi->streams = streams;
|
||||
rmidi->mode = mode;
|
||||
rmidi->poll_fd = fd;
|
||||
rmidi->ops = &snd_rawmidi_hw_ops;
|
||||
rmidi->private = hw;
|
||||
*handlep = rmidi;
|
||||
|
||||
if (inputp) {
|
||||
rmidi = calloc(1, sizeof(snd_rawmidi_t));
|
||||
if (rmidi == NULL)
|
||||
goto _nomem;
|
||||
if (name)
|
||||
rmidi->name = strdup(name);
|
||||
rmidi->type = SND_RAWMIDI_TYPE_HW;
|
||||
rmidi->stream = SND_RAWMIDI_STREAM_INPUT;
|
||||
rmidi->mode = mode;
|
||||
rmidi->poll_fd = fd;
|
||||
rmidi->ops = &snd_rawmidi_hw_ops;
|
||||
rmidi->private = hw;
|
||||
hw->open++;
|
||||
*inputp = rmidi;
|
||||
}
|
||||
if (outputp) {
|
||||
rmidi = calloc(1, sizeof(snd_rawmidi_t));
|
||||
if (rmidi == NULL)
|
||||
goto _nomem;
|
||||
if (name)
|
||||
rmidi->name = strdup(name);
|
||||
rmidi->type = SND_RAWMIDI_TYPE_HW;
|
||||
rmidi->stream = SND_RAWMIDI_STREAM_OUTPUT;
|
||||
rmidi->mode = mode;
|
||||
rmidi->poll_fd = fd;
|
||||
rmidi->ops = &snd_rawmidi_hw_ops;
|
||||
rmidi->private = hw;
|
||||
hw->open++;
|
||||
*outputp = rmidi;
|
||||
}
|
||||
return 0;
|
||||
|
||||
_nomem:
|
||||
close(fd);
|
||||
if (hw)
|
||||
free(hw);
|
||||
if (inputp && *inputp)
|
||||
free(*inputp);
|
||||
if (outputp && *outputp)
|
||||
free(*outputp);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int _snd_rawmidi_hw_open(snd_rawmidi_t **handlep, char *name, snd_config_t *conf,
|
||||
int streams, int mode)
|
||||
int _snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||
char *name, snd_config_t *conf, int mode)
|
||||
{
|
||||
snd_config_iterator_t i;
|
||||
long card = -1, device = 0, subdevice = -1;
|
||||
|
|
@ -284,8 +313,6 @@ int _snd_rawmidi_hw_open(snd_rawmidi_t **handlep, char *name, snd_config_t *conf
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "streams") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "card") == 0) {
|
||||
err = snd_config_get_integer(n, &card);
|
||||
if (err < 0) {
|
||||
|
|
@ -314,6 +341,6 @@ int _snd_rawmidi_hw_open(snd_rawmidi_t **handlep, char *name, snd_config_t *conf
|
|||
}
|
||||
if (card < 0)
|
||||
return -EINVAL;
|
||||
return snd_rawmidi_hw_open(handlep, name, card, device, subdevice, streams, mode);
|
||||
return snd_rawmidi_hw_open(inputp, outputp, name, card, device, subdevice, mode);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,29 +30,29 @@ typedef struct {
|
|||
int (*info)(snd_rawmidi_t *rawmidi, snd_rawmidi_info_t *info);
|
||||
int (*params)(snd_rawmidi_t *rawmidi, snd_rawmidi_params_t *params);
|
||||
int (*status)(snd_rawmidi_t *rawmidi, snd_rawmidi_status_t *status);
|
||||
int (*drop)(snd_rawmidi_t *rawmidi, snd_rawmidi_stream_t stream);
|
||||
int (*drain)(snd_rawmidi_t *rawmidi, snd_rawmidi_stream_t stream);
|
||||
int (*drop)(snd_rawmidi_t *rawmidi);
|
||||
int (*drain)(snd_rawmidi_t *rawmidi);
|
||||
ssize_t (*write)(snd_rawmidi_t *rawmidi, const void *buffer, size_t size);
|
||||
ssize_t (*read)(snd_rawmidi_t *rawmidi, void *buffer, size_t size);
|
||||
} snd_rawmidi_ops_t;
|
||||
|
||||
typedef struct _snd_rawmidi_str {
|
||||
size_t buffer_size;
|
||||
size_t avail_min;
|
||||
unsigned int no_active_sensing: 1;
|
||||
} snd_rawmidi_str_t;
|
||||
|
||||
|
||||
struct _snd_rawmidi {
|
||||
char *name;
|
||||
snd_rawmidi_type_t type;
|
||||
int streams;
|
||||
snd_rawmidi_stream_t stream;
|
||||
int mode;
|
||||
int poll_fd;
|
||||
snd_rawmidi_str_t stream[2];
|
||||
snd_rawmidi_ops_t *ops;
|
||||
|
||||
void *private;
|
||||
size_t buffer_size;
|
||||
size_t avail_min;
|
||||
unsigned int no_active_sensing: 1;
|
||||
snd_rawmidi_t *other;
|
||||
};
|
||||
|
||||
int snd_rawmidi_hw_open(snd_rawmidi_t **handle, char *name, int card, int device, int subdevice, int streams, int mode);
|
||||
int snd_rawmidi_hw_open(snd_rawmidi_t **input, snd_rawmidi_t **output,
|
||||
char *name, int card, int device, int subdevice,
|
||||
int mode);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,28 +50,6 @@ int snd_seq_open(snd_seq_t **seqp, char *name,
|
|||
ERR("Invalid type for SEQ %s definition", name);
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_config_search(seq_conf, "streams", &conf);
|
||||
if (err >= 0) {
|
||||
const char *id = snd_config_get_id(conf);
|
||||
err = snd_config_get_string(conf, &str);
|
||||
if (err < 0) {
|
||||
ERR("Invalid type for %s", id);
|
||||
return err;
|
||||
}
|
||||
if (strcmp(str, "output") == 0) {
|
||||
if (streams == SND_SEQ_OPEN_INPUT)
|
||||
return -EINVAL;
|
||||
} else if (strcmp(str, "input") == 0) {
|
||||
if (streams == SND_SEQ_OPEN_OUTPUT)
|
||||
return -EINVAL;
|
||||
} else if (strcmp(str, "duplex") == 0) {
|
||||
if (streams != SND_SEQ_OPEN_DUPLEX)
|
||||
return -EINVAL;
|
||||
} else {
|
||||
ERR("Invalid value for %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
err = snd_config_search(seq_conf, "type", &conf);
|
||||
if (err < 0) {
|
||||
ERR("type is not defined");
|
||||
|
|
|
|||
|
|
@ -536,8 +536,6 @@ int _snd_seq_hw_open(snd_seq_t **handlep, char *name, snd_config_t *conf,
|
|||
continue;
|
||||
if (strcmp(id, "type") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "streams") == 0)
|
||||
continue;
|
||||
return -EINVAL;
|
||||
}
|
||||
return snd_seq_hw_open(handlep, name, streams, mode);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue